structyl

Dialog API

View component

The full prop reference for the Dialog component. A window overlaid on the primary content, rendering the content underneath inert.

Import

tsx
import { Dialog } from '@structyl/styled';

Props

Root

Container component that manages dialog state and provides context to child components

PropTypeDefault
open#boolean

Controlled dialog open state

defaultOpen#boolean

Initial open state when uncontrolled

false
onOpenChange#(open: boolean) => void

Callback fired when dialog open state changes

modal#boolean

Whether dialog is modal (blocks interaction outside, traps focus) or non-modal

true
children#React.ReactNode

Dialog content and subcomponents

Trigger

Button that toggles the dialog open state; extends HTML button element

PropTypeDefault
asChild#boolean

Render as child element instead of button

className#string

CSS class name

Portal

Portals dialog content outside component hierarchy (typically to document body)

PropTypeDefault
children#React.ReactNode

Content to portal

container#Element | DocumentFragment | null

DOM element to portal into; defaults to document.body

forceMount#boolean

Force-mount content to DOM even when dialog is closed

Overlay

Backdrop overlay behind dialog content; only renders when modal=true; extends HTML div element

PropTypeDefault
asChild#boolean

Render as child element instead of div

forceMount#boolean

Force-mount overlay to DOM even when dialog is closed

className#string

CSS class name

Content

Main dialog container; extends HTML div element; contains title, description, and close button

PropTypeDefault
asChild#boolean

Render as child element instead of div

forceMount#boolean

Force-mount content to DOM even when dialog is closed

onEscapeKeyDown#(event: KeyboardEvent) => void

Callback fired when Escape key pressed; call event.preventDefault() to prevent dismiss

onPointerDownOutside#(event: PointerDownOutsideEvent) => void

Callback fired when pointer down event occurs outside content

onInteractOutside#(event: PointerDownOutsideEvent | FocusOutsideEvent) => void

Callback fired on any interaction outside content (pointer or focus)

onOpenAutoFocus#(event: Event) => void

Callback fired when focus moves into content on open; call event.preventDefault() to prevent

onCloseAutoFocus#(event: Event) => void

Callback fired when focus moves back on close; call event.preventDefault() to prevent

className#string

CSS class name

Title

Dialog title heading; renders as h2 element; extends HTML heading element

PropTypeDefault
asChild#boolean

Render as child element instead of h2

className#string

CSS class name

Description

Dialog description text; renders as p element; extends HTML paragraph element

PropTypeDefault
asChild#boolean

Render as child element instead of p

className#string

CSS class name

Close

Button that closes the dialog; extends HTML button element; includes built-in close functionality

PropTypeDefault
asChild#boolean

Render as child element instead of button

className#string

CSS class name

Header

Convenience wrapper for dialog title section; styled div container

PropTypeDefault
className#string

CSS class name

Anatomy

Import the parts and compose them together.

tsx
<Dialog.Root>
  <Dialog.Trigger />
  <Dialog.Portal>
    <Dialog.Overlay />
    <Dialog.Content>
      <Dialog.Title />
      <Dialog.Description />
      <Dialog.Close />
    </Dialog.Content>
  </Dialog.Portal>
</Dialog.Root>

Keyboard interactions

Adheres to the WAI-ARIA design pattern .

KeyDescription
SpaceOpens/closes the dialog from the trigger.
EnterOpens/closes the dialog from the trigger.
TabMoves focus to the next focusable element; trapped within content.
Shift + TabMoves focus to the previous focusable element.
EscCloses the dialog and moves focus to the trigger.

Source code

If you didn't find what you need here, read the component implementation .

structyl — Accessible React Component Library