fix(tab): set selected to currentIndex after updating

This commit is contained in:
Eric Liu 2020-01-11 18:39:07 -08:00
commit 62719c45cc

View file

@ -8,7 +8,7 @@
export let triggerHref = '#';
export let type = 'default';
import { createEventDispatcher, setContext } from 'svelte';
import { createEventDispatcher, afterUpdate, setContext } from 'svelte';
import { writable, derived } from 'svelte/store';
import ChevronDownGlyph from 'carbon-icons-svelte/lib/ChevronDownGlyph';
import { cx } from '../../lib';
@ -62,10 +62,14 @@
}
});
afterUpdate(() => {
selected = currentIndex;
});
$: currentIndex = selected;
$: currentTab = $tabs[currentIndex] || undefined;
$: currentContent = $content[currentIndex] || undefined;
$: {
selected = currentIndex;
dispatch('change', currentIndex);
if (currentTab) {