Components

Alert Dialog

A confirmation that interrupts the user and waits for an answer - it cannot be dismissed by clicking outside.

Loading...

Installation

npx shadcn@latest add @fujin/alert-dialog

Usage

import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
  <AlertDialogTrigger render={<Button variant="destructive">Delete</Button>} />
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Delete this project?</AlertDialogTitle>
      <AlertDialogDescription>This can't be undone.</AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction variant="destructive" onClick={deleteProject}>
        Delete
      </AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Keep AlertDialogCancel first in the footer. Focus moves to the first button when the dialog opens, so pressing Enter straight away cancels instead of deleting. The footer's flex-col-reverse/sm:flex-row layout still shows the action on the right (or on top, on small screens).

Async actions

AlertDialogAction closes the dialog on click. When the work can fail, use a plain Button with loading and close the dialog yourself once it succeeds, so an error can be shown in place:

const [open, setOpen] = React.useState(false)
const [pending, startTransition] = React.useTransition()
 
<AlertDialog open={open} onOpenChange={setOpen}>
  <AlertDialogContent>
    {/* header */}
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <Button
        variant="destructive"
        loading={pending}
        onClick={() =>
          startTransition(async () => {
            await deleteProject()
            setOpen(false)
          })
        }
      >
        Delete
      </Button>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

What's different from shadcn/ui

  • AlertDialogAction and AlertDialogCancel render a Fujin Button and take its variant and size props directly - no buttonVariants class juggling. Cancel defaults to outline.
  • render replaces asChild, from Base UI.

API Reference

Prop

Type

Every other prop is forwarded to the Base UI Alert Dialog.

On this page