shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A drawer slides a panel in from the edge of the screen and follows the finger, so dragging it back closes it. It suits phones, where a bottom drawer sits under the thumb: a filter list, a delivery slot picker, a short form.
On a wide screen with nothing to swipe, a Sheet does the same job from the side, and a Dialog fits a short task in the middle. On this page the drawer is built on Base UI's drawer, not React Aria, and takes Base UI's props.
Installation
Anatomy

Usage
import { useState } from "react";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter,
DrawerHeader, DrawerTitle, DrawerTrigger,
} from "@/components/ui/drawer";
import {
Field, FieldContent, FieldDescription, FieldLabel, FieldTitle,
} from "@/components/ui/field";
import {
RadioGroup, RadioGroupItem,
} from "@/components/ui/radio-group";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Toaster, toast } from "@/components/ui/toast";
import { useIsMobile } from "@/hooks/use-is-mobile";const deliveryTimes = [
{
badge: "Fastest",
description: "25–35 min · Driver assigned now",
id: "delivery-asap",
label: "Standard delivery",
value: "asap",
},
{
description: "Prep starts at 4:45 PM",
id: "delivery-5-00",
label: "5:00 PM – 5:15 PM",
value: "5-00",
},
{
description: "Good if you're heading home",
id: "delivery-5-30",
label: "5:30 PM – 5:45 PM",
value: "5-30",
},
{
description: "Most popular · High demand",
id: "delivery-6-00",
label: "6:00 PM – 6:15 PM",
value: "6-00",
},
{
description: "Last slot before kitchen closes",
id: "delivery-6-30",
label: "6:30 PM – 6:45 PM",
value: "6-30",
},
];
const DrawerDemo = () => {
const [open, setOpen] = useState(false);
const [deliveryTime, setDeliveryTime] = useState("asap");
const isMobile = useIsMobile();
const handleConfirm = () => {
const selected = deliveryTimes.find((time) => time.value === deliveryTime);
if (!selected) {
return;
}
setOpen(false);
toast("Delivery time confirmed", { description: selected.label });
};
return (
<>
<Toaster />
<Drawer
onOpenChange={setOpen}
open={open}
showSwipeHandle={isMobile}
swipeDirection={isMobile ? "down" : "right"}
>
<DrawerTrigger render={<Button variant="secondary" />}>
Open Drawer
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Pick a delivery time</DrawerTitle>
<DrawerDescription>
We'll prepare your order as soon as possible.
</DrawerDescription>
</DrawerHeader>
<ScrollArea className="min-h-0 flex-1 p-4">
<RadioGroup
aria-label="Delivery time"
className="gap-2"
onChange={setDeliveryTime}
value={deliveryTime}
>
{deliveryTimes.map((time) => (
<FieldLabel htmlFor={time.id} key={time.value}>
<Field orientation="horizontal">
<FieldContent>
<FieldTitle className="flex items-center gap-2">
{time.label}
{time.badge ? (
<Badge variant="secondary">{time.badge}</Badge>
) : null}
</FieldTitle>
<FieldDescription>{time.description}</FieldDescription>
</FieldContent>
<RadioGroupItem id={time.id} value={time.value} />
</Field>
</FieldLabel>
))}
</RadioGroup>
</ScrollArea>
<DrawerFooter>
<Button className="h-[34px]" onClick={handleConfirm} type="button">
Confirm Delivery Time
</Button>
<DrawerClose render={<Button variant="outline" />}>
Cancel
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
);
};
Accessibility
The panel has role="dialog", takes its name from DrawerTitle and its description from DrawerDescription. While it is modal, focus stays inside it and the page behind is hidden from screen readers, and Escape closes it and returns focus to the trigger. Focus starts on the panel itself rather than on its first field. A swipe has no keyboard equivalent, so give every drawer a visible Close or Cancel button.
- Enter
- When focus is on the trigger, opens the drawer.
- Space
- When focus is on the trigger, opens the drawer.
- Tab
- Moves focus to the next focusable element. While the drawer is modal, focus stays inside it.
- Shift+Tab
- Moves focus to the previous focusable element. While the drawer is modal, focus stays inside it.
- EscEscape
- Closes the drawer and moves focus back to the trigger.
Demos
Sides
swipeDirection set to left opens this drawer from the left edge, and a swipe to the left closes it. The other values are right, up and down, the default. Use a side for navigation or a settings tray that sits beside the page, and keep the bottom for phones, where it is under the thumb.
Swipe handle
A bottom drawer with the bar drawn along its top edge, set with showSwipeHandle on Drawer, which is off unless you turn it on. The whole panel follows a drag either way, and the bar is the hint that it can be pulled down. Show it on bottom drawers, and leave it off a side panel, where the Close button does the job.
Nested
Four drawers deep: each footer has a button that opens the next drawer from the same edge, the right on a wide screen and the bottom on a phone. The drawers behind stay mounted, step back and come forward again as the front one closes. Use it for a short drill-in, such as a category and then an item.
Non-modal
A drawer on the right with modal set to false, so the page behind stays usable, and disablePointerDismissal added, so a click on the page doesn't close it. Use it for a reference or help panel beside a form people are filling in. Keep a drawer modal when people have to finish the choice inside it.
Snap points
snapPoints set to 31rem and 1 gives this bottom drawer two heights: it opens at the first and drags up to nearly the full screen at the second. A number up to 1 is a share of the screen's height, a larger number is pixels, and a string takes px or rem. Use it for a map, a playlist or comments that preview first.
Dialog
One edit profile form behind one open state: from 768 pixels wide it opens in a centered Dialog, and below that in a bottom drawer, switched by useIsMobile. The form is one component used in both, and saving it closes whichever is open. Pick this when the same short task runs on desktop and on phones, and only the container should change.
FAQ
When should I use a Drawer instead of a Sheet?
Use a Drawer when people will drag the panel with a finger: it follows the swipe, closes once dragged far enough back toward its edge, and can stop at snap points. That is the bottom panel phone users expect for filters, options or a short form.
A Sheet also slides in from an edge, but it has no gesture: a button, Escape or a click outside closes it. It suits a side panel on a desktop layout, such as an inspector next to a table or a cart.
How do I open a Drawer from the left or the right in React Aria?
Set swipeDirection on Drawer to the direction that closes it: left for a drawer on the left edge, right for the right, up for the top, and down, the default, for the bottom. The panel opens from that same edge, and a swipe toward it closes the panel.
The Sides demo shows it in use.
How do I open and close a Drawer from code in React?
Hold the open state yourself: pass open to Drawer and update it in onOpenChange, which receives the new boolean first.
Set it to false from your own code to close the drawer after a save. The Dialog demo holds one open state this way and hands it to a dialog on wide screens and a drawer on phones.
How do I add snap points to a Drawer?
Pass snapPoints to Drawer, as the Snap points demo does with "31rem" and 1. A number up to 1 is a share of the screen's height, a larger number is pixels, and a string such as "31rem" or "240px" is a length. The drawer opens at the first point unless defaultSnapPoint names another, and snapPoint with onSnapPointChange lets you follow or set it yourself.
How do I show a Dialog on desktop and a Drawer on mobile?
Render one or the other from a media query and give both the same open state, as the Dialog demo does with useIsMobile, which is true below 768 pixels. Put the form in a component of its own and use it in both, so the fields and their handlers stay in one place.
The query is false on the server, so the page first renders the dialog, then switches to the drawer once it hydrates on a phone. Keep the trigger's label the same in both branches, so nothing visible changes when it does.
How do I stop a Drawer from closing on an outside click or a swipe?
Add disablePointerDismissal to Drawer to ignore clicks outside. For Escape or a swipe, call eventDetails.cancel() in onOpenChange when eventDetails.reason is "escape-key" or "swipe", and a swiped drawer springs back into place.
Give people a button that closes it, or they are stuck.
Can I open a Drawer from inside another Drawer?
Yes. Put a second Drawer, with its own trigger and the same swipeDirection, inside the first one's content, and it opens on top from the same edge. The first stays mounted, steps back while the second is open and comes forward when it closes, as in the Nested demo.
Two levels are usually enough. Deeper than that, a page of its own serves people better.
How do I show or hide the drag handle on a Drawer?
The handle is off by default. Add showSwipeHandle to Drawer to draw it along the drawer's inner edge, the top of a bottom drawer, as in the Swipe handle demo. It is only a visual hint: the whole panel follows a drag, handle or not.
API Reference
Drawer
data-slot="drawer"
open?boolean
Whether the drawer is currently open.
defaultOpen?boolean
Whether the drawer is initially open.
To render a controlled drawer, use the open prop instead.
- Default
false
onOpenChange?(open: boolean, eventDetails: DrawerRoot.ChangeEventDetails) → void
Event handler called when the drawer is opened or closed.
- Type
(open: boolean, eventDetails: DrawerRoot.ChangeEventDetails) → void- Parameters
open– booleaneventDetails– DrawerRoot.ChangeEventDetails- Returns
void
snapPoint?DrawerSnapPoint | null
The currently active snap point. Use with onSnapPointChange to control the snap point.
- Type
DrawerSnapPoint | null
defaultSnapPoint?DrawerSnapPoint | null
The initial snap point value when uncontrolled.
- Type
DrawerSnapPoint | null
onSnapPointChange?(snapPoint: DrawerSnapPoint | null, eventDetails: DrawerRoot.SnapPointChangeEventDetails) → void
Callback fired when the snap point changes.
- Type
(snapPoint: DrawerSnapPoint | null, eventDetails: DrawerRoot.SnapPointChangeEventDetails) → void- Parameters
snapPoint– DrawerSnapPoint | nulleventDetails– DrawerRoot.SnapPointChangeEventDetails- Returns
void
actionsRef?React.RefObject<DrawerRoot.Actions | null>
A ref to imperative actions.
- unmount: Ends the closing phase of the drawer after an externally controlled closing animation finishes.
Call preventUnmountOnClose() in onOpenChange first, otherwise the drawer completes closing on its own.
Whether it leaves the DOM is decided by keepMounted on the portal.
- close: Closes the drawer imperatively when called.
- Type
React.RefObject<DrawerRoot.Actions | null>
children?React.ReactNode | PayloadChildRenderFunction<Payload>
The content of the drawer.
- Type
React.ReactNode | PayloadChildRenderFunction<Payload>
defaultTriggerId?string | null
ID of the trigger that the drawer is associated with.
This is useful in conjunction with the defaultOpen prop to create an initially open drawer.
- Type
string | null
disablePointerDismissal?boolean
Whether to prevent the drawer from closing on outside presses. For non-modal drawers, this also prevents the drawer from closing when focus moves outside of it.
- Default
false
handle?DrawerHandle<Payload>
A handle to associate the drawer with a trigger. If specified, allows detached triggers to control the drawer's open state. Can be created with the Drawer.createHandle() method.
- Type
DrawerHandle<Payload>
modal?boolean | "trap-focus"
Determines if the drawer enters a modal state when open.
- true: user interaction is limited to just the drawer: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled.
- false: user interaction with the rest of the document is allowed.
- trap-focus: focus is trapped inside the drawer, but document page scroll is not locked and pointer interactions outside of it remain enabled.
- Type
boolean | "trap-focus"- Default
true
onOpenChangeComplete?(open: boolean) → void
Event handler called after any animations complete when the drawer is opened or closed.
- Parameters
open– boolean- Returns
void
showSwipeHandle?boolean
Shows the handle bar you can drag the drawer by.
- Default
false
snapPoints?DrawerSnapPoint[]
Snap points used to position the drawer.
Use numbers between 0 and 1 to represent fractions of the viewport height,
numbers greater than 1 as pixel values, or strings in px/rem units
(for example, 148px or 30rem).
- Default
[1]
snapToSequentialPoints?boolean
Disables velocity-based snap skipping so drag distance determines the next snap point.
- Default
false
swipeDirection?SwipeDirection
The swipe direction used to dismiss the drawer.
- Default
"down"
triggerId?string | null
ID of the trigger that the drawer is associated with.
This is useful in conjunction with the open prop to create a controlled drawer.
There's no need to specify this prop when the drawer is uncontrolled (that is, when the open prop is not set).
- Type
string | null
DrawerContent
<div> data-slot="drawer-content"
data-snap-points?string
Present when snapPoints is set.
data-swipe-axis?string
Mirrors swipeAxis.
--bleedstring--closed-transformstring--drawer-content-heightstring--drawer-swipe-movement-xstring--drawer-swipe-movement-ystring--drawer-swipe-progressstring--drawer-swipe-strengthstring--nested-drawersstring--peekstring--stack-heightstring--stack-peek-offsetstring--stack-progressstring--stack-scalestring--stack-scale-basestring--stack-shrinkstring--stack-stepstringDrawerTitle
<h2> data-slot="drawer-title"
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
DrawerDescription
<div> data-slot="drawer-description"
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
DrawerTrigger
<button> data-slot="drawer-trigger"
handle?DrawerHandle<Payload>
A handle to associate the trigger with a drawer. Can be created with the Drawer.createHandle() method.
- Type
DrawerHandle<Payload>
id?string
ID of the trigger. In addition to being forwarded to the rendered element,
it is also used to specify the active trigger for drawers in controlled mode (with the Drawer.Root triggerId prop).
nativeButton?boolean
Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).
- Default
true
payload?Payload
A payload to pass to the drawer when it is opened.
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
DrawerOverlay
<div> data-slot="drawer-overlay"
forceRender?boolean
Whether the backdrop is forced to render even when nested.
- Default
false
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string
Merged with the part's classes.
data-state"open" | "closed"
"open" or "closed".
- Type
"open" | "closed"
data-swipingstring--drawer-swipe-progressstring--drawer-swipe-strengthstringDrawerPortal
data-slot="drawer-portal"
container?HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null
A parent element to render the portal element into.
- Type
HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null
keepMounted?boolean
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Default
false
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
DrawerClose
data-slot="drawer-close"
nativeButton?boolean
Whether the component renders a native <button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).
- Default
true
render?ReactElement | ((props: object, state: object) => ReactElement)
Replace the host element or compose it with another component.
- Type
ReactElement | ((props: object, state: object) => ReactElement)
DrawerSwipeHandle
<div> data-slot="drawer-swipe-handle"
className?string
Merged with the part's classes.
DrawerHeader
<div> data-slot="drawer-header"
description?string
The description of the drawer.
title?string
The title of the drawer.
className?string
Merged with the part's classes.
DrawerFooter
<div> data-slot="drawer-footer"
className?string
Merged with the part's classes.












