Axon 911 Frontend DocsAxon 911 Frontend Docs
Axon 911 Frontend Docs
    Loading navigation…
U
User
Switch to light mode
  1. Components
  2. Alert Dialog
  3. Usage

Alert Dialog

Usage

Use AlertDialog to ask for an explicit answer before an action that is destructive or hard to undo: deleting an incident, ending a shift, discarding unsaved work. It is a Dialog with role="alertdialog", a required title and description, and a cancel action that holds focus on open. For a task that needs a form or a choice, use Dialog.
Import @prepared911/ui/alert-dialog and @prepared911/ui/alert-dialog/styles.css. AlertDialog renders Dialog and Button, so also import @prepared911/ui/dialog/styles.css and @prepared911/ui/button/styles.css; the stylesheet does not repeat theirs.
Parts
  • AlertDialog owns open state. Pass open and onOpenChange to control it, or defaultOpen to start open.
  • AlertDialogTrigger wraps one Button or Link and opens the dialog. Focus returns to it on close.
  • AlertDialogContent is the modal surface. title (an h2) names it and description describes it; both are required and always visible. size is Medium (default, 512px) or Small (384px). The description fills the content width and wraps at the edge, as ui-core's does.
  • AlertDialogFooter holds the actions, aligned to the inline end. The cancel goes first and the action last. Both Buttons render at Button's default ButtonSize.Large (32px), which matches the rendered ui-core modal footer (pr-button--large).
  • AlertDialogCancel wraps one Button and closes the dialog without applying the action. It is where focus lands on open.
  • AlertDialogAction wraps one Button. The Button's own onClick performs the action, then the dialog closes.
Labels are the Buttons' children, so there is no default English string in the component.
The answer is explicit
A press on the backdrop does not close an AlertDialog. The person answers with the cancel action, the action, or Escape. Escape and the cancel action both dismiss without running the action; only a press on the action runs it.
Over another dialog
An AlertDialog opened from inside a Dialog stacks above it in the same document, and Escape closes the alert dialog first. Focus returns to the control that opened it, inside the Dialog. To confirm before a dirty form closes, control both roots: veto the form Dialog's close request with details.cancel() and open the AlertDialog; "Keep editing" closes only the alert dialog, and the action closes both.
Closing and vetoing
onOpenChange(open, details) runs once for each request: trigger-press, close-press (the cancel or the action), and close-request (Escape or the platform back gesture). For a close-press, details.source is the pressed Button. Call details.cancel() on a cancelable request to keep the dialog open, for example while an async action runs: control open, start the work in the action's onClick, and veto the close-press until it settles.
Focus
On open, focus moves to the cancel action, so pressing Enter or Space never confirms by accident. For a confirmation that is not destructive, pass initialFocus with a ref to the action. If the dialog has no cancel action, focus goes to the first focusable element. On close, focus returns to the trigger; pass finalFocus to send it elsewhere.
Previous
Alert / Accessibility
Next
Alert Dialog / API and Development
On this page
Parts
The answer is explicit
Over another dialog
Closing and vetoing
Focus