Skip to content

Drawer

OverlaysSince 0.2.0

A panel that slides in from a screen edge, built on native <dialog>.

  • Modal (default): showModal() gives top-layer rendering, an inert background, a backdrop, and native focus containment. AbsoluteUI adds scroll lock and focus restoration.
  • Non-modal (modal: false): show() keeps the page interactive. Focus moves into the drawer on open, and Escape closes it when it is the topmost overlay.

Both modes share Dialog’s close reasons and cancelable close events. Use non-modal drawers only for supplementary panels, such as filters or record details next to live content.

  • Four edgesSlides in from the start, end, top, or bottom, in three sizes, mirrored in RTL.
  • Modal or notModal drawers make the page inert; non-modal ones let users keep working.
  • Cancelable closeEscape, backdrop, and close button raise a cancel event you can veto.
  • Footer actionsAction buttons close the drawer and report which one was pressed.

Use it for

  • Secondary tasks that keep page context visible, such as editing a record from a list.
  • Navigation or settings panels on small screens (modal).
  • Supplementary panels such as filters or details next to live content (non-modal).

Use something else for

  • Short confirmations or destructive prompts: use Dialog (role=alertdialog).
  • Primary page content or long multi-step flows: use a page.
  • Content anchored to a trigger: use a popover or menu.
  • Non-modal drawers for tasks that must be completed before continuing: use a modal drawer.
Anatomy
<dialog class="aui-drawer aui-drawer--{modal|non-modal} aui-drawer--{placement} aui-drawer--{size}"
data-aui-side="left|right|top|bottom" dir aria-labelledby aria-describedby>
<header class="aui-drawer__header">
<h2 class="aui-drawer__title">title</h2>
<button class="aui-button aui-drawer__close" aria-label="Close">icon</button>
</header>
<p class="aui-drawer__description">description</p>
<div class="aui-drawer__body">content</div>
<footer class="aui-drawer__footer">action buttons</footer>
</dialog>

Use the bar above each frame to switch theme, density, direction, and locale.

The part of the Overlays showcase that uses Drawer. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.

