# Drawer (`<z-drawer>`)

> Panel sliding in from a screen edge with a drag handle, swipe-to-dismiss, and offcanvas-style presentations.

- **Kind:** hwc
- **Category:** overlays
- **Inherits:** `DialogMixin`, `Hwc`, `Base`

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `placement` | `DrawerPlacement` | `'bottom'` | — | Edge the drawer slides from: `bottom` (default), `top`, `left`, or `right`. |
| `no-handle` | `boolean` | `false` | — | Hides the drag handle bar. |
| `no-swipe` | `boolean` | `false` | — | Disables drag/swipe dismissal. |
| `blur` | `boolean` | `false` | — | Applies a backdrop blur to the overlay. |

### Inherited from `DialogMixin`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | `false` | `DialogMixin` | Opens the dialog on first render and stays in sync with `show()` and `hide()`. |
| `center` | `boolean` | `false` | `DialogMixin` | Vertically centers the panel within the overlay. |
| `container` | `boolean` | `false` | `DialogMixin` | Adds `z-modal-container` to the overlay for a contained presentation. |
| `full` | `boolean` | `false` | `DialogMixin` | Adds `z-modal-full` to the overlay for a full-screen presentation. |
| `stack` | `boolean` | `false` | `DialogMixin` | Keeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index. |
| `inline` | `boolean` | `false` | `DialogMixin` | Keeps the component in its original DOM position instead of teleporting it to `document.body`. |
| `no-bg-close` | `boolean` | `false` | `DialogMixin` | Disables closing when the overlay background is clicked. |
| `no-esc-close` | `boolean` | `false` | `DialogMixin` | Disables closing with the Esc key. |
| `unmount` | `boolean` | `false` | `DialogMixin` | Removes the rendered DOM after the close transition; the next show mounts it again. |
| `dialog-role` | `'dialog' \| 'alertdialog'` | `'dialog'` | `DialogMixin` | ARIA role of the panel: `dialog` or `alertdialog`. |
| `aria-label` | `string` | `''` | `DialogMixin` | Accessible name for the panel when no `aria-labelledby` is set. |
| `aria-labelledby` | `string` | `''` | `DialogMixin` | Id of the element that names the panel; takes precedence over `aria-label`. |

### Inherited from `Hwc`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `i18n` | `string` | `''` | `Hwc` | Per-instance text overrides as `key: text` pairs, merged over the global `z-i18n` script and the built-in defaults. |
| `floating` | `string` | `''` | `Hwc` | Floating UI placement options (for example `offset` and `shiftPadding`) parsed as `key: value` pairs. |
| `force-prevent-rerender` | `boolean` | `false` | `Hwc` | Skips re-rendering after the first render; an existing `data-host-inner` child is adopted as the rendered DOM. |
| `template` | `string` | `''` | `Hwc` | Selector or id of an external element or `<template>` whose inner content is cloned in place of an inline `template[data-fn="template"]` child. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `drawer`. Default `stl` target: `drawer`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `content` | `z-drawer-content` | ✓ | ✓ | The scrollable content region inside the panel (default `z-drawer-content`). |
| `drawer` | `z-drawer` | ✓ | ✓ | The sliding panel (default `z-drawer`); the default `cls`/`stl` target. |
| `handle` | `z-drawer-handle` | ✓ | ✓ | The drag-handle hit area at the panel's outer edge (default `z-drawer-handle`). |
| `handle-bar` | `z-drawer-handle-bar` | ✓ | ✓ | The visible handle pill inside the hit area (default `z-drawer-handle-bar`). |
| `overlay` | `z-modal z-drawer-overlay` | ✓ | ✓ | The backdrop overlay (default `z-modal z-drawer-overlay`). |

## CSS Variables

