Alert Dialog
AlertDialog stops people to confirm an action that is hard to undo, such as a delete.
<AlertDialog> <AlertDialogTrigger render={<Button>Delete…</Button>} /> <AlertDialogContent> <AlertDialogTitle>Delete workspace?</AlertDialogTitle> <AlertDialogDescription> Everything in it goes with it. </AlertDialogDescription> <AlertDialogCancel>Keep it</AlertDialogCancel> <AlertDialogAction tone="destructive">Delete</AlertDialogAction> </AlertDialogContent></AlertDialog>An alert dialog interrupts people to ask a question with two answers, such as "Delete this file?". It holds a title, a description, a cancel button and an action button, and it arranges these parts for you.
Use an alert dialog before an action that is hard to undo. If the panel holds work, such as a form, or needs any control other than the two buttons, use a Dialog instead.
Write the question as the title, and say in the description what happens if people go ahead. Give the action a short verb, such as Delete, rather than OK. The two buttons sit side by side while both labels fit on one line, with Cancel on the start side. If a label is too long, the buttons stack with the action on top, so a label never wraps.
A press outside the alert does nothing, because a stray click must not answer the question. Escape closes the alert in the same way as Cancel. Both buttons close the alert when they are pressed.
size sets the whole alert: its width, padding, corner, text and buttons. Each size has a fixed width that is narrower than a Dialog of the same size. The page behind the alert dims, and the panel uses the material that your Theme sets.
The alert uses role="alertdialog", so a screen reader announces its title and description when it opens. Focus starts on Cancel, stays inside the alert while it is open, and returns to the trigger when it closes. The part names follow shadcn/ui's alert-dialog (MIT), and the behaviour comes from Base UI.
- Dialog when the person is doing a task.
Topics
Every symbol this component exports, grouped by the job it does. Each one carries the props it declares; each one has an anchor of its own.
Asking the question
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The AlertDialogTrigger and the AlertDialogContent. |
defaultOpen? | boolean | Uncontrolled starting state. |
onOpenChange? | (open: boolean, details: OverlayOpenChangeDetails) => void | Called when the alert opens or closes. |
open? | boolean | Controlled open state. |
size? | "1" | "2" | "3" | "4" | Sets the size step of the whole alert. |
AlertDialogTrigger
The control that opens the alert, usually written as render={<Button/>}. If your app opens the alert from its own state, you do not need a trigger
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The button's label. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
disabled? | boolean | Turns the trigger off, so the alert cannot be raised from here. |
nativeButton? | boolean | Tells the trigger if the rendered element is a real <button>. |
render? | RenderElement | Usually a Kookie Button: <AlertDialogTrigger render={<Button/>}>Delete…</AlertDialogTrigger>. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
Presenting the panel
AlertDialogContent
Shows the panel above the page in a portal, dims the page behind it and centres the panel. It also places the title, the description and the buttons for you
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The alert's parts, in reading order: AlertDialogTitle, AlertDialogDescription, AlertDialogCancel, then AlertDialogAction. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <div>.
Wording it
AlertDialogTitle
The question, shown as a heading and used as the alert's accessible name. The alert's size sets its text size
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The question that the alert asks. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <h2>.
AlertDialogDescription
Tells people what happens if they go ahead. It uses the muted text colour and is the alert's accessible description
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The result of going ahead, such as what is lost and if it can come back. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <p>.
The two ways out
AlertDialogCancel
The safe way out, shown as a medium Button at the alert's size. Write it first, so it comes first in reading order and gets focus when the alert opens
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The label of the safe choice. "Cancel" is always correct. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
disabled? | boolean | Turns off the Cancel button. |
onClick? | React.MouseEventHandler<HTMLButtonElement> | Called on the press, before the alert closes. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
It also takes every prop of a <button>.
AlertDialogAction
The button that goes ahead, always shown as the strong Button at the alert's size. Set tone="destructive" on it when the action deletes something
| Prop | Type | What it does |
|---|---|---|
children? | React.ReactNode | The label of the action. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
disabled? | boolean | Turns off the action button, such as until the person types a name to confirm. |
onClick? | React.MouseEventHandler<HTMLButtonElement> | Called when the action is pressed. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
tone? | "neutral" | "accent" | "destructive" | "blue" | "green" | "orange" | "amber" | "pink" | "purple" | "success" | "warning" | "info" | Sets the colour meaning of the action button. |
It also takes every prop of a <button>.
- A width prop — Each size has a fixed width that suits a short question and two buttons. If your content needs more room, it is doing more than asking a question, so use a
Dialog. - Closing on an outside press — A stray click must not answer a question that could delete something. People can still press Escape, which works the same as Cancel.
- Header and footer parts — The alert arranges the title, the description and the two buttons itself, so you write the parts in order and need no layout parts. Put Cancel first, because that is the button that gets focus.
renderon Cancel and Action — The alert sets the size and position of both buttons, so they cannot become a different element. The action is always the strong button, because it is the only action in the alert.- Arbitrary
children— An alert holds only a title, a description and two buttons. If you need a text field, a checkbox or any other control, use aDialog.