-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation block: Only focus submenu trigger on escape key press #41986
Conversation
Size Change: +2.44 kB (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good 👏🏻 Let's have a second round of testing from @afercia 🙏🏻
@draganescu hello. Quick question, when you have a chance: is the submenu navigation |
@afercia |
@@ -63,11 +61,13 @@ window.addEventListener( 'load', () => { | |||
'.wp-block-navigation-item.has-child' | |||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see some room for performance improvements here, as this run for any keyup event on the page for example for any Tab key press or even when typing within an input field or textarea. It's part of the existing implementation though so I'll open a separate issue.
closeSubmenus( block ); | ||
// Focus the submenu trigger so focus does not get trapped in the closed submenu. | ||
toggle.focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing with a menu with nested submenu, this triggers an error:
Uncaught TypeError: Cannot read properties of null (reading 'focus')
That's because:
- the script loops through all the submenu blocks
- for each submenu block, it gets the toggle with an aria-expanded="true" attribute
- then it closes all the submenu and switches aria-expanded to false
- at this point, it loops to the second submenu block, where the toggle has now an aria-expanded set to false
- querySelector returns null and
toggle
is null - attempting to set focus on
null
triggers the error
I think it would be sufficient to check for the toggle existence before attempting to set focus on it or alternatively return it it's null before setting focus.
Of course, this should be fixed also in the other file for the submenu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afercia Better now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
@draganescu thanks. I do see |
LGTM 👍 Restarted one e2e job that faield, waiting to see if it passes. |
What?
Fixes #41975
Why?
My last change introduced too much bad UX behavior.
How?
Only target escape key press to place focus on the submenu trigger.
Testing Instructions
Screenshots or screencast