Skip to content

Commit

Permalink
SubNav v2 a11y fixes (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
rezrah authored Dec 10, 2024
1 parent 5a28ff4 commit fa277af
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 27 deletions.
9 changes: 9 additions & 0 deletions .changeset/curly-gorillas-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@primer/react-brand': patch
---

`SubNav` accessibility improvements:

- Removed focus-trapping in the menu overlay on narrow viewports
- Added hover state to the `SubNav.Heading`
- Added `aria-current` visual indicator parity on narrow viewports
18 changes: 6 additions & 12 deletions .github/workflows/visual_test_storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
ci:
if: ${{ github.repository == 'primer/brand' }}
name: Storybook
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
env:
NODE_ENV: test
steps:
Expand All @@ -17,7 +17,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: 18
node-version: 20

- name: Cache dependencies
uses: actions/cache@v4
Expand All @@ -43,19 +43,13 @@ jobs:
run: NODE_ENV=test npx start-server-and-test 'npx http-server ./apps/storybook/storybook-static -p 6006' 6006 'cd packages/e2e && npx playwright test'
continue-on-error: true

- name: Upload error screenshots
uses: actions/upload-artifact@v3
if: steps.playwright-step.outcome != 'success'
with:
name: playwright-test-results
path: playwright-test-results

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report
path: playwright-report/
retention-days: 30

- name: Comment on the PR about no visual differences
if: steps.playwright-step.outcome != 'success'
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/e2e/scripts/playwright/run-visual-tests
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cd ../../apps/storybook && npx storybook build && cd ../../packages/e2e
docker run --rm --ipc=host -v ${PWD%/*/*}:/tests mcr.microsoft.com/playwright:v1.24.0-focal /bin/bash -c "cd tests && npm install && npx playwright install chrome && npx playwright install && npx start-server-and-test 'npx http-server ./apps/storybook/storybook-static -p 6006' 6006 'cd packages/e2e && npx playwright test'"
docker run --rm --ipc=host -v ${PWD%/*/*}:/tests mcr.microsoft.com/playwright:v1.24.0-focal /bin/bash -c "cd tests && npm install && npx playwright install chromium && npx playwright install && npx start-server-and-test 'npx http-server ./apps/storybook/storybook-static -p 6006' 6006 'cd packages/e2e && npx playwright test'"
2 changes: 1 addition & 1 deletion packages/e2e/scripts/playwright/update-visual-snapshots
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cd ../../apps/storybook && npx storybook build && cd ../../packages/e2e
docker run --rm --ipc=host -v ${PWD%/*/*}:/tests mcr.microsoft.com/playwright:v1.37.0-jammy /bin/bash -c "cd tests && npm install && npx playwright install && npx start-server-and-test 'npx http-server ./apps/storybook/storybook-static -p 6006' 6006 'cd packages/e2e && npx playwright test --update-snapshots'"
docker run --rm --ipc=host -v ${PWD%/*/*}:/tests mcr.microsoft.com/playwright:v1.46.0-noble /bin/bash -c "cd tests && npm install && npx playwright install && npx start-server-and-test 'npx http-server ./apps/storybook/storybook-static -p 6006' 6006 'cd packages/e2e && npx playwright test --update-snapshots'"
11 changes: 7 additions & 4 deletions packages/react/src/SubNav/SubNav.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

.SubNav__heading:hover {
color: var(--brand-SubNav-color-link-active);
color: var(--brand-color-text-muted);
text-decoration: none !important; /* dotcom override */
}

Expand Down Expand Up @@ -333,6 +333,10 @@
text-decoration: none;
}

.SubNav__links-overlay--open .SubNav__link-label {
position: relative;
}

.SubNav__links-overlay--open .SubNav__link[aria-current]:not([aria-current='false']) * {
color: var(--brand-SubNav-color-link-active);
}
Expand Down Expand Up @@ -394,6 +398,7 @@
.SubNav__link-label {
font-size: var(--brand-text-size-200);
font-weight: var(--base-text-weight-semibold);
padding-block-end: var(--base-size-6);
}

.SubNav__sub-menu--anchor {
Expand All @@ -418,9 +423,7 @@
position: relative;
}

.SubNav .SubNav__link:hover .SubNav__link-label::after,
.SubNav .SubNav__link:focus-visible .SubNav__link-label::after,
.SubNav .SubNav__link[aria-current]:not([aria-current='false']) .SubNav__link-label::after {
.SubNav .SubNav__link--has-sub-menu:hover .SubNav__sub-menu-children .SubNav__link-label::after {
display: none;
}
}
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/SubNav/SubNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {default as clsx} from 'clsx'
import {ChevronDownIcon, ChevronUpIcon} from '@primer/octicons-react'
import {useId} from '@reach/auto-id'
import {useKeyboardEscape} from '../hooks/useKeyboardEscape'
import {useFocusTrap} from '../hooks/useFocusTrap'
import {useOnClickOutside} from '../hooks/useOnClickOutside'
import {useProvidedRefOrCreate} from '../hooks/useRef'
import {useContainsFocus} from './useContainsFocus'
Expand Down Expand Up @@ -154,7 +153,6 @@ const _SubNavRoot = memo(({id, children, className, 'data-testid': testId, fullW

useOnClickOutside(rootRef, closeMenuCallback)
useKeyboardEscape(closeMenuCallback)
useFocusTrap({containerRef: overlayRef, restoreFocusOnCleanUp: true, disabled: !isOpenAtNarrow})

useEffect(() => {
if (isOpenAtNarrow && !isLarge) {
Expand Down Expand Up @@ -241,7 +239,7 @@ const _SubNavRoot = memo(({id, children, className, 'data-testid': testId, fullW
<div ref={rootRef} className={styles['SubNav--header-container-outer']}>
<div className={styles['SubNav__header-container']}>
{HeadingChild && <div className={styles['SubNav__heading-container']}>{HeadingChild}</div>}
{activeLinklabel && (
{(activeLinklabel || isLarge) && (
<span role="separator" className={styles['SubNav__heading-separator']} aria-hidden>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fa277af

Please sign in to comment.