Drawer
A panel that slides in from an edge and can be dragged closed. The content column is 384px wide, the title is 18px and the footer buttons are 44px.
Installation
npx shadcn@latest add @sevenone/drawerUsage
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"Examples
Default
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">Open Drawer</Button>
</DrawerTrigger>
<DrawerContent>
<div className="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Move Goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<div className="flex items-center justify-center gap-2 px-4">
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(-10)} aria-label="Decrease goal">
<Minus />
</Button>
<div className="flex-1 text-center">
<div className="text-7xl font-bold tracking-tighter" aria-live="polite">{goal}</div>
<div className="text-sm text-muted-foreground uppercase">Calories/day</div>
</div>
<Button variant="outline" size="icon" className="rounded-full" onClick={() => change(10)} aria-label="Increase goal">
<Plus />
</Button>
</div>
<DrawerFooter>
<Button>Submit</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>Side
direction opens the drawer from the "top", "right", "bottom" or "left".
<Drawer direction="right">
<DrawerTrigger asChild>
<Button variant="outline">Open from the right</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Filters</DrawerTitle>
<DrawerDescription>Choose what the list shows.</DrawerDescription>
</DrawerHeader>
…
<DrawerFooter>
<Button>Apply</Button>
<DrawerClose asChild>
<Button variant="outline">Cancel</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>Accessibility
- It is a dialog: focus moves into it when it opens and stays inside until it closes; Esc closes it and focus returns to the trigger.
- Dragging is never the only way: keep a Cancel button (DrawerClose) in the footer.
- Always give it a DrawerTitle; screen readers announce it with the description.
- The slide motion stops when people ask for reduced motion.