Skip to Content
Neshel-UI
Components

AlertDialog

A modal confirmation that requires an explicit decision; it never closes on outside press.

Client component ("use client")

Purpose

AlertDialog interrupts the user to confirm an important, usually destructive, action. Unlike a Dialog it cannot be dismissed by pressing outside.

Import

import.tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@neshel-ui/components";

Usage

Preview: alert-dialog-basic
Preview theme
alert-dialog-basic.tsx
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

AlertDialogContentProps
PropTypeDefaultDescription
containerHTMLElement | nulldocument.bodyPortal target (default document.body, wrapped with the trigger's theme).
refRef<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

AlertDialogActionProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——
sizeResponsive<ButtonSize>"md"Button size, static or per breakpoint (default "md").
variantButtonVariant"primary"Button style (Action default "primary", Cancel default "outline").

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

AlertDialogCancelProps

AlertDialogCancelProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——
sizeResponsive<ButtonSize>"md"Button size, static or per breakpoint (default "md").
variantButtonVariant"primary"Button style (Action default "primary", Cancel default "outline").

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

AlertDialogTriggerProps

AlertDialogTriggerProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

AlertDialogTitleProps

AlertDialogTitleProps
PropTypeDefaultDescription
refRef<HTMLHeadingElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

AlertDialogDescriptionProps

AlertDialogDescriptionProps
PropTypeDefaultDescription
refRef<HTMLParagraphElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

AlertDialogPartProps

AlertDialogPartProps
PropTypeDefaultDescription
refRef<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

KeyAction
Tab / Shift+TabMove between Cancel and Action
Enter / SpaceActivate the focused button
EscapeCancel

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").
Edit on GitHub

On this page