Showcase source
// Overlays showcase: a dialog with a confirmation flow, an alert dialog, drawers from each side,
// a bottom sheet with snap points, a popover form, tooltips, and a hover card.
import { Button } from '@absoluteui/components/button';
import { BottomSheet } from '@absoluteui/components/bottom-sheet';
import { Dialog } from '@absoluteui/components/dialog';
import { Drawer } from '@absoluteui/components/drawer';
import { HoverCard } from '@absoluteui/components/hover-card';
import { Popover } from '@absoluteui/components/popover';
import { TextInput } from '@absoluteui/components/text-input';
import { Tooltip } from '@absoluteui/components/tooltip';
import { choice, createShowcase, hostIn, section, toggle } from './kit.js';
const sc = createShowcase({
title: 'Overlays',
description: 'Open each overlay with the mouse or keyboard. Focus moves in and returns to the opener; Escape closes.',
});
let closeOnBackdrop = true;
let placement: 'start' | 'end' | 'top' | 'bottom' = 'end';
const row = (parent: HTMLElement): HTMLElement => {
const r = hostIn(parent);
r.className = 'sc-row';
return r;
};
const opener = (parent: HTMLElement, text: string, variant: 'primary' | 'secondary' | 'danger' = 'secondary'): Button => {
const b = Button.create({ text, variant }, document);
parent.append(b.element);
return b;
};
const hint = (text: string): HTMLElement => {
const p = document.createElement('span');
p.className = 'sc-hint';
p.textContent = text;
return p;
};
const track = (el: HTMLElement, name: string): void => {
sc.listen(el, ['aui-open', 'aui-close'], name);
};
// Dialogs.
const dialogs = row(section(sc, 'Dialogs', ['dialog']));
const edit = opener(dialogs, 'Edit name', 'primary');
edit.element.addEventListener('click', () => {
const body = document.createElement('div');
const field = TextInput.create(hostIn(body), { label: 'Display name', value: 'Ada Lovelace', required: true });
const d = Dialog.create({ title: 'Edit display name', description: 'Shown to everyone in your organization.', content: body, closeOnBackdrop, actions: [{ label: 'Cancel', value: 'cancel' }, { label: 'Save', value: 'save', variant: 'primary' }] });
track(d.element, 'dialog');
d.element.addEventListener('aui-cancel', (e) => {
// Keep the dialog open while the field is invalid.
if ((e as CustomEvent<{ returnValue: string }>).detail.returnValue === 'save' && !field.reportValidity()) e.preventDefault();
});
d.element.addEventListener('aui-close', () => {
queueMicrotask(() => {
d.destroy();
});
});
d.open();
});
const del = opener(dialogs, 'Delete account', 'danger');
del.element.addEventListener('click', () => {
const d = Dialog.create({ role: 'alertdialog', title: 'Delete your account?', description: 'All your data is removed. This cannot be undone.', size: 'sm', actions: [{ label: 'Keep account', value: 'keep', autofocus: true }, { label: 'Delete', value: 'delete', variant: 'danger' }] });
track(d.element, 'alert dialog');
d.element.addEventListener('aui-close', () => {
queueMicrotask(() => {
d.destroy();
});
});
d.open();
});
// Drawer and bottom sheet.
const filters = opener(row(section(sc, 'Drawer', ['drawer'])), 'Open filters drawer');
filters.element.addEventListener('click', () => {
const body = document.createElement('div');
TextInput.create(hostIn(body), { label: 'Search people', type: 'search' });
const d = Drawer.create({ title: 'Filters', content: body, placement, closeOnBackdrop, actions: [{ label: 'Reset', value: 'reset' }, { label: 'Apply', value: 'apply', variant: 'primary' }] });
track(d.element, 'drawer');
d.element.addEventListener('aui-close', () => {
queueMicrotask(() => {
d.destroy();
});
});
d.open();
});
const sheet = opener(row(section(sc, 'Bottom sheet', ['bottom-sheet'])), 'Open bottom sheet');
sheet.element.addEventListener('click', () => {
const s = BottomSheet.create({ title: 'Share', description: 'Drag the handle or use the snap points.', content: 'Copy link, email, or download as PDF.', snapPoints: [0.4, 0.9], closeOnBackdrop });
track(s.element, 'bottom sheet');
sc.listen(s.element, ['aui-snap-change'], 'bottom sheet');
s.element.addEventListener('aui-close', () => {
queueMicrotask(() => {
s.destroy();
});
});
s.open();
});
// Anchored overlays.
const pop = opener(row(section(sc, 'Popover', ['popover'])), 'Quick note');
const noteBody = document.createElement('div');
TextInput.create(hostIn(noteBody), { label: 'Note' });
const popover = Popover.create(pop.element, { title: 'Add a note', content: noteBody, showCloseButton: true });
track(pop.element, 'popover');
const help = Button.create({ icon: 'info', label: 'Help', variant: 'ghost' }, document);
row(section(sc, 'Tooltip', ['tooltip'])).append(help.element, hint('Hover or focus the help button.'));
const tip = Tooltip.create(help.element, { content: 'Notes are visible only to you.', relation: 'description' });
const profile = document.createElement('a');
profile.href = '#ada';
profile.className = 'aui-link';
profile.textContent = 'Ada Lovelace';
profile.addEventListener('click', (e) => {
e.preventDefault();
});
row(section(sc, 'Hover card', ['hover-card'])).append(profile, hint('Hover or focus the name for the profile card.'));
const card = document.createElement('div');
card.textContent = 'Engineering lead, London. Joined 2019.';
const hover = HoverCard.create(profile, { content: card, describe: true });
track(help.element, 'tooltip');
track(profile, 'hover card');
choice(
sc,
'Drawer side',
[
{ value: 'end', label: 'End' },
{ value: 'start', label: 'Start' },
{ value: 'top', label: 'Top' },
{ value: 'bottom', label: 'Bottom' },
],
'end',
(v) => {
placement = v;
},
['drawer'],
);
choice(
sc,
'Anchored placement',
[
{ value: 'bottom', label: 'Below' },
{ value: 'top', label: 'Above' },
{ value: 'right', label: 'Right' },
{ value: 'left', label: 'Left' },
],
'bottom',
(p) => {
popover.update({ placement: p });
tip.update({ placement: p });
hover.update({ placement: p });
},
['popover', 'tooltip', 'hover-card'],
);
toggle(sc, 'Close on backdrop', true, (v) => {
closeOnBackdrop = v;
}, ['dialog', 'drawer', 'bottom-sheet']);
import { Drawer, type DrawerCloseDetail } from '@absoluteui/components/drawer';
const editor = Drawer.create({
title: 'Edit customer',
description: 'Changes are saved when you select Save.',
size: 'lg',
actions: [
{ label: 'Cancel', value: 'cancel' },
{ label: 'Save', value: 'save', variant: 'primary' },
],
});
editor.element.addEventListener('aui-close', (event) => {
const { returnValue } = (event as CustomEvent<DrawerCloseDetail>).detail;
if (returnValue === 'save') {
// persist changes
}
});
editor.open();
import { Drawer } from '@absoluteui/components/drawer';
const filters = Drawer.create({ title: 'Filters', modal: false, placement: 'start', size: 'sm' });
const list = document.createElement('fieldset');
filters.body.append(list);
document.querySelector('#toggle-filters')?.addEventListener('click', () => {
if (filters.isOpen) filters.close();
else filters.open();
});
import { Drawer } from '@absoluteui/components/drawer';
let dirty = true;
const panel = Drawer.create({ title: 'Edit profile', placement: 'bottom' });
panel.element.addEventListener('aui-cancel', (event) => {
if (dirty) event.preventDefault();
});
panel.open();
dirty = false;
Terminal window
npm install @absoluteui/components @absoluteui/core @absoluteui/theme

