Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Alert Dialog

FreeNew

A confirmation that needs an answer: it cannot be dismissed by pressing outside, and focus starts on Cancel.

Installation

pnpm dlx shadcn@latest add @viewport/alert-dialog

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

alert-dialog-demo.tsx
"use client";

import { useState } from "react";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogTrigger } from "@/components/viewport/alert-dialog";
import { Button } from "@/components/viewport/button";

export default function AlertDialogDemo() {
  const [members, setMembers] = useState(12);

  return (
    <div className="flex w-full max-w-sm items-center justify-between gap-4 rounded-2xl border border-border bg-card p-4">
      <div className="min-w-0">
        <p className="text-sm font-medium">Northwind workspace</p>
        <p role="status" className="text-xs text-muted-foreground">
          {members} members
        </p>
      </div>
      <AlertDialog>
        <AlertDialogTrigger asChild>
          <Button variant="outline" size="sm" disabled={members === 0}>
            Remove everyone
          </Button>
        </AlertDialogTrigger>
        <AlertDialogContent title="Remove all 12 members?" description="They lose access to every project in Northwind immediately. You can invite them again, but their personal views and drafts are not restored.">
          <AlertDialogCancel>Keep members</AlertDialogCancel>
          <AlertDialogAction variant="destructive" onClick={() => setMembers(0)}>
            Remove members
          </AlertDialogAction>
        </AlertDialogContent>
      </AlertDialog>
    </div>
  );
}

Props

<AlertDialogContent>

PropTypeDefault
title*string

The question, e.g. "Delete this workspace?".

—
description*string

What happens if the user goes ahead.

—

<AlertDialogAction>

PropTypeDefault
variant"primary" | "destructive"

`destructive` for actions that delete or cannot be undone.

"primary"

Accessibility

  • Built on Radix Alert Dialog with role=alertdialog.
  • Focus starts on the safe choice and returns to the trigger.
  • Buttons stack with the action on top on phones.
  • No scale animation under reduced motion.