Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

chrisvogt
Copy link
Owner

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.

Copy link

netlify bot commented Jul 25, 2024

Deploy Preview for chrisvogt ready!

Name Link
🔨 Latest commit a64a53c
🔍 Latest deploy log https://app.netlify.com/sites/chrisvogt/deploys/66a1a9cd131c200008e37e52
😎 Deploy Preview https://deploy-preview-212--chrisvogt.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@chrisvogt
Copy link
Owner Author

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.

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.46%. Comparing base (2a2a233) to head (a64a53c).
Report is 126 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chrisvogt chrisvogt self-assigned this Sep 7, 2024
@chrisvogt chrisvogt added the accessibility Improves site accessibility label Sep 7, 2024
@chrisvogt chrisvogt closed this Jun 24, 2025
chrisvogt added a commit that referenced this pull request Jun 24, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility Improves site accessibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant