edbnedbn/ui
Get Started
WelcomeChangelogLicenseOverview
Components
ButtonAlert Dialog
PopoverDropdown Menu
Motion
Motion ProviderSpring PresetsHooks
0installs
Components
Blocks
HomeDocsComponentsAlert Dialog

On this page

Alert Dialog

A modal dialog with morphing animations, spring physics, and focus management. Built with Motion for smooth layout animations and transitions.

Usage

import {
  AlertDialog,
  AlertDialogTrigger,
  AlertDialogContainer,
  AlertDialogContent,
  AlertDialogBody,
  AlertDialogHeader,
  AlertDialogFooter,
  AlertDialogTitle,
  AlertDialogSubtitle,
  AlertDialogDescription,
  AlertDialogAction,
  AlertDialogCancel,
} from "@/components/ui/alert-dialog"
<AlertDialog transition={{ type: "spring", bounce: 0.25, duration: 0.5 }}>
  <AlertDialogTrigger>
    <Button>Show Details</Button>
  </AlertDialogTrigger>
  <AlertDialogContainer>
    <AlertDialogContent>
      <AlertDialogBody>
        <AlertDialogHeader>
          <AlertDialogTitle>Spring Animation</AlertDialogTitle>
          <AlertDialogSubtitle>With custom transition</AlertDialogSubtitle>
          <AlertDialogDescription>
            This dialog uses spring physics for smooth animations.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel className="w-full">Dismiss</AlertDialogCancel>
        </AlertDialogFooter>
      </AlertDialogBody>
    </AlertDialogContent>
  </AlertDialogContainer>
</AlertDialog>

Installation

Terminal
npx shadcn@latest add https://ui.edbn.me/r/alert-dialog.json

This will also install: motion-provider, button

Examples

Basic Dialog

A morphing dialog with smooth layout animations and spring physics.

With Subtitle

Use subtitle for additional context and custom spring transitions.

Common Patterns

Example use cases for morphing dialogs.

API Reference

AlertDialog

PropTypeDefaultDescription
childrenReactNode—The content of the dialog including triggers and content
openboolean—Controlled open state. Use with onOpenChange for controlled behavior.
defaultOpenbooleanfalseDefault open state for uncontrolled usage.
onOpenChange(open: boolean) => void—Callback when open state changes.
transitionTransition—Custom transition settings from motion for animation effects.
disableAnimationboolean—Disable all animations for the dialog.

AlertDialogTrigger

PropTypeDefaultDescription
childrenReactNode—Content of the trigger, typically a Button component
classNamestring—Optional CSS class for styling the trigger wrapper
styleReact.CSSProperties—Inline styles for the trigger wrapper
asChildbooleanfalseWhen true, the trigger will merge props with its child element. Recommended for use with Button components.

AlertDialogContainer

PropTypeDefaultDescription
childrenReactNode—Content to render inside the portal, typically AlertDialogContent
classNamestring—Optional CSS class for the container
styleReact.CSSProperties—Inline styles for the container

The Container renders content in a portal with backdrop overlay.

AlertDialogContent

PropTypeDefaultDescription
childrenReactNode—The content displayed within the dialog when it is open
classNamestring—Optional CSS class for styling the content container
styleReact.CSSProperties—Inline styles for the content container
showCloseButtonbooleanfalseShows an X button in the top-right corner for closing the dialog
preventEscapeClosebooleanfalsePrevents closing the dialog when pressing Escape key.
preventOutsideClosebooleanfalsePrevents closing the dialog when clicking outside the content area

AlertDialogBody

PropTypeDefaultDescription
childrenReactNode—The main content of the dialog including header and footer
classNamestring—Optional CSS class for customizing padding and spacing

Provides consistent padding (p-6 sm:p-8), centered layout, and proper spacing.

AlertDialogHeader

PropTypeDefaultDescription
childrenReactNode—Title, subtitle, and description elements
iconReactNode—Optional icon element to display above content
iconClassNamestring—CSS classes for the icon wrapper (e.g., 'bg-destructive/10')
classNamestring—Optional CSS class for the header container

AlertDialogFooter

PropTypeDefaultDescription
childrenReactNode—Action buttons (AlertDialogAction, AlertDialogCancel)
classNamestring—Optional CSS class for customizing button layout

AlertDialogTitle

PropTypeDefaultDescription
childrenReactNode—The title content of the dialog
classNamestring—Optional CSS class for the title element

AlertDialogSubtitle

PropTypeDefaultDescription
childrenReactNode—The subtitle content of the dialog
classNamestring—Optional CSS class for the subtitle element

AlertDialogDescription

PropTypeDefaultDescription
childrenReactNode—The descriptive content of the dialog
classNamestring—Optional CSS class for the description container

AlertDialogAction

PropTypeDefaultDescription
childrenReactNode—Button content
variant"default" | "destructive""default"Button style variant. Use 'destructive' for dangerous actions.
disabledbooleanfalseDisables the button
onClick(e: React.MouseEvent) => void—Click handler. Dialog closes after unless e.preventDefault() is called.
classNamestring—Optional CSS class for the button

AlertDialogCancel

PropTypeDefaultDescription
childrenReactNode"Cancel"Button content
disabledbooleanfalseDisables the button
onClick(e: React.MouseEvent) => void—Click handler. Dialog closes after unless e.preventDefault() is called.
classNamestring—Optional CSS class for the button

Best Practices

Action Clarity

Use asChild pattern
Pair asChild with Button so only the surface morphs and text stays crisp.
Lead with consequence
Put the destructive action first. Keep primary copy short (2 lines max).

Safety Net

Disable until ready
Disable confirmation button until critical data needed to proceed is available.
Explicit confirmation
Require explicit action (checkbox, text confirm) only for irreversible flows.

Copy Guidelines

Use action verbs
Use verbs on actions ("Delete account", "Keep data") so the choice is clear without scanning the body.
Highlight consequences
Add the most alarming fact in the description, not the header (e.g., "removes all backups").

Accessibility

Alert dialog pattern for critical actions that require confirmation.

Keyboard

TabNavigate through dialog
⇧+Tab
Navigate backwards
EscClose dialog (use preventEscapeClose to disable)

Screen Readers

• role="alertdialog" with aria-modal

• Title linked via aria-labelledby

• Async states use aria-busy

Focus Management

Initial focus
Focus moves to the first interactive element when opened.
Focus trapping
Focus stays inside until an action is taken.
Focus restoration
On close, focus returns to the trigger element.