Skip to content

Commit c79a780

Browse files
authored
Merge pull request #807 from glints-dev/feature/fix-modal-scroll-issue
feat: enable scroll when component is unmounted
2 parents 3692373 + 6b02bad commit c79a780

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)