Skip to content

Commit

Permalink
fix broken tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Jan 19, 2022
1 parent 557d973 commit 955d3f9
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/components/tab-group/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}

Expand Down Expand Up @@ -232,35 +232,32 @@ 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)) {
scrollIntoView(this.activeTab, this.nav, 'horizontal', options.scrollBehavior);
}

// 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 } });
}
}
Expand Down

0 comments on commit 955d3f9

Please sign in to comment.