# Alert Dialog

A dialog for confirmations and destructive actions: a click outside does not close it, only a button or Escape does.

- Category: Core Elements
- Page: https://wunderui.com/components/alert-dialog
- Tier: Free

## Install

```bash
npx wunderui-cli add alert-dialog
```

## Import

```tsx
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFeedback, AlertDialogFooter, AlertDialogHeader, AlertDialogIcon, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog"
```

## Minimal usage

Then use it:

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"

export function DeleteProject() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete project</AlertDialogTrigger>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon variant="destructive" />
          <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
          <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

Expected result: You should see a Delete project button. It opens a window with a Cancel and a Delete project button; Cancel or Escape closes it.

## Usage

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"

export function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete project</AlertDialogTrigger>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon variant="destructive" />
          <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
          <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## When to use

### Use Alert Dialog for

- Confirming an action that deletes data or removes access, such as deleting a project
- Leaving a screen with unsaved changes
- A consequence that needs one clear decision before it happens

### Use something else

- [Dialog](https://wunderui.com/components/dialog) for a task with fields or content to work through
- [Toast](https://wunderui.com/components/toast) for saying that something worked, without asking for anything
- [Alert](https://wunderui.com/components/alert) for a message that stays on the page

## Keyboard

The buttons are native buttons, so the browser provides focus and activation. While the window is open the page behind it is inert.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus between the buttons and fields in the window. Focus stays inside it, wrapping from the last element to the first. |
| `Enter` or `Space` | Presses the focused button: `AlertDialogAction` confirms and closes, `AlertDialogCancel` closes. In a text field, Enter does not confirm. |
| `Escape` | Closes the window without confirming, like Cancel. A click on the backdrop does nothing. |

## Behavior

What the window does with focus, state, content and motion.

- **Modal:** While the window is open, the page behind it is inert and does not scroll. The window is an alert dialog named by its title and described by its description; give every window both.
- **No outside dismissal:** A click on the backdrop never closes or confirms. Only a footer button or Escape does, so the decision is always explicit.
- **Focus:** On open, focus moves to the first focusable element: the Cancel button, or the field if there is one (you can choose another). On close it returns to the trigger unless you send it elsewhere.
- **Closing and slow actions:** Both the action and cancel buttons close the window on click. For a request that can fail, control the open state, keep the window open while it runs and close it on success.
- **Long text:** The window has one shrinkable column, so a long title or file name wraps instead of widening it. With long action labels, stack the footer.
- **Footer layout:** By default the footer stacks below the small breakpoint with the main action on top, and sits in a row above it. You can force either layout.
- **Previews in these docs:** The window is portalled to the end of the document and fixed to the screen. The previews here draw the same window inside the card so it does not cover the page.
- **Opening and closing:** The window fades in, zooms from 92 % and slides up 8 px; the backdrop fades. Closing is one step faster and zooms down to 96 %.
- **Reduced motion:** With reduced motion on, zoom and slide are off and the window only fades in and out.

## Anatomy

- `AlertDialog`: Holds the open state. Control it yourself, or leave it uncontrolled and let the trigger and buttons handle it.
- `AlertDialogTrigger`: The element that opens the window, usually the button that starts the action. Focus returns to it when the window closes.
- `AlertDialogContent`: The window, with its own portal and backdrop. It has no corner close button, so the footer buttons are the way out; the large size matches the 440 px Figma set.
- `AlertDialogHeader`: Stacks the icon, the title and the description at the top of the window.
- `AlertDialogIcon`: A 40 px tile with the icon above the title, in a default, warning or destructive tint. Without children it shows an alert circle, a warning triangle or a trash can.
- `AlertDialogTitle`: Names the action and its object, like Delete project Northstar? It is the accessible name of the window.
- `AlertDialogDescription`: Says what will be lost or cannot be undone. It is read out after the title.
- `AlertDialogFeedback`: An announced message above the actions, as an error or warning: what failed, whether anything changed, what to do next.
- `AlertDialogFooter`: The row of buttons. The last button in the markup sits on the right, or on top when the footer is stacked.
- `AlertDialogCancel`: Closes the window without acting. Label it with the safe choice, such as Cancel or Keep editing.
- `AlertDialogAction`: Confirms and closes on click. Primary by default, destructive for removals, or secondary for a third way out such as Discard changes.
- `AlertDialogOverlay`: The dimmed, lightly blurred backdrop, already rendered by the content. Clicking it does nothing.
- `AlertDialogPortal`: Moves the window to the end of the document. The content already uses it; you only need it for a custom window or container.

## Best practices

### Do

- Name the object and the loss in the title, like Delete project Northstar, and put what goes with it in the description. Don't just ask Are you sure.
- Repeat the action on the confirm button and make it destructive for deletions: Delete project after Cancel, so it ends up on the right.
- Label the safe choice with what it does, like Keep editing or Cancel. When the action is hard to undo, focus starts on it.
- For slow or failing actions, control the open state yourself. The action button closes the window on click, so prevent that, show the failure in the feedback area and turn the button into Retry.
- Ask for a typed confirmation only for large deletions that cannot be undone, with a visible label, and never together with an acknowledgement.

### Don't

- Don't confirm with window.confirm. It cannot be styled or tested, while an Alert Dialog keeps the product's look, focus handling and button labels.
- Don't use an Alert Dialog for a form or to report that something worked. A task with fields belongs in a Dialog, and success in a toast.
- Don't ask for confirmation on routine actions that can be undone. Do them and offer Undo; a window for everything teaches people to click through.
- Don't rely on a click outside or a corner close button to dismiss it. Neither exists here: the footer buttons and Escape are the way out.

## API reference

### AlertDialog

| Prop | Type | Default | Description |
|---|---|---|---|
| actionsRef | React.RefObject<AlertDialogRoot.Actions \| null> |  | A ref to imperative actions. - `unmount`: Manually unmounts the alert dialog. Call this after any externally controlled closing animation finishes. - `close`: Closes the alert dialog imperatively when called. |
| children | React.ReactNode \| PayloadChildRenderFunction<Payload> |  | The content of the dialog. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
| defaultOpen | boolean | false | Whether the dialog is initially open. To render a controlled dialog, use the `open` prop instead. |
| defaultTriggerId | string \| null |  | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open dialog. |
| handle | AlertDialogHandle<Payload> |  | A handle to associate the alert dialog with a trigger. If specified, allows external triggers to control the alert dialog's open state. Can be created with the AlertDialog.createHandle() method. |
| onOpenChange | ((open: boolean, eventDetails: AlertDialogRoot.ChangeEventDetails) => void) |  | Event handler called when the alert dialog is opened or closed. |
| onOpenChangeComplete | ((open: boolean) => void) |  | Event handler called after any animations complete when the dialog is opened or closed. |
| open | boolean |  | Whether the dialog is currently open. |
| triggerId | string \| null |  | ID of the trigger that the dialog is associated with. This is useful in conjunction with the `open` prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the `open` prop is… |

### AlertDialogAction

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |
| variant | "primary" \| "destructive" \| "secondary" | "primary" | `secondary` is the plain button for the third action ("Discard changes", "Keep editing"); it closes the dialog like the others. |

Also accepts React.ButtonHTMLAttributes attributes.

### AlertDialogCancel

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.ButtonHTMLAttributes attributes.

### AlertDialogContent

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| finalFocus | boolean \| React.RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => boolean \| HTMLElement \| null \| void) |  | Determines the element to focus when the dialog is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`… |
| initialFocus | boolean \| React.RefObject<HTMLElement \| null> \| ((openType: InteractionType) => boolean \| HTMLElement \| null \| void) |  | Determines the element to focus when the dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual ke… |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| size | "default" \| "lg" | "default" | `lg` is the 440 px Figma width. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogDescription

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogFeedback

| Prop | Type | Default | Description |
|---|---|---|---|
| icon | React.ReactNode |  | Replaces the leading icon; `null` hides it. |
| tone | "warning" \| "error" | "error" | `error` (red) or `warning` (yellow) for the message and its leading icon. The message is announced with `role="alert"`. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogFooter

| Prop | Type | Default | Description |
|---|---|---|---|
| layout | "inline" \| "stacked" |  | `inline` forces one row, `stacked` forces one column; omitted = stacked below `sm`, inline from `sm` up. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogHeader

| Prop | Type | Default |
|---|---|---|


Also accepts React.HTMLAttributes attributes.

### AlertDialogIcon

| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode |  | Replaces the icon too; it wins over `icon`. |
| icon | React.ReactNode |  | Replaces the default icon of the variant with your own. Use a Lucide icon. |
| variant | "warning" \| "default" \| "destructive" | "default" | The tint of the tile and its default icon: `default` (indigo, circle-alert), `warning` (the warning triangle) or `destructive` (red, trash-2). |

Also accepts React.HTMLAttributes attributes.

### AlertDialogOverlay

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| forceRender | boolean | false | Whether the backdrop is forced to render even when nested. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogPortal

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| container | HTMLElement \| ShadowRoot \| React.RefObject<HTMLElement \| ShadowRoot \| null> \| null |  | A parent element to render the portal element into. |
| keepMounted | boolean | false | Whether to keep the portal mounted in the DOM while the popup is hidden. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogTitle

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.HTMLAttributes attributes.

### AlertDialogTrigger

| Prop | Type | Default | Description |
|---|---|---|---|
| className | string \| ((state: State) => string \| undefined) |  | CSS class applied to the element, or a function that returns a class based on the component's state. |
| handle | AlertDialogHandle<Payload> |  | A handle to associate the trigger with an alert dialog. Can be created with the AlertDialog.createHandle() method. |
| id | string |  | ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the dialog in controlled mode (with the DialogRoot `triggerId` prop). |
| nativeButton | boolean | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
| payload | Payload |  | A payload to pass to the dialog when it is opened. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| style | React.CSSProperties \| ((state: State) => React.CSSProperties \| undefined) |  | Style applied to the element, or a function that returns a style object based on the component's state. |

Also accepts React.ButtonHTMLAttributes attributes.

## Examples

### Size: default and large

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"

export function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete project</AlertDialogTrigger>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon variant="destructive" />
          <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
          <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

### Actions: inline, stacked and three actions

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"

export function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="plain" />}>Close editor</AlertDialogTrigger>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon />
          <AlertDialogTitle>Discard unsaved changes?</AlertDialogTitle>
          <AlertDialogDescription>Your latest edits have not been saved.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Keep editing</AlertDialogCancel>
          <AlertDialogAction>Discard changes</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

### Content: project, person, file, count, typed confirmation and acknowledgement

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Folder } from "lucide-react"

export function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>Delete project</AlertDialogTrigger>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon variant="destructive" />
          <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
          <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <div className="flex items-center gap-3 rounded-lg bg-bg-subtle p-3">
          <span className="flex size-9 shrink-0 items-center justify-center rounded-md bg-tint-indigo text-sm font-semibold text-tint-text-indigo"><Folder className="size-[18px]" /></span>
          <div className="flex min-w-0 flex-1 flex-col gap-0.5">
            <span className="text-sm font-semibold [overflow-wrap:anywhere]">Northstar</span>
            <span className="text-xs text-text-secondary">24 members · Last edited Oct 28, 2026</span>
          </div>
        </div>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

### States: ready, submitting, error with retry, warning and long text

```tsx
import { useState } from "react"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
} from "@/components/ui/alert-dialog"

export function Example() {
  const [open, setOpen] = useState(true)

  return (
    <AlertDialog open={open} onOpenChange={setOpen}>
      <AlertDialogContent size="lg">
        <AlertDialogHeader>
          <AlertDialogIcon variant="destructive" />
          <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
          <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter layout="inline">
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete project</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## In context

### Delete project: a danger zone whose first request fails

The trigger sits in a danger zone. The first delete fails: the window stays open, says nothing changed and offers Retry, and the second one goes through.

```tsx
import { useState } from "react"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFeedback,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Spinner } from "@/components/ui/spinner"

export function DangerZone({ onDelete }: { onDelete: () => Promise<void> }) {
  const [open, setOpen] = useState(false)
  const [pending, setPending] = useState(false)
  const [failed, setFailed] = useState(false)

  async function remove() {
    setPending(true)
    setFailed(false)
    try {
      await onDelete()
      setOpen(false)
    } catch {
      setFailed(true)
    } finally {
      setPending(false)
    }
  }

  return (
    <div className="rounded-xl border border-border bg-card p-4">
      <p className="text-sm font-semibold">Danger zone</p>
      <p className="mt-1 text-sm text-text-secondary">Delete this project and all of its tasks and files.</p>
      <AlertDialog open={open} onOpenChange={(next) => { if (!pending) setOpen(next) }}>
        <AlertDialogTrigger render={<Button variant="destructive" className="mt-4" />}>Delete project</AlertDialogTrigger>
        <AlertDialogContent size="lg">
          <AlertDialogHeader>
            <AlertDialogIcon variant="destructive" />
            <AlertDialogTitle>Delete project “Northstar”?</AlertDialogTitle>
            <AlertDialogDescription>The project, its 24 tasks and all files will be permanently deleted. This can’t be undone.</AlertDialogDescription>
          </AlertDialogHeader>
          {failed && (
            <AlertDialogFeedback tone="error">The project could not be deleted. No changes were made.</AlertDialogFeedback>
          )}
          <AlertDialogFooter layout="inline">
            <AlertDialogCancel disabled={pending}>Cancel</AlertDialogCancel>
            <AlertDialogAction
              variant="destructive"
              aria-busy={pending}
              onClick={(event) => {
                // AlertDialogAction closes on click; keep it open until the request has finished.
                event.preventBaseUIHandler()
                void remove()
              }}
            >
              {pending && <Spinner />}
              {pending ? "Deleting…" : failed ? "Retry" : "Delete project"}
            </AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </div>
  )
}
```

### Unsaved changes: keep editing, discard or save and leave

Leaving a form with edits offers the safe way back first. When the edits can be saved in one step, a third action does that.

```tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function ProjectSettings({ onClose }: { onClose: () => void }) {
  return (
    <form className="flex flex-col gap-3 rounded-xl border border-border bg-card p-4">
      <Label htmlFor="project-name">Project name</Label>
      <Input id="project-name" defaultValue="Northstar Studio redesign" />
      <AlertDialog>
        <AlertDialogTrigger render={<Button variant="plain" className="w-fit" type="button" />}>Close</AlertDialogTrigger>
        <AlertDialogContent size="lg">
          <AlertDialogHeader>
            <AlertDialogIcon />
            <AlertDialogTitle>Discard unsaved changes?</AlertDialogTitle>
            <AlertDialogDescription>Your latest edits have not been saved.</AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter layout="inline">
            <AlertDialogCancel>Keep editing</AlertDialogCancel>
            <AlertDialogAction onClick={onClose}>Discard changes</AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </form>
  )
}
```

### Remove team member: say who loses access to what

Removing access isn't deleting. The window says who loses access, that their work stays and that they can be invited again.

```tsx
import { useState } from "react"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"

const MEMBERS = [
  { name: "Nora Lindgren", initials: "NL", role: "Owner" },
  { name: "Daniel Okafor", initials: "DO", role: "Designer" },
  { name: "Priya Raman", initials: "PR", role: "Engineer" },
]

export function Members() {
  const [target, setTarget] = useState(MEMBERS[1])
  const [open, setOpen] = useState(false)

  return (
    <div className="rounded-xl border border-border bg-card p-4">
      <ul className="flex flex-col gap-3">
        {MEMBERS.map((member) => (
          <li key={member.name} className="flex items-center gap-3">
            <Avatar color="purple"><AvatarFallback>{member.initials}</AvatarFallback></Avatar>
            <div className="min-w-0 flex-1">
              <p className="text-sm font-semibold">{member.name}</p>
              <p className="text-xs text-text-secondary">{member.role}</p>
            </div>
            <Button
              variant="plain"
              size="sm"
              aria-label={`Remove ${member.name}`}
              onClick={() => {
                setTarget(member)
                setOpen(true)
              }}
            >
              Remove
            </Button>
          </li>
        ))}
      </ul>
      <AlertDialog open={open} onOpenChange={setOpen}>
        <AlertDialogContent size="lg">
          <AlertDialogHeader>
            <AlertDialogIcon variant="destructive" />
            <AlertDialogTitle>{`Remove ${target.name} from this workspace?`}</AlertDialogTitle>
            <AlertDialogDescription>
              They lose access to WunderUI right away. Their work stays in the workspace, and you can invite them again at any time.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter layout="inline">
            <AlertDialogCancel>Cancel</AlertDialogCancel>
            <AlertDialogAction variant="destructive">Remove member</AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </div>
  )
}
```

### Delete workspace: typed confirmation

For a large deletion that can't be undone, the action enables once the typed name matches.

```tsx
import { useState } from "react"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function WorkspaceSettings() {
  const [value, setValue] = useState("")

  return (
    <div className="rounded-xl border border-border bg-card p-4">
      <p className="text-sm font-semibold">Delete workspace</p>
      <p className="mt-1 text-sm text-text-secondary">Remove WunderUI Studio and every project in it. This can’t be undone.</p>
      <AlertDialog onOpenChange={(open) => { if (!open) setValue("") }}>
        <AlertDialogTrigger render={<Button variant="destructive" className="mt-4" />}>Delete workspace</AlertDialogTrigger>
        <AlertDialogContent size="lg">
          <AlertDialogHeader>
            <AlertDialogIcon variant="destructive" />
            <AlertDialogTitle>Delete workspace “WunderUI Studio”?</AlertDialogTitle>
            <AlertDialogDescription>All projects in this workspace are removed. This can’t be undone.</AlertDialogDescription>
          </AlertDialogHeader>
          <div className="flex flex-col gap-2">
            <Label htmlFor="confirm-name">Type WunderUI Studio to confirm.</Label>
            <Input
              id="confirm-name"
              value={value}
              placeholder="WunderUI Studio"
              aria-invalid={value !== "" && value !== "WunderUI Studio"}
              onChange={(event) => setValue(event.target.value)}
            />
            {value !== "" && (
              <p className={value === "WunderUI Studio" ? "text-xs text-tint-text-green" : "text-xs text-error"}>
                {value === "WunderUI Studio" ? "The name matches." : "The name does not match."}
              </p>
            )}
          </div>
          <AlertDialogFooter layout="inline">
            <AlertDialogCancel>Cancel</AlertDialogCancel>
            <AlertDialogAction variant="destructive" disabled={value !== "WunderUI Studio"}>
              Delete workspace
            </AlertDialogAction>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </div>
  )
}
```

### Bulk delete: the count in the trigger, the title and the action

Name the count three times. The selection stays visible behind the window, and the rows go once it is confirmed.

```tsx
import { useState } from "react"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import { Label } from "@/components/ui/label"

const FILES = [
  { name: "quarterly-report.xlsx", size: "2.4 MB" },
  { name: "brand-guidelines.pdf", size: "8.1 MB" },
  { name: "onboarding-flow.png", size: "1.2 MB" },
  { name: "roadmap-2027.pdf", size: "3.7 MB" },
]

export function Files() {
  const [files, setFiles] = useState(FILES)
  const [selected, setSelected] = useState<string[]>(["brand-guidelines.pdf", "roadmap-2027.pdf"])

  return (
    <div className="rounded-xl border border-border bg-card p-4">
      <div className="mb-3 flex items-center justify-between gap-3">
        <p className="text-sm font-semibold">{selected.length} selected</p>
        <AlertDialog>
          <AlertDialogTrigger render={<Button variant="destructive" size="sm" disabled={selected.length === 0} />}>
            {`Delete ${selected.length} files`}
          </AlertDialogTrigger>
          <AlertDialogContent size="lg">
            <AlertDialogHeader>
              <AlertDialogIcon variant="destructive" />
              <AlertDialogTitle>{`Delete ${selected.length} files?`}</AlertDialogTitle>
              <AlertDialogDescription>The files move to Trash. Anyone using a shared link loses access.</AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter layout="inline">
              <AlertDialogCancel>Cancel</AlertDialogCancel>
              <AlertDialogAction
                variant="destructive"
                onClick={() => {
                  setFiles(files.filter((file) => !selected.includes(file.name)))
                  setSelected([])
                }}
              >
                {`Delete ${selected.length} files`}
              </AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialog>
      </div>
      <ul className="flex flex-col gap-2">
        {files.map((file) => (
          <li key={file.name} className="flex items-center gap-3">
            <Checkbox
              id={file.name}
              checked={selected.includes(file.name)}
              onCheckedChange={(next) =>
                setSelected(next === true ? [...selected, file.name] : selected.filter((name) => name !== file.name))
              }
            />
            <Label htmlFor={file.name} className="flex-1">{file.name}</Label>
            <span className="text-xs text-text-secondary">{file.size}</span>
          </li>
        ))}
      </ul>
    </div>
  )
}
```

## For AI agents

`get_component("alert-dialog")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
