Skip to content

Commit fdf25d1

Browse files
committed
fix: tabs dispatch event when changing tab
1 parent 2ef2597 commit fdf25d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/block/tabs/frontend-tabs.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ class _StackableTabs {
127127
} )
128128

129129
this.activeTab = tabIndex
130+
131+
// Dispatch an event when the tab is changed
132+
this.parentEl.dispatchEvent( new CustomEvent( 'stackable-tabs-change', {
133+
detail: {
134+
element: this.parentEl,
135+
activeTab: tabIndex,
136+
},
137+
} ) )
130138
}
131139

132140
initWindowEventListeners = () => {
@@ -157,7 +165,8 @@ class StackableTabs {
157165
document.querySelectorAll( '.stk-block-tabs' )
158166
.forEach( el => {
159167
if ( ! el._StackableHasInitTabs ) {
160-
new _StackableTabs( el )
168+
const tabs = new _StackableTabs( el )
169+
el.tabs = tabs
161170
el._StackableHasInitTabs = true
162171
}
163172
} )

0 commit comments

Comments
 (0)