Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Alert Dialog for Astro

Astro confirmation dialogs for actions that need an explicit decision.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/alert-dialog

Usage

import {
    AlertDialog,
    AlertDialogAction,
    AlertDialogCancel,
    AlertDialogContent,
    AlertDialogDescription,
    AlertDialogFooter,
    AlertDialogHeader,
    AlertDialogTitle,
    AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
  <AlertDialogTrigger variant="outline">Review draft removal</AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Remove this draft?</AlertDialogTitle>
      <AlertDialogDescription>
        Removing this draft deletes its saved content. Export a copy first if you need to keep it.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Remove draft</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Composition

Arrange the parts as shown for an AlertDialog:

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

Notes

  • Use AlertDialog for irreversible or high-risk actions, not routine inline confirmations.
  • Keep AlertDialogTitle and AlertDialogDescription inside AlertDialogContent so screen readers announce the dialog context clearly.
  • Pair the destructive path with AlertDialogAction and the safe path with AlertDialogCancel.
  • Use size="sm" on AlertDialogContent for compact confirmations and AlertDialogMedia when the dialog needs an icon or visual cue.

API Reference

AlertDialogProps

PropType
defaultOpen?boolean

Initial open state

Typeboolean
closeOnClickOutside?boolean

Close when clicking overlay

Typeboolean
closeOnEscape?boolean

Close when pressing Escape

Typeboolean
lockScroll?boolean

Lock body scroll when open

Typeboolean

AlertDialogContentProps

PropType
size?'default' | 'sm'

Panel width.

Type'default' | 'sm'
Default"default"

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the alert dialog root. The root emits the outbound events.

Outbound events

Event Detail
alert-dialog:change { open: boolean }

Inbound events

Event Detail
alert-dialog:set { open: boolean }

Read the installed source for the complete prop types.

When to use Alert Dialog

Use Alert Dialog before an action whose effect is hard to reverse. Put the specific result in the title and explanation. Keep the cancel control available and label the action with a verb such as “Remove project”. The action button alone does not perform the operation.

Keyboard and behavior

The existing alert-dialog controller manages modal focus and dismissal. Confirm that focus returns to the trigger after cancellation. Run the operation from your own form or script only after the user chooses the action. Test Escape and focus order in the finished page.

Theme and layout

The surface shares dialog colors, border, and footer spacing. Keep copy short enough to fit a narrow screen and allow it to wrap. Destructive button color is useful, but the wording must still explain the outcome without color.