Skip to content
Slotted

Drawer

A panel that comes in from an edge of the screen, over the page or beside it, for the details of a record, a form or a set of filters the reader opens without leaving their place.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Drawer, DrawerActions, DrawerBody, DrawerClose,  DrawerDefaultsProvider, DrawerDescription, DrawerFooter, DrawerHeader,  DrawerPanel, DrawerResizer, DrawerTitle, DrawerTrigger } from '@slotted/react';

Sides

side picks the edge the panel comes from: end (the default) for the details of a row, start for navigation, top for a notice about the whole screen, and bottom for a sheet on a phone. start and end are logical, so the drawer changes sides in a right-to-left document.

Sizes

size sets the panel’s width on start and end to one of five steps: sm (18rem) for one field or a short list, md (24rem, the default) for the details of a record, lg (30rem) for a record with a table, xl (40rem) for two columns, and full for the whole screen. A step wider than the screen is held to the screen’s width. Set --slotted-drawer-extent on the drawer for a width the steps do not hold.

Bottom sheet

On top and bottom the drawer is as tall as its content, up to 4rem short of the screen, and on a wide screen it is at most 40rem wide and centerd. DrawerResizer (slDrawerResizer) draws the grip above the header. On a touch screen the reader can drag the sheet from anywhere on its body; a drag released near the bottom edge, or a fast flick downwards, closes it.

Pickup: Thursday 8 October, 8 AM to noon

Snap points

snapPoints lists the heights a sheet stops at, as fractions of the screen. On top and bottom the height of the content is a stop as well. A drag is released onto the nearest stop, the arrow keys on the grip move to the next stop, and Home and End move to the first and the last. Start the sheet on a stop with defaultExtent in React or [(extent)] in Angular.

Resizing

DrawerResizer (slDrawerResizer) on the panel’s inner edge lets the reader set the width: drag it, or focus it and use the arrow keys, 16 pixels at a time and 64 with Shift. Home and End go to minExtent and maxExtent, Enter collapses the panel to its minimum and restores it, and a double click returns it to its size step. The width is a fraction of the screen: onExtentChange in React and [(extent)] in Angular report it, and undefined means the size step decides.

Non-modal

modal={false} leaves the page behind interactive: nothing is made inert, the page scroll is not locked, focus can leave the panel, and the panel has no aria-modal. The scrim still covers the page and still takes a pointer press, so add scrimFrom={1} to remove it and outsidePress="none" so working on the page does not close the drawer. Here the reader types a rate from the drawer into the field behind it.

Charged to Contoso Foods on invoice INV-2041.

Beside the page

mode="inline" puts the drawer in your own layout instead of over the page: no portal, no scrim, no focus trap, and the panel writes no role. Opening and closing animates the drawer’s own width, so the content beside it reflows through your own layout; here a wrapping flex row, which puts the list under the panel on a narrow screen. The drawer takes no focus when it opens: focus stays on the trigger, which shows and hides the panel.

Status
3 of 5 orders
SO-1182Contoso Foods
Processing
SO-1184Tailspin Market
On hold
SO-1185Adventure Works
Processing

Switching between overlay and inline

mode can change while the drawer is open, for example at your own breakpoint or from a pin button. The panel’s content is kept across the switch, so a half-written note survives it. Type a note, pin the drawer beside the order, then unpin it.

Customer
Contoso Foods, Seattle
Items
14 cases, 3 products
Warehouse
Reno, NV

Long content

The body is the only row that scrolls. The header and the footer stay in place, so the actions are always in reach.

A form in a drawer

Put the form in the body and point the footer’s submit button at it with the form attribute, so the actions stay in the footer row. Validate on submit, show each error in its field, and close the drawer only when the data is valid. Copy the saved values into the form when the drawer opens, so Cancel discards the edits.

Contoso Foods, ap@contoso.com, Net 30

Refusing a close with unsaved changes

Every way of closing, from the ✕, Escape, a press outside or the browser’s back gesture, goes through one request: onOpenChange in React and (openChangeRequest) in Angular. Call request.cancel() to keep the drawer open. Here an edited instruction keeps the drawer open and asks in the footer whether to discard the change. Edit the text, then press Escape.

Loading content

loading marks the body as busy with aria-busy while the header, the ✕ and Escape stay available. Fill the body with skeletons in the shape of the content that is coming, so nothing moves when it arrives.

A drawer over a drawer

A drawer opened from inside another stacks above it. Escape and a press outside close only the top one, and focus returns to the button in the drawer below.

Defaults for a section

