Component
Dialog (JS fallback)
Published on
Description
A JavaScript-based fallback for the dialog component, using custom elements (is="ds-button-dialog" and is="ds-dialog") with the inert attribute. Use this approach for browsers that do not yet support command/commandfor. Prefer the command-based dialog when possible.
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 — command-based (preferred)
- Popover — for non-modal overlays
- Disclosure — for inline show/hide
Variables
none for dialog