-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Gatsby a11y helpers #26376
Gatsby a11y helpers #26376
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments on the README. Overall looks great!
@@ -0,0 +1,102 @@ | |||
# Skip Navigation | |||
|
|||
Many people navigate the web primarily using the keyboard, often with a screen reader. If main content is not the first thing on a page (e.g. if there is a top site banner or navigation menu before the main content starts), these users have to tab through every single link before they can get to the main content. As this is cumbersome and not an ideal user experience, it is recommended that a "skip link" be added at the very top of every page that links to the main content, allowing users to skip right to the most relevant information on the page. It is idiomatic to position this link off of the page so it can only be reached with a keyboard and doesn't interrupt visual flow of the page, and to display the link if it is focused. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many people navigate the web primarily using the keyboard, often with a screen reader. If main content is not the first thing on a page (e.g. if there is a top site banner or navigation menu before the main content starts), these users have to tab through every single link before they can get to the main content. As this is cumbersome and not an ideal user experience, it is recommended that a "skip link" be added at the very top of every page that links to the main content, allowing users to skip right to the most relevant information on the page. It is idiomatic to position this link off of the page so it can only be reached with a keyboard and doesn't interrupt visual flow of the page, and to display the link if it is focused. | |
Many people navigate the web primarily using the keyboard, often with a screen reader. If the main content is not the first thing on a page (e.g. if there is a top site banner or navigation menu before the main content starts), these users have to tab through every single link before they can get to the main content. As this is cumbersome and not an ideal user experience, it is recommended that a "skip link" be added at the very top of every page that links to the main content, allowing users to skip right to the most relevant information on the page. It is idiomatic to position this link off of the page so it can only be reached with a keyboard and doesn't interrupt visual flow of the page, and to display the link if it is focused. |
|
||
### Add `SkipNavLink` and `SkipNavContent` to your Layout | ||
|
||
```javascript:title=src/components/layout.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work in a README, better to remove the title piece
``` | ||
|
||
1. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site. It has pages and components to be used in those pages. | ||
1. **`/components`**: This directory will contain all of the code related to what you will see on the front-end of your site. It has pages and components to be used in those pages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
components doesn't have pages? I think this was inadvertently copied from src
1. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site. It has pages and components to be used in those pages. | ||
1. **`/components`**: This directory will contain all of the code related to what you will see on the front-end of your site. It has pages and components to be used in those pages. | ||
|
||
1. **`/header.css`**: This ensures that our navigation links have focus rings, which are important visual cues when navigating by keyboard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. **`/header.css`**: This ensures that our navigation links have focus rings, which are important visual cues when navigating by keyboard. | |
1. **`/header.css`**: This ensures that your navigation links have focus rings, which are important visual cues when navigating by keyboard. |
1. **`/seo.js`**: This information is necessary to give the site a 100% in [Lighthouse](https://developers.google.com/web/tools/lighthouse) for accessibility since screen readers need a title and language. | ||
|
||
1. **`/pages`**: This directory contains pages that will be automatically built and served by Gatsby. This example includes three pages to demonstrate navigation between them and how your skip nav link behaves. All of these pages use the `Layout` component. | ||
1. **`gatsby-browser.js`**: This file is where you tell the Gatsby to focus the skip navigation when users navigate to a new page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. **`gatsby-browser.js`**: This file is where you tell the Gatsby to focus the skip navigation when users navigate to a new page. | |
1. **`gatsby-browser.js`**: This file is where you tell the browser to focus the skip navigation when users navigate to a new page. |
|
||
1. **`/pages`**: This directory contains pages that will be automatically built and served by Gatsby. This example includes three pages to demonstrate navigation between them and how your skip nav link behaves. All of these pages use the `Layout` component. | ||
1. **`gatsby-browser.js`**: This file is where you tell the Gatsby to focus the skip navigation when users navigate to a new page. | ||
1. **`/cypress`**: This directory is where tests and [Cypress](https://www.cypress.io/) configuration live. You're going to focus on the test. If you want to learn more about using Cypress, check out the [example](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-cypress). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"You're going to focus on the test". This is a bit confusing. Do you mean that the test makes use of navigation focus?
1. **`/pages`**: This directory contains pages that will be automatically built and served by Gatsby. This example includes three pages to demonstrate navigation between them and how your skip nav link behaves. All of these pages use the `Layout` component. | ||
1. **`gatsby-browser.js`**: This file is where you tell the Gatsby to focus the skip navigation when users navigate to a new page. | ||
1. **`/cypress`**: This directory is where tests and [Cypress](https://www.cypress.io/) configuration live. You're going to focus on the test. If you want to learn more about using Cypress, check out the [example](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-cypress). | ||
1. **`/integrations/skip-nav.test.js`**: runs two tests to ensure that you have a skip link and that the skip link is focused on page navigation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. **`/integrations/skip-nav.test.js`**: runs two tests to ensure that you have a skip link and that the skip link is focused on page navigation. | |
1. **`/integrations/skip-nav.test.js`**: This rile runs two tests to ensure that you have a skip link and that the skip link is focused on page navigation. |
|
||
### Running the example | ||
|
||
1. Use the CLI to create run this example |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add install instructions?
|
||
### Problem | ||
|
||
Further research was conducted athte Inclusive Design 24 virtual conference in October 2019 and, new [techniques were developed](https://www.youtube.com/watch?v=Tr21FqQQv-U) to support a wider variety of workflows and disabilities. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further research was conducted athte Inclusive Design 24 virtual conference in October 2019 and, new [techniques were developed](https://www.youtube.com/watch?v=Tr21FqQQv-U) to support a wider variety of workflows and disabilities. | |
Further research was conducted at the Inclusive Design 24 virtual conference in October 2019 and, new [techniques were developed](https://www.youtube.com/watch?v=Tr21FqQQv-U) to support a wider variety of workflows and disabilities. |
LOVE THIS!!! 🥳 I stumbled upon this PR when looking for localizing the "Navigated to" screen-reader announcements. So much good info here!!! QQ: What would the default experience be if a dev does not implement |
all work borrows heavily from madalyn's great work at gatbsy: - gatsbyjs/gatsby#26376 the changes here include: - prerender compatability - manage announcements (RouteAnnouncement -> h1 -> document.title -> location.pathname) - manage focus (WIP) - adds four components: RouteAnnouncement, RouteFocus, and Reach UI's SkipNavLink, SkipNavContent (also WIP as they need CSS)
all work borrows heavily from madalyn's great work at gatbsy: - gatsbyjs/gatsby#26376 the changes here include: - prerender compatability - manage announcements (RouteAnnouncement -> h1 -> document.title -> location.pathname) - manage focus (WIP) - adds four components: RouteAnnouncement, RouteFocus, and Reach UI's SkipNavLink, SkipNavContent (also WIP as they need CSS)
Description
This PR creates a solution for #21059.
There is currently a working bare-bones prototype that gives developers control around client-side routing behavior that Gatsby can hook into.
As it stands we have two components. They are based heavily on @reach/skip-nav and their current implementation is fairly simplistic.
RouteAnnouncement
Gatsby looks for this element when it navigates to a new page in
cache-dir/navigation.js
and outputs its contents to Gatsby's Route Announcer.This component can be used multiple times in a site (e.g. implemented to always use page title in a general
Layout.js
file and then overridden in specific pages or posts for custom announcements) and Gatsby will use the most specific instance. If the announcement should be different from the title of the page, Gatsby makes it easy to change without visually displaying that custom text with thevisuallyHidden
flag.Source
Examples
RouteFocus
Source
Example
TODO
Validation!
Let's set developers up for accessibility success by highlighting common mistakes. We'll likely do this validation inside of a util plugin shipped with Gatsby rather than in the components themselves so we can leverage a11y testing libraries to make our assertions without bloating the component package.
<RouteAnnouncement>
must meet guidelines for page Titles to emulate the behavior of static browser route changes (e.g. check length of text to ensure it doesn't overwhelm)<RouteFocus>
must wrap an interactive element, ideally a skip link, per @marcysutton's researchRobustness
<RouteAnnouncement>
Related Issues
Fixes #21059 & #20801
Related to #19290