Skip to content

Writing Flow: restore early return for no block selection in tab nav hook#69079

Merged
stokesman merged 3 commits into
WordPress:trunkfrom
Mayank-Tripathi32:try/fix-69037-focus-ts-error
Feb 11, 2025
Merged

Writing Flow: restore early return for no block selection in tab nav hook#69079
stokesman merged 3 commits into
WordPress:trunkfrom
Mayank-Tripathi32:try/fix-69037-focus-ts-error

Conversation

@Mayank-Tripathi32

@Mayank-Tripathi32 Mayank-Tripathi32 commented Feb 6, 2025

Copy link
Copy Markdown
Member

What?

Closes #69037
Fixes tab navigation error in Site Editor preview frame

Why?

Tab navigation from preview frame causes console errors after #65204 removed an early return condition. Issue doesn't exist in WP 6.7.1 without Gutenberg.

How?

Restores early return in useTabNav hook:

if (event.defaultPrevented || (!hasMultiSelection() && !getSelectedBlockClientId())) {
    return;
}

This prevents unnecessary processing when no selection exists, fixing the error while maintaining functionality.

Testing Instructions

  • Open Site Editor
  • Tab through UI until preview frame is focused
  • Tab forward/backward from preview frame
  • Verify no console errors appear

Testing Instructions for Keyboard

  • Open Site Editor
  • Use Tab key to navigate through interface elements
  • When preview frame is focused (visible focus outline), press Tab and Shift+Tab
  • Verify seamless navigation without console errors
  • Confirm focus moves correctly to next/previous UI elements

ScreenCast

Test.Focus.mov

@Mayank-Tripathi32 Mayank-Tripathi32 marked this pull request as ready for review February 6, 2025 12:57
@github-actions

github-actions Bot commented Feb 6, 2025

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: stokesman <presstoke@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: singhakanshu00 <akanshusingh@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@stokesman stokesman added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels Feb 8, 2025
@Mayank-Tripathi32

Copy link
Copy Markdown
Member Author

Failing test seems irrelevant to changes as both failed with status exit

@stokesman stokesman changed the title Fixed nonfatal error tabbing away from preview frame in Site Editor Writing Flow: restore early return for no block selection in tab nav hook Feb 11, 2025

@stokesman stokesman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good to me. This rest of this comment is for easier reference and explanation. The early return was removed here. This restores it though moves it to an even earlier location. It’s new location should be inconsequential to the result of the hook. The only concern that I could imagine would be a potential micro-optimization. If it were placed after the other condition for early return that tests for the Tab key. That one might be a lighter test and if so should run first. I doubt it would make any significant difference but I wanted to be thorough in noting what’s different.

@t-hamano

Copy link
Copy Markdown
Contributor

The only concern that I could imagine would be a potential micro-optimization. If it were placed after the other condition for early return that tests for the Tab key.

Do we want to try this? If we follow the original process, it should look like this:

if ( event.keyCode !== TAB ) {
	return;
}

const isShift = event.shiftKey;
const direction = isShift ? 'findPrevious' : 'findNext';

if ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {
	return;
}

const nextTabbable = focus.tabbable[ direction ]( event.target );

@stokesman

Copy link
Copy Markdown
Contributor

Do we want to try this? If we follow the original process, it should look like this:

Your example is true to the prior execution. My nitpick with that would be that the early return we are restoring should go before the isShift and direction assignments since they could go unused. That was small bother for me with the prior code.

if ( event.keyCode !== TAB ) {
	return;
}

if ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {
	return;
}

const isShift = event.shiftKey;
const direction = isShift ? 'findPrevious' : 'findNext';
const nextTabbable = focus.tabbable[ direction ]( event.target );

@Mayank-Tripathi32

Copy link
Copy Markdown
Member Author

Do we want to try this? If we follow the original process, it should look like this:

if ( event.keyCode !== TAB ) {
	return;
}

if ( ! hasMultiSelection() && ! getSelectedBlockClientId() ) {
	return;
}

const isShift = event.shiftKey;
const direction = isShift ? 'findPrevious' : 'findNext';
const nextTabbable = focus.tabbable[ direction ]( event.target );

This seems to work perfectly, should we go ahead with this?

@t-hamano

Copy link
Copy Markdown
Contributor

@Mayank-Tripathi32 Let's give it a try.

@stokesman stokesman merged commit dc40184 into WordPress:trunk Feb 11, 2025
@github-actions github-actions Bot added this to the Gutenberg 20.3 milestone Feb 11, 2025
Kallyan01 pushed a commit to Kallyan01/gutenberg that referenced this pull request Feb 24, 2025
…hook (WordPress#69079)

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: stokesman <presstoke@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: singhakanshu00 <akanshusingh@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…hook (WordPress#69079)

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: stokesman <presstoke@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: singhakanshu00 <akanshusingh@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nonfatal error tabbing away from preview frame in Site Editor

3 participants