mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
Improving Sidebar Scroll
This commit is contained in:
parent
3b24e5404d
commit
672df042d5
@ -15,15 +15,19 @@ interface Props {
|
|||||||
|
|
||||||
const Sidebar: FC<Props> = ({ children, open = false, onClose }) => {
|
const Sidebar: FC<Props> = ({ children, open = false, onClose }) => {
|
||||||
const ref = useRef() as React.MutableRefObject<HTMLDivElement>
|
const ref = useRef() as React.MutableRefObject<HTMLDivElement>
|
||||||
|
console.log(ref, ref.current, open)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref.current) {
|
setTimeout(() => {
|
||||||
if (open) {
|
if (ref.current && open) {
|
||||||
|
window.document.body.style.overflow = 'hidden'
|
||||||
disableBodyScroll(ref.current)
|
disableBodyScroll(ref.current)
|
||||||
} else {
|
} else {
|
||||||
enableBodyScroll(ref.current)
|
window.document.body.style.overflow &&
|
||||||
}
|
setTimeout(() => (window.document.body.style.overflow = 'unset'), 30)
|
||||||
|
!!ref.current && enableBodyScroll(ref.current)
|
||||||
}
|
}
|
||||||
|
}, 30)
|
||||||
return () => {
|
return () => {
|
||||||
clearAllBodyScrollLocks()
|
clearAllBodyScrollLocks()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user