Skip to content
SENVENLI UI

Alert dialog

Asks people to confirm or cancel one consequential action, optionally by typing a confirmation.
Confirm a delete
import { AlertDialog } from "@senvenli/react/overlay";

Examples

Typed confirmation

For deletes that cannot be undone: the button enables once the name is typed.

Warning and neutral

A risky step, and a confirm that neither destroys nor risks anything.

An async action

The confirm button shows pending until the promise settles, then the alert closes.

Guidelines

When to use it

  • Before a destructive or risky action: delete, revoke, discard.

Use something else when

  • The task needs a form or more than a confirm. Dialog
  • The action can be undone, so offer Undo instead of asking first. Toast

Do and avoid

  • Title is the question, body is the consequence, the confirm button repeats the verb.

Accessibility

Keyboard

KeysWhat happens
EscCancels.

Built in

  • Role alertdialog; "Cancel" takes the first focus so Enter never destroys by accident.

You provide

  • A question title and the consequence.

API reference

AlertDialog

isOpen
boolean

Open without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put onOpenChange on the trigger instead: the trigger owns the state there.

defaultOpen
boolean
onOpenChange
(isOpen: boolean) => void
tone
"neutral" | "danger" | "warning"

danger (default: a delete, trash-2, a danger button), warning (triangle-alert, a primary button), or neutral for a confirm that neither destroys nor risks anything, such as reactivating an account (info on a neutral ground, a primary button).

titleRequired
React.ReactNode

The action as a question with the object's name: "PG AB 482 filodan silinsin mi?"

childrenRequired
React.ReactNode

The consequence, and what to do first.

confirmLabelRequired
string

The verb again: "Delete item".

cancelLabel
string

The cancel button's text, and so its accessible name ("No, keep it"), in place of the library's "Cancel" . The app passes it already localized; the DS does not translate it. Left out (or ""), the locale's "Cancel" renders and the DOM is unchanged. A long label wraps inside the button, which takes at most the footer's width; focus, Esc and the pending lock are the same either way.

onConfirmRequired
() => void | Promise<void>

May be async: the button shows pending until it settles, and while it runs the dialog cannot be cancelled (the action is under way); it closes when the action succeeds and stays open when it fails.

requireTypedConfirmation
string

For irreversible deletes: the text the user types before the button enables ("PG AB 482").

isConfirmDisabled
boolean

Holds the confirm back while the app loads what it needs ("Loading linked orders"). The button keeps its name and stays in the dialog, disabled as with requireTypedConfirmation: it cannot be pressed (pointer, Enter or Space) and Tab passes it, so "Cancel" stays the one control; screen readers list it as unavailable. Say why in the description or in the element aria-describedby names. Esc and "Cancel" still work.

aria-describedby
string

More of what the alert says, by id: an element the app renders, inside the alert (a Banner in its body) or outside it (a page notice). Added to the alert's own description in aria-describedby, after it, so the alert is announced with both when it opens.

typedConfirmationLabel
string

The field's label; "Type ORD-482 to confirm" by default.

icon
IconName

Overrides the tone's icon (danger trash-2, warning triangle-alert).

returnFocusRef
RefObject<HTMLElement | null>

Where focus goes when the alert closes and React Aria's return would leave it on the page or on the opener, as on Dialog. Needed when the element React Aria returns to is gone by the close: an alert opened from a menu whose trigger unmounts when it closes (pass a stable button), or a confirmed action that removes the row with its Menu (pass a stable element). Opened from a DS Menu item it is not needed: React Aria returns focus to the Menu button itself, and a ref naming another element does not override that. Read when the alert closes; if the app has already moved focus elsewhere on close, it stays there; if the ref is empty, focus returns as before. There is no initialFocusRef: the alert's controls are its own, and "Cancel" takes the first focus. Nor is there a titleRef: the alert is announced with its title and consequence when it opens (aria-labelledby, aria-describedby), and focus starts on the safe answer, never on its text.

motion
ComponentMotion

auto (follow the device), reduce or none, for this component; the provider's setting otherwise.