Search documentation

Search the documentation and open a page.

A modal dialog that interrupts the user with important content and expects a response.

Loading...

Installation

pnpm dlx shadcn@latest add @wirekyt/alert-dialog

Composition

AlertDialog ├── AlertDialogTrigger └── AlertDialogContent ├── AlertDialogHeader │ ├── AlertDialogMedia (optional) │ ├── AlertDialogTitle │ └── AlertDialogDescription └── AlertDialogFooter ├── AlertDialogCancel └── AlertDialogAction

Examples

Default

Loading...

Destructive

Loading...

Small With Media

Loading...

Small

Loading...

With Media

Loading...

API Reference

AlertDialog

PropTypeDefaultDescription
idstring | undefinedgeneratedUnique identifier used to connect the dialog parts.
idsElementIds | undefined—Overrides generated identifiers for individual parts.
aria-labelstring | undefined—Accessible label used when no visible title labels the dialog.
openboolean | undefined—Open state when controlled. Supports Svelte binding.
defaultOpenboolean | undefinedfalseInitial open state when uncontrolled.
modalboolean | undefinedtrueEnables modal behavior.
trapFocusboolean | undefinedtrueKeeps keyboard focus inside the open dialog.
preventScrollboolean | undefinedtruePrevents document scrolling while the dialog is open.
restoreFocusboolean | undefinedtrueRestores focus after the dialog closes.
initialFocusEl(() => MaybeElement | false) | undefined—Returns the element that should receive initial focus.
finalFocusEl(() => MaybeElement) | undefined—Returns the element that should receive focus after closing.
closeOnInteractOutsideboolean | undefinedtrueCloses the dialog after an allowed outside interaction.
closeOnEscapeboolean | undefinedtrueCloses the dialog when Escape is pressed.
role"dialog" | "alertdialog" | undefined"dialog"Sets the role used by the underlying dialog machine.
persistentElementsArray<() => Element | null> | undefined—Elements that remain interactive while the modal is open.
onEscapeKeyDown((event: KeyboardEvent) => void) | undefined—Runs when Escape is pressed.
onPointerDownOutside((event: PointerDownOutsideEvent) => void) | undefined—Runs when a pointer interaction starts outside the dialog.
onFocusOutside((event: FocusOutsideEvent) => void) | undefined—Runs when focus moves outside the dialog.
onInteractOutside((event: InteractOutsideEvent) => void) | undefined—Runs for pointer or focus interaction outside the dialog.
onRequestDismiss((event: LayerDismissEvent) => void) | undefined—Runs when another dismissable layer requests that the dialog close.
onOpenChange((details: OpenChangeDetails) => void) | undefined—Runs when the open state changes.
triggerValuestring | null | undefined—Active trigger value when controlled. Supports Svelte binding.
defaultTriggerValuestring | null | undefinednullInitial active trigger value when uncontrolled.
onTriggerValueChange((details: TriggerValueChangeDetails) => void) | undefined—Runs when the active trigger value changes.
lazyMountboolean | undefinedfalseMounts the dialog content only after it is first opened.
unmountOnExitboolean | undefinedfalseRemoves the dialog content from the DOM after it closes.
skipAnimationOnMountboolean | undefinedfalseSkips the initial presence animation.
onEnterCompleteVoidFunction | undefined—Runs after the enter animation completes.
onExitCompleteVoidFunction | undefined—Runs after the exit animation completes.

AlertDialogTrigger

PropTypeDefaultDescription
valuestring | undefined—Value used to identify this trigger when activated.

AlertDialogContent

PropTypeDefaultDescription
size"default" | "sm" | undefined"default"Controls the dialog panel size.

AlertDialogAction

PropTypeDefaultDescription
variant"default" | "destructive" | "ghost" | "link" | "outline" | "secondary" | undefined"default"Controls the action button style.
size"default" | "icon" | "icon-lg" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "sm" | "xl" | "xs" | undefined"default"Controls the action button size.

AlertDialogCancel

PropTypeDefaultDescription
variant"default" | "destructive" | "ghost" | "link" | "outline" | "secondary" | undefined"outline"Controls the cancel button style.
size"default" | "icon" | "icon-lg" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "sm" | "xl" | "xs" | undefined"default"Controls the cancel button size.

Context, Hooks, and Types

ExportAPI
AlertDialogContextRender-prop component that exposes component state and actions.
AlertDialogRootProviderProvides an externally created API to the component tree.
useAlertDialogCreates or accesses the component API.
useAlertDialogContextReturns the nearest component API.
AlertDialogOpenChangeDetailsType for the details object passed to the matching change callback.