sideDrawerTitleDrawerDescriptionmodalimport { Button } from "@/components/ui/button"
import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer"
export function EditProfile() {
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 htmlFor="name" className="text-sm font-medium">Name</label>
<input id="name" 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 htmlFor="email" className="text-sm font-medium">Email</label>
<input id="email" 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>
)
}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
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>
);
}import {
Drawer,
DrawerTrigger,
DrawerContent,
DrawerHeader,
DrawerTitle,
DrawerDescription,
DrawerFooter,
DrawerClose,
} from '@/components/ui/drawer';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<div className="flex gap-2 flex-wrap">
{(['left', 'right', 'top', 'bottom'] as const).map((side) => (
<Drawer key={side}>
<DrawerTrigger render={<Button variant="outline" />}>
{side.charAt(0).toUpperCase() + side.slice(1)}
</DrawerTrigger>
<DrawerContent side={side}>
<DrawerHeader>
<DrawerTitle>{side.charAt(0).toUpperCase() + side.slice(1)} Drawer</DrawerTitle>
<DrawerDescription>This drawer slides in from the {side}.</DrawerDescription>
</DrawerHeader>
<DrawerFooter>
<DrawerClose render={<Button variant="outline" />}>Close</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
))}
</div>
);
}import {
Drawer,
DrawerTrigger,
DrawerContent,
DrawerHeader,
DrawerTitle,
} from '@/components/ui/drawer';
import { Button } from '@/components/ui/button';
export function Example() {
return (
<Drawer>
<DrawerTrigger render={<Button variant="outline" />}>
Navigation
</DrawerTrigger>
<DrawerContent side="left">
<DrawerHeader>
<DrawerTitle>Navigation</DrawerTitle>
</DrawerHeader>
<nav className="flex flex-col gap-1">
{['Dashboard', 'Projects', 'Team', 'Settings', 'Help'].map((item) => (
<a key={item} href="#" className="rounded-md px-3 py-2 text-sm hover:bg-accent transition-colors">
{item}
</a>
))}
</nav>
</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
details.cancel() refuses it.side.trap-focus only traps focus.Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Takes the props of the element it renders.
Agent
Inside an AgentProvider, it appears in agent.snapshot() as dialog.
Reads
labelThe DrawerTitle while open. The trigger's name while closed, or while open with no title.
openWhether 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
DrawerTitleand described byDrawerDescription. - 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.