Fix: Tabs dispatch change event on init (#882)

* fix tabs on change problem

* fix(tabs): dispatch change event in update/change context methods

Co-authored-by: metonym <ericyl.us@gmail.com>
This commit is contained in:
Daniel Miedzik 2021-11-18 16:45:47 +01:00 committed by GitHub
commit 9bbc7698a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,7 @@
}, },
update: (id) => { update: (id) => {
currentIndex = $tabsById[id].index; currentIndex = $tabsById[id].index;
dispatch("change", currentIndex);
}, },
change: (direction) => { change: (direction) => {
let index = currentIndex + direction; let index = currentIndex + direction;
@ -77,6 +78,7 @@
} }
currentIndex = index; currentIndex = index;
dispatch("change", currentIndex);
}, },
}); });
@ -91,8 +93,6 @@
$: currentTab = $tabs[currentIndex] || undefined; $: currentTab = $tabs[currentIndex] || undefined;
$: currentContent = $content[currentIndex] || undefined; $: currentContent = $content[currentIndex] || undefined;
$: { $: {
dispatch("change", currentIndex);
if (currentTab) { if (currentTab) {
selectedTab.set(currentTab.id); selectedTab.set(currentTab.id);
} }