<!-- index: /slotted/llms.txt -->
# drawer

`data-ui="drawer"` · Panel that slides in from an edge.

## Import

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

## Minimal example

Example

```tsx
import { useState } from 'react';

import { Badge } from '@slotted/react/badge';
import { Button } from '@slotted/react/button';
import {
  DescriptionList,
  DescriptionListDescription,
  DescriptionListItem,
  DescriptionListTerm,
} from '@slotted/react/description-list';
import {
  Drawer,
  DrawerBody,
  DrawerClose,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerPanel,
  DrawerTitle,
  DrawerTrigger,
} from '@slotted/react/drawer';
import { Inline } from '@slotted/react/inline';
import { Stack } from '@slotted/react/stack';

const DETAILS = [
  { term: 'Ship to', value: '1200 Harbor Ave, Seattle, WA' },
  { term: 'Payment', value: 'Captured, card ending 4242' },
  { term: 'Items', value: '14 cases, 3 products' },
  { term: 'Warehouse', value: 'Reno, NV' },
  { term: 'Total', value: '$1,240.00' },
];

export default function DrawerBasic() {
  const [open, setOpen] = useState(false);

  return (
    <Drawer open={open} onOpenChange={setOpen}>
      <DrawerTrigger
        render={(props) => (
          <Button {...props} tone="secondary" variant="outline">
            View order SO-1182
          </Button>
        )}
      />
      <DrawerPanel>
        <DrawerHeader>
          <DrawerTitle>Order SO-1182</DrawerTitle>
          <DrawerDescription>Contoso Foods, placed on 2 October 2026.</DrawerDescription>
          <DrawerClose />
        </DrawerHeader>
        <DrawerBody>
          <Stack gap={4}>
            <Inline>
              <Badge tone="accent">Ready to ship</Badge>
            </Inline>
            <DescriptionList>
              {DETAILS.map((detail) => (
                <DescriptionListItem key={detail.term}>
                  <DescriptionListTerm>{detail.term}</DescriptionListTerm>
                  <DescriptionListDescription>{detail.value}</DescriptionListDescription>
                </DescriptionListItem>
              ))}
            </DescriptionList>
          </Stack>
        </DrawerBody>
        <DrawerFooter>
          <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}>
            Close
          </Button>
          <Button onClick={() => setOpen(false)}>Create shipment</Button>
        </DrawerFooter>
      </DrawerPanel>
    </Drawer>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, in a portal under mode="overlay" | yes |
| `trigger` | button, or the element render returns | no |
| `backdrop` | div | no |
| `panel` | div, or the element render returns | yes |
| `resizer` | div with role="separator" | no |
| `line` | span | yes |
| `grip` | span[aria-hidden] | yes |
| `header` | header, or the element render returns | no |
| `actions` | div, or the element render returns | no |
| `title` | h2, or the element render returns | no |
| `description` | p, or the element render returns | no |
| `body` | div, or the element render returns | no |
| `footer` | footer, or the element render returns | no |
| `close` | button | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | — | Drawer | Whether the drawer is open, when you own the state. Update it from onOpenChange. |
| `defaultOpen` | `boolean` | — | Drawer | Whether an uncontrolled drawer starts open. It is read once, on mount. |
| `extent` | `number` | — | Drawer | 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. |
| `defaultExtent` | `number` | — | Drawer | The measure an uncontrolled drawer starts at. It is read once, on mount. |
| `minExtent` | `number` | 0.2 | Drawer | 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. |
| `maxExtent` | `number` | 1 | Drawer | 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. |
| `snapPoints` | `readonly number[]` | — | Drawer | 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'` | overlay | Drawer, DrawerDefaultsProvider | overlay 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'` | end | Drawer, DrawerDefaultsProvider | The 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'` | content on top and bottom, md on start and end | Drawer, DrawerDefaultsProvider | The 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'` | active | Drawer, DrawerDefaultsProvider | When 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. |
| `modal` | `boolean` | true | Drawer, DrawerDefaultsProvider | Whether 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'` | close | Drawer, DrawerDefaultsProvider | Whether 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'` | close | Drawer, DrawerDefaultsProvider | Whether a press outside the layer, the scrim included, asks to close the drawer. It has no effect under mode="inline". |
| `back` | `'close' \| 'none'` | close | Drawer, DrawerDefaultsProvider | Whether 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'` | panel | Drawer, DrawerDefaultsProvider | What 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. |
| `scrimFrom` | `number` | 0 | Drawer | 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". |
| `loading` | `boolean` | false | Drawer | 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. |
| `messages` | `Partial<DrawerMessages>` | — | Drawer | 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 \| false` | first | Drawer | 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. |
| `finalFocus` | `RefObject \| false` | — | Drawer | 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'` | — | DrawerBody | none 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. |
| `step` | `number` | 16 | DrawerResizer | How far one arrow key moves the separator, in pixels, when there are no snap points. |
| `largeStep` | `number` | 64 | DrawerResizer | How far Shift and an arrow key move the separator, in pixels, when there are no snap points. |
| `value` | `string` | — | DrawerClose | The result of a close from this button, carried on the close request as result. |
| `render` | `(props) => ReactNode` | — | every part | Replaces 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. |
| `ref` | `Ref<DrawerHandle> on Drawer, Ref<HTMLElement> on every part` | — | Drawer, every part | On a part, the element. On Drawer, a handle with open(), close(result), focus() and panel, the panel element once it is in the document. |
| `container` | `Element \| null` | — | Drawer | 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` | — | inside Drawer | Reads 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 }` | — | a subtree | Sets these nine axes for every drawer under it. A value set on one drawer still wins. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `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 part` | `the element’s own events` | Whenever the element fires them. Your handler runs first, and preventDefault() in it cancels the drawer’s own behavior for that event. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `mode` | `overlay`, `inline` | `overlay` |
| `side` | `start`, `end`, `top`, `bottom` | `end` |
| `size` | `sm`, `md`, `lg`, `xl`, `full`, `content` | content on top and bottom, md on start and end |
| `mount` | `active`, `lazy`, `eager` | `active` |
| `modal` | `true`, `false` | `true` |
| `escape` | `close`, `none` | `close` |
| `outsidePress` | `close`, `none` | `close` |
| `back` | `close`, `none` | `close` |
| `drag` | `panel`, `resizer` | `panel` |

