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: override tablist's tabindex only when necessary #66209

Merged
merged 3 commits into from
Oct 17, 2024

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Oct 17, 2024

What?

Extracted from #66097 (comment)

This PR tweaks the Tabs.Tablist component so that the element's tabbability is primarily controlled by ariakit

Why?

Currently the tablist element has a fixed tabIndex={-1}, which is in place to prevent browsers from focussing the tablist when it's a scroll container — we want to opt out from it since the component knows how to handle keyboard scrolling without interference from the browser.

But this override is a bit too invasive and prevents ariakit from setting tabindex={0} when the selected tab id is null — in that case, in fact, the tablist is meant to be tabbable.

How?

Tweak the tablist code, giving priority to ariakit's tabIndex value and only setting tabIndex={-1} if a value from ariakit is not provided.

Testing Instructions

  • set up a controlled Tab component
  • set selectedTabId to null
  • make sure that no tabs are selected, no tab panels are shown
  • press tab — make sure that the tablist receives focus, and that pressing arrow keys correctly selects tabs in the tablist

@ciampo ciampo self-assigned this Oct 17, 2024
@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components labels Oct 17, 2024
@ciampo ciampo requested a review from a team October 17, 2024 14:17
Copy link

github-actions bot commented Oct 17, 2024

Flaky tests detected in 7619679.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11386979837
📝 Reported issues:

@ciampo ciampo changed the title Tabs: override tablist tabinxed only when necessary Tabs: override tablist's tabindex only when necessary Oct 17, 2024
@ciampo ciampo marked this pull request as ready for review October 17, 2024 14:24
Copy link

github-actions bot commented Oct 17, 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.

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: ciampo <[email protected]>
Co-authored-by: tyxla <[email protected]>

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

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Makes sense and tests as expected 👍 🚀

Might need to tweak a bit if #66208 lands first.

packages/components/src/tabs/tablist.tsx Outdated Show resolved Hide resolved
@ciampo ciampo enabled auto-merge (squash) October 17, 2024 16:29
@ciampo ciampo merged commit b8cd03d into trunk Oct 17, 2024
63 checks passed
@ciampo ciampo deleted the fix/tabs-tablist-tabindex branch October 17, 2024 17:05
@github-actions github-actions bot added this to the Gutenberg 19.6 milestone Oct 17, 2024
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 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