Alert Dialog A modal dialog for confirming destructive or important actions that requires explicit user response
The Alert Dialog component displays a modal dialog that interrupts the user to confirm a critical action. Unlike regular dialogs, alert dialogs cannot be dismissed by clicking the overlay — users must explicitly choose an action. Built on Radix UI Alert Dialog .
import {
AlertDialog ,
AlertDialogTrigger ,
AlertDialogContent ,
AlertDialogHeader ,
AlertDialogFooter ,
AlertDialogTitle ,
AlertDialogDescription ,
AlertDialogAction ,
AlertDialogCancel ,
} from '@nim-ui/components' ;
Basic Alert Dialog Code< AlertDialog >
< AlertDialogTrigger asChild >
< Button variant = "outline" > Delete Item </ Button >
</ AlertDialogTrigger >
< AlertDialogContent >
< AlertDialogHeader >
< AlertDialogTitle > Are you sure? </ AlertDialogTitle >
< AlertDialogDescription > This action cannot be undone. This will permanently delete the item. </ AlertDialogDescription >
</ AlertDialogHeader >
< AlertDialogFooter >
< AlertDialogCancel asChild >
< Button variant = "outline" > Cancel </ Button >
</ AlertDialogCancel >
< AlertDialogAction asChild >
< Button > Continue </ Button >
</ AlertDialogAction >
</ AlertDialogFooter >
</ AlertDialogContent >
</ AlertDialog >
Use variant="destructive" for dangerous actions like account deletion. This adds a red accent border to visually signal danger.
Destructive Alert Dialog Code< AlertDialog >
< AlertDialogTrigger asChild >
< Button variant = "destructive" > Delete Account </ Button >
</ AlertDialogTrigger >
< AlertDialogContent variant = "destructive" >
< AlertDialogHeader >
< AlertDialogTitle > Delete Account </ AlertDialogTitle >
< AlertDialogDescription > This will permanently delete your account and all associated data. </ AlertDialogDescription >
</ AlertDialogHeader >
< AlertDialogFooter >
< AlertDialogCancel asChild >
< Button variant = "outline" > Cancel </ Button >
</ AlertDialogCancel >
< AlertDialogAction asChild >
< Button variant = "destructive" > Delete </ Button >
</ AlertDialogAction >
</ AlertDialogFooter >
</ AlertDialogContent >
</ AlertDialog >
function ControlledAlertDialog () {
const [ open , setOpen ] = useState ( false );
return (
< AlertDialog open ={ open } onOpenChange ={ setOpen }>
< AlertDialogTrigger asChild >
< Button > Controlled </ Button >
</ AlertDialogTrigger >
< AlertDialogContent >
< AlertDialogHeader >
< AlertDialogTitle > Confirm </ AlertDialogTitle >
< AlertDialogDescription > Are you sure? </ AlertDialogDescription >
</ AlertDialogHeader >
< AlertDialogFooter >
< AlertDialogCancel asChild >
< Button variant = "outline" > Cancel </ Button >
</ AlertDialogCancel >
< AlertDialogAction asChild >
< Button onClick ={() => setOpen ( false )}> Confirm </ Button >
</ AlertDialogAction >
</ AlertDialogFooter >
</ AlertDialogContent >
</ AlertDialog >
);
}
Component Description AlertDialogRoot component managing open/close state (Radix AlertDialog.Root) AlertDialogTriggerElement that opens the alert dialog on click AlertDialogContentCentered modal panel with variant styling, rendered via Portal AlertDialogOverlayBackdrop overlay (included automatically by Content) AlertDialogHeaderContainer for Title and Description AlertDialogFooterContainer for Action and Cancel buttons AlertDialogTitleDialog heading, linked via aria-labelledby AlertDialogDescriptionDialog body text, linked via aria-describedby AlertDialogActionConfirm button that closes the dialog AlertDialogCancelCancel button that closes the dialog
Name Type Default Description openboolean- Controlled open state defaultOpenbooleanfalseInitial open state for uncontrolled usage onOpenChange(open: boolean) => void- Callback when the open state changes
Name Type Default Description variant'default' | 'destructive''default'Visual style variant. Use destructive for dangerous actions. classNamestring- Additional CSS classes
Name Type Default Description asChildbooleanfalseUse child element as the button
Built on Radix UI Alert Dialog with full accessibility support:
role="alertdialog" : Content is announced as an alert dialog to screen readers
aria-labelledby : Automatically linked to AlertDialogTitle
aria-describedby : Automatically linked to AlertDialogDescription
Focus trapping : Focus is trapped within the dialog while open
Focus restoration : Focus returns to the trigger when the dialog closes
Escape key : Pressing Escape dismisses the dialog
No overlay dismiss : Clicking the overlay does NOT close the dialog (requires explicit action)
Portal rendering : Content renders outside the DOM hierarchy without affecting the accessibility tree
Key Action Enter / Space Open dialog (on trigger) Escape Close the dialog Tab Navigate within dialog content
Feature Alert Dialog Dialog (Modal) Overlay dismiss No Yes ARIA role alertdialog dialog Use case Destructive/important confirmations General content User response Required (Action or Cancel) Optional
Modal — General-purpose dialog overlay
Popover — Non-modal floating panel