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

A11y: Set focus back to body after link was clicked #2768

Closed
1 task done
osartun opened this issue Aug 13, 2017 · 5 comments
Closed
1 task done

A11y: Set focus back to body after link was clicked #2768

osartun opened this issue Aug 13, 2017 · 5 comments
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@osartun
Copy link

osartun commented Aug 13, 2017

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When navigating from one page to another, the new page should have its focus set on <body> as the document root.

Current Behavior

It's not like this using next/link. Due to being a single page app the focus remains on the link that has been clicked.
The page scrolls to the top to give a visual indication of a page change, but the focus doesn't change.

Steps to Reproduce (for bugs)

I've created an example app to better demonstrate the problem:
https://nextjs-focus-problem-zishcmqatc.now.sh/
Its repo is here: https://github.com/osartun/example-focus-problem

Context

I've noticed the problem while navigating my site with a screen reader and keyboard input. My site has a Next page link at the bottom of the page (see here, fyi: I fixed the problem with a work around on my site, so you can't reproduce it there).
After clicking and navigating to the next page, tabbing through the links started at the bottom of the page where the Next page link was.

Proposed solution

next/link scrolls to the top of the page after a successful navigation.
https://github.com/zeit/next.js/blob/42e21288a91b2f58d90c3cc782766611de30630f/lib/link.js#L77
I think that should be extended with:

document.body.focus();
@timneutkens timneutkens added good first issue Easy to fix issues, good for newcomers help wanted labels Nov 12, 2017
@ppatel221
Copy link

Hey, I'm interested in fixing this bug! is it okay if I work on it?

@osartun
Copy link
Author

osartun commented Jan 25, 2018

Oh, sorry, I missed your message. For me it's totally ok if you work on it. However, I'm not involved in this project, so I don't make any decisions here.

@connor-baer
Copy link
Contributor

connor-baer commented Jan 25, 2018

@osartun @ppatel221 Since it was such a small change, I took the liberty to fix it. #3545 just got merged. 😊

@mtrueblood
Copy link

Question on this: does it matter if the link is pointing to the same page template as the page that it is on? Meaning, page 1 and page 2 both share the same page template. Clicking the link pushes the user to a new URL, but the focus remains on the link of the page. I'm referring to a link in a component that is shared between the 2 different pages, that just happen to share the same page template.

Even after the fix of document.body.focus() in #3545, I'm still experiencing this issue. But the above information doesn't mention if the 2 pages are the same page template or not.

@osartun
Copy link
Author

osartun commented Jul 13, 2018

@mtrueblood From my understanding it shouldn't make a difference whether two pages share the same template or not. But would need to try it out to confirm this assumption.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants