Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-kiwis-promise.md
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 0 additions & 3 deletions src/lib/components/modal-inner/modal-inner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useRef } from "react"
import { usePreventScroll } from "@wethegit/react-hooks"

import { classnames } from "../../../utils/classnames"

Expand All @@ -24,8 +23,6 @@ export function ModalInner({ children, className, ...props }: ModalInnerProps) {
const firstFocusableElement = useRef<HTMLDivElement>(null)
const lastFocusableElement = useRef<HTMLDivElement>(null)

usePreventScroll(true)

const focusStartingPosition = () => {
const element = firstFocusableElement.current
if (element) element.focus()
Expand Down
3 changes: 3 additions & 0 deletions src/lib/components/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -15,6 +16,8 @@ export interface ModalProps extends ModalInnerProps {
}

export function Modal({ appendToBody, className, ...props }: ModalProps) {
usePreventScroll(appendToBody)

if (appendToBody) return ReactDOM.createPortal(<ModalInner {...props} />, document.body)
else
return (
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function CustomModal() {
</button>

{isOpen && (
<Modal>
<Modal appendToBody>
<ModalBackdrop onClick={toggle} className={styles.CustomModalOverlay} />
<ModalContent className={classnames([styles.CustomModalContent])}>
<button onClick={toggle} className={styles.CustomModalClose}>
Expand Down