The minimalistic document archiving platform.
fix(docs): improve tab accessibility (#1497)
Corentin Thomasset9883689e7adf
diff --git a/apps/website/src/docs/components/RandomStringGenerator.astro b/apps/website/src/docs/components/RandomStringGenerator.astroindex a209ea08..35ee1453 100644--- a/apps/website/src/docs/components/RandomStringGenerator.astro+++ b/apps/website/src/docs/components/RandomStringGenerator.astro@@ -18,7 +18,7 @@ const alphabet = alphabets[type];<div class="key-generator" data-length={length} data-alphabet={alphabet}><div class="flex items-center">- <input type="text" readonly class="key-input text-14px font-mono text-muted-foreground bg-transparent border border-muted-foreground/10 rounded-l px-2 w-full py-1" />+ <input type="text" aria-label="Generated secret" readonly class="key-input text-14px font-mono text-muted-foreground bg-transparent border border-muted-foreground/10 rounded-l px-2 w-full py-1" /><button class="btn-refresh flex items-center p-1.5 border-y" title="Generate new key"><span aria-label="Refresh" class="i-tabler-refresh inline-block size-5 text-muted-foreground hover:text-foreground transition" /></button>diff --git a/apps/website/src/docs/components/Tab.astro b/apps/website/src/docs/components/Tab.astroindex f968364e..c29e2db4 100644--- a/apps/website/src/docs/components/Tab.astro+++ b/apps/website/src/docs/components/Tab.astro@@ -1,11 +1,14 @@---+import { nanoid } from 'nanoid';+type Props = {label: string;};const { label } = Astro.props;+const panelId = `tab-panel-${nanoid()}`;----<div data-tab-panel data-tab-label={label} role="tabpanel">+<div data-tab-panel data-tab-label={label} id={panelId} role="tabpanel" aria-labelledby={`${panelId}-tab`} tabindex="0"><slot /></div>diff --git a/apps/website/src/docs/components/Tabs.astro b/apps/website/src/docs/components/Tabs.astroindex 114cc060..bea9c1ee 100644--- a/apps/website/src/docs/components/Tabs.astro+++ b/apps/website/src/docs/components/Tabs.astro@@ -1,17 +1,19 @@----// Astro can't read the props of slotted children, so the labels are extracted from the rendered-// markup: each <Tab> exposes its own via a data attribute, in document order.+// Astro can't read the props of slotted children, so extract labels and panel IDs from the+// rendered markup. Keep these attributes adjacent in <Tab> so the pairs stay in document order.const html = await Astro.slots.render('default');-const labels = [...html.matchAll(/data-tab-label="([^"]*)"/g)].map(([, label]) => label);+const tabs = [...html.matchAll(/data-tab-label="([^"]*)" id="([^"]*)"/g)].map(([, label, panelId]) => ({ label, panelId }));---<div class="tabs my-4" data-tabs><div class="flex items-center gap-2 border-b overflow-x-auto" role="tablist">{- labels.map((label, index) => (+ tabs.map(({ label, panelId }, index) => (<buttontype="button"role="tab"+ id={`${panelId}-tab`}+ aria-controls={panelId}data-tab-triggerdata-active={index === 0 ? '' : undefined}aria-selected={index === 0 ? 'true' : 'false'}