Skip to content

Commit 09bc6e5

Browse files
authored
Fix mobile doc-nav staying open when resizing up to desktop (#62456)
1 parent 2362038 commit 09bc6e5

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/frame/components/sidebar/SidebarCollapseContext.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ export function SidebarCollapseProvider({
8484
setMobileNavOpen(false)
8585
}, [asPath])
8686

87+
// Growing the viewport to the desktop (xxl) layout takes over from the inline
88+
// mobile nav and hides its toggle, so close the mobile nav when we cross the
89+
// breakpoint — otherwise its open state stays stuck and keeps the content
90+
// column hidden. 1400px mirrors breakpoint-xxl.scss.
91+
useEffect(() => {
92+
if (typeof window === 'undefined' || !window.matchMedia) return
93+
const mql = window.matchMedia('(min-width: 1400px)')
94+
const handle = (e: MediaQueryListEvent | MediaQueryList) => {
95+
if (e.matches) setMobileNavOpen(false)
96+
}
97+
handle(mql) // close immediately if already at/above xxl on mount
98+
mql.addEventListener('change', handle)
99+
return () => mql.removeEventListener('change', handle)
100+
}, [])
101+
87102
const value = useMemo(
88103
() => ({
89104
collapsed,

src/frame/components/sidebar/SidebarNav.module.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
}
1212

1313
// When the mobile nav is expanded inline, the rail spans the full width and
14-
// flows in the page (no fixed height / sticky) below the xxl breakpoint.
14+
// flows in the page (no fixed height / sticky) below the xxl breakpoint. At xxl
15+
// the desktop rail takes over, so revert to the fixed rail width even if the
16+
// mobile-open state is momentarily still set (e.g. mid-resize) — otherwise the
17+
// full-width rail covers the article content.
1518
.sidebarFullMobileOpen {
1619
width: 100%;
20+
21+
@include breakpoint-xxl {
22+
width: 326px;
23+
}
1724
}
1825

1926
.sidebarContentFull {

0 commit comments

Comments
 (0)