# AlertDialog

A confirmation dialog that stays open until your app confirms the action worked.

- **Use it for**: Confirming a destructive or irreversible action before it happens.
- **Not for**: Agent actions that need a reviewed proposal and your server’s confirmation. Try [ApprovalCard](https://unseenui.com/components/approval-card/), [Modal](https://unseenui.com/components/modal/).

## Installation

```bash
npm install @stackunseen/ui
```

## Parts

A confirmation you put together from parts. The action only asks; your app closes the dialog once your server answers.

```tsx
<AlertDialog open={open} onOpenChange={setOpen} busy={pending}>
  <AlertDialog.Trigger asChild>
    <Button variant="outline">Archive project</Button>
  </AlertDialog.Trigger>
  <AlertDialog.Content error={error}>
    <AlertDialog.Title>Archive project?</AlertDialog.Title>
    <AlertDialog.Description>You can restore it from the archive.</AlertDialog.Description>
    <AlertDialog.Actions>
      <AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
      <AlertDialog.Action onAction={requestArchive}>Archive project</AlertDialog.Action>
    </AlertDialog.Actions>
  </AlertDialog.Content>
</AlertDialog>
```

1. **`AlertDialog`**: Holds the open state. `busy` stops the action being sent twice. Props: `busy`.
2. **`AlertDialog.Trigger`**: Opens the dialog. Pass your own Button with `asChild`.
3. **`AlertDialog.Content`**: The dialog. `error` shows a failure your server reported. Props: `error`, `container`.
4. **`AlertDialog.Title`**: Says what will happen, with `AlertDialog.Description` under it.
5. **`AlertDialog.Actions`**: Holds Cancel and the action, in that order.
6. **`AlertDialog.Cancel`**: Closes the dialog without doing anything. Props: `variant`, `size`.
7. **`AlertDialog.Action`**: Calls `onAction` and stays open until your server confirms. Props: `onAction`, `variant`, `size`.

## Usage

```tsx
import { AlertDialog } from '@stackunseen/ui';
import { Button } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<AlertDialog open={open} onOpenChange={setOpen} busy={pending}><AlertDialog.Trigger asChild><Button variant="outline">Archive project</Button></AlertDialog.Trigger><AlertDialog.Content error={error}><AlertDialog.Title>Archive project?</AlertDialog.Title><AlertDialog.Description>You can restore it from the archive.</AlertDialog.Description><AlertDialog.Actions><AlertDialog.Cancel>Cancel</AlertDialog.Cancel><AlertDialog.Action onAction={requestArchive}>Archive project</AlertDialog.Action></AlertDialog.Actions></AlertDialog.Content></AlertDialog>
```

## Props

- `open` (`boolean (optional)`): Control whether the confirmation is open, especially for asynchronous actions.
- `onOpenChange` (`(open: boolean) => void (optional)`): Update open when the user opens or dismisses the confirmation.
- `busy` (`boolean (optional)`): Disables Action while a request is pending. Cancel remains available.
- `children` (`ReactNode (optional)`): The compound parts. Action stays open until your application closes the dialog.

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `busy` | `boolean` | Host-owned submission state. |
| `dir` | `"ltr" \| "rtl"` | Set for locally scoped RTL layouts so the portal and trigger share direction. |

## Keyboard

Opening focuses Cancel. Tab remains inside; Escape or Cancel dismisses. Busy prevents repeated action requests while cancellation remains available.

## Works with

[Popover](https://unseenui.com/components/popover/), [Tooltip](https://unseenui.com/components/tooltip/), [ShortcutHelp](https://unseenui.com/components/shortcut-help/), [Modal](https://unseenui.com/components/modal/)

Page: https://unseenui.com/components/alert-dialog/
