fix(tab): do not trigger focus when mounting

This commit is contained in:
Eric Liu 2021-02-05 05:35:41 -08:00
commit 7a70c1d608

View file

@ -20,16 +20,27 @@
/** Obtain a reference to the anchor HTML element */ /** Obtain a reference to the anchor HTML element */
export let ref = null; export let ref = null;
import { getContext } from "svelte"; import { onMount, afterUpdate, getContext, tick } from "svelte";
const { selectedTab, add, update, change } = getContext("Tabs"); const { selectedTab, add, update, change } = getContext("Tabs");
add({ id, label, disabled }); add({ id, label, disabled });
let didMount = false;
$: selected = $selectedTab === id; $: selected = $selectedTab === id;
$: if (selected && ref) {
ref.focus(); onMount(() => {
} tick().then(() => {
didMount = true;
});
});
afterUpdate(() => {
if (didMount && selected && ref) {
ref.focus();
}
});
</script> </script>
<li <li