Skip to content

Commit 2c5502d

Browse files
Merge branch 'refactor/remove-redirect-on-typing' of https://github.com/MatteoGabriele/npmx.dev into refactor/remove-redirect-on-typing
2 parents 1ef63f5 + cec25c7 commit 2c5502d

8 files changed

Lines changed: 139 additions & 29 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<p align="center">
66
<a href="https://npmx.dev/">
7-
<img width="1090" alt="Screenshot of npmx.dev showing the nuxt package" src="https://github.com/user-attachments/assets/229497a2-8491-461c-aa1d-fba981215340">
7+
<img width="1090" alt="Screenshot of npmx.dev showing the nuxt package" src="https://github.com/user-attachments/assets/1a2a3205-0227-46dc-b1f9-48f9a65691d3">
88
</a>
99
</p>
1010

app/components/PackageDownloadAnalytics.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ watch(
4949
5050
const isDarkMode = computed(() => resolvedMode.value === 'dark')
5151
52-
// oklh or css variables are not supported by vue-data-ui (for now)
53-
5452
const accentColorValueById = computed<Record<string, string>>(() => {
5553
const map: Record<string, string> = {}
5654
for (const item of accentColors) {

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
>

app/components/PackageWeeklyDownloadStats.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,32 @@ const dataset = computed(() =>
116116
117117
const lastDatapoint = computed(() => dataset.value.at(-1)?.period ?? '')
118118
119-
// oklh or css variables are not supported by vue-data-ui (for now)
120119
const config = computed(() => {
121120
return {
122121
theme: 'dark',
122+
/**
123+
* The built-in skeleton loader kicks in when the component is mounted but the data is not yet ready.
124+
* The configuration of the skeleton is customized for a seemless transition with the final state
125+
*/
126+
skeletonConfig: {
127+
style: {
128+
backgroundColor: 'transparent',
129+
dataLabel: {
130+
show: true,
131+
color: 'transparent',
132+
},
133+
area: {
134+
color: colors.value.borderHover,
135+
useGradient: false,
136+
opacity: 10,
137+
},
138+
line: {
139+
color: colors.value.borderHover,
140+
},
141+
},
142+
},
143+
// Same idea: initialize the line at zero, so it nicely transitions to the final dataset
144+
skeletonDataset: Array.from({ length: 52 }, () => 0),
123145
style: {
124146
backgroundColor: 'transparent',
125147
animation: { show: false },
@@ -196,16 +218,21 @@ const config = computed(() => {
196218

197219
<div class="w-full overflow-hidden">
198220
<ClientOnly>
199-
<VueUiSparkline class="w-full max-w-xs" :dataset :config />
221+
<VueUiSparkline class="w-full max-w-xs" :dataset :config>
222+
<template #skeleton>
223+
<!-- This empty div overrides the default built-in scanning animation on load -->
224+
<div />
225+
</template>
226+
</VueUiSparkline>
200227
<template #fallback>
201228
<!-- Skeleton matching sparkline layout: title row + chart with data label -->
202-
<div class="max-w-xs">
203-
<!-- Title row: date range -->
204-
<div class="h-5 flex items-center ps-3">
229+
<div class="min-h-[75.195px]">
230+
<!-- Title row: date range (24px height) -->
231+
<div class="h-6 flex items-center ps-3">
205232
<span class="skeleton h-3 w-36" />
206233
</div>
207-
<!-- Chart area: data label left, sparkline right (h-[51px] matches rendered SVG) -->
208-
<div class="h-[55px] flex items-center">
234+
<!-- Chart area: data label left, sparkline right -->
235+
<div class="aspect-[500/80] flex items-center">
209236
<!-- Data label (covers ~42% width) -->
210237
<div class="w-[42%] flex items-center ps-0.5">
211238
<span class="skeleton h-7 w-24" />

app/pages/[...package].vue

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ definePageMeta({
1414
const router = useRouter()
1515
1616
const { packageName, requestedVersion, orgName } = usePackageRoute()
17+
const selectedPM = useSelectedPackageManager()
18+
const activePmId = computed(() => selectedPM.value ?? 'npm')
1719
1820
if (import.meta.server) {
1921
assertValidPackageName(packageName.value)
@@ -845,11 +847,17 @@ function handleClick(event: MouseEvent) {
845847
<!-- Package manager tabs -->
846848
<PackageManagerTabs />
847849
</div>
848-
<ExecuteCommandTerminal
849-
:package-name="pkg.name"
850-
:jsr-info="jsrInfo"
851-
:is-create-package="isCreatePkg"
852-
/>
850+
<div
851+
role="tabpanel"
852+
:id="`pm-panel-${activePmId}`"
853+
:aria-labelledby="`pm-tab-${activePmId}`"
854+
>
855+
<ExecuteCommandTerminal
856+
:package-name="pkg.name"
857+
:jsr-info="jsrInfo"
858+
:is-create-package="isCreatePkg"
859+
/>
860+
</div>
853861
</section>
854862

855863
<!-- Regular packages: Install command with optional run command -->
@@ -873,14 +881,20 @@ function handleClick(event: MouseEvent) {
873881
<!-- Package manager tabs -->
874882
<PackageManagerTabs />
875883
</div>
876-
<InstallCommandTerminal
877-
:package-name="pkg.name"
878-
:requested-version="requestedVersion"
879-
:jsr-info="jsrInfo"
880-
:types-package-name="typesPackageName"
881-
:executable-info="executableInfo"
882-
:create-package-info="createPackageInfo"
883-
/>
884+
<div
885+
role="tabpanel"
886+
:id="`pm-panel-${activePmId}`"
887+
:aria-labelledby="`pm-tab-${activePmId}`"
888+
>
889+
<InstallCommandTerminal
890+
:package-name="pkg.name"
891+
:requested-version="requestedVersion"
892+
:jsr-info="jsrInfo"
893+
:types-package-name="typesPackageName"
894+
:executable-info="executableInfo"
895+
:create-package-info="createPackageInfo"
896+
/>
897+
</div>
884898
</section>
885899

886900
<div class="area-vulns space-y-6">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"validate-npm-package-name": "^7.0.2",
6363
"virtua": "^0.48.3",
6464
"vue": "3.5.27",
65-
"vue-data-ui": "^3.13.6"
65+
"vue-data-ui": "^3.13.7"
6666
},
6767
"devDependencies": {
6868
"@iconify-json/carbon": "1.2.18",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/package-manager-tabs.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { expect, test } from '@nuxt/test-utils/playwright'
2+
3+
test.describe('Package Page', () => {
4+
test('/vue → package manager tabs use roving tabindex', async ({ page, goto }) => {
5+
await goto('/vue', { waitUntil: 'domcontentloaded' })
6+
7+
const tablist = page.locator('[role="tablist"]').first()
8+
await expect(tablist).toBeVisible()
9+
10+
const tabs = tablist.locator('[role="tab"]')
11+
const tabCount = await tabs.count()
12+
expect(tabCount).toBeGreaterThan(1)
13+
14+
const firstTab = tabs.first()
15+
await firstTab.focus()
16+
await expect(firstTab).toBeFocused()
17+
18+
await page.keyboard.press('ArrowRight')
19+
20+
const secondTab = tabs.nth(1)
21+
await expect(secondTab).toBeFocused()
22+
await expect(secondTab).toHaveAttribute('aria-selected', 'true')
23+
await expect(secondTab).toHaveAttribute('tabindex', '0')
24+
await expect(firstTab).toHaveAttribute('tabindex', '-1')
25+
26+
const tabpanel = page.locator('[role="tabpanel"]').first()
27+
const controls = await secondTab.getAttribute('aria-controls')
28+
const panelId = await tabpanel.getAttribute('id')
29+
expect(controls).toBe(panelId)
30+
31+
const labelledBy = await tabpanel.getAttribute('aria-labelledby')
32+
const tabId = await secondTab.getAttribute('id')
33+
expect(labelledBy).toBe(tabId)
34+
})
35+
})

0 commit comments

Comments
 (0)