# Alert Dialog

> Interruptive confirmation dialog that requires an explicit user decision before continuing.

Canonical URL: https://taut-ui.com/docs/components/alert-dialog

```tsx
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogPopup,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export default function Particle() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="outline" />}>
        Archive Project
      </AlertDialogTrigger>
      <AlertDialogPopup className="sm:max-w-md">
        <AlertDialogHeader>
          <AlertDialogTitle>Archive this project?</AlertDialogTitle>
          <AlertDialogDescription>
            The repository will become read-only for all team members. You can
            restore it anytime from workspace settings.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogClose render={<Button variant="ghost" />}>
            Cancel
          </AlertDialogClose>
          <AlertDialogClose render={<Button />}>Archive</AlertDialogClose>
        </AlertDialogFooter>
      </AlertDialogPopup>
    </AlertDialog>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/alert-dialog.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/alert-dialog.tsx"
"use client";

import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
import type React from "react";
import { cn } from "@/lib/utils";

export {
  DialogFooter as AlertDialogFooter,
  DialogHeader as AlertDialogHeader,
  DialogIcon as AlertDialogIcon,
} from "@/components/ui/dialog";

export const AlertDialogCreateHandle: typeof AlertDialogPrimitive.createHandle =
  AlertDialogPrimitive.createHandle;

export const AlertDialog: typeof AlertDialogPrimitive.Root =
  AlertDialogPrimitive.Root;

export const AlertDialogPortal: typeof AlertDialogPrimitive.Portal =
  AlertDialogPrimitive.Portal;

export function AlertDialogTrigger(
  props: AlertDialogPrimitive.Trigger.Props,
): React.ReactElement {
  return (
    <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
  );
}

export function AlertDialogBackdrop({
  className,
  ...props
}: AlertDialogPrimitive.Backdrop.Props): React.ReactElement {
  return (
    <AlertDialogPrimitive.Backdrop
      className={cn(
        "fixed inset-0 z-50 bg-black/32 transition-opacity duration-150 ease-out data-ending-style:opacity-0 data-starting-style:opacity-0 motion-reduce:transition-none",
        className,
      )}
      data-slot="alert-dialog-backdrop"
      {...props}
    />
  );
}

export function AlertDialogViewport({
  className,
  ...props
}: AlertDialogPrimitive.Viewport.Props): React.ReactElement {
  return (
    <AlertDialogPrimitive.Viewport
      className={cn(
        "fixed inset-0 z-50 grid grid-rows-1 place-items-center overflow-hidden p-12 max-sm:p-6",
        className,
      )}
      data-slot="alert-dialog-viewport"
      {...props}
    />
  );
}

export interface AlertDialogPopupProps
  extends AlertDialogPrimitive.Popup.Props {
  portalProps?: AlertDialogPrimitive.Portal.Props;
}

export function AlertDialogPopup({
  className,
  portalProps,
  ...props
}: AlertDialogPopupProps): React.ReactElement {
  return (
    <AlertDialogPortal {...portalProps}>
      <AlertDialogBackdrop />
      <AlertDialogViewport>
        <AlertDialogPrimitive.Popup
          className={cn(
            "relative row-start-1 flex max-h-full min-h-0 w-full min-w-70 max-w-lg origin-center flex-col overflow-hidden rounded-3xl bg-popover text-popover-foreground shadow-lg outline-none will-change-transform",
            "-translate-y-[calc(0.75rem*var(--nested-dialogs,0))] scale-[calc(1-0.05*var(--nested-dialogs,0))] opacity-[calc(1-0.15*var(--nested-dialogs,0))]",
            "[transition-duration:350ms,150ms,350ms] [transition-property:scale,opacity,translate] [transition-timing-function:linear(0,0.42_6%,0.86_14%,1.06_24%,1.07_32%,1.02_46%,0.995_60%,1),ease-out,linear(0,0.42_6%,0.86_14%,1.06_24%,1.07_32%,1.02_46%,0.995_60%,1)]",
            "data-ending-style:scale-85 data-starting-style:scale-85 data-ending-style:opacity-0 data-starting-style:opacity-0 data-ending-style:duration-150 data-ending-style:ease-out motion-reduce:transition-none",
            className,
          )}
          data-slot="dialog-popup"
          {...props}
        />
      </AlertDialogViewport>
    </AlertDialogPortal>
  );
}

export function AlertDialogTitle({
  className,
  ...props
}: AlertDialogPrimitive.Title.Props): React.ReactElement {
  return (
    <AlertDialogPrimitive.Title
      className={cn(
        "font-heading font-semibold text-foreground text-xl leading-7 tracking-tight",
        className,
      )}
      data-slot="alert-dialog-title"
      {...props}
    />
  );
}

export function AlertDialogDescription({
  className,
  ...props
}: AlertDialogPrimitive.Description.Props): React.ReactElement {
  return (
    <AlertDialogPrimitive.Description
      className={cn("text-muted-foreground text-sm leading-5", className)}
      data-slot="alert-dialog-description"
      {...props}
    />
  );
}

export function AlertDialogClose(
  props: AlertDialogPrimitive.Close.Props,
): React.ReactElement {
  return (
    <AlertDialogPrimitive.Close data-slot="alert-dialog-close" {...props} />
  );
}

export {
  AlertDialogPrimitive,
  AlertDialogBackdrop as AlertDialogOverlay,
  AlertDialogPopup as AlertDialogContent,
};
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogPopup,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
```

