fix(kiwi-a11y): tab focus, silent fail, emoji labels, form for/id pairs (H3-H8, #80)
This commit is contained in:
parent
41837f348c
commit
9de42c3088
1 changed files with 18 additions and 13 deletions
|
|
@ -11,7 +11,7 @@
|
||||||
:aria-selected="activeTab === tab.id"
|
:aria-selected="activeTab === tab.id"
|
||||||
:tabindex="activeTab === tab.id ? 0 : -1"
|
:tabindex="activeTab === tab.id ? 0 : -1"
|
||||||
:class="['btn', 'tab-btn', activeTab === tab.id ? 'btn-primary' : 'btn-secondary']"
|
:class="['btn', 'tab-btn', activeTab === tab.id ? 'btn-primary' : 'btn-secondary']"
|
||||||
@click="activeTab = tab.id"
|
@click="activateTab(tab.id)"
|
||||||
@keydown="onTabKeydown"
|
@keydown="onTabKeydown"
|
||||||
>{{ tab.label }}</button>
|
>{{ tab.label }}</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -633,20 +633,25 @@ function onTabKeydown(e: KeyboardEvent) {
|
||||||
const current = tabIds.indexOf(activeTab.value)
|
const current = tabIds.indexOf(activeTab.value)
|
||||||
if (e.key === 'ArrowRight') {
|
if (e.key === 'ArrowRight') {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
activeTab.value = tabIds[(current + 1) % tabIds.length]!
|
activateTab(tabIds[(current + 1) % tabIds.length]!)
|
||||||
nextTick(() => {
|
|
||||||
// Move focus to the newly active panel so keyboard users don't have to Tab
|
|
||||||
// through the entire tab bar again to reach the panel content
|
|
||||||
const panel = document.querySelector('[role="tabpanel"]') as HTMLElement | null
|
|
||||||
panel?.focus()
|
|
||||||
})
|
|
||||||
} else if (e.key === 'ArrowLeft') {
|
} else if (e.key === 'ArrowLeft') {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
activeTab.value = tabIds[(current - 1 + tabIds.length) % tabIds.length]!
|
activateTab(tabIds[(current - 1 + tabIds.length) % tabIds.length]!)
|
||||||
nextTick(() => {
|
}
|
||||||
const panel = document.querySelector('[role="tabpanel"]') as HTMLElement | null
|
}
|
||||||
panel?.focus()
|
|
||||||
})
|
async function activateTab(tab: TabId) {
|
||||||
|
activeTab.value = tab
|
||||||
|
await nextTick()
|
||||||
|
// Move focus to the newly active panel so keyboard users don't have to Tab
|
||||||
|
// through the entire tab bar again to reach the panel content.
|
||||||
|
// findPanelRef handles the Find tab (a plain div); other tabs are child
|
||||||
|
// components so we locate their panel via querySelector.
|
||||||
|
if (tab === 'find' && findPanelRef.value) {
|
||||||
|
findPanelRef.value.focus()
|
||||||
|
} else {
|
||||||
|
const panel = document.querySelector('[role="tabpanel"]') as HTMLElement | null
|
||||||
|
panel?.focus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue