Repository navigation
Fix nested Tabs switching the wrong panels - #3776
Conversation
When a Tabs block sat inside another Tabs block with the outer labels below the content, the frontend script bound click handlers to the first matching labels in the DOM. Those belonged to the inner block. Scope queries to elements whose closest Tabs block is this instance. Fixes #3372 Quality-gated: risk=low; ship=ready. Co-authored-by: Benjamin Intal <bfintal@users.noreply.github.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🤖 Pull request artifacts
|
|
Size Change: +13 B (0%) Total Size: 2.65 MB 📦 View Changed
ℹ️ View Unchanged
|
Triage
Reviewer action
Caution
None.
What was wrong
On the live page, a Tabs block inside another Tabs block could switch the wrong tabs.
This showed up when the outer block's labels were placed below its content. Clicking an inner tab label switched the outer tab instead. Clicking an outer tab label did nothing.
The editor was fine. Only the frontend view script was wrong.
Fixes #3372
Cause
src/block/tabs/frontend-tabs.jslooked up labels and panels withparentEl.querySelector(...).querySelectorreturns the first match anywhere inside the block. When the outer labels sit below the content, the inner Tabs block comes first in the HTML. The outer script then:A single Tabs block (no nesting) still found its own labels first, so that path looked fine.
Fix
Each Tabs instance now keeps only the labels, tablist, and panels whose closest
.stk-block-tabsancestor is that instance.Saved block HTML is unchanged. No deprecation is needed.
Effect on existing sites
How it was tested
Nested tabs with labels below switch their own panelsTabs switch panelse2e still passeswp-scripts lint-jsonsrc/block/tabs/frontend-tabs.jspassedIntent
Fix frontend nested Tabs so clicking a label switches that block's own panels, especially when the outer labels sit below the content. Do not change saved markup or non-nested Tabs behavior.
Diff scope
Fixed point:
origin/develop→ this PRKey files:
src/block/tabs/frontend-tabs.jse2e/tests/frontend-interactive.spec.tsreadme.txt(changelog)Quality gate findings
Notable findings
None.
Verification
CI=1 npm run test:unit→ pass (14 suites / 98 tests).npx playwright test e2e/tests/frontend-interactive.spec.ts -g "Tabs"→ 2 passed. PHP unit skipped (no PHP change).npx wp-scripts lint-js src/block/tabs/frontend-tabs.js→ passGate fix set
e2e/test-utilsimports in the spec file.Merge checklist
Summary by CodeRabbit