A modal dialog the user must answer, never dismissed by a press outside, focused on its least destructive action (APG alert dialog), in each framework.
A dialog that interrupts the user with a message that needs an answer, usually the confirmation
of a destructive action. It takes focus, traps it, makes the rest of the page inert and returns
focus when it closes, as a Dialog does, but a press outside never closes it:
the user answers (one of its buttons) or presses Escape. It follows the WAI-ARIA APG
alert dialog pattern. A dialog the user
may dismiss from outside is a Dialog.
AlertDialog has its own entry and is built on Dialog's parts: the same Trigger, Portal, Backdrop,
Viewport, Popup, Title, Description and Close, whose part attribute names the alert dialog
(alert-dialog-popup). Only its Root is its own.
Open: a press on the Trigger (Enter and Space, as any button). Focus moves to
initialFocus, else the first Close part of the popup (the APG's least destructive action,
which you render as the Close: "Cancel"), else the first tabbable element, else the popup.
Inside: Tab and Shift+Tab wrap inside the popup; everything outside the portal is inert,
and the page does not scroll.
No outside dismissal: a press outside the popup (on the backdrop, on the viewport around
the popup, or on the page) does nothing: the alert dialog stays open, onOpenChange is not
called, and focus stays where it was.
Close: Escape (reason escape-key), a Close part (close-press) or the Trigger again
(trigger-press). Your other actions ("Discard", "Delete") are your own buttons: they act, then
close it through the controlled open, the handle's close() or the actions' close() (reason
imperative-action). Focus moves to finalFocus, else the active trigger, else the element
focused before it opened.
Layers and nesting: as a Dialog's (nested overlays):
Escape closes the newest layer only; an AlertDialog inside a Dialog's popup (or a Dialog inside
an AlertDialog's) is a nested dialog, with the same data-nested, data-nested-dialog-open
and --nested-dialogs.
Detached triggers: as a Dialog's, with an AlertDialog handle
(AlertDialog.createHandle(), detached triggers).
Lifecycle: as a Dialog's: onOpenChange before the change (details.cancel() keeps it as
it is), onOpenChangeComplete(open), the actions close() and unmount(), and the Portal's
keepMounted.
The "Discard" button is yours: it acts, then closes the alert dialog through the actions (reason
imperative-action). A controlled open closes it as well.
Every part also takes what the primitive contract gives. The
names below are React's; Vue binds them the same way (v-model:open, @open-change), and Angular
as inputs and outputs ([(open)], (openChangeDetails)). There is no modal and no outside
dismissal option: an alert dialog is always modal and never dismissed from outside.
every change, with its reason (trigger-press, close-press, escape-key, imperative-action; never outside-press); called before the change, details.cancel() stops it
onOpenChangeComplete
(open: boolean) => void
once an opening or a closing has finished its transitions
actionsRef (react)
{ current: OverlayActions | null }
receives close() (reason imperative-action) and unmount(); Vue exposes them on the Root's template ref, Angular as the root directive's methods
aria-haspopup="dialog" (ARIA has no alertdialog value), aria-expanded, aria-controls (the popup, on the active trigger while open), data-popup-open (the active trigger), data-disabled, an id
Backdrop
aria-hidden="true", data-open / data-closed, data-starting-style, data-ending-style, data-nested, data-nested-dialog-open; hidden while kept mounted and closed
Viewport
role="presentation", data-open / data-closed, data-starting-style, data-ending-style, data-nested, data-nested-dialog-open; hidden while kept mounted and closed
Popup
role="alertdialog", aria-modal="true", aria-labelledby, aria-describedby, tabindex="-1", data-open / data-closed, data-starting-style, data-ending-style, data-nested, data-nested-dialog-open, the inline --nested-dialogs: <n>; hidden while kept mounted and closed
Title, Description
an id (generated unless given)
The APG asks an alert dialog for a name and a description: render a Title and a Description.