Leave Yamada UI a star

Star
Yamada UIYamada UIv1.6.4

Modal

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

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

  • When the modal opens, focus is automatically set to the first enabled element, or the element from initialFocusRef.
  • When the modal closes, focus returns to the element that was focused before the modal activated, or the element from finalFocusRef.
  • Clicking on the overlay closes the modal.
  • Scrolling is blocked on the elements behind the modal.

Set aria-haspopup="dialog" on the element that triggers the modal to inform the user that the dialog will open.

const { isOpen, onOpen, onClose } = useDisclosure()
return (
<>
<Button aria-haspopup="dialog" onClick={onOpen}>
Open Modal
</Button>
<Modal isOpen={isOpen} onClose={onClose}>
<ModalHeader>ドラゴンボール</ModalHeader>
<ModalBody>
『ドラゴンボール』(DRAGON
BALL)は、鳥山明による日本の漫画作品。『週刊少年ジャンプ』(集英社)にて1984年51号から1995年25号まで連載された。世界中に散らばった七つの球をすべて集めると、どんな願いも一つだけ叶えられるという秘宝・ドラゴンボールと、主人公・孫悟空(そん・ごくう)を中心に展開する、「冒険」「夢」「バトル」「友情」などを描いた長編漫画。
</ModalBody>
<ModalFooter>
<Button variant="ghost" onClick={onClose}>
とじる
</Button>
<Button colorScheme="primary">Wikipedia</Button>
</ModalFooter>
</Modal>
</>
)
Copied!

Keyboard Navigation

When the Modal opens, focus is trapped within it. That is, you cannot focus on elements outside the modal unless the modal is closed.

KeyDescriptionState
TabFocuses the next element within the modal that is not disabled. If it's the last element, focuses the first element within the modal that is not disabled.isOpen={true}
Shift + TabFocuses the previous element within the modal that is not disabled. If it's the first element, focuses the last element within the modal that is not disabled.isOpen={true}
EscapeCloses the modal.isOpen={true} + closeOnEsc={true}

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
Modalrole="dialog"Indicates that it is a dialog.
aria-modal="true"Indicates that the displayed widget is a modal.
aria-labelledbySets the id of the associated ModalHeader.
aria-describedbySets the id of the associated ModalBody.
ModalOverlayaria-hidden="true"Excludes the element from the accessibility tree.
ModalCloseButtonaria-label="Close modal"Sets "Close modal" as the label.
ModalHeaderidUsed to associate with Modal.
ModalBodyidUsed to associate with Modal.

Edit this page on GitHub

PreviousOverlayNextDialog