From 70c68d00fe2b068bed0930682230c1de3f81d62e Mon Sep 17 00:00:00 2001 From: Ryan Gossiaux Date: Tue, 28 Dec 2021 16:51:36 -1000 Subject: [PATCH] Tab: fix aria-controls When porting, I thought I was being clever by just using ids instead of refs in $api.panels But I didn't notice that the refs let you distinguish those panels which are rendered from those which are not. My implementation had aria-controls= set for all tabs, even when their panels were not in the DOM. --- src/lib/components/tabs/Tab.svelte | 3 ++- src/lib/components/tabs/TabGroup.svelte | 10 +++++++--- src/lib/components/tabs/TabPanel.svelte | 11 ++++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/components/tabs/Tab.svelte b/src/lib/components/tabs/Tab.svelte index 7f49012..8f59897 100644 --- a/src/lib/components/tabs/Tab.svelte +++ b/src/lib/components/tabs/Tab.svelte @@ -87,11 +87,12 @@ $api.setSelectedIndex(myIndex); } + $: myPanelRef = $api.panels[myIndex]?.ref; $: propsWeControl = { id, role: "tab", type: resolveButtonType({ type: $$props.type, as }, tabRef), - "aria-controls": $api.panels[myIndex], + "aria-controls": $myPanelRef ? $api.panels[myIndex]?.id : undefined, "aria-selected": selected, tabIndex: selected ? 0 : -1, disabled: disabled ? true : undefined, diff --git a/src/lib/components/tabs/TabGroup.svelte b/src/lib/components/tabs/TabGroup.svelte index 6ab0014..d91beb2 100644 --- a/src/lib/components/tabs/TabGroup.svelte +++ b/src/lib/components/tabs/TabGroup.svelte @@ -1,4 +1,8 @@