# 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`). |

## Reference inventories

- [CSS Variables (29)](https://next.0build.dev/docs/components/drawer/css-vars.md)
- [CSS Classes (14)](https://next.0build.dev/docs/components/drawer/css-classes.md)
- [Accessibility (5 ARIA parts)](https://next.0build.dev/docs/components/drawer/accessibility.md)

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

## 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)