DrawerDefaultsProvider in React and provideDrawerDefaults in Angular set mode, side, size, mount, modal, escape, outsidePress, back and drag once for every drawer under them. A value set on one drawer still wins.

Order details beside a table

A non-modal drawer shows the record of the row the reader chose and leaves the table usable. The drawer has no trigger: each row’s button sets the order and opens it, and choosing another row while it is open replaces the content in place.

OrderCustomerTotalActions
SO-1182Contoso Foods$1,240.00
SO-1183Fabrikam Grocers$386.50
SO-1184Tailspin Market$2,075.25
SO-1185Adventure Works$918.00

Filtering a list

The filters are a draft while the drawer is open. The apply button shows how many orders the draft matches, Reset returns the draft to every order, and closing the drawer any other way leaves the applied filters as they were.

8 of 8 orders

Accessibility

KeyEffectFocus
Tabmoves to the next tabbable element inside the panel, and wraps from the last to the first while modalthe next tabbable element inside the panel
Shift+Tabmoves to the previous tabbable element inside the panel, and wraps from the first to the last while modalthe previous tabbable element inside the panel
Escapeasks the topmost layer to close, carrying the reason escape; a layer that refuses stops the request reaching the layer beneath it, so one Escape never closes tworeturns to the element that held it when the drawer opened
ArrowLefton the resizer, moves the separator sixteen pixels, or sixty-four with Shift, to the left of the screen, which grows an end panel in a left-to-right document and shrinks it in a mirrored one; with snap points it moves to the adjacent stopstays on the resizer
ArrowRighton the resizer, moves the separator sixteen pixels, or sixty-four with Shift, to the right of the screen; with snap points it moves to the adjacent stopstays on the resizer
ArrowUpon the resizer, moves the separator sixteen pixels, or sixty-four with Shift, up the screen, which grows a bottom panel and shrinks a top one; with snap points it moves to the adjacent stopstays on the resizer
ArrowDownon the resizer, moves the separator sixteen pixels, or sixty-four with Shift, down the screen; with snap points it moves to the adjacent stopstays on the resizer
Homeon the resizer, gives the panel its smallest allowed extentstays on the resizer
Endon the resizer, gives the panel its largest allowed extentstays on the resizer
Enteron the resizer, collapses the panel to its smallest allowed extent, and from there restores the extent it left. It does not close the drawer, because Escape already means that and a reader pressing Enter on a separator expects the separator to still be therestays on the resizer
  • Under mode="overlay" the drawer follows the WAI-ARIA dialog (modal) pattern. While it is modal, Tab and Shift+Tab move through the panel and wrap at its ends. Escape closes it, and reaches only the topmost layer, so one press never closes two drawers.
  • Under mode="inline" the panel has no role, because a navigation drawer is a navigation landmark and a filter panel is complementary; give it one with render. The trigger has no aria-haspopup there, because an inline drawer is a disclosure, not a popup.
  • aria-modal="true" is written only while the drawer is modal, which is the only state in which the page behind is inert. modal is always false under mode="inline".
  • The separator follows the WAI-ARIA window splitter pattern. The arrow keys move it in the direction they point, Home and End go to the limits, and Enter collapses the panel to its minimum and then restores it. Enter never closes the drawer; Escape does. The values are percentages, and there is no aria-valuetext, so a screen reader announces 40 rather than 40 per cent.
  • A bottom sheet moves under a touch on its body as well as on its separator, and every stop a finger reaches, the height of the content among them, is also reachable with the arrow keys on the separator. It is moved by the page’s own scroll, so a control whose touch-action takes vertical movement keeps its gesture, and a scrolling region at its edge — a message list at its top — passes the pull on to the sheet, unless it sits inside data-drawer-drag="none".
  • A closed panel is inert in both modes, so its controls are in neither the tab order nor the accessibility tree.
  • Focus moves into an overlay panel when it opens, to the first focusable element unless initialFocus names another, and returns on close to the element that had it before; if that element has left the document, focus goes to its nearest ancestor still in it. An inline drawer moves no focus when it opens, and on close restores focus only when focus is inside the panel or on the page body.
  • The ✕ button and the separator are each at least --slotted-target-min across, so both meet the WCAG 2.2 minimum target size of 24 by 24 pixels.

API

Drawer

Props

