Closed D3Portillo closed 1 month ago
UPDATE The hotfix won't work when virtual keyboard pops in mobiles. To fix this I've just trigger the click event when innerWidth changes at resize
// _app.js
const ON_RESIZE = "resize"
useEffect(() => {
let storedWidth = window.innerWidth
function closeMobileMenu() {
const newWidth = window.innerWidth
const navButton = document.querySelector("nav button.md\\:hidden")
const isResizeXEvent = storedWidth !== newWidth
const isShowingMenu = document.body.classList.contains("overflow-hidden")
if (isShowingMenu && navButton && isResizeXEvent) {
navButton.click()
}
storedWidth = newWidth
}
window.addEventListener(ON_RESIZE, closeMobileMenu)
return () => {
window.removeEventListener(ON_RESIZE, closeMobileMenu)
}
}, [])
Hope someone finds it useful
closing due age, I think it was fixed in Nextra v2 or v3, try to upgrade
Preview
https://user-images.githubusercontent.com/26236985/173242429-b998a677-d2ce-4f91-b86b-714d7f888ccb.mp4
How to simulate
A Dirty Workaround