Skip to content
Focsd homeFocsd homeFocsd
Forms

Alert dialog

An interrupting confirmation for destructive or urgent decisions.

  • Tag: focsd-alert-dialog
  • Pattern: Alert dialog
  • Category: Overlays

Example

Delete project

This permanently deletes 26 files. You cannot undo this.

Keep project Delete Atlas
HTML
<focsd-button commandfor="ad-demo" command="show-modal" variant="critical"
>Delete project</focsd-button
>
<focsd-alert-dialog id="ad-demo" headline="Delete Atlas?">
<p>This permanently deletes 26 files. You cannot undo this.</p>
<focsd-button slot="actions" data-dialog-close value="cancel" data-autofocus
>Keep project</focsd-button
>
<focsd-button slot="actions" variant="critical" data-dialog-close value="delete"
>Delete Atlas</focsd-button
>
</focsd-alert-dialog>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-alert-dialog.js';
</script>
<focsd-alert-dialog headline="Delete Atlas?">…</focsd-alert-dialog>

API

Attributes

AttributePropertyTypeDefault
headlineheadlinestring—
openopenbooleanfalse
closedbyclosedBy'any' | 'closerequest' | 'none'closerequest
no-closenoClosebooleanfalse

Methods

MethodDescription
show(opener)Open as a modal dialog. Focus returns to opener (default: the element focused now) on close, which matters in Safari where clicking a button does not focus it.
showModal(opener)Same as show(): Focsd dialogs are always modal.
requestClose(returnValue)Ask to close: fires a cancelable cancel, then closes with returnValue unless it was canceled.
close(returnValue)Close, optionally setting returnValue.

Events

EventDescription
cancelFired before a close request (Escape, backdrop, requestClose); cancel it to keep the dialog open.
closeFired after the dialog closes; read returnValue for how it closed.

Slots

SlotDescription
(default)Default content.
actionsThe dialog's buttons.

CSS parts

Style the inside of the component with ::part(), for example focsd-alert-dialog::part(actions).

PartDescription
actionsThe actions element.
bodyThe body element.
closeThe close (×) button, last in the tab order; it asks to close like Escape (hidden with `no-close`).
dialogThe dialog element.
headlineThe headline element.

Accessibility

  • requestClose() and closedby work as on focsd-dialog; keep the default closedby so Escape still cancels.
  • role="alertdialog", described by its body so the consequence is read with the title.
  • Initial focus goes to data-autofocus (put it on the least destructive action), otherwise the first focusable element.
  • The destructive action names its object ("Delete Atlas").

Keyboard

KeyAction
TabMoves focus within the dialog; the page behind is inert
EscapeCloses (cancels)