---
title: "Alert Dialog"
description: "A modal dialog that interrupts the user with important content and expects a response."
component: true
---

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

export default function AlertDialogDemo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="outline" />}
      >
        Show Dialog
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. This will permanently delete your
            account from our servers.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Continue</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## Installation

<CodeTabs>

<TabsList>
  <TabsTrigger value="cli">Command</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>

<TabsContent value="cli">

```bash
npx solidui-cli@latest add alert-dialog
```

</TabsContent>

<TabsContent value="manual">

<Steps class="mb-0 pt-2">

<Step>Install the following dependencies:</Step>

```bash
npm install @ui-sdk/solid @ui-sdk/core
```

<Step>Install the required Solid UI dependencies:</Step>

```bash
npx solidui-cli@latest add button
```

<Step>Copy and paste the following code into your project.</Step>

```tsx title="components/ui/alert-dialog.tsx"
import { type ComponentProps } from "@solidjs/web"
import {
  AlertDialog as SdkAlertDialog,
  AlertDialogTrigger as SdkAlertDialogTrigger,
  AlertDialogBackdrop as SdkAlertDialogBackdrop,
  AlertDialogContent as SdkAlertDialogContent,
  AlertDialogTitle as SdkAlertDialogTitle,
  AlertDialogDescription as SdkAlertDialogDescription,
  AlertDialogClose as SdkAlertDialogClose
} from "@ui-sdk/solid/alert-dialog"
import { omit, type Component } from "solid-js"

import { cn } from "~/lib/utils"
import { Button, type ButtonProps } from "~/components/ui/button"
type AlertDialogProps = ComponentProps<typeof SdkAlertDialog>
const AlertDialog: Component<AlertDialogProps> = (props) => (
  <SdkAlertDialog {...props} />
)
type AlertDialogTriggerProps = Omit<
  ComponentProps<typeof SdkAlertDialogTrigger>,
  "class"
> & {
  class?: string
}
const AlertDialogTrigger = (props: AlertDialogTriggerProps) => (
  <SdkAlertDialogTrigger {...props} />
)
type AlertDialogOverlayProps = Omit<
  ComponentProps<typeof SdkAlertDialogBackdrop>,
  "class"
> & {
  class?: string
}
const AlertDialogOverlay = (props: AlertDialogOverlayProps) => (
  <SdkAlertDialogBackdrop
    {...props}
    class={cn(
      "bg-black/10 duration-100 data-ending-style:animate-out data-ending-style:fade-out-0 data-ending-style:fill-mode-forwards supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 fixed inset-0 isolate z-50",
      props.class
    )}
  />
)
type AlertDialogContentProps = (Omit<
  ComponentProps<typeof SdkAlertDialogContent>,
  "class"
> & {
  class?: string
}) & {
  size?: "default" | "sm"
}
const AlertDialogContent = (props: AlertDialogContentProps) => {
  const others = omit(props, "size")
  return (
    <>
      <AlertDialogOverlay />
      <SdkAlertDialogContent
        data-size={props.size ?? "default"}
        {...others}
        class={cn(
          "group/alert-dialog-content gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 data-ending-style:animate-out data-ending-style:fade-out-0 data-ending-style:fill-mode-forwards data-ending-style:zoom-out-95 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none",
          props.class
        )}
      />
    </>
  )
}
type AlertDialogHeaderProps = ComponentProps<"div">
const AlertDialogHeader = (props: AlertDialogHeaderProps) => (
  <div
    data-slot="alert-dialog-header"
    {...props}
    class={cn("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]", props.class)}
  />
)
type AlertDialogFooterProps = ComponentProps<"div">
const AlertDialogFooter = (props: AlertDialogFooterProps) => (
  <div
    data-slot="alert-dialog-footer"
    {...props}
    class={cn(
      "-mx-4 -mb-4 rounded-b-xl border-t bg-muted/50 p-4 flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
      props.class
    )}
  />
)
type AlertDialogMediaProps = ComponentProps<"div">
const AlertDialogMedia = (props: AlertDialogMediaProps) => (
  <div
    data-slot="alert-dialog-media"
    {...props}
    class={cn("mb-2 inline-flex size-10 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6", props.class)}
  />
)
type AlertDialogTitleProps = Omit<
  ComponentProps<typeof SdkAlertDialogTitle>,
  "class"
> & {
  class?: string
}
const AlertDialogTitle = (props: AlertDialogTitleProps) => (
  <SdkAlertDialogTitle
    {...props}
    class={cn("text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2", props.class)}
  />
)
type AlertDialogDescriptionProps = Omit<
  ComponentProps<typeof SdkAlertDialogDescription>,
  "class"
> & {
  class?: string
}
const AlertDialogDescription = (props: AlertDialogDescriptionProps) => (
  <SdkAlertDialogDescription
    {...props}
    class={cn("text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground", props.class)}
  />
)
type AlertDialogActionProps = (Omit<
  ComponentProps<typeof SdkAlertDialogClose>,
  "class"
> & {
  class?: string
}) &
  Pick<ButtonProps, "variant" | "size" | "class">
const AlertDialogAction = (props: AlertDialogActionProps) => {
  const others = omit(props, "variant", "size")
  return (
    <SdkAlertDialogClose
      render={(partProps) => (
        <Button
          {...partProps}
          variant={props.variant ?? "default"}
          size={props.size ?? "default"}
        />
      )}

      value="confirm"
      {...others}
      class={cn("", props.class)}
    />
  )
}
type AlertDialogCancelProps = (Omit<
  ComponentProps<typeof SdkAlertDialogClose>,
  "class"
> & {
  class?: string
}) &
  Pick<ButtonProps, "variant" | "size" | "class">
const AlertDialogCancel = (props: AlertDialogCancelProps) => {
  const others = omit(props, "variant", "size")
  return (
    <SdkAlertDialogClose
      render={(partProps) => (
        <Button
          {...partProps}
          variant={
            props.variant === undefined
              ? "outline"
              : (props.variant ?? "default")
          }
          size={props.size ?? "default"}
        />
      )}

      value="cancel"
      {...others}
      class={cn("", props.class)}
    />
  )
}
export {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogMedia,
  AlertDialogOverlay,
  AlertDialogTitle,
  AlertDialogTrigger
}
```

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</CodeTabs>

