-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Do not focus new navigation block menu until loading is finished #59801
Conversation
When a new navigation is created, we place focus on the navigation block. If we place focus while loading is still happening, focus will be lost when focus the loading is finished and the block gets replaced with the new content.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.71 MB ℹ️ View Unchanged
|
Instead of replacing the navigation block after loading, only replace the inside part of it so that focus is not lost
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.
This makes perfect sense to me and it also fixes the original issue.
… used when creating a menu, this way the select block call is later and the focus is maintained
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
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.
Quick code review
// Make sure it's a nav block appender. If it is, the linkControl search input will be opened on enter. | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
// Expect to see the Link creation UI be focused. | ||
const linkUIInput = linkControl.getSearchInput(); | ||
await expect( linkUIInput ).toBeFocused(); |
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.
As this behaviour might change in future, would it be possible to scope the selector for the Add block
to be relative to the Navigaiton block.
So in pseudo code
editor.canvas.getNavBlock().getByLabel('Add block')
…turn a Promise Co-authored-by: Dave Smith <getdavemail@gmail.com>
Thanks for the reviews and fixes, @draganescu and @getdave! This is ready for another review. |
The failed e2e tests pass locally. Rerunning. |
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 tested and this and the behaviour was as described and expected.
In the longer term, I'm wondering whetehr it would probably be better to have focus remain in the sidebar where you invoked the "Create" action. But for now this manages focus in a much better way and resolves the bug.
Great work 👏
This PR should be included in the WordPress 6.5 release during the RC phase. The bug was identified during the RC cycle and represents a focus loss issue which could make navigating the editor very difficult for users of assistive tech. |
) * Do not focus navigation block until loading is finished When a new navigation is created, we place focus on the navigation block. If we place focus while loading is still happening, focus will be lost when focus the loading is finished and the block gets replaced with the new content. * Nest loading state inside of navigation ref Instead of replacing the navigation block after loading, only replace the inside part of it so that focus is not lost * Add coverage for focus loss on menu creation * select the navigatiom after import in an effect similar to the method used when creating a menu, this way the select block call is later and the focus is maintained * remove extraneous dependency causing err on delete newly created menus * Update test to not determine link control behavior * No need to return await inside an async function as it will always return a Promise Co-authored-by: Dave Smith <getdavemail@gmail.com> --------- Co-authored-by: Andrei Draganescu <andrei.draganescu@automattic.com> Co-authored-by: Dave Smith <getdavemail@gmail.com>
I just cherry-picked this PR to the update/packages-rc2-6.5 branch to get it included in the next release: 1d93d98 |
) * Do not focus navigation block until loading is finished When a new navigation is created, we place focus on the navigation block. If we place focus while loading is still happening, focus will be lost when focus the loading is finished and the block gets replaced with the new content. * Nest loading state inside of navigation ref Instead of replacing the navigation block after loading, only replace the inside part of it so that focus is not lost * Add coverage for focus loss on menu creation * select the navigatiom after import in an effect similar to the method used when creating a menu, this way the select block call is later and the focus is maintained * remove extraneous dependency causing err on delete newly created menus * Update test to not determine link control behavior * No need to return await inside an async function as it will always return a Promise Co-authored-by: Dave Smith <getdavemail@gmail.com> --------- Co-authored-by: Andrei Draganescu <andrei.draganescu@automattic.com> Co-authored-by: Dave Smith <getdavemail@gmail.com>
…dPress#59801) * Do not focus navigation block until loading is finished When a new navigation is created, we place focus on the navigation block. If we place focus while loading is still happening, focus will be lost when focus the loading is finished and the block gets replaced with the new content. * Nest loading state inside of navigation ref Instead of replacing the navigation block after loading, only replace the inside part of it so that focus is not lost * Add coverage for focus loss on menu creation * select the navigatiom after import in an effect similar to the method used when creating a menu, this way the select block call is later and the focus is maintained * remove extraneous dependency causing err on delete newly created menus * Update test to not determine link control behavior * No need to return await inside an async function as it will always return a Promise Co-authored-by: Dave Smith <getdavemail@gmail.com> --------- Co-authored-by: Andrei Draganescu <andrei.draganescu@automattic.com> Co-authored-by: Dave Smith <getdavemail@gmail.com>
Fixes #59771
When a new navigation is created, we place focus on the navigation block. If we place focus while loading is still happening, focus will be lost when focus the loading is finished and the block gets replaced with the new content.
Instead of replacing the entire nav HTML element, just replace the inner part of it so focus is not lost.
What?
Why?
How?
Testing Instructions