Skip to content

Alert Dialog

Free

A window that asks a yes or no question before an action that deletes data or cannot be undone. The page waits until the person answers.

  • Base UI
  • React 19
  • Tailwind CSS 4

Added Nov 8, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

AlertDialogAction does not close the alert. Control open, and close it when the action ends.

delete-file-dialog.tsx

AlertDialog

PropTypeDefaultDescription
From Base UIAlertDialog.RootBase UI docs
onOpenChange—Event handler called when the alert dialog is opened or closed.
actionsRefRefObject<DialogRootActions | null>—A ref to imperative actions. - unmount: Ends the closing phase of the alert dialog after an externally controlled closing animation finishes. Call preventUnmountOnClose in onOpenChange first, otherwise the alert dialog completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal. - close: Closes the alert dialog imperatively when called.
handleAlertDialogHandle<Payload>—A handle to associate the alert dialog with a trigger. If specified, allows external triggers to control the alert dialog's open state. Can be created with the AlertDialog.createHandle method.

AlertDialogTrigger

<button>
PropTypeDefaultDescription
classNamestring—
From Base UIDialog.TriggerBase UI docs
payloadPayload—A payload to pass to the dialog when it is opened.
idstring—ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot triggerId prop).
handleAlertDialogHandle<Payload>—A handle to associate the trigger with an alert dialog. Can be created with the AlertDialog.createHandle method.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.

AlertDialogPortal

<div>
PropTypeDefaultDescription
From Base UIDialog.PortalBase UI docs
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
container—A parent element to render the portal element into.
className—CSS class applied to the element, or a function that returns a class based on the component's state.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogOverlay

<div>
PropTypeDefaultDescription
classNamestring—
From Base UIDialog.BackdropBase UI docs
forceRenderbooleanfalseWhether the backdrop is forced to render even when nested.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogContent

<div>
PropTypeDefaultDescription
size"default""sm""default"
classNamestring—
portalProps—Other Base UI props of the inner parts. A className here adds to the component classes.
backdropPropsAlertDialogOverlayProps—
viewportProps—
From Base UIDialog.PopupBase UI docs
initialFocus—Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - false: Do not move focus. - true: Move focus based on the default behavior (first tabbable element or popup). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
finalFocus—Determines the element to focus when the dialog is closed. - false: Do not move focus. - true: Move focus based on the default behavior (trigger or previously focused element). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, null to fall back to the default behavior, or false/undefined to do nothing.
container—A parent element to render the portal element into.
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogHeader

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogMedia

<div>
PropTypeDefaultDescription
tone"destructive""info""neutral""success""warning"—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogTitle

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogDescription

<div>
PropTypeDefaultDescription
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogFooter

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogCancel

<div>
PropTypeDefaultDescription
rounded"default""full"—
size"default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs"—
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary""outline"
classNamestring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

AlertDialogAction

<button>
PropTypeDefaultDescription
glass"clear""dark""light"—
rounded"default""full"—
size"default""icon""icon-lg""icon-sm""icon-xs""lg""sm""xl""xs"—
variant"dashed""default""destructive""destructive-outline""ghost""link""media""outline""secondary"—
classNamestring—
busyboolean—The button waits for the app (busy words): a spinner, aria-busy, and no clicks. Focus stays on the button. The style hook stays data-loading.
spinnerPlacement"center""start"—center (default): the spinner covers the label. start: it takes the leading icon slot. The icon sizes always use center, because their one icon is the label.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.
  • Use it when the user must answer before they go on. An outside click does nothing.
  • Name the thing and the result in the title: "Delete Q3 roadmap.pdf?", not "Are you sure?".
  • Put AlertDialogCancel first in the footer, so the safe choice gets the first focus.
  • For a task, a form, or a detail view, use a Dialog.
  • For a note that needs no answer, use a Toast.
EscCloses the alert dialog. Treat it as Cancel.
TabMoves the focus to the next button. The focus stays in the alert dialog.
ShiftTabMoves the focus to the previous button.
EnterPresses the focused button.

The popup has role="alertdialog" from Base UI, and it is always modal. AlertDialogTitle is an h2 that names it, and a screen reader reads AlertDialogDescription when the alert opens.

The focus moves to the first focusable element and stays in the alert. Put AlertDialogCancel first, so the safe choice has the first focus and Enter never confirms by accident. An outside click does nothing. Esc closes the alert.

There is no close button: AlertDialogCancel is the way out for a touch screen reader. AlertDialogMedia is decorative (aria-hidden).

With loading, AlertDialogAction shows a spinner, sets aria-busy, and stops clicks, and the focus stays on it. Each button grows to a 44px touch target on a touch screen (hit-area).

Open
overlay · 200ms · ease-panel (0.2, 0.4, 0.2, 1) · the panel fades in and scales from 95%, the backdrop fades in
Close
overlay-exit · 150ms · ease-out (0, 0, 0.2, 1) · the panel fades out and scales to 95%, the backdrop fades out

Built with

Installs with Alert Dialog

Components
Button
  1. AddedAlert Dialog, with Button.
Open the release