Skip to content

Commit

Permalink
fix(tabs): set selectedIndex only if differ from previous selectedIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
gyulus3 authored Dec 1, 2023
1 parent c3f7555 commit db96e8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-pumpkins-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lion/ui': patch
---

fix(tabs): set selectedIndex only if value differ from previous value
4 changes: 4 additions & 0 deletions packages/ui/components/tabs/src/LionTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
8 changes: 8 additions & 0 deletions packages/ui/components/tabs/test/lion-tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit db96e8c

Please sign in to comment.