A panel that slides up from the bottom edge, common on mobile. It is a native modal dialog: the trigger is a button with Invoker Commands, closedby=any gives Escape and a click on the backdrop, and the top layer, inert page content and focus return come from the browser. A small client script adds the swipe down on the handle and the header and wires the buttons in browsers without Invoker Commands or closedby.
Browser Support
Limited availability5 featuresDetails
Opens the modal in the top layer with a backdrop and Escape to close.
Opens and closes the drawer from buttons without JavaScript. Without it a small script does the same.
Closes the drawer on a click on the backdrop natively. Without it a small script handles the click.
Slides the drawer in when it opens. Without it the drawer appears at once.
Slides the drawer out when it closes. Without it the drawer disappears at once.
Preview
Installation
Usage
import { Button } from "@/components/ui/button"
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"
export default function Example() {
return (
<Drawer>
<DrawerTrigger asChild>
<Button variant="outline">Open drawer</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Move goal</DrawerTitle>
<DrawerDescription>Set your daily activity goal.</DrawerDescription>
</DrawerHeader>
<DrawerFooter>
<DrawerClose asChild>
<Button>Submit</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
)
}Examples
Long content
The drawer is at most 85% of the screen height and scrolls inside. The swipe starts on the handle or the header, so scrolling the content never closes it.
<DrawerContent className="mx-auto sm:max-w-md">
<DrawerHeader>…</DrawerHeader>
<div className="px-4">Long content scrolls inside</div>
<DrawerFooter>…</DrawerFooter>
</DrawerContent>Without a handle
showHandle={false} hides the grab handle. The swipe still works on DrawerHeader.
<DrawerContent showHandle={false}>…</DrawerContent>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Client components only |
| defaultOpen | boolean | false | Open right after hydration |
| onOpenChange | (open: boolean) => void | - | Called with the new state on every open and close. Client components only: functions cannot cross the server boundary |
| id | string | - | id of the dialog element. Generated when omitted |
| asChild | boolean | false | Merge the props into the only child, for example a Button (DrawerTrigger, DrawerClose) |
| showHandle | boolean | true | Show the grab handle at the top (DrawerContent). The swipe works on the handle and on DrawerHeader |
| className | string | - | Additional CSS classes |
Features
- A native modal dialog with closedby="any": Escape and a click on the backdrop close it.
- Swipe down on the handle or the header closes it when pulled far enough or fast enough; otherwise it springs back.
- Labelled by DrawerTitle and described by DrawerDescription; focus returns to the trigger on close.
- The page behind the drawer is inert and does not scroll.
- Parts are linked without React context, so Drawer and its parts stay server components. A part rendered inside your own component is not reached: keep the parts in the JSX passed to Drawer.