Skip to content
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

fix: focus on the root div after navigation #5593

Closed
wants to merge 1 commit into from

Conversation

jlengstorf
Copy link
Contributor

This fix applies focus to the main app div after page navigation, which triggers screen readers and other assistive tech to announce the new page. Thanks to @NickColley for initially pointing this out, and to @LJWatson for jumping in with a fix!

fix #5581

This fix applies focus to the main app div after page navigation,
which triggers screen readers and other assistive tech to announce
the new page. Thanks to @NickColley for initially pointing this
out, and to @LJWatson for jumping in with a fix!

fix gatsbyjs#5581
@jlengstorf
Copy link
Contributor Author

@calcsam Can you restart this build? It said "gatsby is not found", which makes me thing something hiccupped. https://app.netlify.com/sites/eloquent-golick-4ddc79/deploys/5b0db4f0b13fb1339e945589

@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit 648ce92

https://deploy-preview-5593--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit 648ce92

https://deploy-preview-5593--gatsbygram.netlify.com

@NickColley
Copy link

Nice work, I think we need to test in the following assistive technologies to know this has got us good coverage: https://www.gov.uk/service-manual/technology/testing-with-assistive-technologies#what-to-test

Happy to do this for you :)

@@ -149,6 +149,7 @@ class GatsbyLink extends React.Component {
// This is just a normal link to the current page so let's emulate default
// browser behavior by scrolling now to the top of the page.
window.scrollTo(0, 0)
document.querySelector(`#___gatsby`).focus()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you'll need to add a tabindex="-1" to the element, otherwise you cannot trigger programmatic focus.

This'll then likely show a focus outline that is not useful for most users, so you'd want to add some styles to remove this outline.

@NickColley
Copy link

NickColley commented May 29, 2018

Just tested with NVDA, Firefox, Windows 10 and there's no response, I believe this is because of what I've noted inline. Can test again, or make this update for you if you fancy.

Also, when pressing 'Down' the read the next item, it starts at 'Category: Salads' rather than the top of the page.

@pieh
Copy link
Contributor

pieh commented May 29, 2018

I don't think adding this to gatsby-link cover all grounds here - for example using history.back() will not trigger it.

I think we should create internal plugin that will use gatsby-browser.js onRouteUpdate that is called on all client navigation. Worth noting that this is also called on initial render, so this potentially might cause problem with screen readers - in that case we would have to skip refocusing app div on first route update.

@jlengstorf
Copy link
Contributor Author

Good points, @NickColley and @pieh.

@NickColley, if you want to take this PR and run with it, I'd be happy to hand over the reins.

@pieh I don't have much experience with internal plugins. Any good places to start learning about that?

@pieh
Copy link
Contributor

pieh commented May 30, 2018

@jlengstorf There is not much to learn really about internal plugins:

  • they live here: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby/src/internal-plugins
  • and you add them to plugin list here:
    const internalPlugins = [
    `../../internal-plugins/dev-404-page`,
    `../../internal-plugins/component-page-creator`,
    `../../internal-plugins/component-layout-creator`,
    `../../internal-plugins/internal-data-bridge`,
    `../../internal-plugins/prod-404`,
    `../../internal-plugins/query-runner`,
    ]
  • they are regular plugins (query-runner is only exception - this one is more tightly coupled with gatsby core). They are just shipped with gatsby package and don't have to be explicitly declared in gatsby-config.js. You will need package.json, no-op index.js (both of which you can copy from existing internal plugins and adjust where needed) and for purpose of this feature gatsby-browser.js

@NickColley
Copy link

Would love to run with this, to avoid bugging you with back and forth. Appreciate all the time you've put in so far!

@benrobertsonio
Copy link
Contributor

I tested the Drupal demo on JAWS 2018 on Windows 10 in Chrome and IE11.

Chrome does not read the page title aloud on page change.

IE11 does read the title (twice), although I'm thinking this is because IE11 doesn't support service workers and so is not getting the SPA experience and is actually just loading the page.

I'm happy to test again with JAWS once we have an updated PR.

@benrobertsonio
Copy link
Contributor

Also just wanted to note that since Gatsbygram doesn't have unique page titles I don't think it will be that helpful to test there.

@NickColley
Copy link

Of note: https://reach.tech/router

@m-allanson
Copy link
Contributor

Of note: https://reach.tech/router

See also: #5656

@pieh
Copy link
Contributor

pieh commented Jun 13, 2018

quick update:
I did implement changes I suggested here - pieh/gatsby@master...pieh:fix/link-a11y

and it does focus app container on navigation (app container is visibly outlined), but this doesn't seem to trigger screen reader I used for test (NVDA) to read out new page title/headings. Disabling js (so doing fallback to default browser navigation) does make NVDA to read out new page title/headings

so not sure if focus trick will do good job with this :/

@LJWatson
Copy link

LJWatson commented Jun 15, 2018

@pieh as noted in my comment in 5581, the screen reader behaviour can't be entirely faked, but it's ok because focus is in the expected part of the page to enable the user to explore/discover the information they need.

@NickColley
Copy link

@LJWatson https://reach.tech/router has managed to solve this issue so I'm not sure we have to compromise on that.

@pieh
Copy link
Contributor

pieh commented Jun 15, 2018

@NickColley because changing router component that is deeply embeded into gatsby might not be feasible (breaking change, because it seems like it has different API than react-router from). Even if we switch to it in future, we should still explore possible solutions for this problem short-term when we are using react-router.

@NickColley
Copy link

I meant more, we can copy the approach, not that we should integrate that project.

@KyleAMathews
Copy link
Contributor

I'm going to attempt moving us to reach-router for v2. It's both smaller (33kb -> 18kb) and ready for async React and it fixes this issue. My understanding are that the API changes are minimal and most sites shouldn't have to do anything to upgrade.

@jlengstorf jlengstorf closed this Jul 31, 2018
@jlengstorf jlengstorf deleted the fix/link-a11y branch July 31, 2018 00:06
@KyleAMathews
Copy link
Contributor

FYI, my PR adding @reach/router is about ready to go in #6918

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

a11y issues: page nav doesn't trigger assistive tech
8 participants