Skip to content

Alert Dialog

A modal confirmation that requires an explicit answer before the user continues.

hero.tsx

Usage guidelines

  • Use AlertDialog only for a destructive or must-confirm decision that needs an explicit answer. A task, a form or content to read uses Dialog.
  • Outside presses never dismiss an alert dialog. Escape and AlertDialogCancelButton still close it; when the answer must be explicit, cancel that close in onOpenChange.
  • Put the title and description in AlertDialogHeader. Anything the user fills in or reviews before answering goes in AlertDialogBody.
  • Every alert dialog has an AlertDialogTitle phrased as the question, which names the dialog. The description states the consequence.
  • AlertDialogConfirmButton defaults to a primary destructive button and does not close the dialog. Close it from the handler through actionsRef, a handle or controlled open. Set tone="default" for a confirmation that destroys nothing.
  • Use AlertDialogTrigger under the root for a dedicated button. A menu command opens a sibling alert dialog through a handle, and controlled open is 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

tsx
tsx

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.

type-to-confirm.tsx

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.

pending.tsx

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.

menu-command.tsx

Keyboard

KeyAction
EnterorSpaceOpens the alert dialog from a focused trigger.
TaborShift+TabMoves focus between the dialog's controls. Focus stays inside the dialog while it is open.
EscapeCloses 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.

Base UI AlertDialog.Root docs

AlertDialogBody

Accepts the props of the element it renders.

AlertDialogCancelButton

A button that closes the alert dialog when activated. Renders a <button> element.

Base UI Button docs

Props
PropTypeDefaultDetails
size'large' | 'medium' | 'small''medium'
variant'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary''secondary'
tone'default' | 'destructive''default'
loadingbooleanNo default
Base UI Button docs

Valid prop combinations:

  • variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary', tone?: 'default' | 'destructive'
  • variant: 'ghost-accent' | 'secondary-accent', tone?: 'default'
Data attributes
AttributeDescription
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.

Base UI Button docs

Props
PropTypeDefaultDetails
size'large' | 'medium' | 'small''medium'
loadingbooleanNo default
variant'ghost' | 'ghost-accent' | 'primary' | 'secondary' | 'secondary-accent' | 'tertiary''primary'
tone'default' | 'destructive''destructive'
Base UI Button docs

Valid prop combinations:

  • variant?: 'ghost' | 'primary' | 'secondary' | 'tertiary', tone?: 'default' | 'destructive'
  • variant: 'ghost-accent' | 'secondary-accent', tone?: 'default'
Data attributes
AttributeDescription
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.

Base UI Dialog.Popup docs

Props
PropTypeDefaultDetails
children requiredReact.ReactNodeNo default
backdropPropsDialogBackdropPropsNo default
Base UI Dialog.Popup docs
Data attributes
AttributeDescription
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.

CSS variables
VariableDescription
--nested-dialogs

Values: number

Indicates how many dialogs are nested within.

AlertDialogDescription

A paragraph with additional information about the dialog. Renders a <p> element.

Base UI Dialog.Description docs

AlertDialogFooter

Props
PropTypeDefaultDetails
spacing'compact' | 'default''default'

AlertDialogHeader

Accepts the props of the element it renders.

AlertDialogTitle

A heading that labels the dialog. Renders an <h2> element.

Base UI Dialog.Title docs

AlertDialogTrigger

A button that opens the alert dialog. Renders a <button> element.

Base UI AlertDialog.Trigger docs

Data attributes
AttributeDescription
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>
Return properties
MemberTypeDescription
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 requiredboolean

Whether the dialog is currently open. Returns false while no root is attached to the handle.