Alert dialog
An interrupting confirmation for destructive or urgent decisions.
Example
This permanently deletes 26 files. You cannot undo this.
<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>import { AlertDialog } from '@focsd-dev/react';
export function Example() { return <AlertDialog onCancel={(e) => console.log(e.target)} headline="Delete Atlas?">…</AlertDialog>;}<script setup>import '@focsd-dev/components/focsd-alert-dialog.js';</script>
<template> <focsd-alert-dialog @cancel="onChange" headline="Delete Atlas?">…</focsd-alert-dialog></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-alert-dialog.js';
// template<focsd-alert-dialog (cancel)="onChange($event)" headline="Delete Atlas?">…</focsd-alert-dialog><script> import '@focsd-dev/components/focsd-alert-dialog.js';</script>
<focsd-alert-dialog oncancel={(e) => console.log(e.target)} headline="Delete Atlas?">…</focsd-alert-dialog>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
headline | headline | string | — |
open | open | boolean | false |
closedby | closedBy | 'any' | 'closerequest' | 'none' | closerequest |
no-close | noClose | boolean | false |
Methods
| Method | Description |
|---|---|
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
| Event | Description |
|---|---|
cancel | Fired before a close request (Escape, backdrop, requestClose); cancel it to keep the dialog open. |
close | Fired after the dialog closes; read returnValue for how it closed. |
Slots
| Slot | Description |
|---|---|
(default) | Default content. |
actions | The dialog's buttons. |
CSS parts
Style the inside of the component with ::part(), for example focsd-alert-dialog::part(actions).
| Part | Description |
|---|---|
actions | The actions element. |
body | The body element. |
close | The close (×) button, last in the tab order; it asks to close like Escape (hidden with `no-close`). |
dialog | The dialog element. |
headline | The headline element. |
Accessibility
requestClose()andclosedbywork as onfocsd-dialog; keep the defaultclosedbyso 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
| Key | Action |
|---|---|
| Tab | Moves focus within the dialog; the page behind is inert |
| Escape | Closes (cancels) |
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.