# Alert Dialog

> Modal dialog for confirming critical actions with focus trap and keyboard navigation.

## Playground

An interactive playground for AlertDialog is embedded above. Open the canonical story on Storybook: [https://storybook.laioutr.cloud/?path=/story/ui-kit-organisms-alertdialog--manual-dialog](https://storybook.laioutr.cloud/?path=/story/ui-kit-organisms-alertdialog--manual-dialog)

## Overview

Alert Dialog interrupts the flow when a user is about to do something destructive or irreversible and you need an explicit confirmation. It is built on Reka UI's dialog primitive with `role="alertdialog"`, labelled and described via the matching ARIA attributes, and includes a focus trap that holds focus inside the dialog while it is open.

Buttons are declarative: pass a `buttons` array (each with `text`, `variant`, optional `iconLeft` / `iconRight`, and an `onClick` handler) plus an optional `cancelButton`. The cancel slot uses a translated default label (`$tl('alertDialog.cancel')`) if you don't supply one. Configure dismiss behavior with `closeOnEsc` and `closeOnOverlayClick` (both default `true`); flip them off when the dialog must be answered.

Open dialogs imperatively through `useDialogStore().openDialog(...)`, which returns an id you can pass to `closeDialog(id)`. Mount `<DialogsContainer>` once near the app root and every store entry renders as its own `<AlertDialog>` instance, so multiple concurrent dialogs are addressable by id rather than nested at the call site.

## Key Business & UX Benefits

- Focus trap and `role="alertdialog"` semantics ship without extra work, so compliance audits and screen-reader testing pass on day one.
- Declarative buttons array keeps every confirmation visually consistent app-wide, which earns trust on irreversible operations like order cancellation and account deletion.
- Imperative store API (`openDialog` / `closeDialog`) lets server-driven flows raise a confirmation from anywhere without prop-drilling state down a component tree.
- Configurable mobile and desktop button alignment fits the dialog into checkout flows and admin tools without per-page overrides.

<tip>

Pro-Tip from Larry: Disable `closeOnEsc` and `closeOnOverlayClick` on irreversible actions (delete account, cancel order) so users have to make an explicit choice rather than dismissing the dialog by accident.

</tip>

## Usage

#### Example: LAlertDialog

Live preview: [https://storybook.laioutr.cloud/?path=/story/ui-kit-organisms-alertdialog--manual-dialog](https://storybook.laioutr.cloud/?path=/story/ui-kit-organisms-alertdialog--manual-dialog)

## Feature List

<features :items="["Built on reka-ui with `role=\"alertdialog\"` and matching `aria-labelledby` and `aria-describedby`, so confirmations announce correctly to screen readers","Focus trap holds keyboard focus inside the dialog while open, with no per-page wiring","Declarative `buttons` array (`text`, `variant`, optional `iconLeft`, `iconRight`, `onClick`) plus optional `cancelButton` keeps confirmation chrome consistent","Default cancel label resolves via `$tl('alertDialog.cancel')`, so unprovided cancels still get localized copy","`closeOnEsc` and `closeOnOverlayClick` (both default true) toggle dismiss behavior, so irreversible actions can require an explicit choice","Imperative store API: `useDialogStore().openDialog(...)` returns an id passed to `closeDialog(id)`, paired with a single `<DialogsContainer>` mount"]">



</features>

## API Reference

### LAlertDialog

#### Props

```json
{"type":"object","properties":{"title":{"type":"string"},"buttons":{"type":"array","items":{"type":"object","properties":{"text":{"type":"string"},"iconLeft":{"type":"string"},"iconRight":{"type":["string","undefined"]},"disabled":{"type":"boolean"},"size":{"enum":["s","m","xs","l"],"type":"string"},"variant":{"enum":["primary","secondary","secondary-white","tertiary","ghost-black","ghost-white","glass-black","glass-white","positive","danger","subtle","close-black","close-white","info"],"type":"string"},"href":{"type":["string","undefined"]},"target":{"type":["string","undefined"]},"rel":{"type":["string","undefined"],"description":"`rel` attribute, applied only when the button renders as a link (`href` set).\nIgnored when rendered as `<button>`. Accepts any valid HTML `rel` token or\nspace-separated combination — e.g. `'prev'`, `'next'`, `'noopener'`,\n`'noopener noreferrer'`, `'external nofollow'`."},"loading":{"type":["boolean","undefined"]},"buttonType":{"enum":["submit","button"],"type":"string"},"spinnerType":{"enum":["row","round"],"type":"string","description":"Loading spinner shape. Defaults to `'row'` for text buttons;\n`IconButton` overrides to `'round'` to fit the square footprint."},"block":{"type":["boolean","undefined"],"description":"When `true`, the button stretches to its container's width\n(`display: flex; width: 100%`). Default is `false` — the button\nhugs its content via `display: inline-flex`."}},"additionalProperties":false,"required":["text"]}},"id":{"type":"string"},"titleColor":{"type":"string"},"description":{"type":"string"},"descriptionColor":{"type":"string"},"props":{},"cancelButton":{"type":"object","properties":{"text":{"type":"string"},"iconLeft":{"type":"string"},"iconRight":{"type":["string","undefined"]},"disabled":{"type":"boolean"},"size":{"enum":["s","m","xs","l"],"type":"string"},"variant":{"enum":["primary","secondary","secondary-white","tertiary","ghost-black","ghost-white","glass-black","glass-white","positive","danger","subtle","close-black","close-white","info"],"type":"string"},"href":{"type":["string","undefined"]},"target":{"type":["string","undefined"]},"rel":{"type":["string","undefined"],"description":"`rel` attribute, applied only when the button renders as a link (`href` set).\nIgnored when rendered as `<button>`. Accepts any valid HTML `rel` token or\nspace-separated combination — e.g. `'prev'`, `'next'`, `'noopener'`,\n`'noopener noreferrer'`, `'external nofollow'`."},"loading":{"type":["boolean","undefined"]},"buttonType":{"enum":["submit","button"],"type":"string"},"spinnerType":{"enum":["row","round"],"type":"string","description":"Loading spinner shape. Defaults to `'row'` for text buttons;\n`IconButton` overrides to `'round'` to fit the square footprint."},"block":{"type":["boolean","undefined"],"description":"When `true`, the button stretches to its container's width\n(`display: flex; width: 100%`). Default is `false` — the button\nhugs its content via `display: inline-flex`."}},"additionalProperties":false,"required":["text"]},"closeOnEsc":{"type":"boolean","default":true},"closeOnOverlayClick":{"type":"boolean","default":true},"mobileButtonsAlignment":{"enum":["left","right","center","space-between"],"type":"string","default":"right"},"desktopButtonsAlignment":{"enum":["left","right","center","space-between"],"type":"string","default":"right"},"open":{"type":"boolean"}},"required":["title"]}
```

#### Slots

```json
[{"name":"default","type":"{}","description":"","schema":{"kind":"object","type":"{}","schema":{}}}]
```

#### Events

```json
[{"name":"close","description":"","tags":[],"type":"[]","signature":"(event: \"close\"): void","schema":[]},{"name":"update:open","description":"","tags":[],"type":"[value: boolean]","signature":"(event: \"update:open\", value: boolean): void","schema":[{"kind":"enum","type":"boolean","schema":["false","true"]}]}]
```