## Rules

- 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.

## Tokens

`--slotted-action-gap`, `--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thick`, `--slotted-border-width-thin`, `--slotted-control-font-family`, `--slotted-control-icon-size-md`, `--slotted-control-inner-size-md`, `--slotted-control-radius`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-drawer-backdrop-filter`, `--slotted-drawer-body-color`, `--slotted-drawer-border-color`, `--slotted-drawer-close-active-background`, `--slotted-drawer-close-color`, `--slotted-drawer-close-hover-background`, `--slotted-drawer-color`, `--slotted-drawer-description-color`, `--slotted-drawer-extent`, `--slotted-drawer-extent-lg`, `--slotted-drawer-extent-md`, `--slotted-drawer-extent-sm`, `--slotted-drawer-extent-xl`, `--slotted-drawer-footer-backdrop-filter`, `--slotted-drawer-footer-surface`, `--slotted-drawer-header-backdrop-filter`, `--slotted-drawer-header-surface`, `--slotted-drawer-radius`, `--slotted-drawer-radius-expanded`, `--slotted-drawer-resizer-line-active-color`, `--slotted-drawer-resizer-line-color`, `--slotted-drawer-rule-color`, `--slotted-drawer-scrim`, `--slotted-drawer-scrim-backdrop-filter`, `--slotted-drawer-sheet-dim`, `--slotted-drawer-sheet-floor`, `--slotted-drawer-sheet-height`, `--slotted-drawer-sheet-inline-size`, `--slotted-drawer-sheet-travel`, `--slotted-drawer-slide-duration`, `--slotted-drawer-slide-easing`, `--slotted-drawer-slide-exit-duration`, `--slotted-drawer-slide-exit-easing`, `--slotted-drawer-surface`, `--slotted-drawer-title-color`, `--slotted-drawer-title-font-family`, `--slotted-duration-instant`, `--slotted-duration-long`, `--slotted-duration-medium`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-heading`, `--slotted-font-family-sans`, `--slotted-font-size-lg`, `--slotted-font-size-md`, `--slotted-font-size-xl`, `--slotted-font-weight-semibold`, `--slotted-line-height-lg`, `--slotted-line-height-md`, `--slotted-radius-full`, `--slotted-radius-lg`, `--slotted-radius-sm`, `--slotted-scrim`, `--slotted-shadow-lg`, `--slotted-space-11`, `--slotted-space-12`, `--slotted-space-2`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-space-8`, `--slotted-space-9`, `--slotted-surface-raised`, `--slotted-surface-sunken`, `--slotted-target-comfortable`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-overlay`

## Examples

See [drawer.examples.md](./drawer.examples.md).
