UI

Drawer

A temporary edge-anchored panel for filters, details, settings, or navigation.

import { Drawer } from '@uthereal/ui/drawer'

Drawer playground

Loading interactive preview…

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).

SideAnchor edgeSize boundTypical use
rightRight edgemin(30rem, 100vw - 16px) × 100%Details, filters, settings (default).
leftLeft edgemin(30rem, 100vw - 16px) × 100%Navigation, workspace switching.
topTop edge100% × min(32rem, 100dvh)Quick search, announcements.
bottomBottom edge100% × 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:

GestureEffect
Drag toward the anchored edgeFollows the pointer 1:1 along the drawer axis.
Drag away from the anchored edgeRubber-bands with square-root resistance (-Math.sqrt(-offset)).
Release past 1/3 of panel size, or flick > 500 px/sDismisses the drawer and hands release velocity to a 240 ms smooth spring.
Release before thresholdSprings back to rest on the snappy spring (0.26s, bounce 0.12).
Press a button, link, or input in the headerIgnored 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.

ArgumentType / defaultDescription
titleRequiredstring—Heading of the drawer, required: it names the drawer for assistive technology. Changing it while open morphs the copy in place.
descriptionstring—Supporting text under the title, announced when it opens.
triggerOverlayTriggerDefault: {"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.
sideleft | 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.
draggablebooleanDefault: trueDragging 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.
closeLabelstringDefault: "Close drawer"Accessible name of the close button, e.g. "Close drawer".
defaultOpenbooleanDefault: falseInitial open state. Later argument edits do not reset an existing instance.
dismissiblebooleanDefault: trueEscape, the backdrop and the close button dismiss the drawer. Off, only the host closes it through open.
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeDrawerTheme—Color mode, accent, and modal tokens (padding, titleSize, backdropBlur, sheetRadius, surfaceRadius, overlay, borderStrong). See Theming for all keys and defaults.
motionnone | subtle | expressiveDefault: "subtle"Slide animation preset. System reduced-motion preferences take precedence.
motionOptionsDrawerMotionOptions—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.
dirltr | rtl—Reading direction. Omit it to inherit the page direction.

icon arguments accept names from the icon list.

React integration

PropPurpose
refForwarded to the portalled drawer surface HTMLDivElement.
childrenScrollable drawer body rendered beneath the header.
footerOptional 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.
presetApplication 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.
classNameClass name appended to the drawer surface.
portalContainerPortal target, such as an element inside a native <dialog> top layer or a contained panel host.
containedWith portalContainer, anchors the drawer to that container instead of the viewport.

Keyboard & accessibility

KeyInteraction
Enter, SpaceOpen the drawer from its trigger button.
Tab / Shift+TabMove focus within the drawer; focus wraps and stays trapped.
EscapeClose 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 tokenCSS variableDefaultRole
padding--ui-modal-padding24pxHeader, body, and footer inner padding.
titleSize--ui-modal-title-size18pxHeading font size.
backdropBlur--ui-modal-backdrop-blur4pxBackdrop blur radius (0 disables it).
sheetRadius--ui-modal-sheet-radius22pxInner edge corner radius (18px ≤640px)
overlay--ui-overlaythemeBackdrop tint color.
borderStrong--ui-border-strongthemeBottom grabber fill.
surfaceRaised--ui-surface-raisedthemePanel 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"]
}

On this page