Alert Dialog
Modal dialog for important confirmations with multiple variants.
When to use Alert Dialog vs. Dialog
Use Alert Dialog for "are you sure?" moments: delete confirmations, destructive actions, critical warnings. Title, description, variant (danger/warning/success) and Cancel/Confirm buttons are built in; you provide the copy and handlers.
Reach for Dialog for generic modals with arbitrary content: forms, rich views, multi-step flows. Unopinionated Radix composition with DialogTrigger/DialogContent/DialogFooter.
Preview
Different dialog variants for different contexts
Variants
All available dialog variants
Default
Standard confirmation dialogs
Danger
Destructive actions like delete
Warning
Unsaved changes, data loss
Info
Updates, information prompts
Success
Successful operations
Props
Component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
open* | boolean | — | Controls dialog visibility |
onOpenChange* | (open: boolean) => void | — | Open state change handler |
title* | string | — | Dialog title |
description* | string | — | Dialog description |
variant | "default" | "danger" | "warning" | "info" | "success" | "default" | Visual variant |
confirmText | string | "Confirm" | Confirm button text |
cancelText | string | "Cancel" | Cancel button text |
loading | boolean | false | Show loading spinner |
onConfirm | () => void | — | Confirm button click handler |
onCancel | () => void | — | Called when the dialog is dismissed with Cancel or Escape |
icon | ComponentType<{ className?: string }> | — | Custom icon component |
children | ReactNode | — | Additional dialog content |
Usage
Import and implementation examples
import { useState } from 'react'import { AlertDialog } from '@/components/ui/alert-dialog'import { Button } from '@/components/ui/button'
function DeleteButton() { const [open, setOpen] = useState(false)
return ( <> <Button variant="destructive" onClick={() => setOpen(true)}> Delete Account </Button>
<AlertDialog open={open} onOpenChange={setOpen} title="Delete Account" description="This will permanently delete your account. This action cannot be undone." variant="danger" confirmText="Delete" cancelText="Cancel" onConfirm={() => { console.log('Deleted') setOpen(false) }} /> </> )}
// With loading stateconst [loading, setLoading] = useState(false)
<AlertDialog open={open} onOpenChange={setOpen} title="Processing..." description="Please wait while we process your request." variant="info" loading={loading} onConfirm={() => { setLoading(true) // Async operation setTimeout(() => { setLoading(false) setOpen(false) }, 2000) }}/>Features
Built-in functionality
- 5 variants: Default, danger, warning, info, success
- Loading states: Spinner during async operations
- Keyboard navigation: Escape cancels, Cancel has focus on open
- No accidental dismiss: Clicking the backdrop does not close the dialog
- Custom icons: Override default variant icons
- Customizable buttons: Custom confirm/cancel text
- Body scroll lock: Prevents background scroll
Accessibility
Accessibility considerations
ARIA Attributes
Uses role="alertdialog" for modalaria-labelledby for titlearia-describedby for descriptionaria-modal="true" when openKeyboard Navigation
| Key | Action |
|---|---|
| Escape | Cancel and close dialog |
| Tab | Navigate between buttons |
| Enter | Activate focused button |
Notes
- Built on Radix AlertDialog
- Cancel button receives focus on open
- Focus trapped within dialog when open
- Focus returns to trigger on close
- Screen reader announces dialog content