Registry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.

import { Drawer } from '@absoluteui/components/drawer';
import '@absoluteui/components/drawer/style.css';
import { Drawer } from '@absoluteui/components/drawer';
import '@absoluteui/components/button/style.css';
import '@absoluteui/components/drawer/style.css';
const filters = Drawer.create({ title: 'Filters', modal: false, placement: 'start', size: 'sm' });
document.querySelector('#toggle-filters')?.addEventListener('click', () => {
if (filters.isOpen) filters.close();
else filters.open();
});
More usage
import { Drawer } from '@absoluteui/components/drawer';
const editor = Drawer.create({
title: 'Edit customer',
size: 'lg',
actions: [
{ label: 'Cancel', value: 'cancel' },
{ label: 'Save', value: 'save', variant: 'primary' },
],
});
editor.open();

Using Angular? See Drawer for Angular.

Drawer.create(options: DrawerOptions, doc?: Document): Drawer

Global configuration key: drawer (see Configuration).

Option Type Default Description
title string Accessible name, rendered as the heading. Required.
description string Referenced by aria-describedby.
content Node | string Body content; strings render as text.
actions readonly DrawerAction[] Footer buttons; clicking closes with the action value.
modal boolean true true: showModal() with inert background, backdrop and scroll lock. false: show(); background stays interactive (supplementary panels only). Set at creation only.
icons Partial<{ close: IconRef }> Icon slot overrides.
placement 'start' | 'end' | 'top' | 'bottom' "end" Screen edge; start/end follow the writing direction. Globally configurable.
size 'sm' | 'md' | 'lg' "md" Inline size for side drawers; maximum block size (capped at 85dvh) for top/bottom. Globally configurable.
closeOnEscape boolean true Escape requests close (cancelable) when the drawer is the topmost overlay. Globally configurable.
closeOnBackdrop boolean true Backdrop click requests close (cancelable). Modal only. Globally configurable.
showCloseButton boolean true Render the header close button. Globally configurable.
direction 'ltr' | 'rtl' "ltr" Maps start/end placement to a physical edge; applied as the element’s dir. Globally configurable. Inherited from common configuration.
Property Type Description
element HTMLDialogElement The native dialog element.
body HTMLDivElement Consumer content area.
isOpen boolean Whether the drawer is open.
modal boolean Whether the drawer was created modal.
Method Description
open(): void Open (modal: showModal() and scroll lock; non-modal: show()); moves focus inside and captures focus for restoration.
close(returnValue?: string): void Close programmatically (not cancelable).
update(options: DrawerUpdateOptions): void Merge and apply options (all except modal).
destroy(): void Close if open, remove element, listeners, overlay registration, subscriptions.
Event Detail Bubbles Cancelable Description
aui-open null No No After the drawer opened.
aui-cancel { returnValue: string; reason: 'escape' | 'backdrop' | 'close-button' | 'action' } No Yes Before a user-initiated close; preventDefault keeps it open.
aui-close { returnValue: string; reason: DrawerCloseReason } No No After the drawer closed.
Area Description
body Drawer.body (or content option).

