Modal

Modal is a component that is displayed over the main content to focus the user's attention solely on the information.

Usage

import { Modal } from "@yamada-ui/react"
<Modal.Root>
  <Modal.OpenTrigger />
  <Modal.Overlay />
  <Modal.Content>
    <Modal.CloseButton />
    <Modal.Header>
      <Modal.Title />
    </Modal.Header>
    <Modal.Body />
    <Modal.Footer>
      <Modal.CloseTrigger />
    </Modal.Footer>
  </Modal.Content>
</Modal.Root>

Use props

Change Size

Change Position

To change the display position, set placement to start-center, center-start, etc. By default, center-center is set.

Change Animation

To change the show or hide animation, set animation to "block-start", "inline-end", etc. By default, "scale" is set.

Change Duration

To change the duration, set duration to a numerical value (seconds).

Change Overflow Behavior

By default, "inside" is set, and scrolling only occurs within Modal.Body. If you set "outside", scrolling will occur within the Modal.Content.

Do Not Block Scroll When Modal Opens

By default, when the modal opens, it blocks the scroll of the main content to ensure accessibility. If you do not want to block the scroll of the main content, set blockScrollOnMount to false.

Customize the Overlay

If you want to customize overlay, use Modal.Overlay.

Disable the Overlay

To disable (hide) the modal's overlay, set withOverlay to false.

Customize the Close Button

If you want to customize close button, use Modal.CloseButton.

Disable the Close Button

To disable (hide) the modal's close button, set withCloseButton to false.

Nested Modals

Props

Accessibility

The Modal follows the WAI-ARIA - Dialog (Modal) Pattern for accessibility.

Keyboard Navigation

KeyDescriptionState
TabFocuses the next non-disabled element inside the modal. If on the last element, focuses the first non-disabled element.open={true}
Shift + TabFocuses the previous non-disabled element inside the modal. If on the first element, focuses the last non-disabled element.open={true}
EscapeCloses the modal.open={true} + closeOnEsc={true}

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
Modal.Contentrole="dialog"Indicates that this is a dialog.
aria-modal="true"Indicates that the displayed widget is modal.
aria-labelledbySets to the id of Modal.Title.
aria-describedbySets to the id of Modal.Body.
Modal.OpenTriggeraria-haspopup="dialog"Indicates that a dialog exists.
aria-expandedSets to "true" if the modal is open, and "false" if it is closed.
aria-controlsIf the modal is open, sets to the id of Modal.Content.
aria-labelSets to "Open modal".
Modal.CloseButtonaria-labelSets to "Close modal".
Modal.CloseTriggeraria-labelSets to "Close modal".
Modal.Overlayaria-hiddenExcludes the element from the accessibility tree.