Basic
Dialog with trigger and content.
Accessible modal dialogs with focus management, dismissal, and compound structure.
Import the component and configure it with the same props used in the playground.
Common patterns and practical usage examples.
Dialog with trigger and content.
Requires an explicit close action.
Uses an alternate transition for modal entry and exit.
Uses a larger panel with inside scrolling for long content.
Uses alert dialog semantics for destructive confirmation.
Props available for the React Modal.
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Modal trigger, overlay, content, and compound children. |
modal | boolean | true | Uses modal interaction semantics while open. |
preventScroll | boolean | true | Prevents document scrolling while the modal is open. |
trapFocus | boolean | true | Keeps keyboard focus inside the modal while open. |
initialFocus | RefObject< | - | Element that should receive focus when the modal opens. |
finalFocus | RefObject< | - | Element that should receive focus when the modal closes. |
onOpenAutoFocus | ( | - | Called before focus moves into the modal after opening. |
onCloseAutoFocus | ( | - | Called before focus is restored after closing. |
onEscapeKeyDown | ( | - | Called when Escape is pressed while the modal is open. |
onPointerDownOutside | ( | - | Called when a pointer down occurs outside modal content. |
onInteractOutside | ( | - | Called when an interaction occurs outside modal content. |
role | 'dialog' | 'dialog' | ARIA role applied to the modal content. |
className | string | - | Class name applied to the modal root. |
open | boolean | - | Controlled open state. |
defaultOpen | boolean | - | Initial open state for uncontrolled usage. |
onOpenChange | ( | - | Called when the open state changes. |
closeOnOutsidePress | boolean | true | Closes the modal when the overlay is pressed. |
closeOnEscape | boolean | true | Closes the modal when the Escape key is pressed. |
animation | 'scale' | 'scale' | Animation style used when the modal opens and closes. |
duration | ModalAnimationDuration | - | Animation duration in milliseconds, or separate open and close durations. |
easing | 'standard' | - | Animation easing curve. |
restoreFocus | boolean | true | Restores focus to the previously focused element after closing when supported. |
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Trigger content. |
asChild | boolean | - | Composes trigger behavior onto a single child element. |
disabled | boolean | - | Disables trigger interaction. |
className | string | - | Class name applied to the trigger element. |
| Prop | Type | Default | Description |
|---|---|---|---|
animated | boolean | - | Enables enter and exit animation for the overlay. |
className | string | - | Class name applied to the overlay element. |
forceMount | boolean | - | Keeps the overlay mounted even when the modal is closed. |
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Modal panel content. |
size | 'sm' | - | Preset modal panel width. |
placement | 'center' | - | Vertical placement for the modal panel. |
scrollBehavior | 'inside' | - | Controls whether scrolling happens inside the panel or outside it. |
animated | boolean | - | Enables enter and exit animation for the panel. |
forceMount | boolean | - | Keeps content mounted even when the modal is closed. |
ariaLabel | string | - | Accessible label applied directly to the modal panel. |
ariaLabelledBy | string | - | Id of the element that labels the modal panel. |
ariaDescribedBy | string | - | Id of the element that describes the modal panel. |
className | string | - | Class name applied to the modal panel. |
style | CSSProperties | - | Inline style applied to the modal panel. |
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Header content, typically title and description. |
className | string | - | Class name applied to the header element. |
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Main modal body content. |
className | string | - | Class name applied to the body element. |
| Prop | Type | Default | Description |
|---|---|---|---|
childrenRequired | ReactNode | - | Footer actions or custom footer content. |
className | string | - | Class name applied to the footer element. |
| Prop | Type | Default | Description |
|---|---|---|---|
asChild | boolean | - | Composes close behavior onto a single child element. |
children | ReactElement< | - | Custom close button element. |
aria-label | string | - | Accessible name for the close button. |
className | string | - | Class name applied to the close button. |
Guidance for accessible usage and interaction.
trapFocusrestoreFocusinitialFocusfinalFocusrolechildrencloseOnOutsidePresscloseOnEscaperolescrollBehaviorsize