A modal dialog that interrupts the user with important content and expects a response.
Loading...
Installation
Install the following dependencies:
Copy and paste the following code into your project.
Loading...
Update the import paths to match your project setup.
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
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | — | Unique identifier used to connect the component parts. |
ids | ElementIds | undefined | — | Overrides generated identifiers for individual parts. |
trapFocus | boolean | undefined | — | Configures trap focus. |
preventScroll | boolean | undefined | — | Configures prevent scroll. |
modal | boolean | undefined | — | Configures modal. |
initialFocusEl | (() => MaybeElement) | undefined | — | Configures initial focus el. |
finalFocusEl | (() => MaybeElement) | undefined | — | Configures final focus el. |
restoreFocus | boolean | undefined | — | Configures restore focus. |
closeOnInteractOutside | boolean | undefined | true | Configures close on interact outside. |
closeOnEscape | boolean | undefined | true | Configures close on escape. |
role | "dialog" | "alertdialog" | undefined | — | Configures role. |
open | boolean | undefined | — | Whether the component is open when controlled. |
defaultOpen | boolean | undefined | — | Initial open state when uncontrolled. |
onOpenChange | ((details: OpenChangeDetails) => void) | undefined | — | Runs when open changes. |
triggerValue | string | null | undefined | — | Configures trigger value. |
defaultTriggerValue | string | null | undefined | — | Configures default trigger value. |
onTriggerValueChange | ((details: TriggerValueChangeDetails) => void) | undefined | — | Runs when trigger value changes. |
Context, Hooks, and Types
| Export | API |
|---|---|
AlertDialogContext | Render-prop component that exposes component state and actions. |
AlertDialogRootProvider | Provides an externally created API to the component tree. |
useAlertDialog | Creates or accesses the component API. |
useAlertDialogContext | Returns the nearest component API. |
AlertDialogOpenChangeDetails | Type for the details object passed to the matching change callback. |
Angular
React
Solid
Svelte
Vue