Equality
Equality

Alert Dialog

A modal dialog for confirmations and destructive actions

View Markdown

Overview

A confirmation dialog that blocks interaction until the user acknowledges it. Unlike Dialog, clicking the background overlay won’t dismiss it — the user must choose an action.

Usage

Import the components:

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@eqtylab/equality";
<AlertDialog>
  <AlertDialogTrigger asChild>
    <Button>Delete Item</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete the item.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Delete</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Variants

Action Button Variants

AlertDialogAction and AlertDialogCancel accept variant and size props from Button. Defaults are primary (action) and tertiary (cancel) at size sm.

Use danger for destructive confirmations:

<AlertDialogFooter>
  <AlertDialogCancel>Cancel</AlertDialogCancel>
  <AlertDialogAction variant="danger">Delete</AlertDialogAction>
</AlertDialogFooter>

Controlled State

Control the open state with open and onOpenChange:

const [open, setOpen] = useState(false);

<AlertDialog open={open} onOpenChange={setOpen}>
  <AlertDialogTrigger asChild>
    <Button>Open</Button>
  </AlertDialogTrigger>
  <AlertDialogContent>...</AlertDialogContent>
</AlertDialog>;

Slots

NameDescription
AlertDialogRoot component, manages open state
AlertDialogTriggerOpens the dialog on click
AlertDialogContentDialog panel with header, body, and footer
AlertDialogHeaderContains the title and description
AlertDialogTitleTitle text (required for accessibility)
AlertDialogDescriptionDescribes the action being confirmed
AlertDialogFooterContains action and cancel buttons
AlertDialogActionConfirms and closes the dialog
AlertDialogCancelDismisses without acting

Props

AlertDialog

NameDescriptionTypeDefaultRequired
openWhether the dialog is openboolean-
onOpenChangeCalled when open state changes(open: boolean) => void-

AlertDialogAction

NameDescriptionTypeDefaultRequired
variantButton style variantprimary, danger, secondary, tertiary, link, navigationprimary
sizeButton sizesm, md, lgsm
prefixContent rendered before childrenReactNode-
suffixContent rendered after childrenReactNode-

AlertDialogCancel

NameDescriptionTypeDefaultRequired
variantButton style variantprimary, danger, secondary, tertiary, link, navigationtertiary
sizeButton sizesm, md, lgsm
prefixContent rendered before childrenReactNode-
suffixContent rendered after childrenReactNode-