-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add a skip nav link to improve keyboard navigation #212
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
Conversation
✅ Deploy Preview for chrisvogt ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
I'm holding off on merging this because it's not consistently working as expected: a large number of times it doesn't skip focus and just scrolls to the main content element. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #212 +/- ##
=======================================
Coverage 76.46% 76.46%
=======================================
Files 66 66
Lines 667 667
Branches 167 167
=======================================
Hits 510 510
Misses 143 143
Partials 14 14 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This PR reattempts #212 and adds [a skip navigation link](https://webaim.org/techniques/skipnav/) to the home and page templates. ## AI summary This pull request introduces a new accessibility feature, a "Skip to content" link, for improved navigation by keyboard-first users. It also includes related updates to the codebase, tests, and documentation. Below is a breakdown of the most important changes grouped by theme. ### Accessibility Feature: "Skip to Content" Link * Added `SkipNavLink` and `SkipNavContent` components from the `@reach/skip-nav` library to the `Layout` and `HomeTemplate` components, enabling users to skip directly to the main content. (`theme/src/components/layout.js`, `theme/src/templates/home.js`) [[1]](diffhunk://#diff-3b0e5bbe71b45a4c9eb24943876bed9538777aab09e2dfb633505da858b62828R5) [[2]](diffhunk://#diff-3b0e5bbe71b45a4c9eb24943876bed9538777aab09e2dfb633505da858b62828R36) [[3]](diffhunk://#diff-3b0e5bbe71b45a4c9eb24943876bed9538777aab09e2dfb633505da858b62828L43-R52) [[4]](diffhunk://#diff-95bf18ccdcf26fde4d5f491935d8fc68116d08389b056b905ffd5f23a11065b0R4) [[5]](diffhunk://#diff-95bf18ccdcf26fde4d5f491935d8fc68116d08389b056b905ffd5f23a11065b0R37) * Updated styles by importing `@reach/skip-nav/styles.css` in `gatsby-browser.js`. (`theme/gatsby-browser.js`) ### Navigation Behavior Enhancements * Implemented an `onRouteUpdate` function to focus the main content (`SkipNavContent`) after a route change, improving accessibility for keyboard users. (`theme/gatsby-browser.js`) ### Testing * Added comprehensive unit tests for `shouldUpdateScroll` and `onRouteUpdate` functions, including mock implementations for DOM manipulation. (`theme/gatsby-browser.spec.js`) ### Documentation and Versioning * Updated the `CHANGELOG.md` to document the new feature in version `0.45.0`. (`CHANGELOG.md`) * Updated the `package.json` version to `0.45.0` and added `@reach/skip-nav` as a dependency. (`theme/package.json`) [[1]](diffhunk://#diff-864251b807b1925eadafb797a61b4fb855065215fc4e7129a00ec23a2dd4ed72L4-R4) [[2]](diffhunk://#diff-864251b807b1925eadafb797a61b4fb855065215fc4e7129a00ec23a2dd4ed72R69) ### Snapshot Updates * Updated Jest snapshots to reflect the addition of the "Skip to content" link and the `SkipNavContent` element. (`theme/src/components/__snapshots__/layout.spec.js.snap`) [[1]](diffhunk://#diff-ff59f0caf88f27fbeded37a7967b7b210c0a1ae8b52ba16f03c69763b1933551L1-R1) [[2]](diffhunk://#diff-ff59f0caf88f27fbeded37a7967b7b210c0a1ae8b52ba16f03c69763b1933551R46-R52) [[3]](diffhunk://#diff-ff59f0caf88f27fbeded37a7967b7b210c0a1ae8b52ba16f03c69763b1933551R64-R67)
This PR adds a skip nav link using @reach/skip-nav to improve keyboard navigation. As you navigate between pages, it's cumbersome to TAB through the header links every page. After this change, a new button appears at the top of the page if when you first begin to TAB through the content, allowing you to jump to the main content area.