question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] reach router not always setting focus on route change

See original GitHub issue

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 75.43 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 11.10.1 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.7.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 73.0.3683.103
    Firefox: 64.0
    Safari: 12.1
  npmPackages:
    react: ^16.8.2 => 16.8.6
    react-dom: ^16.8.2 => 16.8.6
    react-static: ^7.0.0 => 7.0.9
    react-static-plugin-reach-router: ^7.0.0 => 7.0.8
    react-static-plugin-sitemap: ^7.0.0 => 7.0.8
    react-static-plugin-source-filesystem: ^7.0.0 => 7.0.8
  npmGlobalPackages:
    react-static: 7.0.9

Steps to Reproduce the problem

With a fresh basic react static installation

  1. click on home (link remains focused)
  2. click on about (link remains focused)
  3. click on dynamic (content gets focused)
  4. click on about (content gets focused)
  5. click on home (link remains focused)

Expected Behavior

The router wrapper div should ALWAYS get focused <div tabindex="-1" role="group" style="outline: none;">

You can use a simple CSS rule to quickly visualise this:

*:focus {
  background-color: yellow;
}

If you place a couple of components directly inside of <Router> - instead of the react static <Routes> component - you will notice that the router placeholder always gets the browser focus

<Router>
  <SomeComponent path="/foo" />
  <SomeComponent path="/bar" />
</Router>

Notes

I’m under the impression this is due to the way <Routes> is rendering the static routes, maybe because of the wrapping <Location> component.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
andrezerocommented, May 16, 2019

Just FYI, meanwhile I completely dropped reach-router because I can’t live with the extra divs injected in my markup

0reactions
SleeplessBytecommented, Jul 17, 2019

Since @reach/router will be deprecated (new react-router will merge the two) and I believe this is in that package, I’ll close this for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SPA Accessibility - focus not reset when route changed · Issue ...
I am using a screen reader to interact with my application. Moving between routes does not reset the focus, which would occur on...
Read more >
Stop Reach Router scrolling down the page after navigating to ...
Try using <Router primary={false}> which will not focus on the route component. Defaults to true. Primary Routers will manage focus on location ...
Read more >
Accessibility - Reach Router
Reach Router provides out-of-the-box focus management so your apps are significantly more accessible without you breaking a sweat. When the location changes, ...
Read more >
Accessibility Improvements to Client Side Routing in Gatsby
We recently released accessibility improvements to client side routing in Gatsby core, building on previous focus management improvements ...
Read more >
Router | RedwoodJS Docs
Sets can take a private prop which makes all Routes inside that Set require authentication. When a user isn't authenticated and attempts to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found