All rules live in the aui.components cascade layer, so application styles override them without specificity battles.

Class Purpose
aui-drawer Native <dialog> element; data-aui-side holds the physical edge (left | right | top | bottom).
aui-drawer--modal | --non-modal Modality modifiers.
aui-drawer--start | --end | --top | --bottom Logical placement modifiers.
aui-drawer--sm | --md | --lg Size modifiers.
aui-drawer__header Title row with close button.
aui-drawer__title Heading (h2).
aui-drawer__close Close button.
aui-drawer__description Description paragraph.
aui-drawer__body Scrollable content area.
aui-drawer__footer Action buttons.
Slot Default icon
close close

Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.

--aui-border-width | --aui-color-backdrop | --aui-color-border | --aui-color-focus-ring | --aui-color-surface | --aui-color-text | --aui-color-text-muted | --aui-drawer-width-lg | --aui-drawer-width-md | --aui-drawer-width-sm | --aui-duration-fast | --aui-duration-normal | --aui-easing-standard | --aui-focus-ring-offset | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-lg | --aui-font-size-md | --aui-font-size-sm | --aui-font-weight-semibold | --aui-line-height-normal | --aui-line-height-tight | --aui-shadow-lg | --aui-space-1 | --aui-space-2 | --aui-space-3 | --aui-space-5

TypeScript definitions
type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';
type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
type DrawerCloseReason = 'escape' | 'backdrop' | 'close-button' | 'action' | 'programmatic';
interface DrawerAction { label: string; value: string; variant?: ButtonVariant; autofocus?: boolean }
interface DrawerCloseDetail { returnValue: string; reason: DrawerCloseReason }
interface DrawerOptions {
title: string;
description?: string;
content?: Node | string;
actions?: readonly DrawerAction[];
modal?: boolean;
direction?: 'ltr' | 'rtl';
icons?: Partial<{ close: IconRef }>;
placement?: DrawerPlacement;
size?: 'sm' | 'md' | 'lg';
closeOnEscape?: boolean;
closeOnBackdrop?: boolean;
showCloseButton?: boolean;
}
type DrawerUpdateOptions = Partial<Omit<DrawerOptions, 'modal'>>;

Pattern: WAI-ARIA APG Dialog (Modal) pattern implemented with native <dialog>.showModal(); non-modal drawers use <dialog>.show() as a non-modal dialog.

Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.

Key Context Action
Tab / Shift+Tab Modal drawer open Moves focus among drawer controls; the background is inert (native modal).
Tab / Shift+Tab Non-modal drawer open Follows document order; focus can leave the drawer and reach the page.
Escape Drawer is the topmost overlay, closeOnEscape=true Emits cancelable aui-cancel, then closes and restores focus.
Escape closeOnEscape=false No effect; the native close request is prevented, including repeated presses.
Escape Nested overlay (e.g. combobox listbox) open Closes only the topmost overlay.
Enter / Space Action or close button focused Activates the button.
Element Role
<dialog> dialog (native)
title heading level 2
Attribute Element Value
aria-labelledby <dialog> id of the title heading
aria-describedby <dialog> id of the description (when provided)
aria-label close button Localized ‘Close’
aria-modal <dialog> Implicit true for modal drawers (native showModal()); absent for non-modal drawers

On open, focus moves to the autofocus action or first focusable element. On close, a modal drawer returns focus to the element focused before opening; a non-modal drawer does so only when focus was inside the drawer, so users working in the page keep their place.

Criterion Level Note
1.3.1 Info and Relationships A
2.1.1 Keyboard A
2.1.2 No Keyboard Trap A
2.4.3 Focus Order A
2.4.7 Focus Visible AA
4.1.2 Name, Role, Value A

