Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/documentation-framework/components/sideNav/sideNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { makeSlug } from '../../helpers';
import globalBreakpointXl from '@patternfly/react-tokens/dist/esm/t_global_breakpoint_xl';
import { trackEvent } from '../../helpers';

const mobileBreakpoint = Number(globalBreakpointXl.value.replace('px', ''));

const getIsActive = (location, section, subsection = null) => {
const slug = makeSlug(null, section, null, null, subsection);
return location.pathname.startsWith(slug);
Expand All @@ -24,14 +26,17 @@ 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 (
<PageContextConsumer key={href + text}>
{({ onSidebarToggle, isSidebarOpen }) => (
{({ onNavToggle, isNavOpen }) => (
<li
key={href + text}
className="pf-v6-c-nav__item"
onClick={() => isMobileView && onSidebarToggle && onSidebarToggle()}
onClick={() => {
if (typeof window !== 'undefined' && onNavToggle && window.innerWidth < mobileBreakpoint) {
onNavToggle();
}
}}
>
<Link
to={href}
Expand All @@ -41,7 +46,7 @@ const NavItem = ({ text, href, isDeprecated, isBeta, isDemo }) => {
className: css('pf-v6-c-nav__link', (isCurrent || pathname.startsWith(href + '/')) && 'pf-m-current')
};
}}
tabIndex={isSidebarOpen ? undefined : -1}
tabIndex={isNavOpen ? undefined : -1}
>
<Flex spaceItems={{ default: 'spaceItemsSm' }}>
<FlexItem>{text}</FlexItem>
Expand Down