Component
Dialog
Published on
Description
The dialog component creates a modal overlay using the native <dialog> element with command/commandfor attributes. No JavaScript is required. Dialogs trap focus and provide built-in keyboard dismissal with Escape.
Example
Accessibility
- Use native
<dialog>withshowModal(). It provides built-in focus trapping and theinertattribute for background content. - The trigger button should use
aria-haspopup="dialog"andaria-expandedto communicate state. - Focus placement on open depends on dialog type: short messages focus the close button, longer content focuses the dialog or heading, action-required dialogs focus the least destructive option, and brief forms focus the first input.
- Always return focus to the triggering element when the dialog closes.
- Use
aria-labelledbypointing to the dialog heading for the accessible name.
References
- Dialog Focus in Screen Readers (opens in new tab) — Adrian Roselli
- Where to Put Focus When Opening a Modal Dialog (opens in new tab) — Adrian Roselli
- Brief Note on Popovers with Dialogs (opens in new tab) — Adrian Roselli
Related
- Dialog (JS fallback) — for browsers without
command/commandforsupport - Popover — for non-modal overlays
- Disclosure — for inline show/hide
Variables
none for dialog