import { Button } from "@senvenli/react/action";
import { AlertDialog, DialogTrigger } from "@senvenli/react/overlay";
export default function Example() {
return (
<DialogTrigger>
<Button variant="primary" tone="danger">Delete invoice</Button>
<AlertDialog title="Delete invoice INV-2041?" confirmLabel="Delete invoice" onConfirm={() => {}}>
The invoice and its payment history are removed for everyone on the team.
</AlertDialog>
</DialogTrigger>
);
}import { AlertDialog } from "@senvenli/react/overlay";Examples
Typed confirmation
For deletes that cannot be undone: the button enables once the name is typed.import { Button } from "@senvenli/react/action";
import { AlertDialog, DialogTrigger } from "@senvenli/react/overlay";
export default function Example() {
return (
<DialogTrigger>
<Button variant="primary" tone="danger">Delete project</Button>
<AlertDialog
title="Delete the project Atlas?"
confirmLabel="Delete project"
requireTypedConfirmation="Atlas"
typedConfirmationLabel="Type the project name to confirm"
onConfirm={() => {}}
>
Its 48 tasks and 12 files are deleted for all 6 members. This cannot be undone.
</AlertDialog>
</DialogTrigger>
);
}Warning and neutral
A risky step, and a confirm that neither destroys nor risks anything.import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { AlertDialog, DialogTrigger } from "@senvenli/react/overlay";
export default function Example() {
return (
<Stack direction="horizontal" space="space-100">
<DialogTrigger>
<Button>Change plan</Button>
<AlertDialog tone="warning" title="Move to the Starter plan?" confirmLabel="Change plan" cancelLabel="Keep Team plan" onConfirm={() => {}}>
Your team keeps access until March 31. After that, 14 of 20 members lose their seats.
</AlertDialog>
</DialogTrigger>
<DialogTrigger>
<Button>Reactivate account</Button>
<AlertDialog tone="neutral" title="Reactivate Ada Lovelace's account?" confirmLabel="Reactivate account" onConfirm={() => {}}>
She can sign in again and sees her projects as she left them.
</AlertDialog>
</DialogTrigger>
</Stack>
);
}An async action
The confirm button shows pending until the promise settles, then the alert closes.import { Button } from "@senvenli/react/action";
import { AlertDialog, DialogTrigger, toast } from "@senvenli/react/overlay";
// Stands in for the request; while it runs the alert cannot be cancelled.
const cancelOrder = () => new Promise<void>((resolve) => setTimeout(resolve, 1500));
export default function Example() {
return (
<DialogTrigger>
<Button>Cancel order</Button>
<AlertDialog
tone="warning"
title="Cancel order ORD-1040?"
confirmLabel="Cancel order"
cancelLabel="Keep order"
onConfirm={async () => {
await cancelOrder();
toast.success("Order canceled", { description: "ORD-1040 · the customer was refunded" });
}}
>
The customer is refunded $248.00 and gets an email about it.
</AlertDialog>
</DialogTrigger>
);
}Guidelines
When to use it
- Before a destructive or risky action: delete, revoke, discard.
Use something else when
Do and avoid
- Title is the question, body is the consequence, the confirm button repeats the verb.
Accessibility
Keyboard
| Keys | What happens |
|---|---|
| Esc | Cancels. |
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
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Open without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put |
defaultOpen | boolean | – | |
onOpenChange | (isOpen: boolean) => void | – | |
tone | "neutral" | "danger" | "warning" | – |
|
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 |
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 |
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 |
typedConfirmationLabel | string | – | The field's label; "Type ORD-482 to confirm" by default. |
icon | IconName | – | Overrides the tone's icon (danger |
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 |
motion | ComponentMotion | – |
|
isOpenbooleanOpen without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put
onOpenChangeon the trigger instead: the trigger owns the state there.defaultOpenbooleanonOpenChange(isOpen: boolean) => voidtone"neutral" | "danger" | "warning"danger(default: a delete,trash-2, a danger button),warning(triangle-alert, a primary button), orneutralfor a confirm that neither destroys nor risks anything, such as reactivating an account (infoon a neutral ground, a primary button).titleRequiredReact.ReactNodeThe action as a question with the object's name: "PG AB 482 filodan silinsin mi?"
childrenRequiredReact.ReactNodeThe consequence, and what to do first.
confirmLabelRequiredstringThe verb again: "Delete item".
cancelLabelstringThe 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.
requireTypedConfirmationstringFor irreversible deletes: the text the user types before the button enables ("PG AB 482").
isConfirmDisabledbooleanHolds 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 elementaria-describedbynames. Esc and "Cancel" still work.aria-describedbystringMore 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.typedConfirmationLabelstringThe field's label; "Type ORD-482 to confirm" by default.
iconIconNameOverrides the tone's icon (danger
trash-2, warningtriangle-alert).returnFocusRefRefObject<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 atitleRef: 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.motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.