Drawer
A panel that slides in from a screen edge and dismisses with a swipe.
Usage guidelines
- Use
Drawerfor a side panel or bottom sheet that follows the drawer model: it slides in from an edge and the user can swipe it away. A centered modal task usesDialog. - Set
swipeDirectionto the edge the drawer dismisses toward. It defaults todownfor a bottom sheet;rightandleftmake full-height side panels, andDrawerPopupstyles each direction fromdata-swipe-direction. - Compose
DrawerPortal,DrawerBackdrop,DrawerViewportandDrawerPopupexplicitly. Put the panel's content inDrawerContent, which scrolls and lets mouse users select text without starting a swipe. - Every drawer has a
DrawerTitle, which names it. Add aDrawerDescriptionwhen a sentence of context helps. DrawerCloseis unstyled. Compose it withIconButtonand anaria-labelfor the corner close icon of a side panel, or withButtonfor a footer action. A bottom sheet with a handle needs no visible close icon; keep a visually hiddenDrawerCloseso screen reader users, who cannot swipe, still have a way out.- Use
DrawerTriggerunder the root for a dedicated button. Items of a list open one drawer at the list by passingpayload; a trigger outside the root connects throughcreateDrawerHandle, and controlledopenis for open state another owner must observe. - Set
modal={false}for a panel the user works beside, such as a detail view next to the page. Pair it withdisablePointerDismissalwhen clicks on the page should not close it.
Anatomy
DrawerSwipeArea, DrawerProvider, DrawerIndent, DrawerIndentBackground and DrawerVirtualKeyboardProvider add swipe-to-open, the indent effect and software keyboard handling from Base UI.
Examples
Bottom sheet
Without swipeDirection, the drawer is a bottom sheet that the user swipes down to dismiss. A decorative handle at the top hints at the gesture, so the visible close icon is dropped and a visually hidden DrawerClose remains for screen readers.
One drawer for a list of items
A list whose items open the same drawer renders one Drawer around the list. Each DrawerTrigger carries its item as payload, and the drawer reads the payload of the trigger that opened it.
- Run 8f2cToday, 09:41Succeeded
- Run 7a19Today, 09:12Failed
- Run 6d03Yesterday, 18:05Succeeded
Non-modal panel
With modal={false} and disablePointerDismissal, the page behind stays interactive and clicks on it leave the panel open. Without a backdrop, the viewport passes pointer events through to the page.
Keyboard
| Key | Action |
|---|---|
| EnterorSpace | Opens the drawer from a focused trigger. |
| TaborShift+Tab | Moves focus between the drawer's controls. Focus stays inside a modal drawer while it is open. |
| Escape | Closes the drawer and returns focus to the trigger. |
API reference
Drawer
Groups all parts of a swipeable drawer or bottom sheet. Doesn't render its own HTML element.
| Prop | Type | Default | Details |
|---|---|---|---|
open | boolean | No default | |
defaultOpen | boolean | false | |
modal | 'trap-focus' | boolean | true | |
onOpenChange | ((open: boolean, eventDetails: BaseDrawer.Root.ChangeEventDetails) => void) | No default | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
disablePointerDismissal | boolean | false | |
actionsRef | React.RefObject<DrawerRootActions | null> | No default | |
handle | BaseDrawer.Handle<Payload> | No default | |
triggerId | string | null | No default | |
defaultTriggerId | string | null | No default | |
children | PayloadChildRenderFunction<Payload> | React.ReactNode | No default | |
swipeDirection | 'down' | 'left' | 'right' | 'up' | 'down' | |
snapPoints | DrawerSnapPoint[] | No default | |
snapToSequentialPoints | boolean | false | |
snapPoint | DrawerSnapPoint | null | No default | |
defaultSnapPoint | DrawerSnapPoint | null | No default | |
onSnapPointChange | ((snapPoint: DrawerSnapPoint | null, eventDetails: BaseDrawer.Root.SnapPointChangeEventDetails) => void) | No default | |
DrawerBackdrop
An overlay displayed beneath the popup. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
forceRender | boolean | false | |
className | string | ((state: DrawerBackdropState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerBackdropState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerBackdropState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the drawer is open. |
data-closed | Present when the drawer is closed. |
data-starting-style | Present when the drawer begins animating in. |
data-ending-style | Present when the drawer is animating out. |
| Variable | Description |
|---|---|
--drawer-swipe-progress | Values: The swipe progress of the drawer gesture. |
DrawerClose
Closes the drawer when activated; unstyled so it can be composed via render with Button or IconButton. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerCloseState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerCloseState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerCloseState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-disabled | Whether the button is currently disabled. |
DrawerContent
A container for the drawer contents. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerContentState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerContentState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerContentState) => React.CSSProperties | undefined) | No default | |
DrawerDescription
A paragraph with additional information about the drawer. Renders a <p> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerDescriptionState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerDescriptionState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerDescriptionState) => React.CSSProperties | undefined) | No default | |
DrawerIndent
A wrapper element intended to contain your app's main UI. Applies data-active when any drawer within the nearest <Drawer.Provider> is open. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerIndentState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerIndentState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerIndentState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-active | Whether any drawer within the nearest |
DrawerIndentBackground
An element placed before <Drawer.Indent> to render a background layer that can be styled based on whether any drawer is open. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerIndentBackgroundState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerIndentBackgroundState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerIndentBackgroundState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-active | Whether any drawer within the nearest |
DrawerPopup
A container for the drawer contents. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
style | React.CSSProperties | ((state: DrawerPopupState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the drawer is open. |
data-closed | Present when the drawer is closed. |
data-starting-style | Present when the drawer begins animating in. |
data-ending-style | Present when the drawer is animating out. |
data-expanded | Present when the drawer is at the expanded (full-height) snap point. |
data-nested-drawer-open | Present when a nested drawer is open. |
data-nested-drawer-swiping | Present when a nested drawer is being swiped. |
data-swipe-dismiss | Present when the drawer is dismissed by swiping. |
data-swipe-direction | Values: Indicates the swipe direction. |
data-swiping | Present when the drawer is being swiped. |
| Variable | Description |
|---|---|
--nested-drawers | Values: The number of nested drawers that are currently open. |
--drawer-height | Values: The height of the drawer popup. |
--drawer-frontmost-height | Values: The height of the frontmost open drawer in the current nested drawer stack. |
--drawer-swipe-movement-x | Values: The swipe movement on the X axis. |
--drawer-swipe-movement-y | Values: The swipe movement on the Y axis. |
--drawer-snap-point-offset | Values: The snap point offset used for translating the drawer. |
--drawer-swipe-strength | Values: A scalar (0.1-1) used to scale the swipe release transition duration in CSS. |
DrawerPortal
A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
keepMounted | boolean | false | |
container | HTMLElement | React.RefObject<HTMLElement | ShadowRoot | null> | ShadowRoot | null | No default | |
className | string | ((state: DrawerPortalState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerPortalState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerPortalState) => React.CSSProperties | undefined) | No default | |
DrawerProvider
Provides a shared context for coordinating global Drawer UI, such as indent/background effects based on whether any Drawer is open. Doesn't render its own HTML element.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
DrawerSwipeArea
An invisible area that listens for swipe gestures to open the drawer. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
disabled | boolean | false | |
swipeDirection | 'down' | 'left' | 'right' | 'up' | No default | |
className | string | ((state: DrawerSwipeAreaState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerSwipeAreaState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerSwipeAreaState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the drawer is open. |
data-closed | Present when the drawer is closed. |
data-disabled | Present when the swipe area is disabled. |
data-swipe-direction | Values: Indicates the swipe direction. |
data-swiping | Present when the drawer is being swiped. |
DrawerTitle
A heading that labels the drawer. Renders an <h2> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerTitleState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerTitleState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerTitleState) => React.CSSProperties | undefined) | No default | |
DrawerTrigger
A button that opens the drawer. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
handle | BaseDrawer.Handle<Payload> | No default | |
payload | Payload | No default | |
id | string | No default | |
className | string | ((state: DrawerTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerTriggerState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-disabled | Whether the trigger is currently disabled. |
data-open | Whether the drawer is currently open and was opened by this trigger. |
DrawerViewport
A positioning container for the drawer popup that can be made scrollable. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DrawerViewportState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DrawerViewportState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DrawerViewportState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the drawer is open. |
data-closed | Present when the drawer is closed. |
data-starting-style | Present when the drawer begins animating in. |
data-ending-style | Present when the drawer is animating out. |
data-nested | Present when the drawer is nested within another drawer. |
| Variable | Description |
|---|---|
--drawer-keyboard-inset | Values: The software keyboard inset, measured from the bottom edge of the layout viewport. Present only when the drawer is wrapped in |
DrawerVirtualKeyboardProvider
Provides keyboard-aware focus and scroll handling for bottom-sheet drawers with form fields.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
createDrawerHandle
Creates a new handle to connect a Drawer.Root with detached Drawer.Trigger components.
Returns
BaseDrawer.Handle<Payload>| Member | Type | Description |
|---|---|---|
open required | (triggerId: string | null) => void | Opens the dialog, optionally associating it with a trigger. This method should only be called in an event handler or an effect (not during rendering). |
openWithPayload required | (payload: Payload) => void | Opens the dialog with the given payload, without associating it with any trigger. This method should only be called in an event handler or an effect (not during rendering). |
close required | () => void | Closes the dialog. This method should only be called in an event handler or an effect (not during rendering). |
isOpen required | boolean | Whether the dialog is currently open. Returns |