| Variable | Default | Scope | Affects | Description |
| --- | --- | --- | --- | --- |
| `--z-drawer-bg` | `var(--z-bg)` | `.z-drawer` | `background-color` | Background color of the panel. |
| `--z-drawer-border-color` | `var(--z-border)` | `.z-drawer` | `border-color` | Border base color, mixed with transparency using `--z-drawer-border-color-o`. |
| `--z-drawer-border-color-o` | `var(--z-border-o)` | `.z-drawer` | `border-color` | Border opacity percentage used in the border color mix. |
| `--z-drawer-border-width` | `1px` | `.z-drawer` | `border-bottom-width`, `border-inline-width`, `border-left-width`, `border-right-width`, `border-top-width` | Border width on the panel's inner edge. |
| `--z-drawer-color` | `var(--z-bg-f)` | `.z-drawer` | `color` | Text color of the panel. |
| `--z-drawer-handle-bg` | `var(--z-border)` | `.z-drawer` | `background-color` | Handle base color, mixed with transparency using `--z-drawer-handle-bg-o`. |
| `--z-drawer-handle-bg-o` | `calc(var(--z-border-o) * 1.25)` | `.z-drawer` | `background-color` | Handle opacity percentage used in the color mix. |
| `--z-drawer-handle-hover-bg-o` | `calc(var(--z-border-o) * 2.25)` | `.z-drawer` | `background-color` | Handle opacity percentage while hovered. |
| `--z-drawer-handle-length` | `5rem` | `.z-drawer` | `height`, `width` | Length of the handle pill. |
| `--z-drawer-handle-radius` | `9999px` | `.z-drawer` | `border-radius` | Corner radius of the handle pill. |
| `--z-drawer-handle-thickness` | `0.375rem` | `.z-drawer` | `height`, `width` | Thickness of the handle pill. |
| `--z-drawer-max-height` | `85dvh` | `.z-drawer` | `max-height` | Maximum height of top/bottom drawers. |
| `--z-drawer-max-width` | `calc(100vw - 2rem)` | `.z-drawer` | `max-width` | Maximum width of left/right drawers. |
| `--z-drawer-radius` | `calc(var(--z-global-radius) * 2)` | `.z-drawer` | `border-end-end-radius`, `border-end-start-radius`, `border-start-end-radius`, `border-start-start-radius` | Corner radius of the panel's outer corners. |
| `--z-drawer-shadow` | `0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)` | `.z-drawer` | `box-shadow` | Box shadow of the panel. |
| `--z-drawer-side-radius` | `0px` | `.z-drawer` | `border-end-end-radius`, `border-end-start-radius`, `border-start-end-radius`, `border-start-start-radius` | Corner radius applied on the placement side. |
| `--z-drawer-transition` | `transform 0.15s cubic-bezier(0.16, 1, 0.3, 1)` | `.z-drawer` | `transition` | Transition timing of the panel slide. |
| `--z-drawer-width` | `24rem` | `.z-drawer` | `width` | Width of left/right drawers. |
| `--z-offcanvas-bar-border-width` | `1px` | `.z-offcanvas-bar` | `border-left-width`, `border-right-width` | Border width of the offcanvas bar's inner edge. |
| `--z-offcanvas-bar-transition` | `left 0.3s ease-out` | `.z-offcanvas-bar` | `transition` | Transition of the offcanvas bar slide. |
| `--z-offcanvas-bar-width` | `288px` | `.z-offcanvas` | `left`, `right`, `width` | Width of the offcanvas bar. |
| `--z-offcanvas-container-transition` | `left 0.3s ease-out` | `.z-offcanvas-container` | `transition` | Transition of the pushed page container. |
| `--z-offcanvas-overlay-bg` | `#000` | `.z-offcanvas-overlay` | `background-color` | Offcanvas backdrop base color, mixed with transparency using `--z-offcanvas-overlay-bg-o`. |
| `--z-offcanvas-overlay-bg-o` | `80%` | `.z-offcanvas-overlay` | `background-color` | Backdrop opacity percentage used in the background mix. |
| `--z-offcanvas-overlay-blur` | `var(--z-global-blur)` | `.z-offcanvas-overlay` | `-webkit-backdrop-filter`, `backdrop-filter` | Backdrop blur radius of the offcanvas overlay. |
| `--z-offcanvas-overlay-opacity` | `1` | `.z-offcanvas-overlay` | `opacity` | Final opacity of the backdrop when open. |
| `--z-offcanvas-overlay-transition` | `opacity 0.15s linear` | `.z-offcanvas-overlay` | `transition` | Transition of the backdrop opacity. |
| `--z-offcanvas-reveal-transition` | `width 0.3s ease-out` | `.z-offcanvas-reveal` | `transition` | Transition of the reveal wrapper's width. |
| `--z-offcanvas-z-index` | `1000` | `.z-offcanvas` | `z-index` | Stacking order of the offcanvas overlay. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-drawer:before-hide` | ✓ | — | Fires before closing; call `preventDefault()` to abort. |
| `z-drawer:before-show` | ✓ | — | Fires before opening; call `preventDefault()` to abort. |
| `z-drawer:destroy` | — | — | Fires when the mounted DOM is removed, via `unmount` or `destroy()`. |
| `z-drawer:hidden` | — | — | Fires after the close transition completes and focus is restored to the opener. |
| `z-drawer:hide` | — | — | Fires when the dialog starts closing. |
| `z-drawer:mount` | — | — | Fires once when the dialog DOM is first mounted. |
| `z-drawer:show` | — | — | Fires when the dialog starts opening, before the transition completes. |
| `z-drawer:shown` | — | — | Fires after the open transition completes. |

## Methods

| Method | Params | Returns | Description |
| --- | --- | --- | --- |
| `destroy()` | `removeHost?: boolean = false` | `Promise<void>` | Closes and unmounts the dialog DOM; optionally removes the host element as well. |
| `hide()` | — | `Promise<void>` | Closes the dialog and restores focus to the opener. |
| `show()` | `trigger?: HTMLElement \| null` | `Promise<void>` | Opens the dialog; the trigger element receives focus back on close. |
| `toggle()` | `trigger?: HTMLElement \| null` | `Promise<void>` | Opens the dialog if closed, otherwise closes it. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-close` | — | `external-trigger` | `trigger` | Clicking the element closes the dialog matched by the selector (usually `#id`). |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-open` | — | `external-trigger` | `trigger` | Clicking the element opens the dialog matched by the selector without toggling. |
| `data-part` | `content`, `drawer`, `handle`, `overlay` | `descendant` | `marker` | Marks adopted server-rendered structure: `overlay`, `drawer`, `handle`, and `content`. |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
| `data-side` | — | `descendant` | `marker` | Set by the component to the resolved placement; selects the edge-specific styling. |
| `data-toggle` | — | `external-trigger` | `trigger` | Clicking the element toggles the dialog matched by the selector (usually `#id`). |

