Drawer
A temporary edge-anchored panel for filters, details, settings, or navigation.
import { Drawer } from '@uthereal/ui/drawer'Drawer playground
Overview
Drawer renders a modal panel that springs in from the left, right, top, or bottom edge. It requires a title, accepts an optional description, and renders children inside a scrollable body beneath a sticky header. While open, focus stays trapped inside the panel, the page behind is inert (except live regions), page scroll locks, and closing returns focus to the trigger.
The surface has a 22 px inner corner radius (18 px on viewports up to 640 px), a hairline beneath the header, a 32 px corner close button centered on the title's first line (with a 40 px coarse-pointer target), and a 4 px blurred backdrop. Bottom drawers add a centered top grabber. Updating title or description while open crossfades the text with a subtle blur and vertical rise.
Use Drawer for secondary tasks that sit beside the current view: filters, record inspectors, settings, or navigation. Use Dialog for centered confirmations and focused tasks.
Usage
'use client'
import { useState } from 'react'
import { Checkbox } from '@uthereal/ui/checkbox'
import { Drawer, useDrawerItem } from '@uthereal/ui/drawer'
export function FilterDrawer() {
return (
<Drawer
title="Filters"
description="Narrow the reports by status and owner."
trigger={{ label: 'Show filters', icon: 'sliders-horizontal' }}
>
<Checkbox label="Only my reports" />
</Drawer>
)
}
export function InspectorDrawer({
selected,
onClose,
}: {
selected: { name: string; summary: string } | null
onClose: () => void
}) {
const item = useDrawerItem(selected)
return (
<Drawer
title={item?.name ?? 'Details'}
open={selected !== null}
onOpenChange={(open) => {
if (!open) onClose()
}}
renderTrigger={null}
>
{item?.summary}
</Drawer>
)
}useDrawerItem retains the last non-null value so drawer content stays rendered during the exit slide instead of clearing the moment open turns false.
Examples
Sides
Horizontal drawers (left and right) clamp to min(30rem, 100vw - 16px) (and 100vw - 12px at 640 px and below) and fill the viewport height. Vertical drawers (top and bottom) span the full width and grow up to min(32rem, 100dvh).
| Side | Anchor edge | Size bound | Typical use |
|---|---|---|---|
right | Right edge | min(30rem, 100vw - 16px) × 100% | Details, filters, settings (default). |
left | Left edge | min(30rem, 100vw - 16px) × 100% | Navigation, workspace switching. |
top | Top edge | 100% × min(32rem, 100dvh) | Quick search, announcements. |
bottom | Bottom edge | 100% × min(32rem, 100dvh) | Compact actions, mobile pickers. |
Drag and dismissal behavior
Set draggable={false} to disable header drag-to-dismiss while keeping Escape, backdrop clicks, and the close button active. Set dismissible={false} when only host state should close the drawer; this hides the close button and blocks drag, Escape, and backdrop dismissal.
Gestures and contained mode
With draggable enabled (default), the header acts as a drag handle driven by a single MotionValue with zero per-frame React re-renders:
| Gesture | Effect |
|---|---|
| Drag toward the anchored edge | Follows the pointer 1:1 along the drawer axis. |
| Drag away from the anchored edge | Rubber-bands with square-root resistance (-Math.sqrt(-offset)). |
| Release past 1/3 of panel size, or flick > 500 px/s | Dismisses the drawer and hands release velocity to a 240 ms smooth spring. |
| Release before threshold | Springs back to rest on the snappy spring (0.26s, bounce 0.12). |
| Press a button, link, or input in the header | Ignored by the pan handler so interactive header controls activate cleanly. |
Pass both portalContainer and contained to anchor the drawer inside an element (which requires position: relative and overflow: hidden) instead of the viewport. Contained drawers use a lighter unblurred backdrop, narrow horizontal width (min(22rem, 100% - 32px)), no drop shadow, and a border on the inner edge only.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
titleRequired | string— | Heading of the drawer, required: it names the drawer for assistive technology. Changing it while open morphs the copy in place. |
description | string— | Supporting text under the title, announced when it opens. |
trigger | OverlayTriggerDefault: {"label":"Open drawer","variant":"outline","tone":"neutral","size":"md"} | The button that opens the drawer when no React trigger is supplied: label, optional icon, variant, tone and size. |
side | left | right | top | bottomDefault: "right" | Edge the drawer opens from: left, right (the default), top or bottom. Sides anchor by the reading direction, so left is the start edge in left-to-right pages. |
draggable | booleanDefault: true | Dragging the header toward the edge dismisses the drawer: past a third of its size or on a quick flick. Off, or with reduced motion, only the close button, Escape and the backdrop dismiss it. |
closeLabel | stringDefault: "Close drawer" | Accessible name of the close button, e.g. "Close drawer". |
defaultOpen | booleanDefault: false | Initial open state. Later argument edits do not reset an existing instance. |
dismissible | booleanDefault: true | Escape, the backdrop and the close button dismiss the drawer. Off, only the host closes it through open. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | DrawerTheme— | Color mode, accent, and modal tokens (padding, titleSize, backdropBlur, sheetRadius, surfaceRadius, overlay, borderStrong). See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Slide animation preset. System reduced-motion preferences take precedence. |
motionOptions | DrawerMotionOptions— | The slide transition, Arc's smooth spring by default. The exit slides back over 240 ms and fades the shadow in its last third. Durations are milliseconds. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
icon arguments accept names from the icon list.
React integration
| Prop | Purpose |
|---|---|
ref | Forwarded to the portalled drawer surface HTMLDivElement. |
children | Scrollable drawer body rendered beneath the header. |
footer | Optional footer rendered below the body. |
open / onOpenChange(open) | Controlled open state and change callback. |
renderTrigger(props, state) | Custom trigger renderer; spread props onto a focusable element. Pass null to omit the trigger. |
preset | Application defaults merged below instance props. |
renderIcon(name, context) | Custom icon renderer for slot: 'trigger' or slot: 'close'. Keep icons decorative. |
tokens | --ui-* CSS variables applied after the typed theme on the trigger and surface. |
className | Class name appended to the drawer surface. |
portalContainer | Portal target, such as an element inside a native <dialog> top layer or a contained panel host. |
contained | With portalContainer, anchors the drawer to that container instead of the viewport. |
Keyboard & accessibility
| Key | Interaction |
|---|---|
Enter, Space | Open the drawer from its trigger button. |
Tab / Shift+Tab | Move focus within the drawer; focus wraps and stays trapped. |
Escape | Close the drawer when dismissible is true. |
The surface renders with role="dialog" and aria-modal="true", labelled by title and described by description. Dragging is always optional: Escape, the backdrop, and the corner close button (closeLabel, default "Close drawer") remain available whenever dismissible is true. Nested overlays opened inside a drawer portal into it and stack above it, with Escape closing the topmost layer first.
In dir="rtl", horizontal sides (left and right) remain anchored to their physical edge and drag sign while header layout, borders, corner radii, close button placement, and the bottom grabber mirror using logical CSS properties. Under forced-colors: active, the panel border, header hairline, and bottom grabber retain high-contrast system colors.
Motion and theming
The drawer springs in fully opaque from its edge on the smooth spring (0.4s, bounce 0, zero overshoot) while the backdrop fades over 240 ms. Standard dismissal slides back over 240 ms on the standard curve and fades the shadow across the final 35% so it leaves smoothly; a fling dismissal keeps release velocity in a 240 ms smooth spring. Reopening mid-exit retargets in flight without treating the reopening press as an outside click.
Under prefers-reduced-motion: reduce, drag-to-dismiss turns off and the backdrop and surface use a 120 ms opacity crossfade with no travel or blur. Setting motion="none" disables dragging and runs all transitions immediately (0 ms).
| Theme token | CSS variable | Default | Role |
|---|---|---|---|
padding | --ui-modal-padding | 24px | Header, body, and footer inner padding. |
titleSize | --ui-modal-title-size | 18px | Heading font size. |
backdropBlur | --ui-modal-backdrop-blur | 4px | Backdrop blur radius (0 disables it). |
sheetRadius | --ui-modal-sheet-radius | 22px | Inner edge corner radius (18px ≤640px) |
overlay | --ui-overlay | theme | Backdrop tint color. |
borderStrong | --ui-border-strong | theme | Bottom grabber fill. |
surfaceRaised | --ui-surface-raised | theme | Panel background color. |
theme also accepts mode, accent, and core color, border, typography, and shadow tokens. Trigger and close buttons inherit recipe, mode, accent, motion, dir, and tokens.
Composition
In an agent composition, Drawer is a container whose children render inside its body.
{
"type": "Drawer",
"props": {
"title": "Filters",
"description": "Narrow the reports by status and owner.",
"trigger": { "label": "Show filters", "icon": "sliders-horizontal" },
"side": "right"
},
"children": ["status-filter", "owner-filter"]
}