AlertDialog
A dialog that asks the user to confirm or cancel before continuing.
<template> <AlertDialog v-model:open="open" title="Delete repository" description="This will permanently delete the repository and all of its scan history. This can't be undone."> <template #cancel> <Button variant="ghost">Cancel</Button> </template> <template #action> <Button variant="destructive" @click="onConfirm">Delete</Button> </template> </AlertDialog></template>Props
| Name | Type | Default |
|---|---|---|
| open | boolean (v-model:open) | false |
| title | string | - |
| description | string | - |
Slots
| Name | Description |
|---|---|
| body | Optional extra content between the description and the actions - keep it short, this isn't a form. |
| cancel | Required. Wrapped in reka-ui's AlertDialogCancel (as-child) - put a single <Button> here, e.g. variant="ghost". Closes on click and is where focus lands when the dialog opens. |
| action | Required. Wrapped in reka-ui's AlertDialogAction (as-child) - put a single <Button> here, e.g. variant="destructive" for a delete/remove. Closes on click; add your own @click handler alongside for the actual confirm logic. |
| title | Escape hatch: replaces the `title` prop's plain text. |
| description | Escape hatch: replaces the `description` prop's plain text. |
Guidelines
Do
- Reach for
AlertDialoginstead ofDialogwhen the user must make an explicit choice before continuing - confirming a destructive or otherwise hard-to-reverse action. If they can safely click away and come back to it later, that's aDialog, not this. - Always provide both
#canceland#action- those are the only two ways out. Put the least destructive choice first: cancel asvariant="secondary", the decision itself last (variant="destructive"for a delete/remove,variant="primary"otherwise). - Bind
v-model:opento a localref(false), same asDialog.
- Give it a
description- an alert dialog interrupts the user, so it should always say why.
Don't
- Don't expect a close (×) button -
AlertDialognever renders one. The only way to dismiss it is#cancel,#action, or the Escape key. - Don't expect clicking the overlay to dismiss it either - unlike
Dialog, outside clicks are ignored on purpose. An alert dialog demands a decision, not a shrug. - Don't put more than one action's worth of content in
#body- this is for a short confirmation, not a form. Reach forDialogif the content needs more room.
- Don't use this for anything non-destructive/reversible "just to be safe" - every extra confirmation the user has to click through trains them to stop reading the ones that actually matter.
Examples
Basic
A destructive action the user must explicitly confirm or cancel - no dismiss-and-forget.
const open = ref(false)<Button variant="secondary" @click="open = true">Delete account</Button><AlertDialog v-model:open="open" title="Delete account" description="This will permanently delete your account and remove all of your data. This can't be undone."> <template #cancel> <Button variant="ghost">Cancel</Button> </template> <template #action> <Button variant="destructive" @click="onConfirm">Delete</Button> </template></AlertDialog>