AlertDialog
A modal confirmation that requires an explicit decision; it never closes on outside press.
Purpose
AlertDialog interrupts the user to confirm an important, usually destructive, action. Unlike a
Dialog it cannot be dismissed by pressing outside.
Import
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@neshel-ui/components";Usage
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
Button,
} from "@neshel-ui/components";
export default function AlertDialogBasic() {
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="destructive">Delete project</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete this project?</AlertDialogTitle>
<AlertDialogDescription>
This permanently removes the project and its data. It cannot be undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
{/* Cancel receives focus first; Escape cancels; outside presses are ignored. */}
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction variant="destructive">Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}API
AlertDialogProps
Also accepts the props of: @radix-ui/react-dialog.
AlertDialogContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
| container | HTMLElement | null | document.body | Portal target (default document.body, wrapped with the trigger's theme). |
| ref | Ref<HTMLDivElement> | — | — |
| size | "sm" | "md" | "lg" | "sm" | Maximum width (default "sm"). |
Also accepts the props of: @radix-ui/react-dialog, @radix-ui/react-dismissable-layer, @radix-ui/react-primitive, React DOM attributes.
AlertDialogActionProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLButtonElement> | — | — |
| size | Responsive<ButtonSize> | "md" | Button size, static or per breakpoint (default "md"). |
| variant | ButtonVariant | "primary" | Button style (Action default "primary", Cancel default "outline"). |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
AlertDialogCancelProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLButtonElement> | — | — |
| size | Responsive<ButtonSize> | "md" | Button size, static or per breakpoint (default "md"). |
| variant | ButtonVariant | "primary" | Button style (Action default "primary", Cancel default "outline"). |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
AlertDialogTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
AlertDialogTitleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLHeadingElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
AlertDialogDescriptionProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLParagraphElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
AlertDialogPartProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
AlertDialogAction and AlertDialogCancel take Button variant and size (Action defaults to
primary, Cancel to outline) and support asChild. Both close the dialog; run your action in
Action's onClick.
Controlled and uncontrolled
Like Dialog: open, defaultOpen, onOpenChange. For an asynchronous action, control open,
render a regular Button (with loading) instead of AlertDialogAction, and close the dialog
yourself when the action completes.
Accessibility
- Role
alertdialog, named by the title and described by the description (both required). - Cancel receives initial focus, so an accidental Enter does not confirm.
- Escape cancels; outside presses are ignored.
Keyboard
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move between Cancel and Action |
| Enter / Space | Activate the focused button |
| Escape | Cancel |
Common mistakes
- Using AlertDialog for information that needs no decision — use a Dialog or inline message.
- Labels like "Yes"/"No": name the action ("Delete project").