Alert Dialog
A modal confirmation that requires an explicit answer before the user continues.
Usage guidelines
- Use
AlertDialogonly for a destructive or must-confirm decision that needs an explicit answer. A task, a form or content to read usesDialog. - Outside presses never dismiss an alert dialog.
EscapeandAlertDialogCancelButtonstill close it; when the answer must be explicit, cancel that close inonOpenChange. - Put the title and description in
AlertDialogHeader. Anything the user fills in or reviews before answering goes inAlertDialogBody. - Every alert dialog has an
AlertDialogTitlephrased as the question, which names the dialog. The description states the consequence. AlertDialogConfirmButtondefaults to a primary destructive button and does not close the dialog. Close it from the handler throughactionsRef, a handle or controlledopen. Settone="default"for a confirmation that destroys nothing.- Use
AlertDialogTriggerunder the root for a dedicated button. A menu command opens a sibling alert dialog through a handle, and controlledopenis for open state another owner must observe. - Keep the dialog open while its request is pending only when closing would lose the outcome or the way to retry. Close it on success and keep it open with the error on failure.
Anatomy
AlertDialogContent bundles the portal, backdrop and centered popup. AlertDialogCancelButton and AlertDialogConfirmButton render Button and take its props.
Examples
Typing to confirm
For an irreversible action on a named resource, ask the user to type the name in AlertDialogBody. A Form with className="contents" keeps the body and footer in the surface layout, and the confirm button submits it once the name matches.
Pending request
Control open to close the dialog when the request succeeds. While it is pending, onOpenChange cancels the close so Escape cannot dismiss it, and the confirm button keeps focus with a stable aria-labelledby name. A failed request keeps the dialog open with the error in AlertDialogBody so the user can retry. In this example, the Fail the next request switch makes the next attempt fail and turns itself off, so the retry succeeds.
Opening from a menu command
Keep the menu and the alert dialog as siblings. The menu item calls open(null) on the dialog's handle, and focus returns to the menu trigger when the dialog closes.
Keyboard
| Key | Action |
|---|---|
| EnterorSpace | Opens the alert dialog from a focused trigger. |
| TaborShift+Tab | Moves focus between the dialog's controls. Focus stays inside the dialog while it is open. |
| Escape | Closes the alert dialog and returns focus to the trigger, unless onOpenChange cancels it. |
API reference
AlertDialog
Groups all parts of a confirmation dialog that requires an explicit user response. Doesn't render its own HTML element.
Outside presses do not dismiss it; users close it with Escape, AlertDialogCancelButton, or your confirm handler.
| Prop | Type | Default | Details |
|---|---|---|---|
onOpenChange | ((open: boolean, eventDetails: BaseAlertDialog.Root.ChangeEventDetails) => void) | No default | |
actionsRef | React.RefObject<DialogRootActions | null> | No default | |
handle | BaseAlertDialog.Handle<Payload> | No default | |
open | boolean | No default | |
defaultOpen | boolean | false | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
children | PayloadChildRenderFunction<Payload> | React.ReactNode | No default | |
triggerId | string | null | No default | |
defaultTriggerId | string | null | No default | |
AlertDialogBody
Accepts the props of the element it renders.
AlertDialogCancelButton
A button that closes the alert dialog when activated. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'small' | 'medium' | |
variant | 'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary' | 'secondary' | |
tone | 'default' | 'destructive' | 'default' | |
loading | boolean | No default | |
focusableWhenDisabled | boolean | false | |
className | string | ((state: ButtonState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ButtonState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
Valid prop combinations:
variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary',tone?: 'default' | 'destructive'variant: 'ghost-accent' | 'secondary-accent',tone?: 'default'
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
AlertDialogConfirmButton
A confirmation button defaulting to variant="primary" and tone="destructive" unless an accent variant is specified. Renders a <button> element.
Does not close the dialog automatically; close it from your handler via actionsRef, a handle, or controlled open.
| Prop | Type | Default | Details |
|---|---|---|---|
size | 'large' | 'medium' | 'small' | 'medium' | |
loading | boolean | No default | |
variant | 'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary' | 'primary' | |
tone | 'default' | 'destructive' | 'destructive' | |
className | string | ((state: ButtonState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ButtonState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ButtonState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
focusableWhenDisabled | boolean | false | |
Valid prop combinations:
variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary',tone?: 'default' | 'destructive'variant: 'ghost-accent' | 'secondary-accent',tone?: 'default'
| Attribute | Description |
|---|---|
data-disabled | Present when the button is disabled. |
AlertDialogContent
A centered modal alert dialog surface bundled with a portal and backdrop. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
children required | React.ReactNode | No default | |
backdropProps | DialogBackdropProps | No default | |
className | string | ((state: DialogPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogPopupState) => React.CSSProperties | undefined) | No default | |
initialFocus | boolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the dialog is open. |
data-closed | Present when the dialog is closed. |
data-starting-style | Present when the dialog begins animating in. |
data-ending-style | Present when the dialog is animating out. |
data-nested | Present when the dialog is nested within another dialog. |
data-nested-dialog-open | Present when the dialog has other open dialogs nested within it. |
| Variable | Description |
|---|---|
--nested-dialogs | Values: Indicates how many dialogs are nested within. |
AlertDialogDescription
A paragraph with additional information about the dialog. Renders a <p> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogDescriptionState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogDescriptionState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogDescriptionState) => React.CSSProperties | undefined) | No default | |
AlertDialogFooter
| Prop | Type | Default | Details |
|---|---|---|---|
spacing | 'compact' | 'default' | 'default' | |
AlertDialogHeader
Accepts the props of the element it renders.
AlertDialogTitle
A heading that labels the dialog. Renders an <h2> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: DialogTitleState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogTitleState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogTitleState) => React.CSSProperties | undefined) | No default | |
AlertDialogTrigger
A button that opens the alert dialog. Renders a <button> element.
| Prop | Type | Default | Details |
|---|---|---|---|
handle | BaseAlertDialog.Handle<Payload> | No default | |
className | string | ((state: DialogTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, DialogTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: DialogTriggerState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
payload | Payload | No default | |
id | string | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the trigger is disabled. |
data-popup-open | Present when the corresponding alert dialog is open. |
createAlertDialogHandle
Creates a new handle to connect an AlertDialog.Root with detached AlertDialog.Trigger components.
Returns
BaseAlertDialog.Handle<Payload>| Member | Type | Description |
|---|---|---|
open required | (triggerId: string | null) => void | Opens the dialog, optionally associating it with a trigger. This method should only be called in an event handler or an effect (not during rendering). |
openWithPayload required | (payload: Payload) => void | Opens the dialog with the given payload, without associating it with any trigger. This method should only be called in an event handler or an effect (not during rendering). |
close required | () => void | Closes the dialog. This method should only be called in an event handler or an effect (not during rendering). |
isOpen required | boolean | Whether the dialog is currently open. Returns |