openboolean
Whether the drawer is open, when you own the state. Update it from onOpenChange.
defaultOpenboolean
Whether an uncontrolled drawer starts open. It is read once, on mount.
extentnumber
The panel’s measure, when you own it: a fraction from 0 to 1 of the screen, or of your layout under mode="inline". undefined means the size step decides. Update it from onExtentChange.
defaultExtentnumber
The measure an uncontrolled drawer starts at. It is read once, on mount.
minExtentnumberDefault 0.2
The smallest measure the reader can set, and the separator’s aria-valuemin. A drag released below it asks to close the drawer, with the reason pointer.
maxExtentnumberDefault 1
The largest measure the reader can set, and the separator’s aria-valuemax. With snap points, both limits default to the first and the last stop.
snapPointsreadonly number[]
The stops the measure moves between, as fractions. With them an arrow key moves to the next stop, Home and End go to the first and the last, and a drag is released onto the nearest.
mode'overlay' | 'inline'Default overlay
On Drawer, DrawerDefaultsProvideroverlay puts the drawer over the page, in a portal; inline puts it in your own layout. The value can change while the drawer is open, and the panel’s content and the state of its fields are kept across the change.
side'start' | 'end' | 'top' | 'bottom'Default end
On Drawer, DrawerDefaultsProviderThe edge the panel comes from. start and end follow the writing direction, so the drawer changes sides in a right-to-left document.
size'sm' | 'md' | 'lg' | 'xl' | 'full' | 'content'Default content on top and bottom, md on start and end
On Drawer, DrawerDefaultsProviderThe panel’s measure at rest: one of the steps sm (18rem), md (24rem), lg (30rem), xl (40rem) and full, or content, which fits what the panel holds, up to 4rem short of the screen. A step wider than the screen is held to it. On a bottom sheet, full is the screen’s height and the footer rests at its bottom.
mount'active' | 'lazy' | 'eager'Default active
On Drawer, DrawerDefaultsProviderWhen an overlay layer is in the document: active only while it is open or closing, lazy from the first open on, and eager from the start, inert while closed. An inline drawer is always in the document.
modalbooleanDefault true
On Drawer, DrawerDefaultsProviderWhether the page behind is inert, its scroll is locked and focus is contained in the panel, and whether the panel carries aria-modal. The scrim is painted either way. Always false under mode="inline".
escape'close' | 'none'Default close
On Drawer, DrawerDefaultsProviderWhether Escape asks to close the drawer. Escape reaches only the topmost layer, and a layer that refuses it does not pass it to the one below.
outsidePress'close' | 'none'Default close
On Drawer, DrawerDefaultsProviderWhether a press outside the layer, the scrim included, asks to close the drawer. It has no effect under mode="inline".
back'close' | 'none'Default close
On Drawer, DrawerDefaultsProviderWhether the browser’s back button or a phone’s back gesture closes a modal drawer instead of leaving the page. The drawer holds one close watcher while it is open where the browser has CloseWatcher, and one history entry elsewhere; a drawer opened without a press shares the way back with the layer opened before it. It has no effect under mode="inline".
drag'panel' | 'resizer'Default panel
On Drawer, DrawerDefaultsProviderWhat a touch moves a bottom sheet by: panel, anywhere on the panel, the sheet and its content scrolling as one; or resizer, the separator only, the body scrolling on its own at the highest stop. A mouse drags the separator, and the sheet settles on the nearest stop.
scrimFromnumberDefault 0
While the measure is below this fraction, the scrim is not painted, a press reaches the page, and the root carries data-undimmed. Use it with modal={false} and outsidePress="none".
loadingbooleanDefault false
Marks the body as busy with aria-busy and gives it a minimum height, so the panel does not jump when the content arrives. The header, the ✕, Escape and the separator stay available.
messagesPartial<DrawerMessages>
Words laid over the current language, key by key: close, the name of the ✕. An aria-label on DrawerClose takes precedence.
initialFocus'first' | 'container' | RefObject | falseDefault first
Where focus goes when an overlay drawer opens: first, the first focusable element; container, the panel itself, for content that is read before it is used; a ref; or false, nowhere. An inline drawer moves no focus.
finalFocusRefObject | false
Where focus goes when the drawer closes, as a ref, or false for nowhere. When unset, it returns to the element that had focus when the drawer opened, usually the trigger.
inset'none'
On DrawerBodynone removes the body’s padding, for content that brings its own inset, such as a page or a list that runs to the panel’s edges.
stepnumberDefault 16
On DrawerResizerHow far one arrow key moves the separator, in pixels, when there are no snap points.
largeStepnumberDefault 64
On DrawerResizerHow far Shift and an arrow key move the separator, in pixels, when there are no snap points.
valuestring
On DrawerCloseThe result of a close from this button, carried on the close request as result.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: DrawerChangeRequest)Before the drawer opens or closes, for every way it can: the trigger, the ✕, Escape, a press outside, the back gesture and the handle. The request carries value, previous, reason (pointer, keyboard, dismiss, escape, outsidePress, back or programmatic), result, the source event and cancel(), which keeps the drawer as it is.
onOpenChangeComplete(open: boolean)After the entrance or the exit has ended: true once the drawer is settled open, false once it has left — the moment an application that renders the drawer conditionally removes it, so the exit runs. A drawer mounted open enters from its closed style, as one opened later does.
onExtentChange(extent: number | undefined, request: DrawerExtentRequest)Before the panel’s measure changes, with the reason pointer for a drag or a tap on the grip, keyboard for an arrow key, Home, End or Enter, and programmatic for a change from code. A drag of the separator fires on every pointer move and can report a value below minExtent; a bottom sheet fires once its scroll comes to rest, with the stop it rests on. undefined means the panel is back on its size step, or on the height of its content under size="content".
onClick, onKeyDown, onPointerDown, on every partthe element’s own eventsWhenever the element fires them. Your handler runs first, and preventDefault() in it cancels the drawer’s own behavior for that event.

