hook-modal
Advanced tools
React Hooks for building accessible modal
Weekly downloads
Readme
React Hook for making modal accessible.
Using yarn:
$ yarn add hook-modal
Using npm:
$ npm install hook-modal
import { createPortal } from "react-dom";
import { useModal } from "hook-modal";
import classes from "./Modal.module.css";
const Modal = ({
isOpen,
onClose,
"aria-labelledby": ariaLabelledby,
"aria-describedby": ariaDescribedby,
children,
}) => {
const props = useModal({ isOpen, onClose });
if (!isOpen) {
return null;
}
return createPortal(
<div className={classes.overlay}>
<div
{...props}
aria-labelledby={ariaLabelledby}
aria-describedby={ariaDescribedby}
className={classes.content}
>
{children}
</div>
</div>,
document.body,
);
};
name | type | required | description | default |
---|---|---|---|---|
isOpen | boolean | required | Set to true if the modal is open | - |
onClose | () => void | required | Callback function to close the modal | - |
closeOnEsc | boolean | optional | If true , close the modal on Esc key pressed | true |
closeOnOutsideClick | boolean | optional | If true , close the modal on outside clicked | true |
role="dialog"
and aria-modal="true"
attributes to modal elementaria-hidden="true"
MIT
FAQs
React Hooks for building accessible modal
The npm package hook-modal receives a total of 922 weekly downloads. As such, hook-modal popularity was classified as not popular.
We found that hook-modal demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.