# AlertDialog A modal that interrupts with something important and waits for an answer. ```ehtml Example import { AlertDialog, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, } from "@elements/ui/alert-dialog"; import { Button } from "@elements/ui/button"; Cancel remove(project)}>Delete ... ``` ## Parts | Part | What it is | |---|---| | `AlertDialog` | The root: owns open, renders the trigger slot and, while open, a modal `` with its panel. | | `AlertDialogHeader` | Stacks media, title and description: centered on phones and in the sm size, left-aligned otherwise. | | `AlertDialogMedia` | An icon or image above the title (beside it at md from 40rem up). Decorative: aria-hidden. | | `AlertDialogTitle` | An `

`; names the alert dialog (aria-labelledby). | | `AlertDialogDescription` | A `

`; the alert message (aria-describedby). | | `AlertDialogFooter` | The actions: right-aligned, stacked full width on phones, two equal columns in the sm size. | | `AlertDialogCancel` | An outline button that closes the dialog. It gets focus when the dialog opens. | | `AlertDialogAction` | A primary button that closes the dialog after its onclick, unless onclick calls e.preventDefault(). | ## Attributes ### AlertDialog | Attribute | Type | Default | Description | |---|---|---|---| | `open` | `boolean` (two-way) | `false` | Whether the dialog is open. Bind it to control it; the dialog writes false back when Escape, Cancel or Action closes it. Omit it and the trigger slot opens it. | | `title` | `string` | `""` | Renders an AlertDialogTitle in a header and names the dialog. | | `description` | `string` | `""` | Renders an AlertDialogDescription under the title and describes the dialog. | | `label` | `string` | `""` | aria-label for a dialog with no visible title. | | `size` | `"md" \| "sm"` | `"md"` | md is the theme's --dialog-width; sm is a narrow, centered layout with the actions side by side. | | `initialFocus` | `DialogFocus` | `""` | CSS selector of the element to focus on open, or a function of the interaction type (keyboard, mouse, touch, pen) that returns an element, a selector, true for the default or false to leave focus. Default: the AlertDialogCancel button, else the panel. | | `returnFocus` | `boolean` | `true` | Return focus to the trigger (or whatever had focus) when the dialog closes. | | `finalFocus` | `DialogFocus` | `""` | CSS selector of the element to focus on close, in place of the trigger, or a function of the interaction type that returns an element, a selector, true for the trigger or false to leave focus. | | `class` | `string` | `""` | Extra classes on the panel. | | `onOpenChangeComplete` | `(open: boolean) => void` | `() => {}` | Called after the enter animation (true) or once the dialog has left the page after its exit (false). | | `onOpenChange` | `(open: boolean, reason?: DialogChangeReason, details?: DialogChangeDetails) => void` | `() => {}` | Called when the dialog opens or closes itself, with a reason: trigger-press, escape-key, close-press, close-watcher (a platform close request such as Android back), or none when the browser closed it. Not called for changes the caller makes. The third argument is an event details object: { reason, event (the DOM event behind the change, or null), trigger (the trigger element on trigger-press) }. | | `onOpenAutoFocus` | `(e: Event) => void` | `() => {}` | Called before focus moves in on open; e.preventDefault() leaves focus to the handler. | | `onCloseAutoFocus` | `(e: Event) => void` | `() => {}` | Called before focus returns on close; e.preventDefault() leaves focus to the handler. | | `onEscapeKeyDown` | `(e: KeyboardEvent) => void` | `() => {}` | Called on Escape before closing; e.preventDefault() keeps it open, and e.allowPropagation() lets the Escape reach the page's own key handlers too. | ### AlertDialogMedia | Attribute | Type | Default | Description | |---|---|---|---| | `variant` | `"default" \| "danger"` | `"default"` | danger tints the media with the danger colors. | ### AlertDialogCancel | Attribute | Type | Default | Description | |---|---|---|---| | `variant` | `ButtonVariant` | `"outline"` | Button variant. | ### AlertDialogAction | Attribute | Type | Default | Description | |---|---|---|---| | `variant` | `ButtonVariant` | `"primary"` | Button variant; danger for a destructive action. | | `loading` | `boolean` | `false` | Shows a spinner over the label at the same size; clicks are ignored. | | `type` | `"button" \| "submit" \| "reset"` | `"button"` | The button type; submit makes the Action the submit button of a form inside the alert. A click still closes it. | ### AlertDialogCancel, AlertDialogAction | Attribute | Type | Default | Description | |---|---|---|---| | `size` | `"xs" \| "sm" \| "md" \| "lg"` | `"md"` | Button size. | | `disabled` | `boolean` | `false` | Disables the button. | | `onclick` | `(e: MouseEvent) => void` | `() => {}` | Runs before the dialog closes; e.preventDefault() keeps it open. | | `attrs` | `Record` | `{}` | Attributes for the `