fix(ui) : TabList — roving tabindex + aria panels + layout non-fenêtré (review)
- focusedKey assure exactement un tab focalisable quand l'actif est hors fenêtre - aria-labelledby conditionnel + fallback aria-label pour panneaux dont le bouton n'est pas rendu - DOM non-fenêtré identique à l'origine (plus de wrapper flex parasite) - reset de la fenêtre (startIndex) au remplacement des tabs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<template>
|
||||
<div v-bind="$attrs">
|
||||
<div class="flex items-center justify-center gap-4">
|
||||
<div v-if="isWindowed" class="flex items-center justify-center gap-4">
|
||||
<button
|
||||
v-if="isWindowed"
|
||||
type="button"
|
||||
aria-label="Onglets précédents"
|
||||
data-test="tab-prev"
|
||||
@@ -29,7 +28,7 @@
|
||||
:aria-selected="activeTab === tab.key"
|
||||
:aria-controls="`${componentId}-panel-${tab.key}`"
|
||||
:aria-disabled="!!tab.disabled"
|
||||
:tabindex="activeTab === tab.key ? 0 : -1"
|
||||
:tabindex="focusedKey === tab.key ? 0 : -1"
|
||||
:disabled="tab.disabled"
|
||||
:class="[
|
||||
'relative flex items-center gap-[18px] text-[24px] font-[600] transition-colors',
|
||||
@@ -51,7 +50,6 @@
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="isWindowed"
|
||||
type="button"
|
||||
aria-label="Onglets suivants"
|
||||
data-test="tab-next"
|
||||
@@ -66,13 +64,49 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
role="tablist"
|
||||
class="flex justify-center gap-[60px] border-b border-m-primary"
|
||||
>
|
||||
<button
|
||||
v-for="tab in visibleTabs"
|
||||
:id="`${componentId}-tab-${tab.key}`"
|
||||
:key="tab.key"
|
||||
role="tab"
|
||||
type="button"
|
||||
:aria-selected="activeTab === tab.key"
|
||||
:aria-controls="`${componentId}-panel-${tab.key}`"
|
||||
:aria-disabled="!!tab.disabled"
|
||||
:tabindex="focusedKey === tab.key ? 0 : -1"
|
||||
:disabled="tab.disabled"
|
||||
:class="[
|
||||
'relative flex items-center gap-[18px] text-[24px] font-[600] transition-colors',
|
||||
activeTab === tab.key
|
||||
? 'cursor-pointer text-m-primary after:content-[\'\'] after:absolute after:-bottom-[3px] after:left-0 after:right-0 after:h-[3px] after:bg-m-primary'
|
||||
: tab.disabled
|
||||
? 'cursor-not-allowed text-m-primary/50'
|
||||
: 'cursor-pointer text-m-primary/50 hover:text-m-primary/70',
|
||||
]"
|
||||
@click="selectTab(tab.key)"
|
||||
>
|
||||
<IconifyIcon
|
||||
v-if="tab.icon"
|
||||
:icon="tab.icon"
|
||||
:width="tab.iconSize ?? 24"
|
||||
/>
|
||||
{{ tab.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="tab in tabs"
|
||||
v-show="activeTab === tab.key"
|
||||
:id="`${componentId}-panel-${tab.key}`"
|
||||
:key="tab.key"
|
||||
role="tabpanel"
|
||||
:aria-labelledby="`${componentId}-tab-${tab.key}`"
|
||||
:aria-labelledby="isTabRendered(tab.key) ? `${componentId}-tab-${tab.key}` : undefined"
|
||||
:aria-label="isTabRendered(tab.key) ? undefined : tab.label"
|
||||
>
|
||||
<slot :name="tab.key" />
|
||||
</div>
|
||||
@@ -134,6 +168,14 @@ const visibleTabs = computed(() =>
|
||||
: props.tabs,
|
||||
)
|
||||
|
||||
const focusedKey = computed(() => {
|
||||
if (!isWindowed.value) return activeTab.value
|
||||
const inView = visibleTabs.value.some(t => t.key === activeTab.value)
|
||||
return inView ? activeTab.value : (visibleTabs.value[0]?.key ?? '')
|
||||
})
|
||||
|
||||
const isTabRendered = (key: string) => !isWindowed.value || visibleTabs.value.some(t => t.key === key)
|
||||
|
||||
const canPrev = computed(() => isWindowed.value && startIndex.value > 0)
|
||||
const canNext = computed(() => isWindowed.value && startIndex.value < maxStartIndex.value)
|
||||
|
||||
@@ -152,6 +194,11 @@ watch(maxStartIndex, (max) => {
|
||||
if (startIndex.value > max) startIndex.value = max
|
||||
})
|
||||
|
||||
// Reset the window to the start when the tab list is replaced.
|
||||
watch(() => props.tabs, () => {
|
||||
startIndex.value = 0
|
||||
})
|
||||
|
||||
function selectTab(key: string) {
|
||||
const tab = props.tabs.find(t => t.key === key)
|
||||
if (tab?.disabled) return
|
||||
|
||||
Reference in New Issue
Block a user