An accessible dialog (modal) component for React & Nature UI
npm install @nature-ui/modalA modal is a window overlaid on either the primary window or another dialog
window. Contents behind a modal dialog are inert meaning that users cannot
interact with content behind the dialog.
``sh
yarn add @nature-ui/modal
npm i @nature-ui/modal
`
`jsx`
import {
Modal,
ModalBody,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
ModalCloseButton,
} from '@nature-ui/core';
When the modal opens, focus is sent into the modal and set to the first tabbable
element. If there are no tabbled element, focus is set on the ModalContent.
`jsx
export const BasicUsage = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
return (
<>
scrollBehavior='outside'
isOpen={isOpen}
onClose={onClose}
>
onClick={onClose}
className='bg-gray-200 hover:bg-gray-300 transition duration-200 mr-3'
>
Cancel
>
);
};
`
When the dialog closes, it returns focus to the element that triggered. Set
finalFocusRef to element that should receive focus when the modal opens.
`jsx
export const ReturnFocus = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const finalRef = React.useRef
return (
<>
finalFocusRef={finalRef}
isOpen={isOpen}
onClose={onClose}
>
Sit nulla est ex ...
>
);
};
``