Drawer
newWait, it's all swipeable? Always has been. A panel that slides in from any edge and swipes away, with a handle, swipe-to-open from the edge, and a bottom that stays above the keyboard.
Installation
Usage
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import {
Drawer,
DrawerBody,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from '@/components/ui/drawer'
</script>
<template>
<Drawer>
<DrawerTrigger as-child>
<Button>Edit profile</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Edit profile</DrawerTitle>
<DrawerDescription>Changes are saved when you press Save.</DrawerDescription>
</DrawerHeader>
<DrawerBody>
<!-- the content -->
</DrawerBody>
<DrawerFooter>
<DrawerClose as-child>
<Button>Save</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</template>
Drawer: holds the state;v-model:openopens it from codeDrawerTrigger: opens itDrawerContent: the panel, with an overlay and a drag handle;sidepicks the edge,bottomby defaultDrawerHeader,DrawerBody,DrawerFooter: the three parts; the body scrolls when neededDrawerClose: wrap any button in it to make it close the drawer
Under the hood it's a Dialog, so focus, Escape and the overlay work the same. The drawer adds gestures on top.
Drag the panel towards its edge: past halfway or with a quick flick, it closes; otherwise it springs back. If the body is scrolled, it scrolls first; at the top, the drawer moves. A mouse works too, and selecting text never starts a drag.
Examples
Sides
Scrollable body
Want the thin ScrollArea scrollbar? Put a scroll area in place of DrawerBody, with min-h-0 flex-1. Gestures work the same: it scrolls first, then the drawer moves.
Form
The keyboard shall not pass. On phones, it usually covers bottom panels, but the drawer lifts itself above it and scrolls the focused field into view.
Not dismissible
Swipe to open
DrawerSwipeArea opens the drawer with a swipe. By default it's an invisible strip along the drawer's edge. Give it a class to move it anywhere or make it visible, like the strip in the demo.
A page with a sheet tucked under its bottom edge.
Controlled
Responsive modal
A dialog on desktop, a drawer on phones, one open state. useMediaQuery comes from @vueuse/core. For menus, DrawerMenu does the same.
Gesture
Drags start only where they make sense. Got a map or a slider inside? Add data-no-drag, and it keeps its drags for itself. Want dragging only by the handle? Set handle-only. modal: false removes the overlay and keeps the page clickable, and the gestures still work.
Snap points
Like the sheet in a maps app. snap-points lists where the panel can stop, smallest first: 0.5 is half the screen, 320 or "320px" is pixels. Make the panel at least as tall as the largest point (h-[95dvh] in the demo).
It opens at the first point, or at v-model:active-snap-point, and goes back there after closing.
A slow release settles on the nearest point, a quick swipe moves one step, and a hard fling goes all the way. Want one step at a time? Set snap-to-sequential-points. Drag below the smallest point to close, unless dismissible is false. Tapping the handle cycles through the points.
The body scrolls only at the largest point; lower down, every drag moves the panel. The overlay shows only from fade-from-index up (the last point by default), so the page stays readable under a small sheet.
Scaled page
Wrap the app in DrawerIndent, and the page politely steps back while a drawer is open: it shrinks, rounds its corners and shows black around it (change it with class). It follows your finger too.
<!-- App.vue -->
<template>
<DrawerIndent>
<RouterView />
</DrawerIndent>
</template>
position: sticky keeps working inside. position: fixed doesn't while the page is scaled, so render fixed things through a portal, as the kit's own overlays do.
- Grace HopperCompiler notes for Monday
- Alan TuringRe: the imitation game
- Katherine JohnsonTrajectory figures attached
Nested drawers
Drawers all the way down. Open one from another, and it stacks on top while the ones below step back. Swipe the top one away, and the stack moves forward under your finger.
From code
Works like opening a dialog from code, with the same service. Put DialogHost inside DrawerIndent, so drawers opened from code step the page back too.
Render DrawerContent and close with useDialogContext(), both imported from the drawer:
<!-- ShareDrawer.vue -->
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { DrawerContent, DrawerHeader, DrawerTitle, useDialogContext } from '@/components/ui/drawer'
const { close } = useDialogContext<string>()
</script>
<template>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Share</DrawerTitle>
</DrawerHeader>
<Button @click="close('Mail')">Mail</Button>
</DrawerContent>
</template>
openDrawer(component, props, options) and defineDrawer() work like openDialog and defineDialog. The options are Drawer's props: side, dismissible, handle-only, modal and snap points. A swipe that closes the drawer gives the reason swipe, and while loading is true, a swipe springs back instead of closing.
holiday.jpg is ready to share.
Motion
| Duration | Easing | |
|---|---|---|
| Open | --transition-duration-medium-4 | --ease-emphasized-decelerate |
| Close | --transition-duration-short-4 | --ease-standard-decelerate |
| Spring back, page scale, stacking | --transition-duration-medium-2 | --ease-standard |
While you drag, there's no transition: the panel follows your finger exactly. With reduced motion, it appears and disappears at once, but still follows a drag.
It all runs on the drawer-slide, drawer-overlay-fade and drawer-indent utilities from @kappa-ui/core/tailwind.css.
Using the per-frame variables (--drawer-swipe-movement, --drawer-swipe-progress, --drawer-nested-progress, --drawer-indent-progress)? Read them on the element that has them, not on its children. They don't inherit, for performance.
| Variable | Default | Description |
|---|---|---|
| --drawer-size | measured | The panel's size along its axis, in px. |
| --drawer-swipe-movement | 0px | On the panel, how far a drag has moved it towards its edge. |
| --drawer-swipe-progress | 0 | On the panel and the overlay, movement divided by size, from 0 to 1. The overlay fades with it; with snap points it stays 0 on the overlay. |
| --drawer-snap-offset | 0px | What the active snap point hides below the edge; added to the swipe movement. |
| --drawer-overlay-opacity | 1 | On the overlay, the opacity from fade-from-index, 0 to 1; multiplied with the swipe fade. |
| --drawer-keyboard-inset | 0px | What the visual viewport lost to the keyboard; a bottom drawer lifts by it. |
| --drawer-nested | 0 | On a drawer, the number of drawers open above it. |
| --drawer-nested-progress | 0 | On a drawer, how far it has stepped back; each drawer above adds up to 1, less while it is swiped away. |
| --drawer-indent-progress | 0 | On the page in DrawerIndent, how far it has stepped back, from 0 to 1; follows the first open drawer. |
| --drawer-indent-top | 0px | On the page, how much of it is above the screen when the indent starts; the scale and clip use the part on screen. |
| --drawer-indent-bottom | 0px | On the page, how much of it is below the screen when the indent starts. |
API Reference
Every part except Drawer, which renders no element, accepts class, merged over its own classes with tailwind-merge. On DrawerContent it styles the panel, so h-[85dvh] sets a bottom drawer's height and bg-* replaces its background.
Drawer
| Prop | Default | Type and description |
|---|---|---|
| side | — | DragSideThe edge the panel slides in from and swipes back to: |
| dismissible | — | booleanWhether a swipe, Escape or a press outside closes it. Off, the panel still follows a drag and springs back. |
| handleOnly | — | booleanStarts a drag only from |
| snapPoints | — | SnapPoint[]The sizes the panel can rest at, in ascending order. A number from 0 to 1 is a share of the viewport along the panel's axis; a larger number or a |
| activeSnapPoint | — | SnapPoint | nullThe point the panel rests at, bound with |
| snapToSequentialPoints | — | booleanKeeps every release to one point in the direction of travel; off, a fast fling goes to the last point or closes. |
| fadeFromIndex | — | numberThe index of the point from which the overlay is fully visible; it fades out towards the point below and is gone at any lower point. The last point by default. |
| open | — | booleanWhether it is open, bound with |
| defaultOpen | — | booleanWhether the drawer starts open when |
| modal | — | booleanShuts the page while open: focus stays in the panel, the page does not scroll, and the overlay takes outside clicks. Off, the page stays live and has no overlay; swipes still work. |
| unmountOnHide | — | booleanRemoves the panel from the DOM while closed. Turn it off to keep its state between openings. |
| Event | Payload and description |
|---|---|
| update:open | [value: boolean]Fires when the drawer opens or closes. |
| update:activeSnapPoint | [value: SnapPoint | null]Fires when the panel settles on another point, from a drag, a handle tap, or the reset after a close. |
| Slot | Scope and description |
|---|---|
| default | { open: boolean; close: () => void; }The trigger, the content and an optional swipe area. Receives |
DrawerTrigger
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a button, merging the trigger's attributes and behaviour onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The trigger's content, or with |
DrawerContent
| Prop | Default | Type and description |
|---|---|---|
| forceMount | — | booleanKeeps the panel mounted while closed, for animating it with a JavaScript library. |
| disableOutsidePointerEvents | — | booleanBlocks pointer events outside the panel. On by default in a modal drawer; a non-modal drawer ignores it. |
| asChild | — | booleanNot supported on this part: the panel adds its own handle and close button, and core adds the hidden title fallback, so there is more than one node to merge onto a single child. |
| as | — | AsTag | ComponentThe element or component to render. |
| showHandle | undefined | booleanShows the drag handle at the top of a bottom drawer or the bottom of a top drawer. On by default for those two sides, off for left and right. |
| showCloseButton | false | booleanShows a close button in the panel's top corner. Off by default: a swipe, Escape and the overlay already close the drawer. |
| Event | Payload and description |
|---|---|
| escapeKeyDown | [event: KeyboardEvent]Fires on Escape. Call |
| pointerDownOutside | [event: PointerDownOutsideEvent]Fires on a pointer press outside. Call |
| focusOutside | [event: FocusOutsideEvent]Fires when focus moves outside. Call |
| interactOutside | [event: PointerDownOutsideEvent | FocusOutsideEvent]Fires on any press or focus outside. Call |
| openAutoFocus | [event: Event]Fires when focus moves into the panel on open. Call |
| closeAutoFocus | [event: Event]Fires when focus returns to the trigger on close. Call |
| Slot | Scope and description |
|---|---|
| default | {}The panel's parts: |
DrawerOverlay
| Prop | Default | Type and description |
|---|---|---|
| forceMount | — | booleanKeeps the overlay mounted while closed, for animating it with a JavaScript library. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}Content placed on the overlay, behind the panel. |
DrawerHandle
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRenders the slot's element instead of its own and puts the handle's behaviour on it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The element |
DrawerSwipeArea
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRenders the slot's element instead of its own and puts the swipe behaviour on it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}Content shown inside the strip, such as a label; empty by default. |
DrawerIndent
| Slot | Scope and description |
|---|---|
| default | {}The page: the app's layout or router view. |
DrawerHeader
| Slot | Scope and description |
|---|---|
| default | {}The title and description. Keeps clear of the close button while there is one. |
DrawerTitle
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The title, which names the drawer for screen readers. |
DrawerDescription
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The description, which describes the drawer for screen readers. |
DrawerBody
| Slot | Scope and description |
|---|---|
| default | {}The content between the header and the footer. Scrolls once the panel reaches the height of the screen, and with snap points only at the largest one. |
DrawerFooter
| Slot | Scope and description |
|---|---|
| default | {}The buttons, stacked on narrow screens and in a row from 640px up, at the end. |
DrawerClose
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}The element that closes the drawer, usually a |
Props
- side
DragSideThe edge the panel slides in from and swipes back to:bottom(the default),top,leftorright. A screen edge, soleftstays on the left in right-to-left text.- dismissible
booleanWhether a swipe, Escape or a press outside closes it. Off, the panel still follows a drag and springs back.- handleOnly
booleanStarts a drag only fromDrawerHandle, so the content keeps every touch for itself.- snapPoints
SnapPoint[]The sizes the panel can rest at, in ascending order. A number from 0 to 1 is a share of the viewport along the panel's axis; a larger number or a"320px"string is pixels. The panel keeps the size its class gives it, so make that at least the largest point.- activeSnapPoint
SnapPoint | nullThe point the panel rests at, bound withv-model:active-snap-point. Starts at the first point and returns to it after a close.- snapToSequentialPoints
booleanKeeps every release to one point in the direction of travel; off, a fast fling goes to the last point or closes.- fadeFromIndex
numberThe index of the point from which the overlay is fully visible; it fades out towards the point below and is gone at any lower point. The last point by default.- open
booleanWhether it is open, bound withv-model:open.- defaultOpen
booleanWhether the drawer starts open whenv-model:openis not used.- modal
booleanShuts the page while open: focus stays in the panel, the page does not scroll, and the overlay takes outside clicks. Off, the page stays live and has no overlay; swipes still work.- unmountOnHide
booleanRemoves the panel from the DOM while closed. Turn it off to keep its state between openings.
Emits
- update:open
[value: boolean]Fires when the drawer opens or closes.- update:activeSnapPoint
[value: SnapPoint | null]Fires when the panel settles on another point, from a drag, a handle tap, or the reset after a close.
Slots
- default
{ open: boolean; close: () => void; }The trigger, the content and an optional swipe area. Receivesopenandclose.
Props
- asChild
booleanRender the single child instead of a button, merging the trigger's attributes and behaviour onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The trigger's content, or withas-childthe element that opens the drawer.
Props
- forceMount
booleanKeeps the panel mounted while closed, for animating it with a JavaScript library.- disableOutsidePointerEvents
booleanBlocks pointer events outside the panel. On by default in a modal drawer; a non-modal drawer ignores it.- asChild
booleanNot supported on this part: the panel adds its own handle and close button, and core adds the hidden title fallback, so there is more than one node to merge onto a single child.- as
AsTag | ComponentThe element or component to render.- showHandle
undefined booleanShows the drag handle at the top of a bottom drawer or the bottom of a top drawer. On by default for those two sides, off for left and right.- showCloseButton
false booleanShows a close button in the panel's top corner. Off by default: a swipe, Escape and the overlay already close the drawer.
Emits
- escapeKeyDown
[event: KeyboardEvent]Fires on Escape. CallpreventDefault()to keep it open.- pointerDownOutside
[event: PointerDownOutsideEvent]Fires on a pointer press outside. CallpreventDefault()to keep it open.- focusOutside
[event: FocusOutsideEvent]Fires when focus moves outside. CallpreventDefault()to keep it open.- interactOutside
[event: PointerDownOutsideEvent | FocusOutsideEvent]Fires on any press or focus outside. CallpreventDefault()to keep it open.- openAutoFocus
[event: Event]Fires when focus moves into the panel on open. CallpreventDefault()to keep focus where it is.- closeAutoFocus
[event: Event]Fires when focus returns to the trigger on close. CallpreventDefault()to keep focus where it is.
Slots
- default
{}The panel's parts:DrawerHeader,DrawerBodyandDrawerFooter, or a layout of your own.
Props
- forceMount
booleanKeeps the overlay mounted while closed, for animating it with a JavaScript library.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}Content placed on the overlay, behind the panel.
Props
- asChild
booleanRenders the slot's element instead of its own and puts the handle's behaviour on it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The elementasChildrenders in place of the bar. Empty by default.
Props
- asChild
booleanRenders the slot's element instead of its own and puts the swipe behaviour on it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}Content shown inside the strip, such as a label; empty by default.
Slots
- default
{}The page: the app's layout or router view.
Slots
- default
{}The title and description. Keeps clear of the close button while there is one.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The title, which names the drawer for screen readers.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The description, which describes the drawer for screen readers.
Slots
- default
{}The content between the header and the footer. Scrolls once the panel reaches the height of the screen, and with snap points only at the largest one.
Slots
- default
{}The buttons, stacked on narrow screens and in a row from 640px up, at the end.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The element that closes the drawer, usually aButtonwithas-child.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| drawer-trigger | data-state | The element that opens the drawer. |
| drawer-overlay | data-state, data-swiping | The scrim; fades with the swipe. |
| drawer-content | data-state, data-side, data-swiping, data-expanded, data-nested-open, data-nested-swiping | The panel; carries the variables above. data-expanded while it shows its full size, without snap points or at the largest one; data-nested-open while a drawer is open above it, data-nested-swiping while that one is swiped. |
| drawer-handle | — | The drag bar; a tap on it closes, or with snap points moves to the next point. |
| drawer-swipe-area | data-side | The strip that opens the drawer with a swipe; its gesture is live while the drawer is closed. |
| drawer-indent | — | The wrapper around the page; its background shows around the scaled page. |
| drawer-indent-page | data-open, data-side, data-swiping | The page. data-open while a modal drawer is open; data-side and data-swiping from the first open drawer, kept until the page has returned. |
| drawer-header | — | The title block. |
| drawer-title | — | The heading that names the drawer. |
| drawer-description | — | The text under the title. |
| drawer-body | — | The scrolling middle. |
| drawer-footer | — | The actions row. |
| drawer-close | — | A button that closes the drawer, including the optional corner one. |
Accessibility
The drawer's name comes from its DrawerTitle and its description from its DrawerDescription; always give it a title. When either is missing, the panel renders an empty hidden one, so Reka UI does not warn. The handle is aria-hidden: keyboard users close the drawer with Escape or a button.
| Key | Action |
|---|---|
| Tab / Shift + Tab | Moves to the next or previous control in the panel, wrapping around inside it. |
| Escape | Closes the drawer and returns focus to the element that opened it. |