Skip to content

Confirm dialog ​

A controlled yes-or-no dialog. Use it directly, or await it through useConfirm.

Open in demo
Open in demo

Usage ​

The dialog is fully controlled. You own open, and the buttons emit confirm and cancel rather than closing themselves. update:open with false covers Escape and an overlay press, which you should treat as a cancel.

The buttons are plain buttons, not the auto-closing action and cancel from the dialog primitive. Those race their close event ahead of the click handler, which is how a confirm gets reported as a cancel.

confirmLabel and cancelLabel default to translation keys, so they follow the language switcher. A string you pass wins.

Examples ​

Destructive ​

variant="destructive" draws the confirm button in the destructive color. It changes nothing else, so the words still have to say what will happen.

Through useConfirm ​

useConfirm().confirm(options) returns a promise of true or false, so a flow reads top to bottom with no dialog state in your component. One host, ConfirmHost, mounted in App.vue, renders whichever dialog the variant asks for and keeps it mounted through its close animation.

A second confirm() while one is open cancels the first, resolving it false, rather than queueing or throwing.

Through useConfirm, a destructive request is retitled: the dialog's heading becomes "Are you sure?" and your own title drops into the body, where it names the target. That is done once at the host, so every call site keeps passing title: 'Delete John Doe?' and the reader still sees those words, one line lower. A default confirm is left alone, because it is already phrased as a question.

API ​

Source: src/shared/components/feedback/ConfirmDialog.vue

Props ​

PropTypeDefaultDescription
openbooleanrequiredYou own it.
titlestringrequiredThe heading. A translation key or a literal.
descriptionstring—The body.
confirmLabelstring'confirm.confirm'Defaults to "Confirm".
cancelLabelstring'confirm.cancel'Defaults to "Cancel".
variant'default' | 'destructive''default'The confirm button's color.

Emits ​

EventPayloadDescription
update:openvalue: booleanfalse on Escape or an overlay press.
confirm—The confirm button.
cancel—The cancel button.

Slots ​

None.

ConfirmOptions ​

What useConfirm().confirm() takes.

KeyTypeDescription
titlestringRequired.
descriptionstring
variant'default' | 'destructive' | 'multi-step'destructive with requireMatch renders the destructive confirm; multi-step renders the multi-step confirm.
requireMatchstringThe text the reader has to type.
confirmLabelstring
cancelLabelstring

Accessibility ​

  • It is an alert dialog: focus moves into it, Tab is trapped inside it, and Escape closes it.
  • The title and the description are wired to the dialog by the primitive, so both are announced on open.
  • Both text runs carry dir="auto". A confirm's words are composed at the call site, so they are routinely English inside a right-to-left document, where a trailing ? or . would otherwise paint at the start of the line. The dialog itself still mirrors; only the text runs are pinned.