overlaysstable

Modal

Accessible modal dialogs with focus management, dismissal, and compound structure.

Documentation
Preview
Live
Animation
Easing
Options

Usage

Import the component and configure it with the same props used in the playground.

tsx

Examples

Common patterns and practical usage examples.

Basic

Dialog with trigger and content.

tsx

No outside dismissal

Requires an explicit close action.

tsx

Fade animation

Uses an alternate transition for modal entry and exit.

tsx

Large scrollable content

Uses a larger panel with inside scrolling for long content.

tsx

Alert dialog

Uses alert dialog semantics for destructive confirmation.

tsx

API

Props available for the React Modal.

50 props

Modal

PropTypeDefaultDescription
childrenRequired
ReactNode-Modal trigger, overlay, content, and compound children.
modal
booleantrueUses modal interaction semantics while open.
preventScroll
booleantruePrevents document scrolling while the modal is open.
trapFocus
booleantrueKeeps keyboard focus inside the modal while open.
initialFocus
RefObject<HTMLElement>-Element that should receive focus when the modal opens.
finalFocus
RefObject<HTMLElement>-Element that should receive focus when the modal closes.
onOpenAutoFocus
((event: ModalAutoFocusEvent) => void)-Called before focus moves into the modal after opening.
onCloseAutoFocus
((event: ModalAutoFocusEvent) => void)-Called before focus is restored after closing.
onEscapeKeyDown
((event: KeyboardEvent) => void)-Called when Escape is pressed while the modal is open.
onPointerDownOutside
((event: ModalOutsideEvent) => void)-Called when a pointer down occurs outside modal content.
onInteractOutside
((event: ModalOutsideEvent) => void)-Called when an interaction occurs outside modal content.
role
'dialog' | 'alertdialog''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
((open: boolean) => void)-Called when the open state changes.
closeOnOutsidePress
booleantrueCloses the modal when the overlay is pressed.
closeOnEscape
booleantrueCloses the modal when the Escape key is pressed.
animation
'scale' | 'slide' | 'fade' | 'none''scale'Animation style used when the modal opens and closes.
duration
ModalAnimationDuration-Animation duration in milliseconds, or separate open and close durations.
easing
'standard' | 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'-Animation easing curve.
restoreFocus
booleantrueRestores focus to the previously focused element after closing when supported.

Modal.Trigger

PropTypeDefaultDescription
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.

Modal.Overlay

PropTypeDefaultDescription
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.

Modal.Content

PropTypeDefaultDescription
childrenRequired
ReactNode-Modal panel content.
size
'sm' | 'md' | 'lg' | 'xl' | 'full'-Preset modal panel width.
placement
'center' | 'top'-Vertical placement for the modal panel.
scrollBehavior
'inside' | 'outside'-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.

Modal.Header

PropTypeDefaultDescription
childrenRequired
ReactNode-Header content, typically title and description.
className
string-Class name applied to the header element.

Modal.Body

PropTypeDefaultDescription
childrenRequired
ReactNode-Main modal body content.
className
string-Class name applied to the body element.

Modal.Footer

PropTypeDefaultDescription
childrenRequired
ReactNode-Footer actions or custom footer content.
className
string-Class name applied to the footer element.

Modal.Close

PropTypeDefaultDescription
asChild
boolean-Composes close behavior onto a single child element.
children
ReactElement<unknown, string | import("react").JSXElementConstructor<any>>-Custom close button element.
aria-label
string-Accessible name for the close button.
className
string-Class name applied to the close button.

Accessibility

Guidance for accessible usage and interaction.

Focus management

Trap focus while open and restore focus to the trigger when the modal closes.
trapFocusrestoreFocusinitialFocusfinalFocus

Dialog labelling

Use title and description content so assistive technology can announce the dialog purpose.
rolechildren

Dismissal

Choose outside press and Escape dismissal behavior based on task criticality.
closeOnOutsidePresscloseOnEscape

Destructive confirmations

Use alert dialog semantics only for urgent decisions that require immediate attention.
role

Scrollable content

Keep title, description, and final actions reachable when modal content is long.
scrollBehaviorsize

Related components

Explore components that are commonly used alongside this one.