Automated test results: Accessibility and compliance.

  • Background inertness and top-layer rendering of modal drawers are provided by the browser.
  • Slide motion is removed under prefers-reduced-motion and data-aui-animation=‘none’.
  • Use non-modal drawers only for supplementary panels (filters, details).
  • Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Import cost Minified gzip brotli CSS brotli
@absoluteui/components/drawer 43.0 kB 14.6 kB 13.0 kB 1.0 kB

Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.

Budget (enforced in CI) Limit
Drawer.open() to showModal() completion < 16 ms (one frame) in headless Chromium

Tested scale: One drawer at a time, alongside other overlays arbitrated by the overlay stack.

Constant work per open/close: one showModal()/show() call, one overlay-stack entry, one scroll-lock reference (modal), and one focus restore point. Budget: open() under 16 ms in headless Chromium.

Measured run times: Performance.

States

closed, opening (slide-in), open, closing (an aui-cancel listener is pending), and closing (slide-out).

State transitions
From Trigger To
closed open() open (focus moves inside; modal: scroll locked, background inert)
open Escape / backdrop (modal) / close button / action aui-cancel -> closed, unless prevented
open close() closed (no aui-cancel)
open consumer <form method="dialog"> submit closed (reason action)
Accessibility notes
  • Initial focus goes to the action with autofocus: true, otherwise the first focusable element (native dialog focusing steps).
  • A modal drawer returns focus to the element that was focused before open().
  • A non-modal drawer returns focus only when focus was inside the drawer at close, so users working in the page keep their place.
  • Non-modal drawers do not trap focus. Keep them supplementary, and give users a visible way to reopen and close them.
  • Slide motion is removed under prefers-reduced-motion and data-aui-animation='none'.
  • Manual screen-reader verification is pending.
Responsive behavior

Side drawers use min(drawer-width token, 100vw) and the full viewport height. Top and bottom drawers use the full inline size and max-block-size: min(drawer-width token, 85dvh). The body scrolls. Below 480px, side drawers take 100vw and footer actions stack full-width.

Right-to-left

start and end resolve against the configured direction: start is the left edge in LTR and the right edge in RTL. The resolved edge is exposed as data-aui-side, the slide direction follows it, and the element receives dir. Inner layout uses logical properties; the close button sits at the inline end.

Theming

Token-driven surface, border, shadow, and backdrop. Only the inner edge has a border. Forced-colors mode uses a CanvasText border.

Global configuration
configureAbsoluteUI({ components: { drawer: { placement: 'start', size: 'lg', closeOnBackdrop: false } } });

Changes apply to existing instances immediately.

Component configuration

Instance options override global and theme defaults. All configurable options are dynamic; modal is init-only.

Icons

icons.close (default close), resolved through the global icon provider/registry.

Security

Title, description, and string content use textContent. No HTML parsing, no inline styles. CSP-safe.

Data handling

No persistence, network access, or telemetry.

Supported data scale

Not data-driven. Body content size is limited only by the consumer; the body scrolls.

Edge cases
  • closeOnEscape: false also blocks repeated Escape presses. Chrome would otherwise let the second Escape through without user activation.
  • A non-modal drawer yields Escape to a modal dialog opened elsewhere, because it is inert behind that dialog.
  • Escape closes a non-modal drawer when it is the topmost overlay, even if focus is in the page.
  • Destroying an open drawer releases the scroll lock and overlay registration, and restores focus.
Errors
Code Category Cause
DRAWER_TITLE configuration Missing or blank title.
DRAWER_OPTIONS configuration Invalid modal or actions.
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION configuration Invalid or unknown configuration, such as an unknown placement.

A failed construction or update leaves no rendering, listeners, overlay registration, or subscriptions behind, and a failed update() keeps the previous options.

Known limitations
  • Non-modal drawers are not in the top layer. They use z-index: 1000, so page content with a higher stacking context can cover them.
  • The element’s dir follows the configured direction (default 'ltr'), not the document’s dir attribute.
  • Slide animations need @starting-style and transition-behavior: allow-discrete. Older browsers open and close without animation.
  • Manual screen-reader verification is pending.
Unsupported scenarios
  • Switching modal after creation.
  • Swipe-to-dismiss gestures.
  • HTML strings as content: pass a Node instead.