Skip to content

Commit 8a247eb

Browse files
committed
fix: resolve conflicts
1 parent 9791d35 commit 8a247eb

2 files changed

Lines changed: 60 additions & 376 deletions

File tree

app/components/PackageManagerTabs.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
11
<script setup lang="ts">
22
const selectedPM = useSelectedPackageManager()
3+
4+
const tablistNavigationKeys = new Set(['ArrowRight', 'ArrowLeft', 'Home', 'End'])
5+
6+
function onTabListKeydown(event: KeyboardEvent) {
7+
if (!tablistNavigationKeys.has(event.key)) return
8+
const tablist = event.currentTarget as HTMLElement | null
9+
if (!tablist) return
10+
11+
const tabs = Array.from(tablist.querySelectorAll<HTMLElement>('[role="tab"]'))
12+
const count = Math.min(tabs.length, packageManagers.length)
13+
if (!count) return
14+
15+
event.preventDefault()
16+
17+
let activeIndex = packageManagers.findIndex(pm => pm.id === selectedPM.value)
18+
if (activeIndex < 0) activeIndex = 0
19+
20+
let nextIndex = activeIndex
21+
if (event.key === 'ArrowRight') nextIndex = (activeIndex + 1) % count
22+
if (event.key === 'ArrowLeft') nextIndex = (activeIndex - 1 + count) % count
23+
if (event.key === 'Home') nextIndex = 0
24+
if (event.key === 'End') nextIndex = count - 1
25+
26+
const nextTab = tabs[nextIndex]
27+
const nextId = packageManagers[nextIndex]?.id
28+
if (nextId && nextId !== selectedPM.value) {
29+
selectedPM.value = nextId
30+
}
31+
32+
nextTick(() => nextTab?.focus())
33+
}
334
</script>
435

536
<template>
637
<div
738
class="flex items-center gap-1 p-0.5 bg-bg-subtle border border-border-subtle rounded-md overflow-x-auto"
839
role="tablist"
940
:aria-label="$t('package.get_started.pm_label')"
41+
@keydown="onTabListKeydown"
1042
>
1143
<button
1244
v-for="pm in packageManagers"
1345
:key="pm.id"
46+
:id="`pm-tab-${pm.id}`"
1447
role="tab"
1548
:data-pm-tab="pm.id"
1649
:aria-selected="selectedPM === pm.id"
50+
:aria-controls="`pm-panel-${pm.id}`"
51+
:tabindex="selectedPM === pm.id ? 0 : -1"
52+
type="button"
1753
class="pm-tab px-2 py-1.5 font-mono text-xs rounded transition-colors duration-150 border border-solid focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fg/50 inline-flex items-center gap-1.5 hover:text-fg"
1854
@click="selectedPM = pm.id"
1955
>

0 commit comments

Comments
 (0)