fix(next): remove keyboard focus for closed nav items #9558
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.
Fixes: #9610.
What?
Currently some links inside the main nav are still focusable with a keyboard when the main nav is closed.
Why?
This leads to the active keyboard focus getting lost until it eventually finds its way to the hamburger menu button. It can also lead to links that are not currently visible being selected accidentally.
How?
When the inert attribute is set to
true
, we can prevent focus on any child elements automatically. We simply toggle the attribute on or off based on whether the nav is open or closed.The inert attribute has great compatibility with modern browsers these days, making it a solid choice to resolve this issue.
Recordings
Before
You can see down the bottom left of the screen that links available in the main nav are still focusable even when the main nav is closed.
main-nav-focus-before.mp4
After
You can see that focus is immediately moved to the hamburger menu when the main nav is closed.
main-nav-focus-after.mp4