diff --git a/packages/gatsby-theme-carbon/src/components/Container/Container.js b/packages/gatsby-theme-carbon/src/components/Container/Container.js index bab47c2fa..a03ca4dd2 100644 --- a/packages/gatsby-theme-carbon/src/components/Container/Container.js +++ b/packages/gatsby-theme-carbon/src/components/Container/Container.js @@ -50,6 +50,9 @@ const Container = ({ children, homepage, theme }) => { />
diff --git a/packages/gatsby-theme-carbon/src/components/LeftNav/LeftNav.js b/packages/gatsby-theme-carbon/src/components/LeftNav/LeftNav.js index f96a360c3..3c2a0a4ce 100644 --- a/packages/gatsby-theme-carbon/src/components/LeftNav/LeftNav.js +++ b/packages/gatsby-theme-carbon/src/components/LeftNav/LeftNav.js @@ -11,9 +11,12 @@ import LeftNavWrapper from './LeftNavWrapper'; import { sideNavDark } from './LeftNav.module.scss'; const LeftNav = (props) => { - const { leftNavIsOpen, leftNavScrollTop, setLeftNavScrollTop } = useContext( - NavContext - ); + const { + leftNavIsOpen, + leftNavScrollTop, + setLeftNavScrollTop, + toggleNavState, + } = useContext(NavContext); const sideNavRef = useRef(); const sideNavListRef = useRef(); @@ -36,9 +39,17 @@ const LeftNav = (props) => { const navItems = useNavItems(); + const closeSwitcher = () => { + toggleNavState('switcherIsOpen', 'close'); + }; + // TODO: replace old addon website styles with sass modules, move to wrapper return ( - + { + const lgBreakpoint = useMedia('min-width: 1056px'); const { switcherIsOpen } = useContext(NavContext); + const listRef = useRef(null); + const [height, setHeight] = useState(null); + + // calculate and update height + useEffect(() => { + if (switcherIsOpen) { + setHeight(listRef.current.offsetHeight + 40); + } else { + setHeight(0); + } + }, [listRef, switcherIsOpen]); + + const maxHeight = !lgBreakpoint && switcherIsOpen ? '100%' : `${height}px`; return ( ); }; @@ -33,13 +49,14 @@ export const SwitcherLink = ({ const href = disabled || !hrefProp ? undefined : hrefProp; const className = disabled ? linkDisabled : link; const { switcherIsOpen } = useContext(NavContext); + const openTabIndex = disabled ? '-1' : 0; return (