Skip to content

React Alert Dialog

A glass React alert dialog that asks before destructive actions, focuses the safe choice first and stays open with the error if the action fails.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert-dialog.json

Aurora redesign

42 files, 6 collaborators.

  • AlertDialog
  • AlertDialogIcon
  • AlertDialogClose
  • AlertDialogTitle
  • AlertDialogAction
  • +14 more
  • +11 more

Destructive confirmation

onConfirm returns a promise: the action shows a spinner, Cancel and Escape wait, and the dialog closes when it resolves. Turn on the failure to see the inline error.

Files to copy

8 folders · 14 files · 4 packages
From theme/src/
  • components/alert-dialog/
  • components/button/
  • components/input/
  • components/spinner/
  • hooks/{use-controllable.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, tokens.ts}
  • lib/{cn.ts, field-size.ts, form.ts, modal-tab-trap.ts, popup-motion.ts, state-light.tsx, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/alert-dialog.jsonRegistry item: alert-dialog. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/toast/
  • hooks/use-direction.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/toast.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Type to confirm

For the irreversible: the action stays disabled until the name is typed exactly. Enter submits.

useConfirm()

Ask from any event handler and await the answer: true once the action has finished, false if dismissed. One dialog serves the whole list. After a key is revoked, focus moves to the next row's Revoke button (or to Restore once the list is empty), never to the page; pass finalFocus to choose another target.

  • Production deploysk_live_…4f2a · 2 min ago
  • Stagingsk_test_…9c1e · Yesterday
  • CI pipelinesk_test_…07bd · 3 days ago
  • Local dev (Mira)sk_test_…e6a0 · Last month

Composed from parts

Build your own layout from the pieces. tone sets the icon and the action's color (danger → danger button).

ConfirmDialog

PropTypeDefaultDescription
triggerReactElement<unknown, string | JSXElementConstructor<any>>NoneElement that opens the dialog, e.g. <Button variant="danger">Delete</Button>. Omit it to control the dialog with open.
openbooleanNoneControlled open state. Pair it with onOpenChange.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange((open: boolean) => void)NoneCalled with the next open state when the dialog opens or is dismissed.
onOpenChangeComplete((open: boolean) => void)NoneCalled after the close animation has finished.
toneAlertDialogTone"danger"Colours the icon and the action button, and decides what is focused first.
iconReactNodeNoneReplace the tone icon, or pass null to hide it.
title (required)ReactNodeNoneThe question, e.g. "Delete 3 files?". It names the dialog for screen readers.
descriptionReactNodeNoneSupporting text: what happens and whether it can be undone.
childrenReactNodeNoneExtra content between the text and the buttons (a list of what will be affected, …).
confirmLabelReactNodeNoneShorthand for labels.confirm.
cancelLabelReactNodeNoneShorthand for labels.cancel.
onConfirm(() => unknown)NoneRuns when the action is pressed. Return a promise to show a loading state: the dialog stays open (and can't be dismissed) until it settles, closes on success, and shows the error on failure.
onCancel(() => void)NoneCalled when the dialog is dismissed without confirming (Cancel, Escape).
confirmationTextstringNoneRequire typing this text (e.g. a project name) before the action is enabled.
errorMessage((error: unknown) => ReactNode)NoneTurn a thrown error into the message shown in the dialog.
labelsPartial<ConfirmDialogLabels>defaultConfirmDialogLabelsEvery other string, for translation: labels={{ confirm: "…" }}; omitted keys keep the English of defaultConfirmDialogLabels. All 5 keys of ConfirmDialogLabels are listed in the key table under the props table.
initialFocusboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void)Cancel (danger, warning), the action (info)Element focused when it opens: Cancel for danger / warning, the action for info, and the field with confirmationText.
finalFocusboolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void)the trigger (or the element focused before it opened)Where focus goes when it closes.
classNamestringNoneAdds extra classes to the dialog panel.
ConfirmDialogLabels keys and English defaults (5)
Pass any key in labels; the rest keep the defaults of defaultConfirmDialogLabels.
KeyEnglish default
confirmConfirm
cancelCancel
pendingWorking…
errorSomething went wrong. Please try again.
typeToConfirm(text) => ( <> Type <span className="font-sheen-mono font-semibold text-sheen-fg">{text}</span> to confirm ...

Parts and hook

PropTypeDefaultDescription
AlertDialogBase UI AlertDialog.RootNoneopen / defaultOpen / onOpenChange, handle for detached triggers.
AlertDialogHeaderdivNoneIcon + title + description: centered on phones, icon on the left from sm.
useConfirm()[confirm(options) => Promise<boolean>, dialog]NoneRender dialog once; await confirm() anywhere. Options are ConfirmDialog props (finalFocus / initialFocus included).
createAlertDialogHandle()() => HandleNoneOne dialog for many triggers (e.g. every table row).

AlertDialogAction props

PropTypeDefaultDescription
size"sm" | "md" | "lg" | "icon""md"Height and padding, the same scale as every form field: "sm" 32px, "md" 40px, "lg" 48px (sm and md are 44px on touch screens), or "icon" for a square as tall as "md".
nativeButtonbooleantrue; false when render is a non-button elementWhether the rendered element is a native <button>. Defaults to true, or to false when render is something else (e.g. a link): then type/disabled are not added and the disabled state is announced with aria-disabled instead.
trailingReactNodeNoneRenders an icon after the children.
loadingbooleanfalseShows a spinner, ignores clicks and sets aria-busy. Focus stays on the button.
leadingReactNodeNoneRenders an icon before the children.
fullWidthbooleanfalseStretch to the full width of the container.
stateLightbooleanfalseLights the button by state: loading glows in the accent colour (data-state="working"), and a data-state of "success", "warning" or "error" flashes its own glow once (an aura, a light pool and a lit edge, drawn on the button's own layer). The state is never conveyed by light alone: keep the label or icon that says it. Off with reduced transparency and forced colours; instant with reduced motion.
closeOnClickbooleantrueClose the dialog when pressed. Turn off to run async work first (and set loading).
variant"link" | "danger" | "primary" | "glass" | "outline" | "ghost""danger" for the danger tone, otherwise "primary"Visual style. By default it follows the dialog's tone: a danger button for the danger tone, a primary one for every other tone.

AlertDialogCancel props

PropTypeDefaultDescription
variant"link" | "danger" | "primary" | "glass" | "outline" | "ghost""glass"Look: "primary" (accent fill), "glass" (frosted), "outline" (edge only), "ghost" (text only), "link" (inline link look) or "danger" (destructive).
size"sm" | "md" | "lg" | "icon""md"Height and padding, the same scale as every form field: "sm" 32px, "md" 40px, "lg" 48px (sm and md are 44px on touch screens), or "icon" for a square as tall as "md".
loadingbooleanfalseShows a spinner, ignores clicks and sets aria-busy. Focus stays on the button.
leadingReactNodeNoneRenders an icon before the children.
trailingReactNodeNoneRenders an icon after the children.
fullWidthbooleanfalseStretch to the full width of the container.
stateLightbooleanfalseLights the button by state: loading glows in the accent colour (data-state="working"), and a data-state of "success", "warning" or "error" flashes its own glow once (an aura, a light pool and a lit edge, drawn on the button's own layer). The state is never conveyed by light alone: keep the label or icon that says it. Off with reduced transparency and forced colours; instant with reduced motion.
nativeButtonbooleantrue; false when render is a non-button elementWhether the rendered element is a native <button>. Defaults to true, or to false when render is something else (e.g. a link): then type/disabled are not added and the disabled state is announced with aria-disabled instead.

AlertDialogContent props

PropTypeDefaultDescription
childrenReactNodeNoneHolds the dialog body: usually AlertDialogHeader and AlertDialogFooter.
toneAlertDialogTone"danger"Colours the icon and the default action button.
iconReactNodethe built-in icon for the toneReplace the tone icon, or pass null to hide it.
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | nulldocument.bodySets where the dialog is portalled.
backdropClassNamestringNoneSets the class of the dimmed scrim.

AlertDialogIcon props

PropTypeDefaultDescription
toneAlertDialogTonethe surrounding dialog's toneWhich tone's shape and color to draw; defaults to the surrounding dialog's tone.

Keyboard

KeysAction
Enter/SpaceOpen it from the trigger.
Tab/Shift + TabCycle inside; focus is trapped.
EscapeDismiss it (blocked while the action runs) and return focus to the trigger.
EnterIn a type-to-confirm field, submit once the text matches.

Accessibility

  • role="alertdialog" named by the title and described by the description; the page behind is inert.
  • Initial focus lands on Cancel for danger and warning tones (the safe choice), on the action for info, or on the type-to-confirm field.
  • While pending, aria-busy and a polite status announce it; errors use role="alert". The tone icon is decorative, so the title carries the meaning.
  • If the trigger was removed (a deleted row), focus lands on the same spot in the list.

All exports on this page

  • AlertDialog — Root of an alert dialog: holds the open state and wires the trigger, popup and buttons together.
  • AlertDialogAction — The confirming action.
  • AlertDialogCancel — Closes the dialog without doing anything.
  • AlertDialogClose — Any element inside the dialog that closes it when pressed (Base UI AlertDialog.Close).
  • AlertDialogContent — The dialog panel: portal, dimmed scrim and a glass popup.
  • AlertDialogDescription — Supporting text under the title (Base UI AlertDialog.Description).
  • AlertDialogFooter — Buttons row: stacked full-width on phones (action on top, in thumb reach), a right-aligned row from sm.
  • AlertDialogHeader — Icon + title + description.
  • AlertDialogIcon — The tone icon in a soft tinted disc.
  • AlertDialogTitle — The dialog's name (Base UI AlertDialog.Title, an <h2>).
  • AlertDialogTrigger — The button that opens an AlertDialog (Base UI AlertDialog.Trigger).
  • ConfirmDialog — A complete confirmation dialog in one component: tone icon, title, description, Cancel and the action, a loading state while an async onConfirm runs.
  • createAlertDialogHandle — Connects an AlertDialog to triggers rendered elsewhere (e.g.
  • defaultAlertLabels — The English AlertLabels used when labels is omitted; a partial labels prop is merged over it.
  • defaultConfirmDialogLabels — The English strings of ConfirmDialog (Confirm, Cancel, Working…, a generic error, the type-to-confirm prompt).
  • useConfirm — Ask from any event handler and await the answer: const [confirm, confirmDialog] = useConfirm().

When to use the alert dialog

  • Use it as a delete confirmation modal before deleting a project, revoking an API key or discarding unsaved changes, where the person must choose because an outside click will not dismiss it, only nudge the panel.
  • Use ConfirmDialog when you want the whole thing prebuilt: icon, title, description, Cancel and action, a loading state while an async onConfirm runs, and inline errors if it throws.
  • Use useConfirm in an event handler when awaiting the answer reads best, as in if (await confirm({ title: "Delete?" })), or add type-to-confirm for actions as serious as deleting an organization.
  • Skip it when the content is informational or a form that people may dismiss freely; Dialog closes on an outside press, and Toast fits a quiet notice better than a blocking prompt.
  • Pair it with Button for the trigger through the render prop, Toast to confirm that the action happened, and DataTable rows, where ConfirmDialog and useConfirm move focus to the matching control in the neighboring row after a delete.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .