Skip to content

Commit 4a15bc5

Browse files
committed
fix: unable scrolling when pop up is open
1 parent efb4ad2 commit 4a15bc5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/ui/Popup.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classNames from "classnames";
2-
import { ReactElement } from "react";
2+
import { ReactElement, useEffect } from "react";
33

44
/**
55
* Popups interface props
@@ -31,6 +31,15 @@ interface PopupProps {
3131
* @returns {ReactElement}
3232
*/
3333
export default function Popup({ center, onClose, show, children, className = "" }: PopupProps): ReactElement {
34+
35+
useEffect(() => {
36+
if (show) {
37+
document.body.style.overflow = "hidden";
38+
} else {
39+
document.body.style.overflow = "auto";
40+
}
41+
}, [show]);
42+
3443
return show ? (
3544
<div className={classNames(`fixed z-999 w-screen h-screen overflow-y-scroll top-0 left-0 ${className}`, { "flex items-center": center })}>
3645
<div className="opacity-25 fixed inset-0 z-0 bg-black w-full h-screen top-0 left-0" onClick={onClose} />

0 commit comments

Comments
 (0)