Skip to content

CodeQuality: Tab List: Remove the unused tabIndex context from the tab buttons - #86432

Merged
hbhalodia merged 2 commits into
WordPress:trunkfrom
hbhalodia:fix/tabs-improve-dead-code
Nov 6, 2026
Merged

hbhalodia merged 2 commits into
WordPress:trunkfrom
hbhalodia:fix/tabs-improve-dead-code

Conversation

@hbhalodia

Copy link
Copy Markdown
Contributor

I have not created the issue for the same because of a quick CodeQuality update

What?

Follow-up to #77439

Removes the data-wp-context='{"tabIndex":N}' directive that the Tab List render callback adds to each tab button.

Why?

Nothing reads it. view.js only reads tabsId and activeTabIndex from the context, and the state.tabIndex getter works out a tab's index from the button's id instead. The context is a leftover from the restructure that removed the core/tab block in #77439.

How?

  • Removes the set_attribute( 'data-wp-context', … ) call from block_core_tab_list_render_callback(), and the mention of it in the function's docblock.
  • Behaviour doesn't change. When a tab is activated, setActiveTab writes activeTabIndex through the button's context. The button's own context never had that key, so the Interactivity API already wrote it to the Tabs block's context (proxies/context.ts). Without a button context, getContext() returns the Tabs block's context directly.

Tab Panel's core/tab-label context is also unused in core since #77439, but it's left in place. Block context is a public API, documented in the Tab Panel README, and blocks from other plugins inside a tab panel may read it.

Testing Instructions

  1. Create a post with a Tabs block that has three tabs, with a paragraph in each panel. Save and view the post.
  2. View the page source. The tab buttons no longer have a data-wp-context attribute.
  3. Click each tab. Each one opens its panel.
  4. Use the Arrow, Home and End keys on the tabs, then press Enter or Space. Focus moves between the tabs, and the focused tab opens.
  5. Add an HTML anchor to a block inside the second panel and open the post URL with that anchor. The second tab opens.
  6. Run the tests: npm run test:e2e -- editor/blocks/tabs.spec.js

Testing Instructions for Keyboard

Step 4 covers the keyboard: reach the tabs with Tab, then use the Arrow, Home and End keys, and Enter or Space.

Use of AI Tools

I used Claude Code (Claude Opus 5.5) to check that the context is unused and to draft the change and this description. I reviewed and tested the changes myself.

@hbhalodia
hbhalodia requested a balanced review from Copilot November 6, 2026 12:08
@hbhalodia hbhalodia self-assigned this Nov 6, 2026
@hbhalodia hbhalodia added [Type] Code Quality Issues or PRs that relate to code quality [Package] Block library /packages/block-library [Block] Tabs Affects the Tabs Block labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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: hbhalodia <hbhalodia@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

Copilot AI 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.

🟢 Approval recommended

No active review issues are recorded for the unused tab-button context removal and related docblock update.

No open issues 🎉

What changed in this PR

Removes unused per-button Interactivity API context from the Tab List render callback, cleaning up a leftover from the Tab block removal in #77439.

Changes:

  • Removes the data-wp-context attribute containing tabIndex from tab buttons.
  • Updates the callback’s docblock to match the remaining attributes.
File Description
packages/​block-library/​src/​tab-list/​index.php Removes unused button context and updates the docblock.

Review effort: Balanced

@hbhalodia
hbhalodia requested a review from t-hamano November 6, 2026 12:10
@hbhalodia

Copy link
Copy Markdown
Contributor Author

Hi @t-hamano, Sorry for the ping and much of the PRs to review 😅.

Can you check the small code quality improvement for this. It's a dead code present in tabs block. Details present in PR description.

@t-hamano t-hamano 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.

👍

@hbhalodia
hbhalodia enabled auto-merge (squash) November 6, 2026 12:32
@hbhalodia
hbhalodia merged commit e65bd0d into WordPress:trunk Nov 6, 2026
97 of 99 checks passed
@hbhalodia
hbhalodia deleted the fix/tabs-improve-dead-code branch November 6, 2026 12:57
@github-actions github-actions Bot added this to the Gutenberg 24.5 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Tabs Affects the Tabs Block [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants