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(next): remove keyboard focus for closed nav items #9558

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

rilrom
Copy link
Contributor

@rilrom rilrom commented Nov 27, 2024

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

Copy link
Member

@AlessioGr AlessioGr left a comment

Choose a reason for hiding this comment

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

Thank you!

@AlessioGr AlessioGr merged commit 2d2e7d5 into payloadcms:main Nov 29, 2024
61 of 62 checks passed
Copy link
Contributor

github-actions bot commented Dec 3, 2024

🚀 This is included in version v3.3.0

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.

Some main nav links are still accessible with a keyboard when it is closed
2 participants