Skip to content

Components / Alert Dialog

Alert Dialog

An explicit decision before a destructive action. Explain what will be lost, focus the safe Cancel action, and require a deliberate confirmation. Unlike Dialog, clicking outside does not dismiss it.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

Write the decision and its consequence. Cancel receives focus; Continue only closes this uncontrolled preview and deletes nothing.

React / TSX
"use client";

import { Button } from "@/components/ui/yads-button";
import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from "@/components/ui/yads-alert-dialog";

export default function DeleteConfirmation() {

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/alert-dialog#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Alert Dialog samples include their layout styles. Install Button separately when imported by a sample.

Run in a project configured for shadcn. Installs @/components/ui/yads-alert-dialog, its CSS module, @radix-ui/[email protected] and JetBrains Mono 5.3.0. No Tailwind, reset, global theme provider, Dialog or other YADS primitive is needed. Adjust the alias for your project.

Examples compose the separately installed Button registry item for triggers. Copy sample includes a complete client module and any recipe CSS even while collapsed, with no Tailwind layout requirement. Input is used only for documentation controls and is not part of the install.

Controlled confirmation

Only Delete project changes local state. Action closes through onOpenChange; Cancel and Escape close without changing the result. Clicking outside never dismisses. Reset restores the demonstration, not real deleted data.

Spring launch is unchanged.

React / TSX
"use client";

import { useState } from "react";
import { Button } from "@/components/ui/yads-button";
import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from "@/components/ui/yads-alert-dialog";

Async confirmation

Action normally closes immediately; an async handler alone does not delay it. This example calls preventDefault synchronously, then waits 600ms locally. Failure stays open with an announced error; success explicitly closes. Cancel and Escape remain available while pending and invalidate that attempt, so its later completion cannot change the result or close a newly opened dialog. No request is sent.

Reports are unchanged.

React / TSX
"use client";

import { useRef, useState } from "react";
import { Button } from "@/components/ui/yads-button";
import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from "@/components/ui/yads-alert-dialog";

Customization

Content accepts className and style. This complete recipe widens the panel and changes its border while keeping focus and theme colors. Cancel composes a separately installed Button through asChild; use one ref-forwarding child that accepts native button props. Action and Cancel are already styled native buttons without Button.

React / TSX
"use client";

import { Button } from "@/components/ui/yads-button";
import { AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction } from "@/components/ui/yads-alert-dialog";

export default function CustomConfirmation() {

The nearest explicit .light or .dark ancestor of the root is carried into the body portal and observed live, including light islands. Light is the fallback. Content exposes --yads-alert-dialog-background, --yads-alert-dialog-foreground, --yads-alert-dialog-muted, --yads-alert-dialog-border and --yads-alert-dialog-ring. Check contrast in both themes. Target Content’s own class, not a page-wrapper descendant: the panel is portalled.

Accessibility

  • Always include a meaningful Title, concise Description explaining the consequence, and a Cancel button. Radix associates the heading and description with role=alertdialog. Do not use this for passive notifications or ordinary editing workflows.
  • Cancel receives initial focus. Tab and Shift+Tab stay inside; background interactions and scrolling are blocked and background content is hidden from assistive technology. Cancel and Escape close without confirming; outside clicks do not close or confirm. Keep a trigger mounted for focus restoration.
  • Action closes by default but performs no deletion itself. Own the operation and error state. Never perform destructive work in onOpenChange: cancellation also calls it. Async confirmation must prevent default closing synchronously and close explicitly on success.
  • Keep a usable cancellation path, including while awaiting work. Ref and asChild types describe the default native element; when replacing it you own its semantics, ref and keyboard behavior. Do not compose actions with navigation links for a local destructive operation.
  • Visible focus uses a 2px ring, actions have a 44px minimum height, and reduced motion removes fades and button transitions. The panel keeps a one-rem viewport gutter, wraps long text and scrolls within the dynamic viewport; actions stack below 480px. There is no swipe dismissal.

API reference

Import all nine exports from @/components/ui/yads-alert-dialog. Root, Trigger, Action, Cancel, Title and Description retain Radix props. Styled elements forward refs, native IDs, ARIA/data attributes, events and styles. AlertDialogContentProps is exported. Content excludes forceMount (also ignored for untyped callers) because it owns its portal lifecycle; asChild is supported with one child and forwards classes/props to it. No Portal, Overlay or generic Close export is provided.

Alert Dialog props and defaults
ExportPropsType / defaultBehavior
AlertDialogopen / defaultOpen / onOpenChangeboolean / false / (open: boolean) => voidControlled or uncontrolled visibility. Always modal; no modal prop. Pair open with onOpenChange. Root has no DOM ref.
AlertDialogTriggerasChild, ref, disabled, native button propsboolean / false; HTMLButtonElementNative button by default. asChild merges into one ref-forwarding child; use an actual button for correct keyboard semantics.
AlertDialogContentasChild, ref, className, style, native attributesboolean / false; HTMLDivElementDiv by default, role=alertdialog, associated title/description. Owns body portal and overlay, mounts only while open. No forceMount or independent portal/overlay controls.
AlertDialogContentonOpenAutoFocus / onCloseAutoFocusRadix event callbacksCancel is focused on open, trigger on close. Prevent defaults only when moving focus to a sensible alternative. Always include Cancel.
AlertDialogContentonEscapeKeyDownRadix keyboard callbackEscape cancels by default. Outside pointer/focus dismissal is prevented by Radix; no onPointerDownOutside or onInteractOutside API.
AlertDialogTitle / AlertDialogDescriptionasChild, ref, native attributesh2 / p by defaultMeaningful title and consequence. IDs are linked automatically. Refs target HTMLHeadingElement and HTMLParagraphElement by default.
AlertDialogHeader / AlertDialogFooterref, className, style, native attributesHTMLDivElementLayout-only divs; no asChild or independent semantics. Footer stacks below 480px.
AlertDialogAction / AlertDialogCancelasChild, ref, disabled, onClick, native button propsboolean / false; HTMLButtonElementStyled native buttons with type=button by default. Both close. Only Action should perform the destructive operation. Cancel receives initial focus.
AlertDialogActiononClick(event)React.MouseEventHandler<HTMLButtonElement>Call event.preventDefault() synchronously to keep open, including async work. Disabled blocks activation. Promises are not awaited automatically.

No backend, validation, pending-state management or undo is built in. Consumer handlers can prevent default autofocus, Escape or closing; those overrides are responsible for preserving an accessible response and sensible focus. Nested confirmations are not demonstrated. General Dialog behavior is unchanged.