Usage
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.
@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.
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.details.cancel() and open the AlertDialog; "Keep editing" closes only the alert dialog, and the action closes both.
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.
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.