Dialog

qds-dialog provides a native modal surface for focused workflows. It uses HTMLDialogElement.showModal(): background content is inert and the surface escapes clipping ancestors without moving application DOM.

<script type="module" src="/assets/components/dialog/qds-dialog.js"></script>
<qds-dialog id="review" label="Review changes">
  <p>Check the changes before saving.</p>
  <div slot="footer"><button type="button" id="save">Save</button></div>
</qds-dialog>
<script type="module">
  document.querySelector('#save').onclick = () => review.close('saved');
  review.show();
</script>

Content and appearance

State and cancellation

Focus and async actions

The title receives initial focus so long content begins at its heading. Set initialFocus to an element, or use autofocus, for a shorter workflow. Tab and Shift+Tab stay within the active modal, including slotted controls with open shadow roots. Closing returns focus to the invoker; set returnFocus to a logical successor when the invoker will be removed. Nested dialogs retain the outer scroll lock and focus scope.

For a pointer-triggered workflow, call dialog.show(event.currentTarget) from the trigger’s click handler. This preserves the logical invoker in browsers where clicking a button does not focus it. Programmatic opening without an invoker captures the currently focused element.

runAction(async signal => ..., 'saved') sets busy, prevents user dismissal, and closes on success. Returning false keeps the dialog open. Rejection leaves it open, announces the error, and emits action-error with the original error. Its AbortSignal aborts on close or removal. Disable custom action buttons while busy; repeated runAction calls are rejected while an action is pending.

Confirmation composition

import { confirmDialog } from '/assets/components/dialog/confirm-dialog.js';
const confirmed = await confirmDialog({
  title: 'Archive report?',
  message: 'This report will leave the active list.',
  confirmLabel: 'Archive',
  destructive: true,
  onConfirm: async signal => archiveReport({ signal })
});

The helper uses text-only title/message values, focuses Cancel, cleans up after closing, and resolves to a boolean. A failed action stays open for retry. Provide container when composing inside an existing modal and returnFocus for the logical destination (including pointer-triggered workflows).

Compatibility

Use modern browsers supporting native dialog. Existing select and date-picker panels remain descendants of the modal and participate in its focus order. The new shared overlay helpers do not change those controls’ established APIs.

See the demo for slots, nested dialogs, scrolling, async retries, and confirmation composition.