mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
fix(tabs): selected tab should not steal focus if updated programmatically (#1320)
Fixes #572
This commit is contained in:
parent
0801e1d078
commit
0f621c2545
2 changed files with 11 additions and 17 deletions
|
@ -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 -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue