Alert Dialog
A confirmation modal for decisions that require explicit acknowledgement.
Default
A decision that must be acknowledged before work continues. The footer defaults to layout="equal", so the two actions share the width.
Destructive
Add AlertDialogIcon and pass layout="end" to right-align the actions. Name the object in the title and the action.
Controlled
Pass open and onOpenChange to raise the alert from code, such as when someone leaves a page with unsaved changes.
Best practices
When to use
- Use for a consequential decision that must be acknowledged before work continues: deleting an agent, discarding unsaved prompt changes.
- Use Dialog when the decision needs fields, and Toast with Undo when the action is easily reversible.
Behavior
- The footer defaults to layout="equal" (actions share the width). Use layout="end" with AlertDialogIcon for destructive confirmations.
- Clicking the overlay or pressing Escape dismisses the alert, the same as Cancel.
- Pass open and onOpenChange to raise the alert from code, such as a navigation guard.
Content
- Use a sentence-case title that names the object, often as a question: “Delete Support agent?”. The primary action repeats the verb: “Delete agent”, never “OK” or “Confirm”.
- Keep the dismissal action “Cancel”, or a specific alternative such as “Keep editing”. Say in the description what is lost and that it cannot be undone.
Accessibility
- Render actions with AlertDialogCancel and AlertDialogAction so both close the alert and focus returns to the trigger.