diff --git a/.changeset/serious-kiwis-promise.md b/.changeset/serious-kiwis-promise.md new file mode 100644 index 0000000..4c39803 --- /dev/null +++ b/.changeset/serious-kiwis-promise.md @@ -0,0 +1,5 @@ +--- +"@wethegit/react-modal": patch +--- + +Fixes and issue where the modal would lock the body even though `appendToBody` wasn't set to `true` diff --git a/src/lib/components/modal-inner/modal-inner.tsx b/src/lib/components/modal-inner/modal-inner.tsx index d6a1a24..ae3e826 100644 --- a/src/lib/components/modal-inner/modal-inner.tsx +++ b/src/lib/components/modal-inner/modal-inner.tsx @@ -1,5 +1,4 @@ import { useEffect, useRef } from "react" -import { usePreventScroll } from "@wethegit/react-hooks" import { classnames } from "../../../utils/classnames" @@ -24,8 +23,6 @@ export function ModalInner({ children, className, ...props }: ModalInnerProps) { const firstFocusableElement = useRef(null) const lastFocusableElement = useRef(null) - usePreventScroll(true) - const focusStartingPosition = () => { const element = firstFocusableElement.current if (element) element.focus() diff --git a/src/lib/components/modal/modal.tsx b/src/lib/components/modal/modal.tsx index d268289..666fc8b 100644 --- a/src/lib/components/modal/modal.tsx +++ b/src/lib/components/modal/modal.tsx @@ -1,4 +1,5 @@ import ReactDOM from "react-dom" +import { usePreventScroll } from "@wethegit/react-hooks" import { ModalInner } from "../modal-inner" import type { ModalInnerProps } from "../modal-inner" @@ -15,6 +16,8 @@ export interface ModalProps extends ModalInnerProps { } export function Modal({ appendToBody, className, ...props }: ModalProps) { + usePreventScroll(appendToBody) + if (appendToBody) return ReactDOM.createPortal(, document.body) else return ( diff --git a/src/main.tsx b/src/main.tsx index ee356f1..f628efc 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -20,7 +20,7 @@ function CustomModal() { {isOpen && ( - +