Skip to content

Confirm ​

showConfirm() asks a yes-or-no question from anywhere in your code and returns a promise. It is window.confirm() in your own markup: it does not freeze the page, it can be styled and translated, and it is a real te-modal underneath — so Escape, the focus trap and the inert page behind it come from the browser.

Usage ​

js
import { showConfirm } from 'vue3-tailwind-elements';

async function remove() {
  const ok = await showConfirm({
    title: 'Delete project',
    message: 'This cannot be undone.',
    confirmLabel: 'Delete',
    type: 'danger',
  });

  if (ok) await api.deleteProject();
}

The promise resolves true only from the confirm button. Cancel, the close button, the backdrop and Esc all resolve false, so a dismissed dialog is a "no" rather than a promise left hanging.

Focus opens on Cancel, which is where you want it when the question is destructive.

Options ​

OptionTypeDefaultDescription
titlestring''Heading. Omit it for a bare question.
messagestring''The question. Line breaks are kept.
confirmLabelstring'Confirm'Label of the yes button.
cancelLabelstring'Cancel'Label of the no button.
typeVariant'primary'Variant of the confirm button.
centeredbooleantrueCentres the dialog vertically.
size'' | 'sm' | 'lg' | 'xl''sm'Dialog width.
showCloseButtonbooleantrueThe × in the header.
closeOnBackdropbooleantrueA click outside answers no.

Server-side rendering ​

With no DOM there is nobody to answer, so showConfirm() resolves false instead of throwing. Guard the call if that would be the wrong default:

js
if (typeof document !== 'undefined' && await showConfirm({ message: 'Sure?' })) {
  // …
}