AlertDialog
Asks the person to confirm or cancel an action, such as deleting, with a destructive variant for actions that cannot be undone.
Stability: experimental
Props
| Prop | Type | Default | Means |
title | string | | The question, as the heading and the accessible name. |
message | string | | What will happen; the dialog is described by it. |
confirmLabel | string | Confirm | The confirm button's label, such as Delete. |
cancelLabel | string | Cancel | The cancel button's label. |
destructive | boolean | false | Shows the confirm button in the danger colour. |
open | boolean | bindable(false) | Whether the dialog shows. Bind it with bind:open={name}; it clears itself when either button is pressed. |
onConfirm | () => void | | Runs when the confirm button is pressed. |
onCancel | () => void | | Runs when the cancel button is pressed or Escape is pressed. |
Pieces
| Piece | Means |
trigger | The control that opens it. Focus returns to it on close. |
States
| State | Looks like |
open | A panel up to 360px wide, centred over the scrim, with Cancel (secondary) then Confirm, end-aligned. |
destructive | The confirm button is a danger Button. |
opening | The scrim fades in and the panel grows from 95%, in 160 ms; at once with reduced motion. |
Accessibility
| |
| role | alertdialog with aria-modal="true", described by its message |
| name | The title prop (aria-label). |
| focus | On open, focus goes to the cancel button, the safe choice. Tab stays inside; the page behind is inert. On close, focus returns to the control that opened it. |
| keyboard | Escape cancels. A press on the backdrop does nothing, so the choice is always deliberate. |
Theme tokens
color.scrim color.surface color.ink color.muted color.primary color.danger shadow.lg radius.lg space.2 space.5 space.6 text.heading text.body
Example
<AlertDialog title="Delete this post?" confirmLabel="Delete" destructive bind:open={confirming} onConfirm={remove} />