Design system

Alert dialog

A blocking confirmation for destructive or consequential actions.

Use an alert dialog when the user must acknowledge a consequence before continuing. The action should be clear, specific and easy to cancel.

Built on Radix UI Alert DialogUpstream API
Confirmation is required.

Import

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@workshop1/ui/components/alert-dialog"

Anatomy

Use AlertDialogTitle and AlertDialogDescription to state the action and its consequence. Put the safe escape route first in AlertDialogFooter; keep the destructive action explicit with the destructive button variant.

<AlertDialog>
  <AlertDialogTrigger asChild><Button variant="destructive">Delete</Button></AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete this item?</AlertDialogTitle>
      <AlertDialogDescription>...</AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction variant="destructive">Delete</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Behaviour

  • Alert dialogs trap focus and prevent accidental interaction with the page behind them.
  • Do not dismiss a destructive confirmation by clicking the overlay; the cancel action is the deliberate escape route.
  • Describe what is lost, whether it can be recovered and what the action affects.

Best practices

  • Name the object in the title and repeat the action on the confirm button.
  • Use an ordinary dialog for choices that are not consequential.
  • Move focus back to the initiating control after cancellation.