fix(tabs): allow initialization without children

This commit is contained in:
Thijs Louisse 2022-03-21 21:43:20 +01:00 committed by Thijs Louisse
parent 0b5ed48e74
commit 03c294c9ea
3 changed files with 11 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/tabs': patch
---
tabs: allow to be initialized withhout children

View file

@ -164,7 +164,7 @@ export class LionTabs extends LitElement {
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);
this.__setupSlots();
if (this.tabs[0].disabled) {
if (this.tabs[0]?.disabled) {
this.selectedIndex = this.tabs.findIndex(tab => !tab.disabled);
}
}

View file

@ -112,6 +112,11 @@ describe('<lion-tabs>', () => {
);
expect(selectedTab.textContent).to.equal('tab 2');
});
it('can initially be instantiated without children', async () => {
const el = /** @type {LionTabs} */ (await fixture(html` <lion-tabs> </lion-tabs> `));
expect(el.tabs).to.eql([]);
});
});
describe('Tabs ([slot=tab])', () => {