Skip to content

Commit

Permalink
fix: Fix non-modal drawers without overlay to properly set body point…
Browse files Browse the repository at this point in the history
…er events (#460)

* fix: Fix non-modal drawers without overlay to properly set body pointer events

* Remove window check inside useEffect
  • Loading branch information
KajSzy authored Oct 1, 2024
1 parent 633ba25 commit 995e36a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,15 @@ export function Root({
}
}

React.useEffect(() => {
if (!modal) {
// Need to do this manually unfortunately
window.requestAnimationFrame(() => {
document.body.style.pointerEvents = 'auto';
});
}
}, [modal]);

return (
<DialogPrimitive.Root
defaultOpen={defaultOpen}
Expand Down Expand Up @@ -778,13 +787,6 @@ export const Overlay = React.forwardRef<HTMLDivElement, React.ComponentPropsWith

// Overlay is the component that is locking scroll, removing it will unlock the scroll without having to dig into Radix's Dialog library
if (!modal) {
// Need to do this manually unfortunately
if (typeof window !== 'undefined') {
window.requestAnimationFrame(() => {
document.body.style.pointerEvents = 'auto';
});
}

return null;
}

Expand Down

0 comments on commit 995e36a

Please sign in to comment.