-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix shift+tab from post title #69520
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
Conversation
Size Change: +18 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
The e2e test I added is failing in Firefox yet testing manually in Firefox works as expected. In the e2e focus is ending up on the UPDATE: I can reproduce testing manually. It only happens when the canvas is iframed and the post is new. The "Open publish panel" button is the last tab stop in the page. It’s like Firefox is moving focus as if the active element were the |
I've discovered a few clues regarding this. It seems that the tab focus doesn't work well if the block inserter button is displayed in Firefox: 157e2275d4bc809adcac96740b3296a3.mp4But I don't know why this problem only occurs in Firefox 🤷 |
4027a79
to
c73b0c9
Compare
I figured out the issue in Firefox. It stems from two event listeners moving focus—first on Like Aki noted, this corresponds with when the default block appender button is visible, though merely because the second focus move is conditioned to happen only if no blocks are present. The solution I’ve tried in 1e40320 was to remove the second movement. From my testing the conditions where it actually happened are very rare and I haven’t yet seen what good it actually does. On the contrary it causes a focus loss in some. I have tried to figure it out by looking into the history, it’s from ac07149 which doesn’t make it obvious. It’s clearly intended for an undo related concern so that pretty much means it should not be happening from a tab navigation. An alternative to removing it would be refining the conditions so won’t interfere with tab navigation. Now the e2e I added is passing but many other tests aren’t. They seem unrelated failures and they’re passing locally. I noticed some of the recent PRs are experiencing the same. I’ll keep this drafted anyway until that’s sorted out. |
- Avoid error if focus capture elements are not present by returning early. - Support navigation from generic elements within the container, such as the post title, by removing early return for no block selection.
c73b0c9
to
1e40320
Compare
All e2e tests seem to pass now, so let's undraft it. |
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. |
This may be very rare, but I found that the focus might be lost in the following situations:
Videoe5d2dc69c56ac3acd7c6a65263a4b599.mp4If I revert 1e40320, the focus isn't lost as the writing flow wrapper gets focus (Confirm that the screen reader reads "section" when the block is deleted in the following video). Video7336d21b6c01a0eb67c8420526d28c4c.mp4Is there a another approach to solve this problem? |
I'm thinking about adding the Tab key check to the conditional statement: function onFocusOut( event ) {
// ...
if (
! event.relatedTarget &&
ownerDocument.activeElement === ownerDocument.body &&
getBlockCount() === 0 &&
event.keyCode !== TAB
) {
node.focus();
} If pressing the Tab key causes focus to be lost, it should mean the focus is moved outside of the editor, which is what should be expected. |
Thanks for testing Aki. I am glad you found this context where this logic seems suitable. I’ve pushed d057813 that restores it with an added condition that stops it from interfering with shift+tab from the post title in Firefox. Still, I want to touch on a point regarding how this worked with the logic removed.
When I test the same scenario, after deleting the last block the Aside from that, there is also another "hole" in the implementation. In Firefox, deleting a block does not cause a One more general point about this. It does not seem to belong in the tab nav hook. Tabbing never makes the block count change. So while I believe something like this is a useful idea, I feel like it should be implemented elsewhere. Additionally, I think we can do better than focus the wrapper in most cases by focusing a child (either the appender button or the post title) since one will almost always be available. This would be akin to how if you delete a single block and there is a previous sibling then focus goes to that sibling. |
Thanks for the suggestion 🙇 The catch is that since it’s a |
Flaky tests detected in c21a8b8. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13960634244
|
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.
Thanks for the detailed explanation! This PR solves the problem with a very simple approach. As far as I've tested, it all works correctly.
I think it's worth backporting into 6.8 as this PR fixes the issue that first appears in 6.8.
@stokesman Would it be ok to merge/backport this PR? It's not a big problem, so maybe we could include it in RC1 instead of Beta3. cc @Mamaduka |
Yes, let's sync this in RC1. I've already released packages for beta 3. |
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
@t-hamano, @stokesman, is this good to merge? |
As far as I can tell this is good to merge. |
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 far as I can tell this is good to merge.
@stokesman, agreed! I just left one suggestion that could be helpful in the future. Feel free to merge this at your leisure.
@@ -125,20 +124,26 @@ export default function useTabNav() { | |||
return; | |||
} | |||
|
|||
if ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) { |
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.
@stokesman, could you add a comment here about why we can remove this condition now? This is primarily for the future.
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 condition and early return when met lets focus to move, as it does innately, to the closest adjacent tab stop. Since the post title is not a block, when shift+tabbing from there it was trapping focus because:
- shift+tab moves focus to the writing flow wrapper (closest adjacent tab stop)
- a subsequent shift+tab moves focus to the focus capture element which moves it back to the post title
By removing this conditional early return, tabbing from the post title moves focus to the adjacent tab stop outside of the wrapper. Thus it avoids the sibling focus capture elements and the focus trap.
For further reference, this early return was removed in #65204 previous to this PR but that surfaced another bug #69037. It wasn’t clear that the removing the early return had been intentional so we restored it in #69079. That’s how we got here. Though I’m still not sure its prior removal was intentional.
It’s also worth nothing that prior to #65204 when the same conditional early return was there shift+tabbing from the post title worked differently. It took two steps to get outside the canvas, the first step focusing the canvas/writing flow wrapper. I didn’t figure out why/how it worked like that before and why now this same condition/return caused trapping of focus.
It occurred to me that this seems it could change behavior for consumers but it’s been shipping that way in Gutenberg for some time so perhaps it’s fine. The scenario in which I'm thinking of would be a consumer that’s adding some tabbable elements as children of I'm unaware of consumers for which this would be applicable. I did get concerned about WooCommerce because I know their beta product editor uses the canvas and has various tabbable elements in it. I tested that out and it looks like they are always wrapped in blocks so nothing should change. Nor did I find any changes from my quick testing. |
That's interesting. I was testing that behavior on WP 6.7, and it seems broken.
I think this is a good improvement, so let's go with this fix in WP 6.8. |
In my experience as well, I have never heard of a plugin that injects such elements. I think it’s safe to merge this PR and backport it to 6.8. |
I also think this is an improvement and should be safe. Thanks for the reviews and consideration.
Yes, that particular scenario is confusing. I think it’d be nice to follow up on that and see if we can make the tab order match the visual order. The "Add block" button appears to be after the paragraph but it’s in a popover that precedes the entire canvas. |
* Add e2e test for shift+tab * Fix tab nav hook - Avoid error if focus capture elements are not present by returning early. - Support navigation from generic elements within the container, such as the post title, by removing early return for no block selection. * Rename ref * Reduce changes; remove condition for container having focus * Don’t move focus to writing flow wrapper on focus out * Do move focus to writing flow wrapper if target is block * Move check for focus capture elements after check for tab key * Simplify e2e test * Use a better locator in e2e test Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> --------- Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: afercia <afercia@git.wordpress.org>
I just cherry-picked this PR to the wp/6.8 branch to get it included in the next release: 4b49562 |
* Add e2e test for shift+tab * Fix tab nav hook - Avoid error if focus capture elements are not present by returning early. - Support navigation from generic elements within the container, such as the post title, by removing early return for no block selection. * Rename ref * Reduce changes; remove condition for container having focus * Don’t move focus to writing flow wrapper on focus out * Do move focus to writing flow wrapper if target is block * Move check for focus capture elements after check for tab key * Simplify e2e test * Use a better locator in e2e test Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> --------- Co-authored-by: stokesman <presstoke@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: afercia <afercia@git.wordpress.org>
What?
Closes #69486
Enables shift+tab from the post title (in "post-only" mode) to navigate to the preceding tab stop as expected.
Why?
The inability to navigate to the previous tab stop from the post title breaks keyboard use and is a regression since WP 6.7.
How?
Testing Instructions
E2E test
git switch -
)Testing Instructions for Keyboard
General testing of tab navigation