Dialog
A modal window that appears on top of the main content.
Anatomy
<Dialog.Root>
<Dialog.Trigger />
<Dialog.Backdrop />
<Dialog.Positioner>
<Dialog.Content>
<Dialog.Title />
<Dialog.Description />
<Dialog.CloseTrigger />
</Dialog.Content>
</Dialog.Positioner>
</Dialog.Root>
Examples
Controlled
Use open and onOpenChange to control the open state.
Root Provider
Use RootProvider with the useDialog hook to access the state and methods from outside the component.
Alert Dialog
Use role="alertdialog" for critical confirmations or destructive actions. Unlike a regular dialog:
- Automatic focus: the close/cancel button gets focus on open, so the safest action comes first
- Explicit dismissal: an outside click doesn't close it; only a button or Escape does
Lazy Mount
lazyMount renders the content on first open. Add unmountOnExit to unmount it on close. Prefer this over
conditionally rendering Dialog.Root (see Conditional Rendering).
Initial Focus
Use initialFocusEl to choose the element focused on open.
Final Focus
Use finalFocusEl to choose the element focused on close. Defaults to the trigger.
Non-Modal
Set modal={false} to allow interaction outside the dialog. This disables focus trapping and scroll locking.
Inside Scroll
Use maxHeight and overflow: auto to scroll the content while the header and footer stay fixed.
Outside Scroll
Make the positioner scrollable so the dialog can grow past the viewport.
Context
Access the dialog's state and methods with Dialog.Context or the useDialogContext hook.
Open from Menu
Open the dialog from a menu item's onClick handler.
Nested
The parent of a nested dialog gets data-has-nested and the --nested-layer-count CSS variable, for effects like
zoom-out:
[data-dialog-content][data-has-nested] {
transform: scale(calc(1 - var(--nested-layer-count) * 0.05));
}
Multiple Triggers
Share one dialog across several triggers. Give each Dialog.Trigger a value and use onTriggerValueChange to update
the content for the clicked trigger.
Confirmation
Intercept close attempts to confirm before discarding unsaved changes.
Guides
Close Behavior
closeOnEscape={false}- Prevent closing on EscapecloseOnInteractOutside={false}- Prevent closing on outside click
For conditional control, use onEscapeKeyDown or onInteractOutside with e.preventDefault().
Conditional Rendering
Unmounting Dialog.Root on toggle can break focus, scroll lock, and cleanup. Keep the root mounted and control it with
open / onOpenChange.
To remove portal content from the DOM while closed, add lazyMount and unmountOnExit to the root.
import { Dialog } from '@ark-ui/react/dialog'
import { Portal } from '@ark-ui/react/portal'
// ❌ Avoid
const Dont = () => {
if (isOpen) {
return (
<Dialog.Root open={isOpen} onOpenChange={(e) => setOpen(e.open)}>
<Portal>...</Portal>
</Dialog.Root>
)
}
return null
}
// ✅ Prefer
const Do = () => {
return (
<Dialog.Root open={isOpen} onOpenChange={(e) => setOpen(e.open)} lazyMount unmountOnExit>
<Portal>...</Portal>
</Dialog.Root>
)
}
Z-Index Stacking
Use a shared overlay z-index with --layer-index to keep stacked overlays in order:
[data-dialog-content] {
z-index: calc(var(--z-index-overlay) + var(--layer-index, 0));
}
[data-dialog-positioner] {
z-index: var(--z-index, var(--z-index-overlay));
}
[data-dialog-backdrop] {
z-index: calc(var(--z-index, var(--z-index-overlay)) - 1);
}
See the Styling guide.
Dynamic Imports
With lazyMount and React.lazy or Next.js dynamic, wrap the imported component in Suspense:
import { Dialog } from '@ark-ui/react/dialog'
import { Suspense } from 'react'
import dynamic from 'next/dynamic'
const HeavyComponent = dynamic(() => import('./HeavyComponent'))
export const Demo = () => (
<Dialog.Root lazyMount>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Content>
<Suspense fallback={<div>Loading...</div>}>
<HeavyComponent />
</Suspense>
</Dialog.Content>
</Dialog.Root>
)
API Reference
Props
Root
| Prop | Default | Type |
|---|---|---|
aria-label | stringHuman readable label for the dialog, in event the dialog title is not rendered | |
closeOnEscape | true | booleanWhether to close the dialog when the escape key is pressed |
closeOnInteractOutside | `true` for modal dialogs, `false` for non-modal dialogs | booleanWhether to close the dialog when the outside is clicked |
defaultOpen | false | booleanThe initial open state of the dialog when rendered. Use when you don't need to control the open state of the dialog. |
defaultTriggerValue | stringThe initial active trigger value when rendered. Use when you don't need to control the active trigger value. | |
finalFocusEl | () => MaybeElementElement to receive focus when the dialog is closed | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the elements in the dialog. Useful for composition. | |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
initialFocusEl | () => false | MaybeElementElement to receive focus when the dialog is opened. Return `false` to skip moving focus, or `null` to use the default. | |
lazyMount | false | booleanWhether to enable lazy mounting |
modal | true | booleanWhether to prevent pointer interaction outside the element and hide all content below it |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onEscapeKeyDown | (event: KeyboardEvent) => voidFunction called when the escape key is pressed | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
onOpenChange | (details: OpenChangeDetails) => voidFunction to call when the dialog's open state changes | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
onRequestDismiss | (event: LayerDismissEvent) => voidFunction called when this layer is closed due to a parent layer being closed | |
onTriggerValueChange | (details: TriggerValueChangeDetails) => voidFunction to call when the active trigger changes | |
open | booleanThe controlled open state of the dialog | |
persistentElements | (() => Element | null)[]Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event | |
present | booleanWhether the node is present (controlled by the user) | |
preventScroll | true | booleanWhether to prevent scrolling behind the dialog when it's opened |
restoreFocus | booleanWhether to restore focus to the element that had focus before the dialog was opened | |
role | 'dialog' | 'dialog' | 'alertdialog'The dialog's role |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
trapFocus | true | booleanWhether to trap focus inside the dialog when it's opened |
triggerValue | stringThe controlled active trigger value | |
unmountOnExit | false | booleanWhether to unmount on exit. |
Backdrop
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DialogBackdropState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-dialog-backdrop] | <uid> |
[data-state] | "open" | "closed" |
[data-nested] | Present when the backdrop is nested within another {{widget}} |
[data-has-nested] | Present when the backdrop has nested {{widget}}s |
| CSS Variable | Description |
|---|---|
--layer-index | The index of the dismissable in the layer stack |
CloseTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Content
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DialogContentState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-dialog-content] | <uid> |
[data-state] | "open" | "closed" |
[data-nested] | dialog |
[data-has-nested] | dialog |
| CSS Variable | Description |
|---|---|
--layer-index | The index of the dismissable in the layer stack |
--nested-layer-count | The number of nested dialogs |
Description
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Positioner
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DialogPositionerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-dialog-positioner] | <uid> |
[data-nested] | Present when the positioner is nested within another {{widget}} |
[data-has-nested] | Present when the positioner has nested {{widget}}s |
RootProvider
| Prop | Default | Type |
|---|---|---|
value | UseDialogReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
hideMode | 'display-none' | HideModeHow to hide content when mounted but not present. - `'display-none'`: HTML `hidden` attribute. Effects stay alive. - `'activity'`: React 19 `<Activity mode="hidden">`. Effects pause. Requires React 19+. |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
lazyMount | false | booleanWhether to enable lazy mounting |
onEnterComplete | VoidFunctionFunction called when the animation ends in the open state | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
present | booleanWhether the node is present (controlled by the user) | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
unmountOnExit | false | booleanWhether to unmount on exit. |
Title
Defines the <h2> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
Trigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<DialogTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
value | stringThe value that identifies this specific trigger |
| Attribute | Description |
|---|---|
[data-dialog-trigger] | <uid> |
[data-value] | The value of the item |
[data-state] | "open" | "closed" |
[data-current] | Present when current |
Context
API
| Property | Type |
|---|---|
open | booleanWhether the dialog is open |
modal | booleanWhether the dialog is modal |
setOpen | (open: boolean, reason?: OpenChangeReason) => voidFunction to open or close the dialog |
triggerValue | string | nullThe active trigger value |
setTriggerValue | (value: string | null) => voidFunction to set the active trigger value |
getTriggerState | (props?: TriggerProps) => TriggerStateReturns the state of a specific trigger, including whether it's the currently active one |
getBackdropState | () => BackdropStateReturns the state of the backdrop |
getPositionerState | () => PositionerStateReturns the state of the positioner |
getContentState | () => ContentStateReturns the state of the content |
Accessibility
Complies with the Dialog WAI-ARIA design pattern.
Keyboard Support
| Key | Description |
|---|---|
Enter | When focus is on the trigger, opens the dialog. |
Tab | Moves focus to the next focusable element within the content. Focus is trapped within the dialog. |
Shift + Tab | Moves focus to the previous focusable element. Focus is trapped within the dialog. |
Esc | Closes the dialog and moves focus to trigger or the defined final focus element |