## Child Content

- `<script data-fn="config">` — JSON configuration script parsed by the base class (i18n, cls, stl, floating).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `config` | Marks the script as configuration (value: `config`). |
  | `data-reactive` | — | `boolean` | Re-parses the configuration when the script mutates. |

- `<select data-fn="data-source">` — Hidden select parsed into grouped option data by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `data-source` | Marks the select as the data source (value: `data-source`). |
  | `data-reactive` | — | `boolean` | Re-parses the options when the select mutates. |

  - `<optgroup>` — Groups options under a label.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `label` | ✓ | `string` | Group header text; also the default group key. |
    | `disabled` | — | `boolean` | Disables every option in the group. |
    | `data-key` | — | `string` | Overrides the group key used in the parsed data. |
    | `data-keywords` | — | `comma-separated string` | Comma-separated keywords stored with the group's data. |

    - `<option>` — One option entry within the group.

      | Attribute | Required | Type | Description |
      | --- | --- | --- | --- |
      | `value` | — | `string` | Value carried by this option in the parsed data. |
      | `disabled` | — | `boolean` | Makes the option non-selectable. |
      | `selected` | — | `boolean` | Marks the option as initially selected. |
      | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated; searched alongside the label and value. |

  - `<option>` — One ungrouped option entry.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `value` | — | `string` | Value carried by this option in the parsed data. |
    | `disabled` | — | `boolean` | Makes the option non-selectable. |
    | `selected` | — | `boolean` | Marks the option as initially selected. |
    | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated. |

