🚸 Prevent scrolling when hamburger menu is open (#1631)

This commit is contained in:
Ming-jun Lu 2023-11-14 02:05:10 +08:00 committed by GitHub
parent 221c0545d0
commit eddd14baa3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -20,6 +20,14 @@ const Hamburger = () => {
return () => Router.events.off('routeChangeStart', onRouteChangeStart) return () => Router.events.off('routeChangeStart', onRouteChangeStart)
}, []) }, [])
useEffect(() => {
if (isOpen) {
document.body.classList.add('overflow-hidden')
} else {
document.body.classList.remove('overflow-hidden')
}
}, [isOpen])
return ( return (
<div className={styles.hamburger}> <div className={styles.hamburger}>
<button <button

View File

@ -114,6 +114,10 @@ pre {
padding: 1em; padding: 1em;
} }
.overflow-hidden {
overflow: hidden;
}
.overflow-x-adjust { .overflow-x-adjust {
overflow-x: auto; overflow-x: auto;
} }