Component

Dialog (JS fallback)

Published on

Description anchor

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 anchor

Open in new tab (opens in new tab)
View HTML markup
  <button type="button" is="ds-button-dialog" data-dialog="dialog-id">Open dialog</button>
<dialog closedby="any" id="dialog-id" aria-labelledby="dialog-heading" inert="" is="ds-dialog">
  <form method="dialog" novalidate="">
    <header>
      <h1 id="dialog-heading">Heading</h1>
    </header>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    <footer>Dialog footer<button type="submit" autofocus="">close</button></footer>
  </form>
</dialog>

Accessibility anchor

  • Use native <dialog> with showModal(). It provides built-in focus trapping and the inert attribute for background content.
  • The trigger button should use aria-haspopup="dialog" and aria-expanded to 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-labelledby pointing to the dialog heading for the accessible name.

References anchor

Variables anchor

none for dialog