From 3330bdc2a36ba005ff39666a3f9ecf4178913b1c Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Mon, 27 Jul 2026 12:00:14 -0400 Subject: [PATCH] fix(nav): close sidebar on mobile breakpoint --- .../components/sideNav/sideNav.js | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/packages/documentation-framework/components/sideNav/sideNav.js b/packages/documentation-framework/components/sideNav/sideNav.js index e3fdc8f304..5ed403435c 100644 --- a/packages/documentation-framework/components/sideNav/sideNav.js +++ b/packages/documentation-framework/components/sideNav/sideNav.js @@ -20,7 +20,6 @@ const DIVIDER_STYLES = { marginBottom: 'var(--pf-t--global--spacer--xs)' }; import { makeSlug } from '../../helpers'; -import globalBreakpointXl from '@patternfly/react-tokens/dist/esm/t_global_breakpoint_xl'; import { trackEvent } from '../../helpers'; const getIsActive = (location, section, subsection = null) => { @@ -31,14 +30,13 @@ const getIsActive = (location, section, subsection = null) => { const defaultValue = 50; const NavItem = ({ text, href, isDeprecated, isBeta, isDemo }) => { - const isMobileView = window.innerWidth < Number.parseInt(globalBreakpointXl.value, 10); return ( - {({ onSidebarToggle, isSidebarOpen }) => ( + {({ onSidebarToggle, isSidebarOpen, isMobile }) => (
  • isMobileView && onSidebarToggle && onSidebarToggle()} + onClick={() => isMobile && onSidebarToggle && onSidebarToggle()} > { } }, []); - const groupedItems = React.useMemo(() => - (navItems || []).filter(entry => entry && entry.title), [navItems]); - const ungroupedItems = React.useMemo(() => - (navItems || []).filter(entry => entry && !entry.title), [navItems]); + const groupedItems = React.useMemo(() => (navItems || []).filter((entry) => entry && entry.title), [navItems]); + const ungroupedItems = React.useMemo(() => (navItems || []).filter((entry) => entry && !entry.title), [navItems]); - const renderNavItem = React.useCallback((item) => { - if (!item) return null; - - return item.section ? ( - - {({ location }) => ExpandableNav({ groupedRoutes, location, section: item.section })} - - ) : NavItem({ - key: item.href || `nav-item-${Math.random()}`, - text: item.text || (item.href ? capitalize(item.href.replace(/\//g, '').replace(/-/g, ' ')) : 'Untitled'), - href: item.href - }); - }, [groupedRoutes]); + const renderNavItem = React.useCallback( + (item) => { + if (!item) return null; + + return item.section ? ( + + {({ location }) => ExpandableNav({ groupedRoutes, location, section: item.section })} + + ) : ( + NavItem({ + key: item.href || `nav-item-${Math.random()}`, + text: item.text || (item.href ? capitalize(item.href.replace(/\//g, '').replace(/-/g, ' ')) : 'Untitled'), + href: item.href + }) + ); + }, + [groupedRoutes] + ); return ( ); -}; \ No newline at end of file +};