Skip to content

Commit

Permalink
Fixed modal dialog scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Nov 1, 2024
1 parent 5f861c6 commit a7ff98a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/features/ui/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createPortal } from "react-dom";
import React, { createContext, HTMLProps, useEffect, useMemo, useState } from "react";
import { classNameObject, useFilteredProps } from "@ui/util";
import { AnimatePresence, motion } from "framer-motion";
import { useLockBodyScroll, useMount, useUnmount } from "react-use";
import { useMount, useUnmount } from "react-use";
import useMountedState from "react-use/lib/useMountedState";

interface Props {
Expand Down Expand Up @@ -39,7 +39,6 @@ export function Modal(props: Omit<HTMLProps<HTMLDivElement>, "size"> & Props) {
const isAnimated = useMemo(() => props.animation ?? true, [props.animation]);

const isMounted = useMountedState();
useLockBodyScroll(show);

useMount(() => document.addEventListener("keyup", onKeyUp));
useUnmount(() => document.removeEventListener("keyup", onKeyUp));
Expand All @@ -56,6 +55,12 @@ export function Modal(props: Omit<HTMLProps<HTMLDivElement>, "size"> & Props) {
}
}, [show]);

useEffect(() => {
show
? document.body.classList.add("overflow-hidden")
: document.body.classList.remove("overflow-hidden");
}, [show]);

const onKeyUp = (e: KeyboardEvent) => {
if (e.key === "Escape") {
setShow(false);
Expand Down

0 comments on commit a7ff98a

Please sign in to comment.