From c47343bccdf01400c0a621a9b0637d20a2f77e85 Mon Sep 17 00:00:00 2001 From: Chris Vogt Date: Mon, 23 Jun 2025 20:26:22 -0700 Subject: [PATCH 1/4] feat: add skip to content link for keyboard users --- theme/gatsby-browser.js | 11 ++++++++++ theme/package.json | 1 + .../__snapshots__/layout.spec.js.snap | 13 ++++++++++- theme/src/components/layout.js | 11 +++++++++- theme/src/templates/home.js | 2 ++ yarn.lock | 22 +++++++++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/theme/gatsby-browser.js b/theme/gatsby-browser.js index 18dec7b6..17227e41 100644 --- a/theme/gatsby-browser.js +++ b/theme/gatsby-browser.js @@ -7,6 +7,7 @@ import 'lightgallery/css/lightgallery.css' import 'lightgallery/css/lg-thumbnail.css' import 'lightgallery/css/lg-zoom.css' import 'prismjs/themes/prism-solarizedlight.css' +import '@reach/skip-nav/styles.css' //this will show/hide the link on focus export { default as wrapRootElement } from './wrapRootElement' @@ -26,3 +27,13 @@ export const shouldUpdateScroll = ({ routerProps }) => { // For actual page changes, use default scroll behavior return true } + +// See https://fossies.org/linux/gatsby/examples/using-reach-skip-nav/README.md +export const onRouteUpdate = ({ prevLocation }) => { + if (prevLocation !== null) { + const skipContent = document.querySelector('[data-reach-skip-nav-content]') // Comes with the component. + if (skipContent) { + skipContent.focus() + } + } +} diff --git a/theme/package.json b/theme/package.json index 3eac2952..12e34c58 100644 --- a/theme/package.json +++ b/theme/package.json @@ -66,6 +66,7 @@ "@mdx-js/loader": "^3.0.1", "@mdx-js/mdx": "^3.0.1", "@mdx-js/react": "^3.0.1", + "@reach/skip-nav": "^0.18.0", "@reduxjs/toolkit": "^2.8.2", "@theme-ui/color": "^0.17.2", "@theme-ui/components": "^0.17.2", diff --git a/theme/src/components/__snapshots__/layout.spec.js.snap b/theme/src/components/__snapshots__/layout.spec.js.snap index 6a69483b..0a7fd72d 100644 --- a/theme/src/components/__snapshots__/layout.spec.js.snap +++ b/theme/src/components/__snapshots__/layout.spec.js.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`Layout matches the snapshot 1`] = `
+ + Skip to content +
+
diff --git a/theme/src/components/layout.js b/theme/src/components/layout.js index 9f374a71..5a957a85 100644 --- a/theme/src/components/layout.js +++ b/theme/src/components/layout.js @@ -2,6 +2,7 @@ import { jsx } from 'theme-ui' import { useSelector } from 'react-redux' import React from 'react' +import { SkipNavLink, SkipNavContent } from '@reach/skip-nav' import BackgroundPattern from './animated-background' import Footer from './footer' @@ -32,6 +33,7 @@ const Layout = ({ children, disableMainWrapper, hideHeader, hideFooter }) => { }} > + {/* NOTE(chrisvogt): hide the top navigation on the home and 404 pages */} {!hideHeader && ( @@ -40,7 +42,14 @@ const Layout = ({ children, disableMainWrapper, hideHeader, hideFooter }) => {
)} - {disableMainWrapper ? children :
{children}
} + {disableMainWrapper ? ( + children + ) : ( +
+ + {children} +
+ )} {!hideFooter &&