fix(tabs): set selectedIndex only if differ from previous selectedIndex
This commit is contained in:
parent
c3f7555c73
commit
db96e8cc07
3 changed files with 17 additions and 0 deletions
5
.changeset/small-pumpkins-peel.md
Normal file
5
.changeset/small-pumpkins-peel.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/ui': patch
|
||||
---
|
||||
|
||||
fix(tabs): set selectedIndex only if value differ from previous value
|
||||
|
|
@ -356,7 +356,11 @@ export class LionTabs extends LitElement {
|
|||
* @param {number} value The new index
|
||||
*/
|
||||
set selectedIndex(value) {
|
||||
if (value === this.__selectedIndex) {
|
||||
return;
|
||||
}
|
||||
const stale = this.__selectedIndex;
|
||||
/** @type {number | undefined} */
|
||||
this.__selectedIndex = value;
|
||||
this.__updateSelected(false);
|
||||
this.dispatchEvent(new Event('selected-changed'));
|
||||
|
|
|
|||
|
|
@ -75,6 +75,14 @@ describe('<lion-tabs>', () => {
|
|||
expect(spy).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not send event "selected-changed" after selecting currently selected tab', async () => {
|
||||
const el = /** @type {LionTabs} */ (await fixture(basicTabs));
|
||||
const spy = sinon.spy();
|
||||
el.addEventListener('selected-changed', spy);
|
||||
el.selectedIndex = 0;
|
||||
expect(spy).not.to.have.been.called;
|
||||
});
|
||||
|
||||
it('logs warning if unequal amount of tabs and panels', async () => {
|
||||
const stub = sinon.stub(console, 'warn');
|
||||
await fixture(html`
|
||||
|
|
|
|||
Loading…
Reference in a new issue