```tsx
<AlertDialog>
  <AlertDialogTrigger>Delete</AlertDialogTrigger>
  <AlertDialogPopup>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogClose>Cancel</AlertDialogClose>
      <AlertDialogClose>Continue</AlertDialogClose>
    </AlertDialogFooter>
  </AlertDialogPopup>
</AlertDialog>
```

## Examples [#examples]

### Destructive with Icon [#destructive-with-icon]

```tsx
import { Trash2Icon } from "lucide-react";
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogIcon,
  AlertDialogPopup,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export default function Particle() {
  return (
    <AlertDialog>
      <AlertDialogTrigger render={<Button variant="destructive" />}>
        Delete Workspace
      </AlertDialogTrigger>
      <AlertDialogPopup className="sm:max-w-md">
        <AlertDialogHeader>
          <AlertDialogIcon className="bg-[color-mix(in_oklab,var(--color-popover),var(--color-destructive)_16%)] text-destructive">
            <Trash2Icon />
          </AlertDialogIcon>
          <AlertDialogTitle>Delete workspace permanently?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. All projects, deployments, and API
            keys inside this workspace will be permanently erased.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogClose render={<Button variant="ghost" />}>
            Cancel
          </AlertDialogClose>
          <AlertDialogClose render={<Button variant="destructive" />}>
            Delete forever
          </AlertDialogClose>
        </AlertDialogFooter>
      </AlertDialogPopup>
    </AlertDialog>
  );
}
```

### Async Action [#async-action]

```tsx
"use client";

import { useState } from "react";
import {
  AlertDialog,
  AlertDialogClose,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogPopup,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";

export default function Particle() {
  const [open, setOpen] = useState(false);
  const [isPending, setIsPending] = useState(false);

  function handleRevoke() {
    setIsPending(true);
    setTimeout(() => {
      setIsPending(false);
      setOpen(false);
    }, 1200);
  }

  return (
    <AlertDialog onOpenChange={setOpen} open={open}>
      <AlertDialogTrigger render={<Button variant="outline" />}>
        Revoke Sessions
      </AlertDialogTrigger>
      <AlertDialogPopup className="sm:max-w-md">
        <AlertDialogHeader>
          <AlertDialogTitle>Sign out all devices?</AlertDialogTitle>
          <AlertDialogDescription>
            Every active session except this browser will be signed out
            immediately.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogClose
            disabled={isPending}
            render={<Button variant="ghost" />}
          >
            Cancel
          </AlertDialogClose>
          <Button
            loading={isPending}
            onClick={handleRevoke}
            variant="destructive"
          >
            Revoke all
          </Button>
        </AlertDialogFooter>
      </AlertDialogPopup>
    </AlertDialog>
  );
}
```

## API Reference [#api-reference]

### AlertDialog [#alertdialog]

Re-exports `AlertDialog.Root` from `@base-ui/react/alert-dialog`. Unlike `Dialog`, clicking the backdrop does not dismiss the dialog.

| Prop           | Type                      | Default | Description                        |
| -------------- | ------------------------- | ------- | ---------------------------------- |
| `open`         | `boolean`                 | -       | Controlled open state              |
| `defaultOpen`  | `boolean`                 | `false` | Initial uncontrolled open state    |
| `onOpenChange` | `(open: boolean) => void` | -       | Called when the open state changes |

### AlertDialogPopup / AlertDialogContent [#alertdialogpopup--alertdialogcontent]

Composes `AlertDialogPortal`, `AlertDialogBackdrop`, `AlertDialogViewport`, and `AlertDialog.Popup`.

| Prop          | Type                      | Default | Description                                    |
| ------------- | ------------------------- | ------- | ---------------------------------------------- |
| `portalProps` | `AlertDialog.Portal.Props`| -       | Props forwarded to `AlertDialogPortal`         |
| `className`   | `string`                  | -       | Additional CSS classes                         |

### AlertDialogHeader / AlertDialogIcon / AlertDialogTitle / AlertDialogDescription / AlertDialogFooter / AlertDialogTrigger / AlertDialogClose [#alertdialogheader--alertdialogicon--alertdialogtitle--alertdialogdescription--alertdialogfooter--alertdialogtrigger--alertdialogclose]

Composable layout and action primitives built on `Dialog` header/footer slots and Base UI `AlertDialog`.
