Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(switcher): automate max height, closes on bg click, update disabled tab index #870

Merged
merged 23 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e9262fe
v1.17.2
jnm2377 Nov 21, 2019
1780aa4
v1.17.3
jnm2377 Nov 21, 2019
96eab47
Merge branch 'fix-global-spacing' of github.com:jnm2377/gatsby-theme-…
jnm2377 Nov 21, 2019
03213c8
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jan 7, 2020
04bf871
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jan 8, 2020
0304639
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jan 17, 2020
dd706d7
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jan 21, 2020
3d0f4a0
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jan 31, 2020
3d5a93a
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Feb 17, 2020
6b63c13
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Apr 13, 2020
25c29f7
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 May 14, 2020
febc454
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 May 28, 2020
4d09518
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jun 1, 2020
0adbf68
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jun 2, 2020
66104a6
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
jnm2377 Jun 3, 2020
a2dea55
feat: closing func, disabled focus, styles
jnm2377 Jun 3, 2020
b1496da
chore: add comment
jnm2377 Jun 3, 2020
3854a1d
fix: accidentally deleted onclick for close
jnm2377 Jun 3, 2020
2649e01
chore: clean up comments
jnm2377 Jun 3, 2020
6f2b62d
fix: update media query and styles
jnm2377 Jun 4, 2020
ee368e8
fix: eslint cleanup
vpicone Jun 16, 2020
f3d2580
Update packages/gatsby-theme-carbon/src/components/Switcher/Switcher.…
vpicone Jun 16, 2020
3e518b3
Merge branch 'master' into update-switcher
vpicone Jun 16, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const Container = ({ children, homepage, theme }) => {
/>
<main
id="main-content"
role="presentation" // needed for jsx-a11y/no-noninteractive-element-interactions
onClick={closeNavs}
onKeyPress={closeNavs}
aria-hidden={overlayVisible}
className={containerClassNames}
>
Expand Down
19 changes: 15 additions & 4 deletions packages/gatsby-theme-carbon/src/components/LeftNav/LeftNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 (
<LeftNavWrapper expanded={leftNavIsOpen}>
<LeftNavWrapper
expanded={leftNavIsOpen}
onClick={closeSwitcher}
onKeyPress={closeSwitcher}
>
<SideNav
ref={sideNavRef}
expanded
Expand Down
25 changes: 22 additions & 3 deletions packages/gatsby-theme-carbon/src/components/Switcher/Switcher.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import React, { useContext } from 'react';
import React, { useContext, useRef, useEffect, useState } from 'react';
import cx from 'classnames';
import useMedia from 'use-media';
import NavContext from '../../util/context/NavContext';
import { nav, open, divider, link, linkDisabled } from './Switcher.module.scss';

const Switcher = ({ children }) => {
const { switcherIsOpen } = useContext(NavContext);

const listRef = useRef(null);
const [height, setHeight] = useState(null);

// calculate and update height
useEffect(() => {
switcherIsOpen
? setHeight(listRef.current.offsetHeight + 40)
: setHeight(0);
}, [listRef, switcherIsOpen]);

const lgBreakpoint = useMedia('min-width: 1056px');
const styles = {
/* eslint no-unused-expressions: [2, { allowShortCircuit: true, allowTernary: true }] */
jnm2377 marked this conversation as resolved.
Show resolved Hide resolved
maxHeight: !lgBreakpoint && switcherIsOpen ? '100%' : `${height}px`,
};

return (
<nav
className={cx(nav, { [open]: switcherIsOpen })}
aria-label="IBM Design ecosystem navigation"
aria-expanded={switcherIsOpen}
tabIndex="-1"
style={styles}
>
<ul>{children}</ul>
<ul ref={listRef}>{children}</ul>
</nav>
);
};
Expand All @@ -33,13 +51,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 (
<li>
<a
aria-disabled={disabled}
role="button"
tabIndex={switcherIsOpen ? 0 : '-1'}
tabIndex={switcherIsOpen ? openTabIndex : '-1'}
className={className}
href={href}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
transition: all $duration--fast-02 carbon--motion("exit");
@include carbon--breakpoint("lg") {
transform: translateX(0);
max-height: 0;
height: auto;
}
}
Expand All @@ -36,7 +35,6 @@
// https://css-tricks.com/using-css-transitions-auto-dimensions/
// Tied to the height of the app switcher. Allows for animating up to auto.
// Matching the height exactly is imperitive to keep the correct animation timing.
vpicone marked this conversation as resolved.
Show resolved Hide resolved
max-height: 538px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.5); // header__menu shadow
}
}
Expand Down