Installation
$ pnpm dlx shadcn@latest add @synccn/alert-dialogFirst time in this project? Connect synccn with one command.
Usage
import { AlertDialog } from "@/components/ui/alert-dialog";<AlertDialog open={open} onOpenChange={setOpen} destructive confirmText="web-app" />API reference
Generated from the component's TypeScript types, so it always matches the code.
AlertDialog
Interrupting confirmation. Unlike Dialog it doesn't close on outside click, and can require the user to type a phrase before the action unlocks.
- openrequired
booleanWhether the dialog is shown.
- onOpenChangerequired
(open: boolean) => voidCalled when the dialog should open or close.
- titlerequired
stringHeading, also used as the accessible name.
- description
React.ReactNodeSupporting text under the title.
- confirmLabel
stringDefault
"Continue"Text on the confirm button.
- cancelLabel
stringDefault
"Cancel"Text on the cancel button.
- destructive
booleanDefault
falseRed confirm button and a warning icon.
- confirmText
stringPhrase the user must type before the confirm button unlocks.
- onConfirm
() => unknownRuns on confirm. A returned promise shows a spinner until it settles.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Components
- Button for
Button
Helpers
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for TriangleAlert
Keyboard
- TaborShift+TabMove focus; it stays inside while open
- EscClose
Accessibility
- role alertdialog with aria-modal. Clicking outside does not close it, so the user has to choose.
- With confirmText, the confirm button stays disabled until the phrase is typed exactly.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: alertdialog
- ARIA attributes: aria-label, aria-modal
- Keys handled: Escape
- Keeps keyboard focus inside while open, and returns it when closed
- Stops the page behind from scrolling while open
- Labels are tied to their controls