## Usage

```tsx showLineNumbers
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger
} from "~/components/ui/alert-dialog"
```

```tsx showLineNumbers
<AlertDialog>
  <AlertDialogTrigger>Show Dialog</AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete your account
        from our servers.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>
```

## Composition

Use the following composition to build an `AlertDialog`:

```text
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
    ├── AlertDialogHeader
    │   ├── AlertDialogMedia
    │   ├── AlertDialogTitle
    │   └── AlertDialogDescription
    └── AlertDialogFooter
        ├── AlertDialogCancel
        └── AlertDialogAction
```

## Basic

A basic alert dialog with a title, description, and cancel and continue buttons.

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

export default function AlertDialogBasic() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="outline" />}
      >
        Show Dialog
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. This will permanently delete your
            account and remove your data from our servers.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Continue</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## Small

Use the `size="sm"` prop to make the alert dialog smaller.

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

export default function AlertDialogSmall() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="outline" />}
      >
        Show Dialog
      </AlertDialogTrigger>
      <AlertDialogContent size="sm">
        <AlertDialogHeader>
          <AlertDialogTitle>Allow accessory to connect?</AlertDialogTitle>
          <AlertDialogDescription>
            Do you want to allow the USB accessory to connect to this device?
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Don&apos;t allow</AlertDialogCancel>
          <AlertDialogAction>Allow</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## Media

Use the `AlertDialogMedia` component to add a media element such as an icon or image to the alert dialog.

```tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogMedia,
  AlertDialogTitle,
  AlertDialogTrigger
} from "~/components/ui/alert-dialog"
import { Button } from "~/components/ui/button"

export default function AlertDialogMediaExample() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="outline" />}
      >
        Share Project
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogMedia>
            <svg
              width="24"
              height="24"
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
            >
              <path d="M12 2v13" />
              <path d="m16 6-4-4-4 4" />
              <path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8" />
            </svg>
          </AlertDialogMedia>
          <AlertDialogTitle>Share this project?</AlertDialogTitle>
          <AlertDialogDescription>
            Anyone with the link will be able to view and edit this project.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Share</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## Small with Media

Use the `size="sm"` prop to make the alert dialog smaller and the `AlertDialogMedia` component to add a media element such as an icon or image to the alert dialog.

```tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogMedia,
  AlertDialogTitle,
  AlertDialogTrigger
} from "~/components/ui/alert-dialog"
import { Button } from "~/components/ui/button"

export default function AlertDialogSmallMedia() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="outline" />}
      >
        Show Dialog
      </AlertDialogTrigger>
      <AlertDialogContent size="sm">
        <AlertDialogHeader>
          <AlertDialogMedia>
            <svg
              width="24"
              height="24"
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
            >
              <path d="M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2" />
            </svg>
          </AlertDialogMedia>
          <AlertDialogTitle>Allow accessory to connect?</AlertDialogTitle>
          <AlertDialogDescription>
            Do you want to allow the USB accessory to connect to this device?
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Don&apos;t allow</AlertDialogCancel>
          <AlertDialogAction>Allow</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## Destructive

Use the `AlertDialogAction` component to add a destructive action button to the alert dialog.

```tsx
// Inline SVG icons from Lucide (https://lucide.dev), ISC License, Copyright (c) Lucide Icons and Contributors.

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogMedia,
  AlertDialogTitle,
  AlertDialogTrigger
} from "~/components/ui/alert-dialog"
import { Button } from "~/components/ui/button"

export default function AlertDialogDestructive() {
  return (
    <AlertDialog>
      <AlertDialogTrigger
        render={(partProps) => <Button {...partProps} variant="destructive" />}
      >
        Delete Chat
      </AlertDialogTrigger>
      <AlertDialogContent size="sm">
        <AlertDialogHeader>
          <AlertDialogMedia class="bg-destructive/10 text-destructive dark:bg-destructive/20 dark:text-destructive">
            <svg
              width="24"
              height="24"
              viewBox="0 0 24 24"
              fill="none"
              stroke="currentColor"
              stroke-width="2"
              stroke-linecap="round"
              stroke-linejoin="round"
              aria-hidden="true"
            >
              <path d="M10 11v6" />
              <path d="M14 11v6" />
              <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" />
              <path d="M3 6h18" />
              <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
            </svg>
          </AlertDialogMedia>
          <AlertDialogTitle>Delete chat?</AlertDialogTitle>
          <AlertDialogDescription>
            This will permanently delete this chat conversation. View{" "}
            <a href="#">Settings</a>, then delete any memories saved during this
            chat.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel variant="outline">Cancel</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Delete</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}
```

## API Reference

### size

Use the `size` props on the `AlertDialogContent` component to control the size of the alert dialog. It accepts the following values:

| Prop   | Type                | Default     |
| ------ | ------------------- | ----------- |
| `size` | `"default" \| "sm"` | `"default"` |

See the [UI SDK](https://ui-sdk.dev/docs/solid/components/alert-dialog) documentation for more information.
