Dialog
Introduction
Section titled “Introduction”A modal dialog built on native <dialog>.showModal(). The browser provides top-layer rendering, an inert background, and focus containment. AbsoluteUI adds:
- deterministic Escape and backdrop policy;
- cancelable close events;
- focus restoration;
- scroll lock;
- localization.
- Native modalBuilt on the native dialog element, with an inert page and contained focus.
- Cancelable closeEscape and backdrop clicks follow a set policy and raise a cancel event you can veto.
- Focus restoredFocus returns to where it was before the dialog opened.
- Footer actionsAction buttons close the dialog and report which one was pressed.
- Alert dialogsAn alert dialog role for confirmations of destructive actions.
Use it for
- Tasks that must be completed or dismissed before returning to the page.
- Confirmations of destructive actions (role=alertdialog).
Use something else for
- Non-blocking information: use an inline message, alert, or toast.
- Complex multi-step flows better served by a page or wizard.
- Contextual content anchored to a trigger: use a popover.
Anatomy
<dialog class="aui-dialog aui-dialog--{size}" aria-labelledby aria-describedby [role=alertdialog]> <header class="aui-dialog__header"> <h2 class="aui-dialog__title">title</h2> <button class="aui-button aui-dialog__close" aria-label="Close">icon</button> </header> <p class="aui-dialog__description">description</p> <div class="aui-dialog__body">content</div> <footer class="aui-dialog__footer">action buttons</footer></dialog>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Dialog in the Overlays showcase
Section titled “Dialog in the Overlays showcase”The part of the Overlays showcase that uses Dialog. 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']);Destructive confirmation (alertdialog)
Section titled “Destructive confirmation (alertdialog)”import { Dialog, type DialogCloseDetail } from '@absoluteui/components/dialog';
const confirm = Dialog.create({ title: 'Delete project?', description: 'This permanently removes the project.', role: 'alertdialog', actions: [ { label: 'Cancel', value: 'cancel', autofocus: true }, { label: 'Delete', value: 'delete', variant: 'danger' }, ],});confirm.element.addEventListener('aui-close', (event) => { const { returnValue } = (event as CustomEvent<DialogCloseDetail>).detail; if (returnValue === 'delete') { // perform deletion }});confirm.open();Prevent closing with unsaved changes
Section titled “Prevent closing with unsaved changes”import { Dialog } from '@absoluteui/components/dialog';
let dirty = true;const editor = Dialog.create({ title: 'Edit profile', closeOnBackdrop: true });editor.element.addEventListener('aui-cancel', (event) => { if (dirty) event.preventDefault();});editor.open();dirty = false;Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Dialog } from '@absoluteui/components/dialog';import '@absoluteui/components/dialog/style.css';First use
Section titled “First use”import { Dialog } from '@absoluteui/components/dialog';import '@absoluteui/components/button/style.css';import '@absoluteui/components/dialog/style.css';
const d = Dialog.create({ title: 'Settings', content: 'Preferences are saved automatically.' });document.querySelector('#open')?.addEventListener('click', () => { d.open();});More usage
import { Dialog } from '@absoluteui/components/dialog';
const confirm = Dialog.create({ title: 'Delete project?', role: 'alertdialog', actions: [ { label: 'Cancel', value: 'cancel', autofocus: true }, { label: 'Delete', value: 'delete', variant: 'danger' }, ],});confirm.open();Using Angular? See Dialog for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Dialog.create(options: DialogOptions, doc?: Document): DialogGlobal configuration key: dialog (see Configuration).
Options
Section titled “Options”| 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 DialogAction[] |
Footer buttons; clicking closes with the action value. | |
role |
'dialog' | 'alertdialog' |
"dialog" |
Use alertdialog for urgent confirmations. |
icons |
Partial<{ close: IconRef }> |
Icon slot overrides. | |
closeOnEscape |
boolean |
true |
Escape requests close (cancelable). Globally configurable. |
closeOnBackdrop |
boolean |
false |
Backdrop click requests close (cancelable). Globally configurable. |
showCloseButton |
boolean |
true |
Render the header close button. Globally configurable. |
size |
'sm' | 'md' | 'lg' |
"md" |
Maximum inline size. Globally configurable. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
element |
HTMLDialogElement |
The native dialog element. |
body |
HTMLDivElement |
Consumer content area. |
isOpen |
boolean |
Whether the dialog is open. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
open(): void |
Open modally; locks scroll; captures focus for restoration. |
close(returnValue?: string): void |
Close programmatically (not cancelable). |
update(options: Partial<DialogOptions>): void |
Merge and apply options. |
destroy(): void |
Close if open, remove element, listeners, subscriptions. |
Events
Section titled “Events”| Event | Detail | Bubbles | Cancelable | Description |
|---|---|---|---|---|
aui-open |
null |
No | No | After the dialog 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: DialogCloseReason } |
No | No | After the dialog closed. |
Content areas
Section titled “Content areas”| Area | Description |
|---|---|
body |
Dialog.body (or content option). |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-dialog |
Native <dialog> element. |
aui-dialog--sm | --md | --lg |
Size modifiers. |
aui-dialog__header |
Title row with close button. |
aui-dialog__title |
Heading (h2). |
aui-dialog__close |
Close button. |
aui-dialog__description |
Description paragraph. |
aui-dialog__body |
Scrollable content area. |
aui-dialog__footer |
Action buttons. |
Icon slots
Section titled “Icon slots”| Slot | Default icon |
|---|---|
close |
close |
Design tokens
Section titled “Design tokens”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-dialog-width-lg | --aui-dialog-width-md | --aui-dialog-width-sm | --aui-duration-fast | --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-radius-lg | --aui-shadow-lg | --aui-space-1 | --aui-space-2 | --aui-space-3 | --aui-space-4 | --aui-space-5
TypeScript definitions
type DialogCloseReason = 'escape' | 'backdrop' | 'close-button' | 'action' | 'programmatic';interface DialogAction { label: string; value: string; variant?: ButtonVariant; autofocus?: boolean }interface DialogCloseDetail { returnValue: string; reason: DialogCloseReason }interface DialogOptions { title: string; description?: string; content?: Node | string; actions?: readonly DialogAction[]; role?: 'dialog' | 'alertdialog'; icons?: Partial<{ close: IconRef }>; closeOnEscape?: boolean; closeOnBackdrop?: boolean; showCloseButton?: boolean; size?: 'sm' | 'md' | 'lg';}Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: WAI-ARIA APG Dialog (Modal) and Alert Dialog patterns, implemented with native <dialog>.showModal().
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.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| Tab / Shift+Tab | Dialog open | Moves focus among dialog controls; background is inert (native modal). |
| Escape | Dialog open, closeOnEscape=true | Emits cancelable aui-cancel, then closes and restores focus. |
| Escape | Dialog open, closeOnEscape=false | No effect; the native close request is prevented. |
| 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) or alertdialog |
| title | heading level 2 |
ARIA attributes
Section titled “ARIA attributes”| 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’ |
On open, focus moves to the autofocus action or first focusable element. On close, focus returns to the element focused before opening.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| 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.
Notes and known caveats
Section titled “Notes and known caveats”- Background inertness and top-layer rendering are provided by the browser.
- Scroll lock uses scrollbar-gutter to avoid layout shift.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/dialog |
41.4 kB | 14.1 kB | 12.5 kB | 0.9 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Dialog.open() to showModal() completion | < 16 ms (one frame) in headless Chromium |
Tested scale: Nested dialog stacking is native; tested with one dialog containing a combobox.
Constant work per open/close: one showModal() call, one scroll-lock reference, and one focus restore point. Budget: open() under 16 ms in headless Chromium (performance test).
Measured run times: Performance.
Details
Section titled “Details”States
closed, open, and closing (an aui-cancel listener is pending).
State transitions
| From | Trigger | To |
|---|---|---|
| closed | open() |
open (focus moves inside, scroll locked) |
| open | Escape / backdrop / 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). - For alert dialogs, set
autofocuson the least destructive action. - On close, focus returns to the element that was focused before
open(). - Verified with axe (WCAG 2.2 AA) in 3 themes.
- Manual screen-reader verification is pending.
Responsive behavior
Width is min(size token, 100vw - 2rem) and height is capped at 100dvh - 2rem; the body scrolls. Below 480px, footer actions stack full-width.
Right-to-left
Logical properties throughout; the close button sits at the inline end.
Theming
Token-driven surface, border, radius, shadow, and backdrop. Forced-colors mode uses a CanvasText border.
Global configuration
configureAbsoluteUI({ components: { dialog: { closeOnBackdrop: true, size: 'lg' } } });Component configuration
Instance options override global and theme defaults. All configurable options are dynamic and re-render the open dialog.
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. Verified under a strict CSP with Trusted Types enforced.
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: falsealso blocks repeated Escape presses. Chrome would otherwise let the second Escape through without user activation.- Escape in a focused combobox that has a value but a closed listbox clears the combobox first, per the APG.
- Destroying an open dialog releases the scroll lock and restores focus.
Errors
| Code | Category | Cause |
|---|---|---|
DIALOG_TITLE |
configuration | Missing or blank title. |
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION |
configuration | Invalid or unknown configuration. |
Known limitations
- The close transition is not animated; the open transition uses
@starting-styleand is removed under reduced motion. - Only modal dialogs are supported.
- Manual screen-reader verification is pending.
Unsupported scenarios
- Non-modal dialogs.
- HTML strings as content: pass a
Nodeinstead.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.