From 7fab3540ea75ecaeb3f7317391d61eb68e4e7d97 Mon Sep 17 00:00:00 2001 From: Steven RYDELL Date: Sat, 1 Aug 2026 19:07:22 +0200 Subject: [PATCH] fix(ui): keep mobile sidebar open when switching sections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tapping Management/Settings/Account in the sidebar footer navigated to that section's default page, which triggered the same effect that closes the sidebar after picking a leaf page on mobile — so the sidebar snapped shut right after switching sections, forcing users to reopen it just to browse the new section's pages. Have handleSectionClick flag the navigation as section-only via a ref; the mobile auto-close effect consumes that flag and skips closing for that one navigation, leaving normal leaf-page navigation unaffected. Verified on a mobile viewport: switching sections now keeps the sidebar open, while picking a specific page still closes it as before. --- src/components/layout/Sidebar.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 67b2fbb..73493f1 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -334,6 +334,11 @@ export function Sidebar() { const hasPermission = useAccountStore((s) => s.hasPermission); const [upsellOpen, setUpsellOpen] = useState(false); const navRef = useRef(null); + // Set by handleSectionClick right before navigating: switching sections + // from the footer should keep the sidebar open so the new section's pages + // are still browsable, instead of closing right back up like a leaf-page + // navigation would. + const skipCloseOnNavigateRef = useRef(false); // Build the permission checks from the permissions array itself: the store // accessors are stable refs, so depending on them alone would keep a stale @@ -346,6 +351,10 @@ export function Sidebar() { useEffect(() => { if (typeof window === 'undefined') return; + if (skipCloseOnNavigateRef.current) { + skipCloseOnNavigateRef.current = false; + return; + } if (window.matchMedia('(max-width: 767px)').matches) { setSidebarOpen(false); } @@ -371,7 +380,10 @@ export function Sidebar() { last ?? findFirstAccessibleLinkInLayout(schema, target, edition, canGet, hasPermission) ?? findFirstVisibleLinkInLayout(schema, target, edition, canGet, hasPermission); - if (first) navigate(`/${target.name}/${first}`); + if (first) { + skipCloseOnNavigateRef.current = true; + navigate(`/${target.name}/${first}`); + } }; return (