Skip to main content

alert dialog

A modal dialog temporarily interrupts the user's workflow with important content, requiring immediate attention and a response before allowing further interaction.

Philosophy

Alert dialogs are the nuclear option of UI interruption. Unlike regular dialogs, they can't be dismissed by clicking outside or pressing Escape - the user must explicitly choose an action. Reserve them for destructive operations where an accidental dismissal could mean data loss.

Installation


npx @gentleduck/cli add alert-dialog

npx @gentleduck/cli add alert-dialog

Usage

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
<AlertDialog>
  <AlertDialogTrigger>Open</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>
<AlertDialog>
  <AlertDialogTrigger>Open</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>

Examples

Active Trigger on Open

Style the trigger to appear active while the alert dialog is open using data-[state=open]:

Component Composition

Loading diagram...

RTL Support

Set dir="rtl" on AlertDialog for a local override, or set DirectionProvider once at app/root level for global direction. AlertDialog extends Dialog, so direction is inherited by all child parts.

<AlertDialog dir="rtl">
  <AlertDialogTrigger>Open</AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>هل انت متاكد؟</AlertDialogTitle>
      <AlertDialogDescription>
        هذا الاجراء لا يمكن التراجع عنه.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>الغاء</AlertDialogCancel>
      <AlertDialogAction>متابعة</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>
<AlertDialog dir="rtl">
  <AlertDialogTrigger>Open</AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>هل انت متاكد؟</AlertDialogTitle>
      <AlertDialogDescription>
        هذا الاجراء لا يمكن التراجع عنه.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>الغاء</AlertDialogCancel>
      <AlertDialogAction>متابعة</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Motion

Use MotionAlertDialog and MotionAlertDialogContent for smooth enter/exit animations powered by motion. Uses a stiffer spring to convey urgency compared to the regular dialog.

API Reference

AlertDialog

PropTypeDefaultDescription
defaultOpenboolean-Determines if the dialog should be open by default
openboolean-Controls the visibility of the dialog
onOpenChange(open: boolean) => void-Callback fired when the dialog opens or closes
dir'ltr' | 'rtl'-Text direction. Resolved by primitives useDirection (dir prop -> DirectionProvider -> 'ltr'). Inherited from the Dialog primitive.
childrenReact.ReactNode(required)Child elements (typically Trigger and Content)
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Root>-Additional props inherited from AlertDialogPrimitive.Root

AlertDialogTrigger

PropTypeDefaultDescription
asChildbooleanfalseIf true, renders using a Slot instead of a button element
childrenReact.ReactNode--Content of the trigger
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Trigger>-Additional props inherited from AlertDialogPrimitive.Trigger

AlertDialogPortal

PropTypeDefaultDescription
containerHTMLElement-Optional portal container
forceMounttrue-Forces mounted state for all portal children
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Portal>-Additional props inherited from AlertDialogPrimitive.Portal

AlertDialogOverlay

PropTypeDefaultDescription
classNamestring-Additional class names to apply
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>-Additional props inherited from AlertDialogPrimitive.Overlay

AlertDialogContent

PropTypeDefaultDescription
classNamestring-Additional class names to apply
childrenReact.ReactNode-Content displayed inside the dialog
forceMountbooleanfalseIf true, forces the content to stay mounted in the DOM
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>-Additional props inherited from AlertDialogPrimitive.Content

MotionAlertDialog

Same props as AlertDialog. Wraps with useMotionRoot for exit animation support. Requires the motion package.

MotionAlertDialogContent

PropTypeDefaultDescription
openboolean-Required. Controlled open state for AnimatePresence enter/exit
classNamestring-Additional class names to apply
childrenReact.ReactNode-Content displayed inside the dialog

Requires motion package installed. Uses a spring transition (stiffness 400, damping 30) for a snappier feel that conveys urgency. Automatically respects prefers-reduced-motion.

AlertDialogHeader

PropTypeDefaultDescription
classNamestring--Additional class names to apply
childrenReact.ReactNode--Header content (typically Title and Description)
...propsReact.HTMLAttributes<HTMLDivElement>-Additional props to spread to the header container

AlertDialogFooter

PropTypeDefaultDescription
classNamestring--Additional class names to apply
childrenReact.ReactNode--Footer content (typically Action and Cancel buttons)
...propsReact.HTMLAttributes<HTMLDivElement>-Additional props to spread to the content div

AlertDialogTitle

PropTypeDefaultDescription
classNamestring--Additional class names to apply
childrenReact.ReactNode--Title text content
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>-Additional props inherited from AlertDialogPrimitive.Title

AlertDialogDescription

PropTypeDefaultDescription
classNamestring--Additional class names to apply
childrenReact.ReactNode--Description text content
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>-Additional props inherited from AlertDialogPrimitive.Description

AlertDialogAction

PropTypeDefaultDescription
classNamestring-Additional class names merged with default button styles
childrenReact.ReactNode-Action button content
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>-Additional props inherited from AlertDialogPrimitive.Action

AlertDialogCancel

PropTypeDefaultDescription
classNamestring-Additional class names merged with outline button styles
childrenReact.ReactNode-Cancel button content
...propsReact.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>-Additional props inherited from AlertDialogPrimitive.Cancel