Alert dialog
npx shadcn add @klarhimmel/alert-dialog @klarhimmel/buttonCopy for AIExamples
Destructive
Confirm
Controlled
DetailsAbout, usage, props and more
A confirmation that cannot be dismissed by accident. Built on Dialog.
When to use
Use for
A decision with consequences that must not be taken by accident: delete, send, publish.
Not for
Information. Use Banner. A task with fields. Use Dialog.
Pairs with
Button, a short sentence.
Preview
Nothing deleted yet.
Import
Import
- Files
- alert-dialog.tsx, button.tsx, in components/klarhimmel/ui/. With it: dialog, editing, theme, utils. npm: radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Same as Dialog. |
defaultOpen | boolean | - | |
onOpenChange | (open: boolean) => void | - | Same as Dialog. |
trigger | ReactNode | - | The element that opens it (a Button). Omit for a controlled dialog. |
title | string | required | Required: the question, written as one ("Delete the Garden room?"). |
description | string | required | What happens if they say yes. Read out with the title. |
confirmLabel | string | required | The label of the yes button. Name the action ("Delete room"), never "OK". |
cancelLabel | string | 'Cancel' | The label of the safe button. |
onConfirm | () => void | required | Called when the confirm button is pressed; the dialog closes after it. |
destructive | boolean | - | Styles the confirm button in the danger colour. |
Accessibility
| Key | Does |
|---|---|
Tab / Shift+Tab | Cycles inside the dialog |
Escape | Cancels and returns focus to the trigger |
Enter / Space | Activates the focused button |
A click outside does not close it. Write the confirm label as the action, not "OK".
Accessibility