From 672df042d50ec17670df31a23d48613163ae81a1 Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Mon, 31 May 2021 17:02:45 -0300 Subject: [PATCH] Improving Sidebar Scroll --- components/ui/Sidebar/Sidebar.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/ui/Sidebar/Sidebar.tsx b/components/ui/Sidebar/Sidebar.tsx index de31af3ec..08a06240e 100644 --- a/components/ui/Sidebar/Sidebar.tsx +++ b/components/ui/Sidebar/Sidebar.tsx @@ -15,15 +15,19 @@ interface Props { const Sidebar: FC = ({ children, open = false, onClose }) => { const ref = useRef() as React.MutableRefObject + console.log(ref, ref.current, open) useEffect(() => { - if (ref.current) { - if (open) { + setTimeout(() => { + if (ref.current && open) { + window.document.body.style.overflow = 'hidden' disableBodyScroll(ref.current) } else { - enableBodyScroll(ref.current) + window.document.body.style.overflow && + setTimeout(() => (window.document.body.style.overflow = 'unset'), 30) + !!ref.current && enableBodyScroll(ref.current) } - } + }, 30) return () => { clearAllBodyScrollLocks() }