- `<template data-fn="icons">` — Instance-level icon repository.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `icons` | Marks the template as an icon source (value: `icons`). |
  | `data-reactive` | — | `boolean` | Re-parses the icons when the template mutates. |

  - `<*>` — One icon element.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `data-key` | ✓ | `string` | Icon key referenced by `$icons`. |

- `<template data-fn="template">` — Deferred content template mounted by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `template` | Marks the template for deferred mounting (value: `template`). |
  | `data-reactive` | — | `boolean` | Re-parses the template when it mutates. |

## CSS Classes

| Class | Role | Applies to | Description |
| --- | --- | --- | --- |
| `.z-drawer` | `root` | `z-drawer` | Root class of the sliding panel. |
| `.z-drawer-content` | `state` | `.z-drawer` | Scrollable content region of the panel. |
| `.z-drawer-handle` | `state` | `.z-drawer` | Drag-handle hit area along the panel's outer edge. |
| `.z-drawer-handle-bar` | `state` | `.z-drawer` | The visible handle pill. |
| `.z-drawer-overlay` | `element` | `.z-drawer` | The drawer's backdrop overlay. |
| `.z-offcanvas` | `element` | `.z-drawer` | Fixed side-bar overlay root (offcanvas presentation). |
| `.z-offcanvas-bar` | `element` | `.z-drawer` | The sliding side bar itself. |
| `.z-offcanvas-bar-animation` | `element` | `.z-drawer` | Enables the bar's slide transition. |
| `.z-offcanvas-container` | `element` | `.z-drawer` | Page container that can be pushed aside by the bar. |
| `.z-offcanvas-container-animation` | `modifier` | `.z-drawer` | Pushes the container by the bar width while open. |
| `.z-offcanvas-flip` | `modifier` | `.z-drawer` | Mirrors the offcanvas to the right edge. |
| `.z-offcanvas-overlay` | `element` | `.z-drawer` | Overlay presentation: dims the page behind the bar. |
| `.z-offcanvas-page` | `element` | `.z-drawer` | Page root class clipping horizontal overflow while an offcanvas is open. |
| `.z-offcanvas-reveal` | `element` | `.z-drawer` | Reveal presentation: the bar's wrapper grows in width instead of sliding. |

## Accessibility

| Part | Attributes | Description |
| --- | --- | --- |
| `content` | — | Scrollable content region; no ARIA attributes. |
| `drawer` | `aria-label="${ifDefined(aria.ariaLabel)}"`, `aria-labelledby="${ifDefined(aria.labelledBy)}"`, `aria-modal="true"`, `role="${aria.role}"` | Sliding panel: `aria-modal="true"` with the configured `dialog`/`alertdialog` role, named via `aria-label` or `aria-labelledby`. |
| `handle` | `aria-hidden="true"` | Drag-handle hit area, `aria-hidden="true"` (decorative; the panel itself is draggable). |
| `handle-bar` | — | Visual handle pill; no ARIA attributes. |
| `overlay` | — | Backdrop wrapper; no ARIA attributes of its own. |

> Shares the dialog accessibility model: modal panel with the configured role, focus moved in on open and restored to the opener on close.

> Swipe dismissal ignores interactive content and scrollable regions that can still scroll toward the dismiss direction.

## Notes

- Drag the handle (or the panel when no handle is present) toward the placement edge to dismiss; a fast flick dismisses even below the halfway point.
- Content placed inside the host is adopted into `.z-drawer-content`; an existing `.z-drawer`/`.z-offcanvas-bar` structure is preserved.
- The offcanvas classes style side-bar presentations (slide, reveal, overlay, push) and mirror with `.z-offcanvas-flip`.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Dialog](https://next.0build.dev/docs/components/dialog.md)
- [Drop](https://next.0build.dev/docs/components/drop.md)
