Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Modal

Modal dialogs are used to inform users about a task and can contain critical information, require decisions, or involve multiple tasks. Modal dialogs disable app functionality when they appear, and remain on screen until confirmed, dismissed, or a required action has been taken.

Import

  • Modal: A Provider component that provides the context to the components it wraps.
  • ModalOverlay: The overlay of the modal.
  • ModalContent: The content of the modal.
  • ModalHeader: The header of the modal.
  • ModalBody: The body of the modal.
  • ModalFooter: The footer of the modal.

Modal components

Below is a static modal example, including modal header (optional), modal body (required when padding is necessary), and modal footer (optional).

You can also compose your modal components when customization is needed.

EDITABLE EXAMPLE

Usage

Click the button below to toggle a modal. The modal will show up in the center of the screen.

EDITABLE EXAMPLE

Sizes

Use the size prop to change the size of the Modal. You can set the value to auto, xs, sm, md, lg, xl, or full.

EDITABLE EXAMPLE

Nested modals

EDITABLE EXAMPLE

Transitions

The modal doesn't come with transitions by default. You can use the Transition components to provide simple transitions.

When using transitions, you have to set isOpen to true, or the transition will not take effect when closing the modal.

Adding scale transition

EDITABLE EXAMPLE

Adding slide-in transition

EDITABLE EXAMPLE

Props

Modal

NameTypeDefaultDescription
ensureFocusbooleanfalseIf true, it will always bring the focus back to the Modal descendants, which does not allow the focus to escape while open.
autoFocusbooleanfalseIf true and ensureFocus is true and initialFocusRef is not set, it will automatically set focus on the first focusable element.
finalFocusRefReact.refThe ref of element to receive focus when the modal closes.
initialFocusRefReact.refThe ref of the element to receive focus when the modal opens.
isClosablebooleanfalseIf true, a close button will appear on the right side.
isOpenbooleanfalseIf true, the modal is shown.
closeOnEscbooleanfalseIf true, close the modal when the esc key is pressed.
closeOnOutsideClickbooleanfalseIf true, close the modal when click outside of the modal.
onClosefunctionCallback fired when the modal closes.
sizestring'auto'The size of the modal. One of: 'auto', 'xs', 'sm', 'md', 'lg', 'xl', 'full'
scrollBehaviorstring'inside'Control the scroll behavior of the modal if the content overflows. One of: 'inside', 'outside'

ModalOverlay

NameTypeDefaultDescription
childrenReactNode

ModalContent

NameTypeDefaultDescription
childrenReactNode

ModalHeader

NameTypeDefaultDescription
childrenReactNode

ModalBody

NameTypeDefaultDescription
childrenReactNode

ModalFooter

NameTypeDefaultDescription
childrenReactNode