From 955d3f9dd52940536c566678a3cf915fe5c401aa Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Wed, 19 Jan 2022 10:01:22 -0500 Subject: [PATCH] fix broken tabs --- src/components/tab-group/tab-group.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/tab-group/tab-group.ts b/src/components/tab-group/tab-group.ts index 973101be6..c14f44a90 100644 --- a/src/components/tab-group/tab-group.ts +++ b/src/components/tab-group/tab-group.ts @@ -124,7 +124,7 @@ export default class SlTabGroup extends LitElement { return [...(slot.assignedElements() as SlTab[])].filter(el => { return includeDisabled ? el.tagName.toLowerCase() === 'sl-tab' - : el.tagName.toLowerCase() === 'sl-tab' && el.disabled; + : el.tagName.toLowerCase() === 'sl-tab' && !el.disabled; }); } @@ -232,24 +232,20 @@ export default class SlTabGroup extends LitElement { } } - setActiveTab(tab: SlTab | undefined, options?: { emitEvents?: boolean; scrollBehavior?: 'auto' | 'smooth' }) { + setActiveTab(tab: SlTab, options?: { emitEvents?: boolean; scrollBehavior?: 'auto' | 'smooth' }) { options = { emitEvents: true, scrollBehavior: 'auto', ...options }; - if (tab && tab !== this.activeTab && !tab.disabled) { + if (tab !== this.activeTab && !tab.disabled) { const previousTab = this.activeTab; this.activeTab = tab; // Sync active tab and panel - this.tabs.forEach(el => { - el.active = el === this.activeTab; - }); - this.panels.forEach(el => { - el.active = el.name === tab.panel; - }); + this.tabs.map(el => (el.active = el === this.activeTab)); + this.panels.map(el => (el.active = el.name === this.activeTab?.panel)); this.syncIndicator(); if (['top', 'bottom'].includes(this.placement)) { @@ -257,10 +253,11 @@ export default class SlTabGroup extends LitElement { } // Emit events - if (options.emitEvents === true) { + if (options.emitEvents) { if (previousTab) { emit(this, 'sl-tab-hide', { detail: { name: previousTab.panel } }); } + emit(this, 'sl-tab-show', { detail: { name: this.activeTab.panel } }); } }