fix(tabs): selected tab should not steal focus if updated programmatically (#1320)

Fixes #572
This commit is contained in:
metonym 2022-05-29 10:12:55 -07:00 committed by GitHub
commit 0f621c2545
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 17 deletions

View file

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