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.
Installation
Anatomy

Usage
<script setup lang="ts">
import { shallowRef } from "vue"
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 { toast } from "@/components/ui/toast"
// React's state setter argument: the next value, or a function of the last.
type SetStateAction<T> = T | ((value: T) => T)
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 open = shallowRef(false)
const setOpen = (next: SetStateAction<typeof open.value>) => {
open.value = typeof next === "function" ? next(open.value) : next
}
const deliveryTime = shallowRef("asap")
const setDeliveryTime = (next: SetStateAction<typeof deliveryTime.value>) => {
deliveryTime.value = typeof next === "function" ? next(deliveryTime.value) : next
}
const isMobile = false
const handleOpenChange = (next: boolean) => {
setOpen(next);
}
const handleDeliveryTimeChange = (value: string | null) => {
if (value !== null) {
setDeliveryTime(value);
}
}
const handleConfirm = () => {
const selected = deliveryTimes.find((time) => time.value === deliveryTime.value);
if (!selected) {
return;
}
setOpen(false);
toast.create({
description: selected.label,
title: "Delivery time confirmed",
});
}
</script>
<template>
<Drawer
@open-change="handleOpenChange"
:open="open"
:swipeDirection='isMobile ? "down" : "right"'
>
<DrawerTrigger>
<template #render="{ props }">
<Button v-bind="props" variant="secondary">Open Drawer</Button>
</template>
</DrawerTrigger>
<DrawerContent :showBar="isMobile">
<DrawerHeader>
<DrawerTitle>Pick a delivery time</DrawerTitle>
<DrawerDescription>
We'll prepare your order as soon as possible.
</DrawerDescription>
</DrawerHeader>
<div class="scroll-fade flex-1 overflow-y-auto p-4">
<RadioGroup
class="gap-2"
@value-change="handleDeliveryTimeChange"
:value="deliveryTime"
>
<FieldLabel v-for="time in deliveryTimes" :key="time.value">
<Field orientation="horizontal">
<FieldContent>
<FieldTitle class="flex items-center gap-2">
{{ time.label }}<Badge v-if="time.badge" variant="secondary">{{ time.badge }}</Badge>
</FieldTitle>
<FieldDescription>{{ time.description }}</FieldDescription>
</FieldContent>
<RadioGroupItem :value="time.value">
<span class="sr-only">{{ time.label }}</span>
</RadioGroupItem>
</Field>
</FieldLabel>
</RadioGroup>
</div>
<DrawerFooter>
<Button class="h-[34px]" @click="handleConfirm">Confirm Delivery Time</Button>
<DrawerClose>
<template #render="{ props }">
<Button v-bind="props" variant="outline">Cancel</Button>
</template>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</template>
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 first focusable element inside, or on the panel itself when it was opened by touch, so a phone's keyboard doesn't pop up. 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. On the swipe handle of a drawer with more than one snap point, moves it to the next larger one, and from the largest back to the smallest.
- Space
- When focus is on the trigger, opens the drawer. On the swipe handle of a drawer with more than one snap point, moves it to the next larger one, and from the largest back to the smallest.
- Arrow Up
- On the swipe handle, moves a bottom drawer to its next larger snap point and a top drawer to its next smaller one, without wrapping around.
- Arrow Down
- On the swipe handle, moves a bottom drawer to its next smaller snap point and a top drawer to its next larger one, without wrapping around.
- Arrow Left
- On the swipe handle, moves a right drawer to its next larger snap point and a left drawer to its next smaller one, without wrapping around.
- Arrow Right
- On the swipe handle, moves a left drawer to its next larger snap point and a right drawer to its next smaller one, without wrapping around.
- Home
- On the swipe handle, moves the drawer to its smallest snap point.
- End
- On the swipe handle, moves the drawer to its largest snap point.
- 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, the top one when drawers are nested, and moves focus back to its 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
Two bottom drawers, one with the bar along its top edge and one without. showBar on DrawerContent draws the bar and is on unless you set it to false, as the second drawer does. The whole panel follows a drag either way, and the bar only hints that it can be pulled down. 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 closeOnInteractOutside set to false, 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, and a larger one is pixels. The handle switches heights on a press or the arrow keys. 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 UI SDK?
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. left and right keep their edges under a right-to-left locale, while start and end follow the reading direction.
The Sides demo shows it in use.
How do I open and close a Drawer from code in Vue?
Hold the open state in a ref and bind it with v-model:open on Drawer, or pass open and listen to @open-change, 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?
Set closeOnInteractOutside to false on Drawer to ignore clicks outside, and closeOnEscape to false to ignore Escape. To refuse a swipe as well, set dismissible to false, and a swiped drawer resists and 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 bar shows by default. Set showBar to false on DrawerContent to hide it, as the second drawer in the Swipe handle demo does, and the whole panel follows a drag either way. With one snap point or none it is only a visual hint, hidden from screen readers, and with more it is a button named Resize that moves the drawer to its next snap point.
API Reference
Drawer
open?boolean
Whether the dialog is open. Pass it to control the dialog. Two-way with v-model or v-model:open.
defaultOpen?boolean
Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.
- Default
false
snapPoint?DrawerSnapPoint | null
The snap point it rests on. Pass it to control it. Two-way with v-model:snapPoint.
- Type
DrawerSnapPoint | null
defaultSnapPoint?DrawerSnapPoint
The snap point it opens at, when uncontrolled.
closeOnOutsidePress?boolean
Whether pressing outside the drawer, like on its backdrop, closes it.
- Default
true, or false while the drawer isn't modal
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
controller?DrawerController<any, any>
Opens, closes and moves the drawer from anywhere, and connects triggers and outlets outside it. Create one with createDrawerController().
- Type
DrawerController<any, any>
debug?boolean
Logs every state change with its reason to the console, in development builds.
disablePointerDismissal?boolean
The other bases' name for closeOnOutsidePress={false}.
dismissible?boolean
Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass false while a form has unsaved changes, and ask in onDismissAttempt.
- Default
true
driver?SheetDriverName
How it moves. "pointer" follows touch, mouse and pen with a spring fitted to iOS. "scroll-snap" uses the browser's own scrolling for bottom drawers. "auto" picks scroll snap for a bottom drawer on a touch screen, unless modalAbove is set or expandOnScroll is false, and the pointer driver otherwise.
- Default
"auto"
expandOnScroll?boolean
Whether dragging toward a larger snap point on scrollable content moves the drawer first, until it's at its largest.
- Default
true
modal?"trap-focus" | boolean
true: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the drawer. "trap-focus": traps focus and leaves the page usable. false: a drawer beside the page. See modalAbove to make it modal only above a snap point.
- Type
"trap-focus" | boolean- Default
true
modalAbove?SnapPoint
At or below this snap point the page stays usable and undimmed, like Maps: no inert page, no scroll lock, no aria-modal, and presses beside the drawer reach the page. Above it, modal applies. Changes once the drawer comes to rest.
pendingAnnouncement?string
What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
- Default
"Loading"
persistentElements?(string | Element)[] | (() → Element[])
Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.
- Type
(string | Element)[] | (() → Element[])- Parameters
string | Element)[] | ((- Returns
Element[])
physics?Partial<SheetPhysics>
Overrides the motion: spring, projection, rubber band and dim. Starts from sheetPhysics.ios.
- Type
Partial<SheetPhysics>
preventEdgeSwipe?boolean
Whether presses on the drawer near the screen's left and right edges are kept from starting iOS Safari's back and forward swipe. Taps right at those edges then don't click. Read when the content mounts.
- Default
false
showSwipeHandle?boolean
Shows the handle bar you can drag the drawer by.
- Default
false
snapPoints?DrawerSnapPoint[]
Where it can rest, from the edge it comes from.
- Default
[1]
swipeDirection?DrawerSwipeDirection
The direction that swipes it closed, so the edge it comes from.
- Default
"down"
themeColor?boolean
Whether <meta name="theme-color"> dims with the backdrop, so Safari's toolbars darken too. Written where motion starts and ends, never per frame.
- Default
false
@open-change(open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) → void
Runs when the drawer wants to open or close. details.reason says why, "swipe" included, details.cancel() stops it, and details.returnValue carries what closed it.
- Type
(open: boolean, details: DialogOpenChangeDetails<DrawerOpenChangeReason>) → void- Parameters
open– booleandetails– DialogOpenChangeDetails<DrawerOpenChangeReason>- Returns
void
@snap-point-change(snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) → void
Runs when the drawer moves to another snap point. details.reason says why: a swipe, the handle, the keyboard, a resize or the controller.
- Type
(snapPoint: SnapPoint, details: ChangeDetails<DrawerSnapPointChangeReason>) → void- Parameters
snapPoint– SnapPointdetails– ChangeDetails<DrawerSnapPointChangeReason>- Returns
void
@dismiss-attempt(details: DrawerDismissAttemptDetails) → void
Runs when a dismissal was refused because dismissible is false, including a swipe. The drawer resists and springs back. Ask "Discard changes?" here.
- Type
(details: DrawerDismissAttemptDetails) → void- Parameters
details– DrawerDismissAttemptDetails- Returns
void
@open-change-complete(open: boolean) → void
Runs once the dialog has finished opening or closing, after any animation.
- Parameters
open– boolean- Returns
void
@payload-change(payload: unknown, details: ChangeDetails<DrawerPayloadChangeReason>) → void
Runs when the payload the content shows changes: a trigger with another payload opens the drawer, or takes a non-modal drawer over while it's open, which fires no onOpenChange, and so does a controller's open({ payload }) on the open drawer. details.cancel() keeps the previous payload.
- Type
(payload: unknown, details: ChangeDetails<DrawerPayloadChangeReason>) → void- Parameters
payload– unknowndetails– ChangeDetails<DrawerPayloadChangeReason>- Returns
void
DrawerTrigger
<button> data-slot="drawer-trigger"
controller?PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
Connects a trigger outside the dialog, like one per table row, to the dialog with this controller.
- Type
PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
disabled?boolean
Stops the trigger from opening the dialog. A native button can't be focused or pressed, unless focusableWhenDisabled is set.
- Default
false
focusableWhenDisabled?boolean
Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.
- Default
false
payload?unknown
Data for the content to render when this trigger opens the dialog, like the row it belongs to.
shortcut?string
A keyboard shortcut that presses the trigger, like "mod+k". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
data-closed?string
Present while the drawer is closed, including while it animates out.
data-disabled?string
Present when the trigger is disabled.
data-open?string
Present while the drawer is open. On a trigger, while it's open from that trigger.
DrawerPortal
DrawerClose
<button> data-slot="drawer-close"
action?(event: Event, details: ActionDetails) → unknown
Runs when the part is pressed, before the dialog closes. A returned Promise keeps the dialog open while it runs: the part gets data-pending, aria-busy and aria-disabled, screen readers hear the dialog's pendingAnnouncement after a second, and nothing but the controller closes the dialog. It closes with reason "action" once the Promise resolves. A rejection keeps it open and puts the reason in the part's error state until the next press, or until the dialog opens again. details.source says how the part was pressed, for changes made after an await.
- Type
(event: Event, details: ActionDetails) → unknown- Parameters
event– Eventdetails– ActionDetails- Returns
unknown
value?string
Reported as returnValue in onOpenChange and by the controller's open(). createConfirm() resolves true for "confirm".
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
data-disabled?stringdata-pending?string
Present on a Close part while its action runs.
DrawerOverlay
<div> data-slot="drawer-backdrop"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-closed?string
Present while the drawer is closed, including while it animates out.
data-dragging?string
Present while a finger, mouse or pen drags it.
data-ending-style?string
Present while the drawer animates out.
data-interactive?string
Present while it rests at or below modalAbove, so the page behind is usable. The backdrop lets presses through.
data-open?string
Present while the drawer is open. On a trigger, while it's open from that trigger.
data-starting-style?string
Present for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
DrawerSwipeHandle
<button> data-slot="drawer-swipe-handle"
class?string
Merged with the part's classes.
data-expanded?string
Present while it rests at its largest snap point.
data-snap-point"content" | "0.2"
The snap point it rests on or is moving to, as written, like 0.5 or content.
- Type
"content" | "0.2"
DrawerContent
<div> data-slot="drawer-content"
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget
Where focus goes when the dialog closes while focus is inside it.
- Default
"trigger"
initialFocus?DialogInitialFocus
Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than "auto".
- Default
"auto"
keepMounted?boolean
Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.
- Default
false
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
data-closed?string
Present while the drawer is closed, including while it animates out.
data-dragging?string
Present while a finger, mouse or pen drags it.
data-driver"pointer" | "scroll-snap"
What moves it.
- Type
"pointer" | "scroll-snap"
data-ending-style?string
Present while the drawer animates out.
data-expanded?string
Present while it rests at its largest snap point.
data-interactive?string
Present while it rests at or below modalAbove, so the page behind is usable. The backdrop lets presses through.
data-open?string
Present while the drawer is open. On a trigger, while it's open from that trigger.
data-side"top" | "right" | "bottom" | "left"
The edge it comes from, with start and end resolved for the writing direction.
- Type
"top" | "right" | "bottom" | "left"
data-snap-point"content" | "0.2"
The snap point it rests on or is moving to, as written, like 0.5 or content.
- Type
"content" | "0.2"
data-starting-style?string
Present for the first frame. The drawer slides itself, so leave the content's translate and the backdrop's opacity alone.
--bleedstring--drawer-dimstring
How dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expandstring
0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
--drawer-progressstring
How far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-stackstring
How many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
DrawerHeader
<div> data-slot="drawer-header"
description?string
The description of the drawer.
title?string
The title of the drawer.
class?string
Merged with the part's classes.
DrawerFooter
<div> data-slot="drawer-footer"
class?string
Merged with the part's classes.
DrawerTitle
<h2> data-slot="drawer-title"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
DrawerDescription
<p> data-slot="drawer-description"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.












