
Accessible alert dialog with focus trap, keyboard handling, and portal rendering.
pnpm dlx edbn-ui@latest add alert-dialogCreate a file and paste the following code into it.
Groups all parts of the alert dialog. Always modal and requires an explicit user response.
defaultOpenbooleanfalseInitial open state
openbooleanControlled open state
onOpenChange(open: boolean, eventDetails: AlertDialog.Root.ChangeEventDetails) => voidCalled when the alert dialog opens or closes
onOpenChangeComplete(open: boolean) => voidCalled after animation completes
actionsRefRefObject<AlertDialog.Root.Actions | null>Imperative close and unmount actions
handleAlertDialog.Handle<Payload>Handle for detached triggers
defaultTriggerIdstring | nullInitial associated trigger id
triggerIdstring | nullControlled associated trigger id
childrenReactNode | PayloadChildRenderFunction<Payload>Alert dialog content or payload-aware render child
A button that opens the dialog. Renders a button element.
handleAlertDialog.Handle<Payload>Associates this trigger with a detached root
payloadPayloadPayload passed to a render-child root
idstringElement and active trigger id
nativeButtonbooleantrueRender as native button
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-popup-open | Present when dialog is open |
| data-disabled | Present when disabled |
Moves the popup to a different part of the DOM. Renders a div element.
containerHTMLElement | ShadowRoot | RefObject | nullPortal container
keepMountedbooleanfalseKeep in DOM when closed
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
An overlay displayed beneath the popup. Renders a div element.
forceRenderbooleanfalseForce rendering even when nested
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-open | Present when dialog is open |
| data-closed | Present when dialog is closed |
| data-starting-style | Present when animating in |
| data-ending-style | Present when animating out |
A positioning container for scrollable alert dialogs. Renders a div element.
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-open | Present when dialog is open |
| data-closed | Present when dialog is closed |
| data-starting-style | Present when animating in |
| data-ending-style | Present when animating out |
| data-nested | Present when nested within another dialog |
| data-nested-dialog-open | Present when nested dialogs are open within |
A container for the dialog contents. Renders a div element.
initialFocusboolean | RefObject<HTMLElement> | functionElement to focus on open
finalFocusboolean | RefObject<HTMLElement> | functionElement to focus on close
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-open | Present when dialog is open |
| data-closed | Present when dialog is closed |
| data-starting-style | Present when animating in |
| data-ending-style | Present when animating out |
| data-nested | Present when nested within another dialog |
| data-nested-dialog-open | Present when nested dialogs are open within |
| Variable | Description |
|---|---|
| --nested-dialogs | Number of dialogs nested within |
A heading that labels the dialog. Renders an h2 element.
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
A paragraph with additional information about the dialog. Renders a p element.
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
A button that closes the dialog. Renders a button element.
nativeButtonbooleantrueRender as native button
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-disabled | Present when disabled |
EDBN destructive action helper built on AlertDialog.Close. Renders a button element.
nativeButtonbooleantrueRender as native button
classNamestring | functionCSS class name
styleCSSProperties | functionInline style or state-based style function
renderReactElement | functionCustom render function
| Attribute | Description |
|---|---|
| data-disabled | Present when disabled |
EDBN layout helper for grouping AlertDialogTitle and AlertDialogDescription. Renders a div element.
classNamestringCSS class name
EDBN layout helper for alert dialog actions. Renders a div element.
classNamestringCSS class name
Base UI handle utility for detached triggers and imperative alert dialog control.
isOpenbooleanreadonlyWhether the associated alert dialog is open
open(triggerId: string | null) => voidmethodOpen and associate the alert dialog with a trigger id
openWithPayload(payload: Payload) => voidmethodOpen with payload for render-child alert dialog roots
close() => voidmethodClose the associated alert dialog
Function exported as createAlertDialogHandle for creating typed detached-trigger handles.
returnAlertDialog.Handle<Payload>A new imperative alert dialog handle