fix broken tabs

This commit is contained in:
Cory LaViska
2022-01-19 10:01:22 -05:00
parent 557d973ba4
commit 955d3f9dd5

View File

@@ -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 } });
}
}