Drawer
A panel that slides in from the edge of the screen, typically used for navigation or forms.
Anatomy
<Drawer.Root>
<Drawer.Trigger />
<Drawer.Backdrop />
<Drawer.Positioner>
<Drawer.Content>
<Drawer.Grabber>
<Drawer.GrabberIndicator />
</Drawer.Grabber>
<Drawer.Title />
<Drawer.Description />
<Drawer.CloseTrigger />
</Drawer.Content>
</Drawer.Positioner>
</Drawer.Root>
Examples
Swipe Direction
Use swipeDirection to set the edge the drawer slides in from.
Snap Points
Use snapPoints to define positions the drawer snaps to.
Modal
Set modal={false} to allow interaction with the page while the drawer is open.
Controlled
Use open and onOpenChange to control the open state.
Scrollable
No Drag Area
Add data-no-drag to an element inside the drawer so dragging can't start on it.
Non Draggable
Set draggable to false to disable drag-to-dismiss entirely.
Indent Background
Use Drawer.IndentBackground to indent the page behind the drawer.
Multiple Triggers
Give each Drawer.Trigger a value to share one drawer across triggers. onTriggerValueChange fires when a different
trigger is activated.
Using the Root Provider
Use Drawer.RootProvider with the useDrawer hook to control the drawer from outside the component tree.
Guides
Styling by Swipe Direction
Drawer.Content exposes data-swipe-direction (up | down | left | right), the resolved physical direction the
drawer slides in from. Use it for direction-aware styles, such as rounding the corners that face the viewport:
[data-drawer-content] {
/* Top drawer */
&[data-swipe-direction='up'] {
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-left-radius: 16px;
border-bottom-right-radius: 16px;
}
/* Bottom drawer */
&[data-swipe-direction='down'] {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
}
/* Left drawer */
&[data-swipe-direction='left'] {
border-top-left-radius: 0;
border-bottom-right-radius: 16px;
border-top-left-radius: 16px;
border-top-right-radius: 0;
}
/* Right drawer */
&[data-swipe-direction='right'] {
border-top-right-radius: 0;
border-bottom-left-radius: 16px;
border-top-left-radius: 0;
border-top-right-radius: 16px;
}
}
Preventing Overdrag Gaps
Dragging past the open position can leave a gap between the drawer and the viewport edge. Extend the background past its
bounds with an ::after pseudo-element:
[data-drawer-content] {
--bleed: 3rem;
position: relative;
/* Bleed effect */
&::after {
content: '';
position: absolute;
inset-inline: 0;
top: 100%;
height: var(--bleed);
background-color: inherit;
pointer-events: none;
}
}
For side drawers, extend it horizontally:
[data-drawer-content] {
/* Right drawer */
&[data-swipe-direction='right']::after {
inset-inline: auto;
inset-block: 0;
top: 0;
left: 100%;
width: var(--bleed);
height: auto;
}
/* Left drawer */
&[data-swipe-direction='left']::after {
inset-inline: auto;
inset-block: 0;
top: 0;
right: 100%;
width: var(--bleed);
height: auto;
}
}
The ::after element inherits the background and sits just outside the content, so overdrag reveals it instead of a
gap.
API Reference
Props
Root
| Prop | Default | Type |
|---|---|---|
closeOnEscape | true | booleanWhether to close the drawer when the escape key is pressed. |
closeOnInteractOutside | true | booleanWhether to close the drawer when the outside is clicked. |
closeThreshold | 0.25 | numberThe threshold distance for dismissing the drawer. |
defaultOpen | booleanThe initial open state of the drawer. | |
defaultSnapPoint | SnapPoint | |
defaultTriggerValue | stringThe default trigger value (uncontrolled). | |
finalFocusEl | () => MaybeElementElement to receive focus when the sheet is closed. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the drawer. Useful for composition. | |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
initialFocusEl | () => false | MaybeElementElement to receive focus when the sheet is opened. Return `false` to skip moving focus, or `null` to use the default. | |
lazyMount | false | booleanWhether to enable lazy mounting |
modal | true | booleanWhether to prevent pointer interaction outside the element and hide all content below it. |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onEscapeKeyDown | (event: KeyboardEvent) => voidFunction called when the escape key is pressed | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
onOpenChange | (details: OpenChangeDetails) => voidFunction called when the open state changes. | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
onRequestDismiss | (event: LayerDismissEvent) => voidFunction called when this layer is closed due to a parent layer being closed | |
onSnapPointChange | (details: SnapPointChangeDetails) => voidCallback fired when the snap point changes. | |
onTriggerValueChange | (details: TriggerValueChangeDetails) => voidCallback when the active trigger value changes. | |
open | booleanWhether the drawer is open. | |
present | booleanWhether the node is present (controlled by the user) | |
preventDragOnScroll | true | booleanWhether to prevent dragging on scrollable elements. When enabled, the sheet will not start dragging if the user is interacting with a scrollable element. |
preventScroll | true | booleanWhether to prevent scrolling behind the sheet when it's opened |
restoreFocus | true | booleanWhether to restore focus to the element that had focus before the sheet was opened. |
role | 'dialog' | 'dialog' | 'alertdialog'The sheet's role |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
snapPoint | SnapPointThe currently active snap point. | |
snapPoints | [1] | SnapPoint[]The snap points of the drawer. Array of numbers or strings representing the snap points. |
snapToSequentialPoints | false | booleanWhether the drawer should snap to sequential points when swiping. |
stack | DrawerStackOptional external store for coordinating app-level drawer stack visuals (e.g. indent and background layers). | |
swipeDirection | 'down' | SwipeDirectionThe direction in which the drawer can be swiped. |
swipeVelocityThreshold | 700 | numberThe threshold velocity (in pixels/s) for closing the drawer. |
trapFocus | true | booleanWhether to trap focus inside the sheet when it's opened. |
triggerValue | stringThe value of the trigger that currently controls the drawer. | |
unmountOnExit | false | booleanWhether to unmount on exit. |
Backdrop
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DrawerBackdropState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-drawer-backdrop] | <uid> |
[data-state] | "open" | "closed" |
[data-swiping] | |
[data-nested] | Present when the backdrop is nested within another {{widget}} |
[data-has-nested] | Present when the backdrop has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--drawer-swipe-progress | The drawer swipe progress value for the Backdrop |
--drawer-swipe-strength | The drawer swipe strength value for the Backdrop |
--layer-index | The index of the dismissable in the layer stack |
CloseTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
draggable | true | booleanWhether the drawer content is draggable. If false, the drawer can only be dragged by the grabber. |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DrawerContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-drawer-content] | <uid> |
[data-state] | "open" | "closed" |
[data-expanded] | Present when expanded |
[data-swipe-direction] | |
[data-swiping] | |
[data-dragging] | Present when in the dragging state |
[data-nested-drawer-open] | |
[data-nested-drawer-swiping] | |
[data-nested] | Present when the content is nested within another {{widget}} |
[data-has-nested] | Present when the content has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--drawer-translate | The drawer translate value for the Content |
--drawer-translate-x | The drawer translate x value for the Content |
--drawer-translate-y | The drawer translate y value for the Content |
--drawer-snap-point-offset-x | The offset position for drawer snap point |
--drawer-snap-point-offset-y | The offset position for drawer snap point |
--drawer-swipe-movement-x | The drawer swipe movement x value for the Content |
--drawer-swipe-movement-y | The drawer swipe movement y value for the Content |
--drawer-swipe-strength | The drawer swipe strength value for the Content |
--nested-drawers | The nested drawers value for the Content |
--drawer-height | The height of the Content |
--drawer-frontmost-height | The height of the Content |
--layer-index | The index of the dismissable in the layer stack |
--nested-layer-count | The number of nested drawers |
Description
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
GrabberIndicator
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Grabber
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
IndentBackground
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Indent
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Positioner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DrawerPositionerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-drawer-positioner] | <uid> |
[data-state] | "open" | "closed" |
[data-swipe-direction] | |
[data-nested] | Present when the positioner is nested within another {{widget}} |
[data-has-nested] | Present when the positioner has nested {{widget}}s |
RootProvider
| Prop | Default | Type |
|---|---|---|
value | UseDrawerReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
lazyMount | false | booleanWhether to enable lazy mounting |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
present | booleanWhether the node is present (controlled by the user) | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
unmountOnExit | false | booleanWhether to unmount on exit. |
SwipeArea
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DrawerSwipeAreaState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-drawer-swipe-area] | <uid> |
[data-state] | "open" | "closed" |
[data-swiping] | |
[data-swipe-direction] | |
[data-disabled] | Present when disabled |
Title
Defines the <h2> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Trigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DrawerTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe value that identifies this specific trigger |
| Attribute | Description |
|---|---|
[data-drawer-trigger] | <uid> |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-current] | Present when current |
Context
API
| Property | Type |
|---|---|
open | booleanWhether the drawer is open. |
modal | booleanWhether the drawer is modal. |
dragging | booleanWhether the drawer is currently being dragged. |
triggerValue | string | nullThe value of the active trigger. |
setTriggerValue | (value: string | null) => voidSet the active trigger value. |
setOpen | (open: boolean, reason?: OpenChangeReason) => voidFunction to open or close the menu. |
snapPoints | SnapPoint[]The snap points of the drawer. |
swipeDirection | SwipeDirectionThe swipe direction of the drawer. |
snapPoint | SnapPoint | nullThe currently active snap point. |
setSnapPoint | (snapPoint: SnapPoint | null) => voidFunction to set the active snap point. |
getOpenPercentage | () => numberGet the current open percentage of the drawer. |
getSnapPointIndex | () => numberGet the index of the currently active snap point. |
getContentSize | () => number | nullGet the current main-axis size of the drawer content. |
getPositionerState | () => PositionerStateReturns the state of the positioner |
getContentState | () => ContentStateReturns the state of the content |
getTriggerState | (props?: TriggerProps) => TriggerStateReturns the state of a specific trigger, including whether it's the currently active one |
getBackdropState | () => BackdropStateReturns the state of the backdrop |
getSwipeAreaState | (props?: SwipeAreaProps) => SwipeAreaStateReturns the state of the swipe area |
Accessibility
Complies with the Dialog WAI-ARIA design pattern.
| Key | Description |
|---|---|
Enter | When focus is on the trigger, opens the dialog. |
Tab | Moves focus to the next focusable element within the content. Focus is trapped within the dialog. |
Shift + Tab | Moves focus to the previous focusable element. Focus is trapped within the dialog. |
Esc | Closes the dialog and moves focus to trigger or the defined final focus element |