From f89666cb3eb6b481c7ea212fd5c9a058b2295fbc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 4 Nov 2026 11:00:30 +0000 Subject: [PATCH 1/2] Fix nested Tabs switching the wrong panels 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 --- e2e/tests/frontend-interactive.spec.ts | 108 ++++++++++++++++++++++++- readme.txt | 1 + src/block/tabs/frontend-tabs.js | 13 ++- 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/e2e/tests/frontend-interactive.spec.ts b/e2e/tests/frontend-interactive.spec.ts index 1bd5c38550..a3134f37da 100644 --- a/e2e/tests/frontend-interactive.spec.ts +++ b/e2e/tests/frontend-interactive.spec.ts @@ -1,5 +1,9 @@ -import { test, expect } from 'e2e/test-utils' -import { publishAndVisitFrontend, getEditorPostId } from 'e2e/test-utils' +import { + test, + expect, + publishAndVisitFrontend, + getEditorPostId, +} from 'e2e/test-utils' const pickDefaultLayoutIfPresent = async editor => { const picker = editor.canvas.locator( '.stk-variation-picker' ) @@ -117,6 +121,106 @@ test.describe( 'Interactive frontend', () => { await expect( tabButtons.nth( 1 ) ).toHaveAttribute( 'aria-selected', 'true' ) } ) + test( 'Nested tabs with labels below switch their own panels', async ( { + page, editor, requestUtils, admin, + } ) => { + const tabPanel = { customAttributes: [ [ 'role', 'tabpanel' ] ] } + + await editor.insertBlock( { + name: 'stackable/tabs', + innerBlocks: [ + { + name: 'stackable/tab-content', + innerBlocks: [ + { + name: 'stackable/column', + attributes: tabPanel, + innerBlocks: [ + { + name: 'stackable/tabs', + innerBlocks: [ + { + name: 'stackable/tab-labels', + attributes: { + tabLabels: [ + { label: 'Inner 1', icon: '' }, + { label: 'Inner 2', icon: '' }, + ], + }, + }, + { + name: 'stackable/tab-content', + innerBlocks: [ + { + name: 'stackable/column', + attributes: tabPanel, + innerBlocks: [ { + name: 'stackable/heading', + attributes: { text: 'Inner panel 1' }, + } ], + }, + { + name: 'stackable/column', + attributes: tabPanel, + innerBlocks: [ { + name: 'stackable/heading', + attributes: { text: 'Inner panel 2' }, + } ], + }, + ], + }, + ], + }, + ], + }, + { + name: 'stackable/column', + attributes: tabPanel, + innerBlocks: [ { + name: 'stackable/heading', + attributes: { text: 'Outer panel 2' }, + } ], + }, + ], + }, + { + name: 'stackable/tab-labels', + attributes: { + tabLabels: [ + { label: 'Outer 1', icon: '' }, + { label: 'Outer 2', icon: '' }, + ], + }, + }, + ], + } ) + + await expect( editor.canvas.getByText( 'Inner panel 1' ) ).toBeVisible() + await expect( editor.canvas.getByText( 'Outer 2' ) ).toBeVisible() + + await publishAndVisitFrontend( page, editor, requestUtils, admin ) + + const innerPanel1 = page.getByText( 'Inner panel 1' ) + const innerPanel2 = page.getByText( 'Inner panel 2' ) + const outerPanel2 = page.getByText( 'Outer panel 2' ) + + await expect( page.getByRole( 'tab', { name: 'Inner 1' } ) ).toBeVisible() + await expect( innerPanel1 ).toBeVisible() + await expect( innerPanel2 ).toBeHidden() + await expect( outerPanel2 ).toBeHidden() + + await page.getByRole( 'tab', { name: 'Inner 2' } ).click() + await expect( page.getByRole( 'tab', { name: 'Inner 2' } ) ).toHaveAttribute( 'aria-selected', 'true' ) + await expect( page.getByRole( 'tab', { name: 'Outer 1' } ) ).toHaveAttribute( 'aria-selected', 'true' ) + await expect( innerPanel2 ).toBeVisible() + await expect( innerPanel1 ).toBeHidden() + await expect( outerPanel2 ).toBeHidden() + + await page.getByRole( 'tab', { name: 'Outer 2' } ).click() + await expect( page.getByRole( 'tab', { name: 'Outer 2' } ) ).toHaveAttribute( 'aria-selected', 'true' ) + await expect( outerPanel2 ).toBeVisible() + } ) + test( 'Carousel next control changes the slide', async ( { page, editor, requestUtils, admin, } ) => { diff --git a/readme.txt b/readme.txt index 97b6b689d0..3d4053a102 100644 --- a/readme.txt +++ b/readme.txt @@ -317,6 +317,7 @@ Nope. Stackable only works with Gutenberg, the new WordPress editor. * Fixed: Hero block - content alignment now applies to the whole block #3739 * Fixed: Design Library - opens when Show Template is enabled #3737 * Fixed: Timeline block - text alignment works on tablet and mobile #3738 +* Fixed: Tabs block - nested tabs with labels below now switch the correct tab #3372 = 3.20.2 = diff --git a/src/block/tabs/frontend-tabs.js b/src/block/tabs/frontend-tabs.js index c4e1077458..e8aa801741 100644 --- a/src/block/tabs/frontend-tabs.js +++ b/src/block/tabs/frontend-tabs.js @@ -16,13 +16,20 @@ class _StackableTabs { getDefaultState = () => { this.activeTab = parseInt( this.parentEl.getAttribute( 'data-initial-tab' ) || '1', 10 ) - this.tabList = this.parentEl.querySelector( '[role="tablist"]' ) - this.tabs = this.parentEl.querySelector( '.stk-block-tab-labels__wrapper' ).children - this.contents = this.parentEl.querySelector( '.stk-block-tab-content > .stk-inner-blocks' ).children + this.tabList = this.getOwnElement( '[role="tablist"]' ) + this.tabs = this.getOwnElement( '.stk-block-tab-labels__wrapper' ).children + this.contents = this.getOwnElement( '.stk-block-tab-content > .stk-inner-blocks' ).children this.customTabAnchors = {} } + // Nested Tabs blocks also match descendant selectors. Keep the first + // element whose closest Tabs block is this instance. + getOwnElement = selector => { + return Array.from( this.parentEl.querySelectorAll( selector ) ) + .find( el => el.closest( '.stk-block-tabs' ) === this.parentEl ) + } + initTabs = () => { const tabAnchors = [] // Set Aria attributes From d991112391f0517049eb76fc33ec4d40866086a0 Mon Sep 17 00:00:00 2001 From: Benjamin Intal Date: Thu, 12 Nov 2026 17:39:59 +0800 Subject: [PATCH 2/2] Apply suggestion from @bfintal --- readme.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/readme.txt b/readme.txt index 3d4053a102..97b6b689d0 100644 --- a/readme.txt +++ b/readme.txt @@ -317,7 +317,6 @@ Nope. Stackable only works with Gutenberg, the new WordPress editor. * Fixed: Hero block - content alignment now applies to the whole block #3739 * Fixed: Design Library - opens when Show Template is enabled #3737 * Fixed: Timeline block - text alignment works on tablet and mobile #3738 -* Fixed: Tabs block - nested tabs with labels below now switch the correct tab #3372 = 3.20.2 =