Composition

render(props) => ReactNode
On every partReplaces the element a part renders and passes it every attribute the drawer wrote. On DrawerPanel it replaces the panel, not the layer, which is how an inline drawer becomes a nav or an aside.
refRef<DrawerHandle> on Drawer, Ref<HTMLElement> on every part
On Drawer, every partOn a part, the element. On Drawer, a handle with open(), close(result), focus() and panel, the panel element once it is in the document.
containerElement | null
An element to portal this layer into instead of the shared portal root, for an application shell with its own stacking context. setPortalContainer from @slotted/core/portal sets one for the whole document.
useDrawer()() => DrawerContextValue
On inside DrawerReads the drawer inside Drawer: whether it is open, the measure, the ids, the resolved axes and close(reason, result). It throws outside a drawer.
DrawerDefaultsProvider{ mode, side, size, mount, modal, escape, outsidePress, back, drag }
On a subtreeSets these nine axes for every drawer under it. A value set on one drawer still wins.

Parts

PartElementRequiredPurpose
rootdiv, in a portal under mode="overlay"YesThe layer. Under mode="overlay" it is fixed to the viewport and stacked above the page; under mode="inline" it is a box in your own layout, and its own width or height is what opens and closes. It carries data-ui="drawer", every axis as a data attribute, and data-open, data-loading and data-dragging.
triggerbutton, or the element render returnsNoThe control that opens and closes the drawer, rendered where it is written. It carries aria-expanded and aria-controls in both modes, and aria-haspopup="dialog" only under mode="overlay", because an inline drawer is a disclosure. A press on it is never read as a press outside the drawer.
backdropdivNoThe scrim behind the panel, painted from --slotted-drawer-scrim under mode="overlay" whether the drawer is modal or not, and not painted while the measure is below scrimFrom. It takes a press like the page would, so a press on it is a press outside the drawer. Set --slotted-drawer-scrim: transparent to paint none.
paneldiv, or the element render returnsYesThe surface, aligned to side. Under mode="overlay" it carries role="dialog", and aria-modal="true" while modal; under mode="inline" it has no role, so use render to make it a nav or an aside. Its rows are the header, the body and the footer, and only the body scrolls.
resizerdiv with role="separator"NoThe separator the reader drags, or focuses and moves with the keyboard, to resize the panel. Rendering it is what makes the drawer resizable. It carries role="separator", tabindex="0", aria-orientation, aria-valuenow, aria-valuemin and aria-valuemax as percentages, aria-controls naming the panel and aria-labelledby naming the title. On start and end it sits on the panel’s inner edge; on top and bottom it is the grip above the header.
linespanYesA hairline on each side of the grip on start and end, which runs the whole edge under the pointer, under focus and during a drag. It is not drawn on top and bottom.
gripspan[aria-hidden]YesThe mark the pointer aims at: a dot grid on start and end, and a pill above the header on top and bottom. It is hidden from assistive technology, because the separator around it is already named and valued.
headerheader, or the element render returnsNoLays out the title and the description in one column, the actions in a second when they are rendered, and the close button in the last, so a title that wraps grows the row instead of moving the buttons.
actionsdiv, or the element render returnsNoOne or two actions beside the title, such as icon buttons for history and a new conversation, on the title’s row between the title and the close button. The buttons keep the size you give them.
titleh2, or the element render returnsNoThe visible name of the drawer. The panel and the separator point at it with aria-labelledby, and only while it is rendered.
descriptionp, or the element render returnsNoThe sentence under the title. The panel points at it with aria-describedby while it is rendered.
bodydiv, or the element render returnsNoThe row that scrolls, and the row that carries aria-busy while loading is set. A wheel that reaches its end does not scroll the page behind. inset="none" removes its padding, for content that brings its own, such as a list that runs to the panel’s edges.
footerfooter, or the element render returnsNoThe actions, in a wrapping row aligned to the end, on a sunken surface with a rule above it.
closebuttonNoThe ✕ button. Its target is at least --slotted-target-min in both directions. It closes the drawer with the reason dismiss, and its value is the result of that close.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every drawer inside it.

