Skip to content

Commit 6b02bad

Browse files
author
Afzal
committed
feat: enable scroll when component is unmounted
1 parent 3692373 commit 6b02bad

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/@next/Modal/Modal.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,21 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
5858
ref
5959
) {
6060
useEffect(() => {
61+
if (typeof window === 'undefined' || !window.document) return;
62+
63+
const enableScroll = () => {
64+
document.body.style.overflow = 'unset';
65+
};
66+
6167
if (isOpen) {
62-
if (typeof window != 'undefined' && window.document) {
63-
document.body.style.overflow = 'hidden';
64-
}
68+
document.body.style.overflow = 'hidden';
6569
} else {
66-
document.body.style.overflow = 'unset';
70+
enableScroll();
6771
}
72+
73+
return () => {
74+
enableScroll();
75+
};
6876
}, [isOpen]);
6977

7078
if (!isOpen) {

0 commit comments

Comments
 (0)