diff --git a/src/components/ContentSwitcher/Switch.svelte b/src/components/ContentSwitcher/Switch.svelte index bc3c7f7b..f88314b3 100644 --- a/src/components/ContentSwitcher/Switch.svelte +++ b/src/components/ContentSwitcher/Switch.svelte @@ -6,8 +6,8 @@ export let disabled = false; export let style = undefined; + import { afterUpdate, getContext } from 'svelte'; import { cx } from '../../lib'; - import { getContext } from 'svelte'; const id = Math.random(); const { currentId, add, update, change } = getContext('ContentSwitcher'); @@ -16,10 +16,13 @@ add({ id, text, selected }); + afterUpdate(() => { + if (selected) { + buttonRef.focus(); + } + }); + $: selected = $currentId === id; - $: if (selected && buttonRef) { - buttonRef.focus(); - }