Drawer tokens

TokenDefault
--slotted-drawer-backdrop-filternone
--slotted-drawer-body-colorvar(--slotted-text, CanvasText)
--slotted-drawer-border-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-drawer-close-active-backgroundvar(--slotted-tone-secondary-subtle-active)
--slotted-drawer-close-colorvar(--slotted-text-muted, GrayText)
--slotted-drawer-close-hover-backgroundvar(--slotted-tone-secondary-subtle-hover)
--slotted-drawer-colorvar(--slotted-text, CanvasText)
--slotted-drawer-description-colorvar(--slotted-text-muted, GrayText)
--slotted-drawer-extentvar(--_step)
--slotted-drawer-extent-lg30rem
--slotted-drawer-extent-md24rem
--slotted-drawer-extent-sm18rem
--slotted-drawer-extent-xl40rem
--slotted-drawer-footer-backdrop-filternone
--slotted-drawer-footer-surfacevar(--slotted-surface-sunken, Canvas)
--slotted-drawer-header-backdrop-filternone
--slotted-drawer-header-surfacevar(--slotted-drawer-surface, var(--slotted-surface-raised, Canvas))
--slotted-drawer-radiusvar(--_radius)
--slotted-drawer-radius-expanded0px
--slotted-drawer-resizer-line-active-colorvar(--slotted-text-muted, ButtonText)
--slotted-drawer-resizer-line-colorvar(--slotted-border-strong, ButtonBorder)
--slotted-drawer-rule-colorvar(--slotted-border-subtle, ButtonBorder)
--slotted-drawer-scrimvar(--slotted-scrim, Canvas)
--slotted-drawer-scrim-backdrop-filternone
--slotted-drawer-sheet-dim1
--slotted-drawer-sheet-floor100%
--slotted-drawer-sheet-height0px
--slotted-drawer-sheet-inline-sizevar(--slotted-drawer-extent-xl, 40rem)
--slotted-drawer-sheet-travel0px
--slotted-drawer-slide-durationvar(--slotted-duration-long)
--slotted-drawer-slide-easingvar(--slotted-easing-standard)
--slotted-drawer-slide-exit-durationvar(--slotted-duration-medium)
--slotted-drawer-slide-exit-easingvar(--slotted-easing-exit)
--slotted-drawer-surfacevar(--slotted-surface-raised, Canvas)
--slotted-drawer-title-colorvar(--slotted-text, CanvasText)
--slotted-drawer-title-font-familyvar( --slotted-font-family-heading, var(--slotted-font-family-sans, ui-sans-serif, system-ui, sans-serif) )

Theme tokens it reads

TokenDefault
--slotted-action-gapcomfortable 8px · compact 6px · dense 4px
--slotted-border-strongSet per scheme by the theme
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thick2px
--slotted-border-width-thin1px
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-icon-size-mdcomfortable 16px · compact 14px · dense 13px
--slotted-control-inner-size-mdcomfortable 24px · compact 20px · dense 18px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-duration-instant1ms
--slotted-duration-long320ms
--slotted-duration-medium200ms
--slotted-duration-short120ms
--slotted-easing-entercubic-bezier(0.05, 0.7, 0.1, 1)
--slotted-easing-exitcubic-bezier(0.3, 0, 0.8, 0.15)
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-headingvar(--slotted-font-family-sans)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-size-lg1rem
--slotted-font-size-md0.875rem
--slotted-font-size-xl1.125rem
--slotted-font-weight-semibold600
--slotted-line-height-lg1.5
--slotted-line-height-md1.5
--slotted-radius-full9999px
--slotted-radius-lg8px
--slotted-radius-sm4px
--slotted-scrimSet per scheme by the theme
--slotted-shadow-lgSet per scheme by the theme
--slotted-space-113rem
--slotted-space-124rem
--slotted-space-20.25rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-space-71.25rem
--slotted-space-81.5rem
--slotted-space-92rem
--slotted-surface-raisedSet per scheme by the theme
--slotted-surface-sunkenSet per scheme by the theme
--slotted-target-comfortable44px
--slotted-target-min24px
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme
--slotted-z-index-overlay1000