From ce523b316bdd781eecb85e65a33801fbf109f38e Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 10 May 2023 19:00:19 +0100 Subject: [PATCH 1/4] feat: accessible tab kbd navigation --- src/lib/components/tab.svelte | 67 +++++++++++++++++++++++++++++++++-- src/lib/helpers/style.ts | 16 +++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/lib/helpers/style.ts diff --git a/src/lib/components/tab.svelte b/src/lib/components/tab.svelte index 246d9db0d1..db46fb6b2c 100644 --- a/src/lib/components/tab.svelte +++ b/src/lib/components/tab.svelte @@ -1,5 +1,6 @@
  • {#if href} - + {:else} @@ -22,7 +82,10 @@ class="tabs-button" class:is-selected={selected} on:click|preventDefault - on:click={track}> + on:click={track} + tabindex={selected ? 0 : -1} + on:keydown={handleKeyDown} + role="tab"> {/if} diff --git a/src/lib/helpers/style.ts b/src/lib/helpers/style.ts new file mode 100644 index 0000000000..fef15c8cc6 --- /dev/null +++ b/src/lib/helpers/style.ts @@ -0,0 +1,16 @@ +type Direction = 'rtl' | 'ltr'; + +function isDirection(dir: string): dir is Direction { + return dir === 'rtl' || dir === 'ltr'; +} + +function parseDirection(dir: string): Direction { + return isDirection(dir) ? dir : 'ltr'; +} + +export function getElementDir(el: HTMLElement): Direction { + if (window.getComputedStyle) { + return parseDirection(window.getComputedStyle(el, null).getPropertyValue('direction')); + } + return parseDirection(el.style.direction); +} From e37436d1044b022acb420d3a3209b14cf80b19d5 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 31 May 2023 18:52:55 +0100 Subject: [PATCH 2/4] feat: tabs focus on navigate --- src/lib/components/tab.svelte | 27 ++++++++++++++++++++++----- src/lib/helpers/waitUntil.ts | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/lib/helpers/waitUntil.ts diff --git a/src/lib/components/tab.svelte b/src/lib/components/tab.svelte index db46fb6b2c..3fdf830963 100644 --- a/src/lib/components/tab.svelte +++ b/src/lib/components/tab.svelte @@ -1,14 +1,31 @@