Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 104 additions & 1 deletion e2e/tests/frontend-interactive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
test, expect, publishAndVisitFrontend, getEditorPostId,
test,
expect,
publishAndVisitFrontend,
getEditorPostId,
} from 'e2e/test-utils'

const pickDefaultLayoutIfPresent = async editor => {
Expand Down Expand Up @@ -118,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,
} ) => {
Expand Down
13 changes: 10 additions & 3 deletions src/block/tabs/frontend-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading