Since you mentioned in the comments that you may not use react-overlay
If you don't need to use react-overlays, you could just have a component which looks something like
const Modal = ({children, className, ...props}) => {
useEffect(() => {
document.body.classList.add("no-scroll");
return document.body.classList.remove("no-scroll")
};
return (
<div className="modal-background">
<div
className={`modal ${className}`}
{...props}
>
{children}
</div>
</div>
);
};
.modal-background {
position: fixed;
width: 100vw;
height: 100vh;
z-index: 2;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0,0,0,0.4);
}
.modal {
z-index: 3;
}
.no-scroll{
overflow: hidden;
}
The useEffect adds a no scrolling event to the document body when the ccomponent renders, an removes it when the component unmounts. The modal-background element is an overlay which would disable interation of everything else than has a z-index of less than 2. You could customize this modal to behave how you want. It probably won't do dialog-stacking
or easily-pluggable animation
because I don't know what that means. I'm trying to figure out how to set the focus to the first child in this question