Drawer
A panel that slides in from any edge and follows your finger, with snap points, a working handle and nested drawers that stack.
- Overlay components
- 13 parts
- 12 examples
@base-ui/react
See it in a real product: Artifact and Inventory
View blockpnpm dlx shadcn@latest add https://hextaui.com/r/drawer.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react @tabler/icons-react cnCopy and paste the following code into your project.
components/ui/drawer.tsx components/ui/sheet.tsx components/ui/button.tsx Update the import paths to match your project setup.
Set swipeDirection on <Drawer /> to pick the edge. The drawer opens from that edge and swipes back towards it. Top and bottom drawers show a handle by default.
Pass snapPoints to rest a bottom drawer at preset heights. Numbers from 0 to 1 are fractions of the viewport, larger numbers are pixels, and strings take px or rem. The visible part always fits its content, so nothing hides below the screen.
<DrawerBody /> scrolls on its own, so the header and footer stay in place. Swiping only starts once the body is scrolled back to the top.
Wrap <DrawerContent /> in <DrawerVirtualKeyboardProvider /> when a bottom drawer holds text fields. On phones, the focused field scrolls into view above the software keyboard instead of hiding behind it. Keep the fields in <DrawerBody /> so the header and footer stay put.
A drawer opened from a drawer on the same edge stacks on top. The ones behind shrink, peek out above it and follow your finger as you swipe the top one away.
Dialogs, alert dialogs, sheets and drawers on another edge layer on top instead of stacking. The drawer steps back and a lighter backdrop covers it.
Change swipeDirection with a media query to show a side panel on desktop and a bottom sheet on phones.
With modal={false} there is no backdrop, the page keeps scrolling and focus can leave the drawer.
Pass open and onOpenChange to open it from anywhere, without a trigger.
Share one drawer between several triggers with createDrawerHandle. Each trigger passes a payload that the drawer renders through a function child.
Pass dir="rtl" to <DrawerContent /> to mirror its content. swipeDirection names a physical edge, so "left" stays on the left and the handle stays on the inner edge.
| Key | Action |
|---|---|
| EnterSpace | On the trigger, opens the drawer and moves focus inside it. |
| TabShift + Tab | Moves between focusable elements. Focus stays inside a modal drawer. |
| Esc | Closes the topmost drawer and returns focus to its trigger. |
- The drawer is a dialog.
<DrawerTitle />labels it and<DrawerDescription />describes it, so always include a title. - Swiping is never the only way out: Escape, the backdrop and a
<DrawerClose />button all close it too. - The handle is decorative and hidden from assistive tech. With a mouse, text inside the drawer can be selected without dragging it.
- With reduced motion enabled, the drawer fades in and out instead of sliding. Dragging still follows the pointer.
Built on the Base UI drawer. Every part accepts the props of the primitive it wraps.
| Prop | Type | Default |
|---|---|---|
swipeDirectionThe edge it opens from and the direction that dismisses it. | "up" | "down" | "left" | "right" | "down" |
showSwipeHandleShows the handle. Defaults to true for up and down, false for left and right. | boolean | – |
snapPointsHeights a vertical drawer can rest at. 0–1 is a fraction of the viewport, >1 is pixels, strings take px or rem. | (number | string)[] | – |
snapPoint | number | string | null | – |
defaultSnapPoint | number | string | null | – |
onSnapPointChange | (snapPoint, details) => void | – |
defaultOpen | boolean | false |
open | boolean | – |
onOpenChange | (open: boolean, details) => void | – |
onOpenChangeCompleteCalled after the open or close animation ends. | (open: boolean) => void | – |
modalThe backdrop only renders when true. | boolean | "trap-focus" | true |
disablePointerDismissalKeep it open when the backdrop is clicked. | boolean | false |
handle | DrawerHandle<Payload> | – |
children | ReactNode | ({ payload }) => ReactNode | – |
| Prop | Type | Default |
|---|---|---|
handle | DrawerHandle<Payload> | – |
payload | Payload | – |
render | ReactElement | (props, state) => ReactElement | <button> |
| Attribute | Description |
|---|---|
data-slot="drawer-trigger" | Target the trigger in CSS. |
data-popup-open | Present while its drawer is open. |
Renders the portal, backdrop, viewport and popup, plus the handle. Vertical drawers fit their content up to the viewport height minus 4rem. Side drawers are 75% wide, up to 24rem from the sm breakpoint. Override with h-* or w-*, or scope it to one axis with data-[swipe-axis=y]:.
| Prop | Type | Default |
|---|---|---|
initialFocus | boolean | RefObject | (type) => HTMLElement | boolean | – |
finalFocus | boolean | RefObject | (type) => HTMLElement | boolean | – |
className | string | (state) => string | – |
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="drawer-popup" | The drawer panel. |
data-slot="drawer-content" | The inner wrapper around your children. It scrolls when nothing else does. |
data-swipe-direction | up, right, down or left. |
data-swipe-axis | x or y. |
data-open | Present while the drawer is open. |
data-starting-style | Present while it animates in. |
data-ending-style | Present while it animates out. |
data-swiping | Present while it is being dragged. |
data-snap-points | Present when the drawer has snap points. |
data-expanded | Present at the full-height snap point. |
data-nested-drawer-open | Present while another drawer is open on top. |
data-stack | Present while a drawer on the same edge is stacked on top. |
--drawer-inset | Floats the drawer away from the viewport edges. Defaults to 0px. |
--drawer-bleed-background | Fills the area revealed when dragged past its edge. Defaults to the popover color. |
--drawer-swipe-movement-x | Horizontal drag distance. A -y variable exists too. |
--drawer-snap-point-offset | How far the current snap point sits below the top. |
--nested-drawers | How many drawers are open on top. |
Rendered by <DrawerContent /> when modal is true. It fades as you swipe, and stays at least half visible when there are snap points. A drawer layered over a sheet or a drawer on another edge gets a lighter backdrop.
| Attribute | Description |
|---|---|
data-slot="drawer-overlay" | The backdrop. |
data-nested | Present on lighter backdrops of layered drawers. |
--drawer-overlay-min-opacity | The lowest opacity it fades to while swiping. 0, or 0.5 with snap points. |
Rendered by <DrawerContent /> on the inner edge when showSwipeHandle is on. The whole drawer can be dragged, so the handle is a visual cue.
| Attribute | Description |
|---|---|
data-slot="drawer-swipe-handle" | The handle. |
Plain <div> elements that lay out the drawer. The header centers its text in vertical drawers on small screens, the body scrolls and takes the remaining space, and the footer stacks its actions.
| Attribute | Description |
|---|---|
data-slot="drawer-header" | Title and description. |
data-slot="drawer-body" | Scrollable content. |
data-slot="drawer-footer" | Actions. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <h2> |
| Attribute | Description |
|---|---|
data-slot="drawer-title" | Labels the drawer. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <p> |
| Attribute | Description |
|---|---|
data-slot="drawer-description" | Describes the drawer. |
Renders no element. Place it inside <Drawer />, around <DrawerContent />. While the software keyboard is open, it adds room below the drawer’s scroll container, scrolls the focused field into view, and makes taps on fields open the keyboard on iOS. Drawers without it are unaffected.
| Prop | Type | Default |
|---|---|---|
children | ReactNode | – |
| Attribute | Description |
|---|---|
--drawer-keyboard-inset | Set on the viewport while the keyboard is open: how much of it overlaps the page. Use it with a 0px fallback. |
| Prop | Type | Default |
|---|---|---|
render | ReactElement | (props, state) => ReactElement | <button> |
| Attribute | Description |
|---|---|
data-slot="drawer-close" | Closes the drawer when pressed. |
createDrawerHandle<Payload>() returns a handle that connects a <Drawer /> to triggers rendered elsewhere. Create it once, outside your component.
- SheetA panel that slides in from any edge, with swipe-to-dismiss, scroll lock and stacked nesting.
- Alert dialogA confirmation dialog for destructive or important actions that waits for async work, and becomes a bottom sheet on phones.
- CommandA searchable list of actions, inline or as a ⌘K palette, with pages, shortcuts and highlighted matches.
- Context menuA menu of actions on right click or long press, with submenus, checkbox and radio items, and hold feedback on touch.
- DialogA window over the page for forms and focused tasks, with a pinned header and footer, nesting, and a swipeable bottom sheet on phones.
- Dropdown menuA menu of actions and options behind a button, with groups, submenus, checkbox and radio items, and shortcuts.
Used in Pro blocks
Blocks that build on Drawer.
Every block comes with HextaUI Pro, and Prompt Input is free.