fix(tabs): dispatch "change" event only if index has changed (#1279)

Fixes #1278
This commit is contained in:
metonym 2022-05-02 20:48:59 -07:00 committed by GitHub
commit 9911764df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,7 +52,6 @@
},
update: (id) => {
currentIndex = $tabsById[id].index;
dispatch("change", currentIndex);
},
change: (direction) => {
let index = currentIndex + direction;
@ -78,16 +77,22 @@
}
currentIndex = index;
dispatch("change", currentIndex);
},
});
afterUpdate(() => {
selected = currentIndex;
if (prevIndex > -1 && prevIndex !== currentIndex) {
dispatch("change", currentIndex);
}
prevIndex = currentIndex;
});
let dropdownHidden = true;
let currentIndex = selected;
let prevIndex = -1;
$: currentIndex = selected;
$: currentTab = $tabs[currentIndex] || undefined;