Overview
Reference usage
Pre-wired modal dialog for user-initiated binary decisions: "proceed" or "cancel". Focus defaults to the cancel button — the industry-standard guard against accidental destructive confirms.
See the dialog preset boundary for the preserved role, acknowledgement, and dismissal contract.
Below a 760px viewport, the dialog is a bottom sheet with a grabber. Cancel stays compact when both actions fit on one row. When they stack, both buttons fill the available width, with confirmation above Cancel. Both have a 44px hit area and Cancel keeps initial focus. Escape closes the sheet. Set sheetBelow to a CSS length to adjust the breakpoint or to false for the centred dialog at every width.
Dialog model
ConfirmDialog is one of three dialog-level components:
Modal— generic shell for rich content and forms. Use when the interaction requires more than two actions or rich body content.ConfirmDialog— this component. Preset for user-initiated yes/no decisions. Escape, backdrop click, and the close-X all fireonCancel.AlertDialog— preset for urgent blocking acknowledgements. Cannot be dismissed by Escape or backdrop click. No close button. The user must click an action button.
The key distinction between ConfirmDialog and AlertDialog is who initiates the interruption:
- ConfirmDialog is for user-initiated actions that need a safety gate ("You clicked Delete — are you sure?"). Escape is a safe exit; cancel is the default focus.
- AlertDialog is for system-initiated or out-of-band urgency ("Your session expired", "A background process failed"). Escape is blocked; acknowledgement is mandatory.
Choosing this component
- Asking the user to confirm before deleting, discarding, or publishing something that cannot easily be undone.
- Any two-action flow where the only choices are "proceed" and "cancel" — ConfirmDialog saves you from composing Modal + two Buttons manually.
- Destructive actions: set
destructiveto apply the danger variant to the confirm button.
Choosing something else
- When the dialog body needs rich content beyond a list, a note and a few labelled controls (a long form of many fields, several sections, markup around controls) — compose
Modaldirectly instead. A plain list, a short note, or one or two labelled controls that change what the confirmation does (a checkbox, a reason field) go inoptions; see A list or a note inoptions. - When more than two actions are needed — use
Modalwith a customfootersnippet. - When the dialog is triggered by a system event or out-of-band condition requiring mandatory acknowledgement — use
AlertDialoginstead. - Non-blocking notifications — use a toast or inline alert that does not interrupt the flow.
Related components
Modal— the underlying primitive; use directly when you need more control over content or actions.AlertDialog— sticky blocking acknowledgement; cannot be dismissed by Escape or backdrop click.
Usage
A list or a note in options
Put what each choice does in options. A plain <ul> as a direct child is drawn as flat rows: no bullets, a hairline between rows, and long words wrap. Each <li> is one item, usually a <strong> name and one sentence; join them with a full stop or a colon. A <p> as a direct child is a note and takes the description's muted, small treatment. Do not wrap the list in a card, callout, or tinted panel: the dialog is already the surface, and the page adds no CSS for the list.
Cancel keeps the first focus. The exception is a form in options that the person fills in before anything can be confirmed: put autofocus on its first field and that field, which comes before Cancel in the dialog, takes the first focus instead.
Waiting for the answer: pending
Set pending while what the dialog confirms is still being worked out, such as a count the server has not answered. The description and options regions show a skeleton that keeps the room the answer will take, pendingLabel is announced once as a status, and the confirm button cannot be pressed. Cancel stays enabled and keeps the first focus, so a person can leave while the answer is in flight. The typed field waits with the rest of the body, and entering pending clears what was typed, so a new answer is confirmed afresh. Nothing describes the dialog while it waits; aria-describedby returns with the description.
A different next step after a failure: errorAction
By default a failure keeps the confirm button armed, so pressing it again is the retry. When that is the wrong next step, set errorAction to { label, onAction }: the action is drawn in the failure callout and the confirm button is not drawn while the failure shows. Use it for a preview that must be counted again, or work that cannot be repeated as it was. errorTone="warning" draws a refusal nothing was done about, such as a stale preview, as a warning instead of a danger callout. Clear error and the confirm button returns. Below the sheet breakpoint a lone action normally fills the footer row, but here Cancel (relabel it "Close" with cancelLabel) is the only button of the row and the callout's action is what leads, so Close is compact at the inline end instead of a full-width button that outweighs it (an owner exception to the lone-action rule, 2026-11-21). A dialog with nothing to confirm and no failure action keeps the full-width Close.
A form that is not valid yet, and nothing to confirm
confirmEnabled={false} disables the confirm button while the answer it confirms is incomplete, such as a form in options that is not valid yet. confirmVisible={false} draws no confirm button when there is nothing to confirm, such as the answer to a finished action: Cancel is then the one action, so name it with cancelLabel ("Close").
When to use
- Requiring an explicit yes/no acknowledgement before performing a destructive or irreversible action.
- Asking the user to confirm a discrete decision with two clear outcomes.
- Collecting a long form of many fields or sections: compose a modal instead. One or two labelled controls fit in options.
- Announcing a non-blocking result — use toast-region or banner.
Examples
Confirm dialog
A destructive action gated behind an explicit confirm and cancel prompt.
Delete account
A destructive ConfirmDialog for permanent account and data deletion. Default focus lands on Cancel to guard against accidental confirmation.
Error action: a different next step after a failure
errorAction puts an action in the failure callout and takes the confirm button away while the failure shows, for a failure where pressing confirm again is the wrong next step. errorTone="warning" draws a refusal nothing was done about, here a preview that went stale, as a warning. The first press fails; Refresh preview clears the failure and arms Purge again with the new count.
In flight, then failed, then retried
closeOnConfirm={false} keeps the dialog open while the work runs. busy shows the busy label on an inert button and blocks every way out; a failure shows a danger callout between the body and the actions, keeps the typed identifier, and leaves Delete agent armed, so pressing it again is the retry. The first press fails; the second succeeds.
Options below the description
The description is a sentence and may carry monospace (a file path) as a snippet. options sits below it for a choice that changes what the confirmation does: here an unchecked checkbox that says what each choice does. The glyph on the confirmation is a trash can.
Pending: a count the server has not answered
pending shows a skeleton where the description and options go, announces the pendingLabel once as a status, and disables the confirm button. Cancel stays enabled and keeps the first focus, so a person can leave while the count is in flight. The typed field waits with the rest of the body, and what was typed for an older answer is cleared.
Restart now: a glyph on the confirmation
A confirmation that is not destructive keeps the primary button, and confirmIcon draws a glyph before its label so the label and the glyph say what happens. The dialog names the effect on running work, and Cancel keeps the first focus.
Props
Name | Type | Default | Description |
|---|---|---|---|
open bindable | boolean | false | Controls visibility. Bindable. |
title required | text | Modal title; passed through to <Modal>. | |
description | text | Optional body description — a short sentence or two. Rendered as a single <p> and wired
to aria-describedby. A string is plain text; a snippet may add phrasing content inside the
sentence, such as a key in <code>. Anything bigger than a sentence (a list, a code block, a
checkbox) goes in options, below it. Screen readers announce aria-describedby targets as one
continuous run, so keep the description short either way. | |
options | snippet | Content rendered below the description and above the typed confirmation: a checkbox that
changes what the confirmation does, or the exact command about to run in a code block. The
description says what the dialog does; the options say what each choice does. Keep the
description short, and keep controls here labelled. Cancel keeps the first focus unless a
control here carries autofocus: it comes before Cancel in the dialog, so it takes the first
focus instead. Use that for a form the person fills in before anything can be confirmed. | |
cancelLabel | text | 'Cancel' | Label for the cancel button, which ALWAYS renders. |
confirmLabel required | text | Confirm button label. Required — no default. Name the action being confirmed: - Destructive: "Delete", "Discard changes", "Remove from organization". - Non-destructive: "Save", "Continue", "Publish". Never use "OK" or "Confirm" in production — they don't describe the action. | |
confirmIcon | snippet | Glyph at the start of the confirm button, such as a restart, stop or trash icon. Decorative: the label names the action. | |
destructive | boolean | false | When true, the confirm button uses variant="danger". The cancel button still receives default focus regardless — color is never the sole destructive signal. |
busy | boolean | false | True while the confirmed work is in flight. The confirm button shows busyLabel and a spinner
and ignores presses (it stays focusable), Cancel is inert, the typed field is read-only, and
the dialog cannot be dismissed (Escape, the backdrop and the close button do nothing) until
the work answers. Pair it with closeOnConfirm={false}, so the dialog stays open to show the
answer. |
busyLabel | text | Confirm button label while busy, such as "Restoring…" or "Deleting…". Defaults to
confirmLabel, so the words stay put and only the spinner shows. | |
errorTitle | text | Title of the failure callout, such as "Couldn’t delete the agent.", drawn on its own line above
error as every Callout title is. Shown only with error. | |
error | text | Why the confirmed work failed, in a danger callout between the body and the actions that is announced as it appears: "Nothing was deleted." The dialog stays open, the typed text stays, and the confirm button stays armed under its own label, so pressing it again is the retry. Clear it to hide the callout. | |
errorTone | 'danger' | 'warning' | 'danger' | Tone of the failure callout: danger (the default) for work that failed, warning for a
refusal that nothing was done about, such as a preview that went stale before it was confirmed. |
errorAction | {
/** The action's label, such as "Refresh preview" or "Retry". */
label: string;
/** Called when the action is pressed. The dialog stays open; the page d… Show full type{
/** The action's label, such as "Refresh preview" or "Retry". */
label: string;
/** Called when the action is pressed. The dialog stays open; the page decides what follows. */
onAction: () => void;
} | An action in the failure callout, in place of the confirm button. Without it, the failure keeps
the confirm button armed and pressing it again is the retry. With it, the confirm button is
gone while the failure shows, because pressing it again is the wrong next step (a preview that
must be counted again, work that cannot be repeated as it was), and the callout offers the
right one: label names it and onAction runs it. Shown only with error. | |
pending | boolean | false | True while what the dialog confirms is still being worked out, such as a count the server has
not answered: the description and options show a skeleton, the typed field waits, and the
confirm button cannot be pressed. Cancel stays enabled and focusable. Entering pending
clears the typed text, so a new answer is confirmed afresh. |
pendingLabel | text | 'Loading' | What the skeleton is waiting for, announced once as a status when pending starts, such as
"Counting the workflows a purge would delete". |
confirmEnabled | boolean | true | Whether the confirm button can be pressed. Set false while the answer it confirms is
incomplete, such as a form in options that is not valid yet. The typed confirmation and
pending disable it as well. |
confirmVisible | boolean | true | Whether the confirm button is drawn. Set false when there is nothing to confirm, such as the
answer to a finished action: Cancel is then the one action, so name it with cancelLabel
("Close"). |
closeOnConfirm | boolean | true | Whether the dialog closes itself when the confirm button is pressed. Set false when the
confirmed work can fail and the page needs the dialog to stay open to show it: the page then
closes the dialog with open = false once the work succeeds. |
typeToConfirm | text | When set, renders a labelled text input and disables the confirm button until the trimmed input matches this value case-insensitively. The input sits in the footer, above the buttons it gates and outside the scrolling body, so a long description or list never pushes it out of view and it is always in view with the confirm button. | |
typeToConfirmLabel | text | Visible label for the typed-confirmation input. Defaults to Type "<value>" to confirm. | |
onConfirm required | () => void | Fired when the user activates the confirm button. Required. The component closes itself
after, unless closeOnConfirm is false. | |
onCancel | () => void | Called when the user cancels (cancel button, Escape, or backdrop per the dialog's policy). | |
triggerRef | HTMLElement | null | null | Forwarded to <Modal>; focus is restored here on close. |
sheetBelow | text | '760px' | Viewport width below which the dialog is a bottom sheet. Cancel stays compact when both
actions fit on one row. When the actions stack, both fill the row width, with confirmation
above Cancel. Both have 44px hit areas and Cancel keeps initial focus. A CSS length such as
"760px", or false for the centred dialog at every width. |
onExitComplete | () => void | Fired once the underlying modal's exit transition has completed. |