Skip to content

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Installation

npm i @huin-core/react-dialog

API Reference

Dialog

PropTypeDescription
defaultOpenbooleanDetermines whether the component should be open by default when it is initially rendered.
openbooleanControls the open state of the component. When set to true, the component is displayed; when false, it is hidden.
modalbooleanThe modality of the dialog. When set to true, interaction with outside elements will be disabled and only dialog content will be visible to screen readers.
onOpenChangefunctionEvent handler called when the open state of the component changes.

DialogTrigger

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

DialogPortal

PropTypeDescription
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.

DialogOverlay

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.

DialogContent

PropTypeDescription
variant"center" | "top" | "right" | "bottom" | "left"Defines a different style or appearance of the component, allowing for customization of its look and feel based on specific use cases.
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.
onOpenAutoFocusfunctionEvent handler called when focus moves into the component after opening. It can be prevented by calling event.preventDefault.
onCloseAutoFocusfunctionEvent handler called when focus moves to the trigger after closing. It can be prevented by calling event.preventDefault.
onEscapeKeyDownfunctionEvent handler called when the escape key is down. It can be prevented by calling event.preventDefault.
onPointerDownOutsidefunctionEvent handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault
onInteractOutsidefunctionEvent handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault.

DialogHeader

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

DialogTitle

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

DialogDescription

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

DialogFooter

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

Keyboard Interactions

KeyDescription
Space
Enter
Opens the dialog from its trigger.
Tab
Moves focus to the next element, trapped inside the dialog.
Shift
Tab
Moves focus to the previous element.
Esc
Closes the dialog and returns focus to the trigger.