Support Reach Router by ignoring tabindex="-1" #246
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reach Router uses a focus wrapper element which is used to contain focus when no other element has it. It gains focus on initial page load, and it is used as a focus target when route is changed in SPA mode to recreate the native browser-like focus management upon switching page.
The wrapper element is rendered as:
In general
tabindex="-1"elements can only be focused without a keyboard so we should probably always ignore them.Why is this needed
Without this change
focus-visiblestyles are incorrectly applied to Reach Router's focus wrapper element. Also without this change the 100ms timeout inonBlurwill incorrectly assume user is switching tabs if a client-side redirect occurs upon page loading and as a result element is focused by code as a side-effect. This results into a bug wherefocus-visibletoggles style on the focused element upon fresh page load where user has not used the keyboard at all.Other thoughts
onBlurmight need some adjustments to remove the possibility to trigger incorrectly upon focus by code triggering on initial page load. However this proposed change already greatly reduces the chance of focus style triggering incorrectly.