Skip to content
synccn

Alert Dialog

Confirmation that interrupts, with optional type-to-confirm.

Installation

$ pnpm dlx shadcn@latest add @synccn/alert-dialog

First 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
    boolean

    Whether the dialog is shown.

  • onOpenChangerequired
    (open: boolean) => void

    Called when the dialog should open or close.

  • titlerequired
    string

    Heading, also used as the accessible name.

  • description
    React.ReactNode

    Supporting text under the title.

  • confirmLabel
    string

    Default "Continue"

    Text on the confirm button.

  • cancelLabel
    string

    Default "Cancel"

    Text on the cancel button.

  • destructive
    boolean

    Default false

    Red confirm button and a warning icon.

  • confirmText
    string

    Phrase the user must type before the confirm button unlocks.

  • onConfirm
    () => unknown

    Runs 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

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseFocusTrap (keeps focus inside while open), useIsClient (renders portals only in the browser), useLockScroll (locks page scroll while open), usePresence (animates in and out)

npm packages

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