Skip to content

Drawer

A panel that slides in from a screen edge and dismisses with a swipe.

hero.tsx

Usage guidelines

  • Use Drawer for 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 uses Dialog.
  • Set swipeDirection to the edge the drawer dismisses toward. It defaults to down for a bottom sheet; right and left make full-height side panels, and DrawerPopup styles each direction from data-swipe-direction.
  • Compose DrawerPortal, DrawerBackdrop, DrawerViewport and DrawerPopup explicitly. Put the panel's content in DrawerContent, which scrolls and lets mouse users select text without starting a swipe.
  • Every drawer has a DrawerTitle, which names it. Add a DrawerDescription when a sentence of context helps.
  • DrawerClose is unstyled. Compose it with IconButton and an aria-label for the corner close icon of a side panel, or with Button for a footer action. A bottom sheet with a handle needs no visible close icon; keep a visually hidden DrawerClose so screen reader users, who cannot swipe, still have a way out.
  • Use DrawerTrigger under the root for a dedicated button. Items of a list open one drawer at the list by passing payload; a trigger outside the root connects through createDrawerHandle, and controlled open is 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 with disablePointerDismissal when clicks on the page should not close it.

Anatomy

tsx
tsx

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.

bottom-sheet.tsx

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:41
    Succeeded
  • Run 7a19Today, 09:12
    Failed
  • Run 6d03Yesterday, 18:05
    Succeeded
payload.tsx

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.

non-modal.tsx

Keyboard

KeyAction
EnterorSpaceOpens the drawer from a focused trigger.
TaborShift+TabMoves focus between the drawer's controls. Focus stays inside a modal drawer while it is open.
EscapeCloses 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.

Base UI Drawer.Root docs

DrawerBackdrop

An overlay displayed beneath the popup. Renders a <div> element.

Base UI Drawer.Backdrop docs

Data attributes
AttributeDescription
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.

CSS variables
VariableDescription
--drawer-swipe-progress

Values: number

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.

Base UI Drawer.Close docs

Data attributes
AttributeDescription
data-disabled

Whether the button is currently disabled.

DrawerContent

A container for the drawer contents. Renders a <div> element.

Base UI Drawer.Content docs

DrawerDescription

A paragraph with additional information about the drawer. Renders a <p> element.

Base UI Drawer.Description docs

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.

Base UI Drawer.Indent docs

Data attributes
AttributeDescription
data-active

Whether any drawer within the nearest <Drawer.Provider> is open.

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.

Base UI Drawer.IndentBackground docs

Data attributes
AttributeDescription
data-active

Whether any drawer within the nearest <Drawer.Provider> is open.

DrawerPopup

A container for the drawer contents. Renders a <div> element.

Base UI Drawer.Popup docs

Data attributes
AttributeDescription
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: 'up' | 'down' | 'left' | 'right'

Indicates the swipe direction.

data-swiping

Present when the drawer is being swiped.

CSS variables
VariableDescription
--nested-drawers

Values: number

The number of nested drawers that are currently open.

--drawer-height

Values: CSS length

The height of the drawer popup.

--drawer-frontmost-height

Values: CSS length

The height of the frontmost open drawer in the current nested drawer stack.

--drawer-swipe-movement-x

Values: CSS length

The swipe movement on the X axis.

--drawer-swipe-movement-y

Values: CSS length

The swipe movement on the Y axis.

--drawer-snap-point-offset

Values: CSS length

The snap point offset used for translating the drawer.

--drawer-swipe-strength

Values: number

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.

Base UI Drawer.Portal docs

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.

Base UI Drawer.Provider docs

DrawerSwipeArea

An invisible area that listens for swipe gestures to open the drawer. Renders a <div> element.

Base UI Drawer.SwipeArea docs

Data attributes
AttributeDescription
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: 'up' | 'down' | 'left' | 'right'

Indicates the swipe direction.

data-swiping

Present when the drawer is being swiped.

DrawerTitle

A heading that labels the drawer. Renders an <h2> element.

Base UI Drawer.Title docs

DrawerTrigger

A button that opens the drawer. Renders a <button> element.

Base UI Drawer.Trigger docs

Data attributes
AttributeDescription
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.

Base UI Drawer.Viewport docs

Data attributes
AttributeDescription
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.

CSS variables
VariableDescription
--drawer-keyboard-inset

Values: CSS length

The software keyboard inset, measured from the bottom edge of the layout viewport. Present only when the drawer is wrapped in Drawer.VirtualKeyboardProvider.

DrawerVirtualKeyboardProvider

Provides keyboard-aware focus and scroll handling for bottom-sheet drawers with form fields.

Base UI Drawer.VirtualKeyboardProvider docs

createDrawerHandle

Creates a new handle to connect a Drawer.Root with detached Drawer.Trigger components.

Returns

BaseDrawer.Handle<Payload>
Return properties
MemberTypeDescription
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 requiredboolean

Whether the dialog is currently open. Returns false while no root is attached to the handle.