Drawer

A panel that slides in from an edge, for people and agents.

Source
$npx @dinachi/cli@latest add drawer
side
DrawerTitle
DrawerDescription
modal

Usage

import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"

export function Settings() {
  return (
    <Drawer swipeDirection="right">
      <DrawerTrigger render={<Button variant="outline" />}>Open settings</DrawerTrigger>
      <DrawerContent>
        <DrawerHeader>
          <DrawerTitle>Settings</DrawerTitle>
          <DrawerDescription>Changes save as you make them.</DrawerDescription>
        </DrawerHeader>
        <DrawerFooter>
          <DrawerClose render={<Button variant="outline" />}>Done</DrawerClose>
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  )
}

Examples

A form panel that slides in from the right.
import {
  Drawer,
  DrawerTrigger,
  DrawerContent,
  DrawerHeader,
  DrawerTitle,
  DrawerDescription,
  DrawerFooter,
  DrawerClose,
} from '@/components/ui/drawer';
import { Button } from '@/components/ui/button';

export function Example() {
  return (
    <Drawer>
      <DrawerTrigger render={<Button variant="outline" />}>
        Open Drawer
      </DrawerTrigger>
      <DrawerContent>
        <DrawerHeader>
          <DrawerTitle>Edit Profile</DrawerTitle>
          <DrawerDescription>Make changes to your profile settings.</DrawerDescription>
        </DrawerHeader>
        <div className="space-y-4 py-4">
          <div className="space-y-2">
            <label className="text-sm font-medium">Name</label>
            <input defaultValue="John Doe" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
          </div>
          <div className="space-y-2">
            <label className="text-sm font-medium">Email</label>
            <input type="email" defaultValue="john@example.com" className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm" />
          </div>
        </div>
        <DrawerFooter>
          <DrawerClose render={<Button variant="outline" />}>Cancel</DrawerClose>
          <Button>Save</Button>
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  );
}

Notes

Swipe direction

side only places the panel. The dismiss swipe comes from swipeDirection on Drawer, default down. For the default right-hand panel, pass swipeDirection="right"; for side="left", pass "left".

Swiping

  • The backdrop dims with the drag.
  • A flick closes faster than a slow release past the threshold.
  • A click close takes the normal duration.

API

openboolean
Controlled open state.
defaultOpenboolean = false
Starting open state when uncontrolled.
onOpenChange
agent
(open, details) => void
Runs on open and close, from either side. details.cancel() refuses it.
swipeDirection"up" | "down" | "left" | "right" = "down"
The swipe that dismisses the drawer. Match it to side.
modalboolean | "trap-focus" = true
Traps focus, locks page scroll and blocks outside clicks. trap-focus only traps focus.
disablePointerDismissalboolean = false
Keeps the drawer open on an outside click.
snapPoints(number | string)[]
Resting heights. Fractions of the viewport, pixels, or px and rem strings.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as dialog.

Reads

label

The DrawerTitle while open. The trigger's name while closed, or while open with no title.

open

Whether the drawer is showing. Open drawers are listed first.

Actions

open()

While closed. act returns the opened drawer under appeared.

close()

While open.

An agent's open or close runs through onOpenChange. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. Controls inside report the drawer's title as in.

await agent.act({
  steps: [{ ref: "Open Drawer", action: "open" }],
})

Accessibility

  • The panel is a dialog named by DrawerTitle and described by DrawerDescription.
  • Give every drawer a DrawerTitle. The agent reads the same name.
  • While modal, focus is trapped and the page cannot scroll or take clicks.
  • Focus returns to the trigger when the drawer closes.
  • Reduced motion fades the panel in place instead of sliding.