# AlertDialog (@limerdev/zest) A dialog that asks for a decision before the user goes on, announced as an alertdialog: `` holds an `AlertDialog.Trigger` and an `AlertDialog.Content` with a `Header` (`Title`, `Description`, optional `Media` icon) and a `Footer` with an `AlertDialog.Cancel` and an `AlertDialog.Action` (both styled as buttons: `variant`, `size`). Focus starts inside; a click outside doesn't close it; Escape and Cancel close it. Action does not close it by itself, so it can wait for the work to finish: set its `loading` while the work runs (a spinner; clicks are ignored) and `bind:open` to false when done. - Category: Overlays - Import: `import { AlertDialog } from '@limerdev/zest'` - Bits UI: `AlertDialog`, https://bits-ui.com/docs/components/alert-dialog - Exports: `AlertDialog.Root`, `AlertDialog.Title`, `AlertDialog.Action`, `AlertDialog.Cancel`, `AlertDialog.Portal`, `AlertDialog.Footer`, `AlertDialog.Header`, `AlertDialog.Trigger`, `AlertDialog.Overlay`, `AlertDialog.Content`, `AlertDialog.Description`, `AlertDialog.Media` - Use for: Confirming something that can't be undone: deleting, sending, discarding changes. - Don't: Content or forms the user can close without deciding: use `Dialog`. Confirming something easily undone: just do it and offer undo. ```svelte Delete project Delete Zest? Its 412 logged hours go with it. Cancel Delete ``` Props of `AlertDialog.Root`: - `onOpenChange` (`OnChangeFn`): A callback that is called when the popover's open state changes. - `onOpenChangeComplete` (`OnChangeFn`): A callback called when the dialog finishes opening/closing animations. - `open` (`boolean`, default `false`, bindable): The open state of the dialog. Props of `AlertDialog.Title`: - `level` (`1 | 2 | 3 | 4 | 5 | 6`): The heading level of the dialog title. Props of `AlertDialog.Action`: - `loading` (`boolean`, default `false`): Waiting for the work the action started: a spinner shows, it is marked busy and unavailable, and clicks do nothing. It keeps keyboard focus, unlike `disabled`. - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'primary'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `AlertDialog.Cancel`: - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'outline'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `AlertDialog.Portal`: - `disabled` (`boolean`, default `false`): Disable portalling and render the component inline - `to` (`PortalTarget`, default `document.body`): Where to portal the content to. Props of `AlertDialog.Trigger`: - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'primary'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `AlertDialog.Overlay`: - `forceMount` (`boolean`): Whether to force mount the component. Props of `AlertDialog.Content`: - `escapeKeydownBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Escape behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. - `forceMount` (`boolean`): Whether to force mount the component. - `interactOutsideBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Interact outside behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to the parent element. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. - `onCloseAutoFocus` (`EventCallback`): Event handler called when auto-focusing on close. Can be prevented. - `onEscapeKeydown` (`((e: KeyboardEvent) => void)`): Callback fired when escape is pressed. - `onFocusOutside` (`((event: FocusEvent) => void)`): Callback fired when focus leaves the dismissible layer. - `onInteractOutside` (`InteractOutsideEventHandler`): Callback fired when an outside interaction event completes, which is either a `pointerup`, `mouseup`, or `touchend` event, depending on the user's input device. - `onOpenAutoFocus` (`EventCallback`): Event handler called when auto-focusing on open. Can be prevented. - `portalProps` (`PortalProps`): Props for the portal the content renders in: `to` (the element to render in, the body by default) and `disabled` (render in place). - `preventBodyPointerEvents` (`boolean`, default `true`): Whether to set `pointer-events: none` on the `` while the dialog is open. When `false` and a `Dialog.Overlay` is rendered, the overlay blocks pointer interaction with the page instead, which avoids restyling every element on the page when the dialog opens and closes. Without an overlay, the body is still blocked. Elements stacked above the overlay that aren't part of the dialog (toasts, a header with a higher `z-index`) receive pointer events when this is `false`. - `preventOverflowTextSelection` (`boolean`, default `true`): Passing `true` will prevent the overflow of text selection outside the element, provided the element is the top layer. - `preventScroll` (`boolean`, default `true`): Whether to prevent body scrolling when the content is open. - `restoreScrollDelay` (`number | null`, default `null`): The delay in milliseconds before the scrollbar is restored after closing the dialog. This is only applicable when using the `child` snippet for custom transitions and `preventScroll` is `true`. You should set this to a value greater than the transition duration to prevent content from shifting during the transition. - `size` (`"default" | "sm"`, default `'default'`): The dialog's width: `default`, or `sm` for a short question. - `trapFocus` (`boolean`, default `false`): Whether focus is trapped within the focus scope. Example: Confirm Confirm what can't be undone. A click outside doesn't close it; Escape cancels. Action doesn't close it by itself: it shows loading while the work runs, then bind:open closes it. ```svelte {deleted ? 'Deleted' : 'Delete project'} Delete Zest? Its 412 logged hours and 3 invoices go with it. This can't be undone. Keep it Delete project ```