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

Tabs: delay activeId updates until focus can be properly detected #58625

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

chad1008
Copy link
Contributor

@chad1008 chad1008 commented Feb 2, 2024

What?

Make sure the Tabs component doesn't update its internal activeId too early.

Why?

Tabs uses Ariakit internally, which uses an activeId property to track focus internally. In certain situations, it's possible for that internal focus to become out of sync with actual browser focus, so we update it accordingly to ensure arrow key behavior works as expected.

In some cases, such as #56959, the browser focus value doesn't update quickly enough, and our internal syncing efforts lead to arrow keys not working at all, which is obviously not the desired outcome. This PR addresses such cases by delaying the update.

How?

Wrapping our existing logic in requestAnimationFrame() allows enough time to make sure the currently focused ID has finished updating before we check for a mismatch and update our internal focus value.

Testing Instructions

  1. First check out Implement Tabs in site-editor settings #56959, as that PR demonstrates the issue we're solving the most clearly.
  2. Open a template in the Site Editor
  3. Click on the Template tab in the editor setting sidebar
  4. Press RightArrow several times. Notice that focus does not move over to the Block tab as it should.
  5. Check out this PR, and rebase it off of the branch from the site-editor PR you checked out in a previous step.
  6. Refresh the site editor and repeat the test above.
  7. Confirm that focus now follows arrow key presses as expected.

@chad1008 chad1008 added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Feb 2, 2024
@chad1008 chad1008 requested a review from a team February 2, 2024 16:40
@chad1008 chad1008 self-assigned this Feb 2, 2024
@chad1008 chad1008 requested a review from ajitbohra as a code owner February 2, 2024 16:40
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

🚀

Copy link

github-actions bot commented Feb 2, 2024

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.

Core SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: shireling, mciampini.

GitHub Merge commits

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: chad1008 <shireling@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

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

@chad1008 chad1008 enabled auto-merge (squash) February 2, 2024 17:07
@chad1008 chad1008 merged commit b550b13 into trunk Feb 2, 2024
58 checks passed
@chad1008 chad1008 deleted the fix/tabs-animation-frame branch February 2, 2024 17:20
@github-actions github-actions bot added this to the Gutenberg 17.7 milestone Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants