Skip to content

Commit 9b63f04

Browse files
authored
fix: remove compare icon from header, add c shortcut (#571)
1 parent 980c47b commit 9b63f04

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

app/components/AppHeader.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ onKeyStroke(
7272
},
7373
{ dedupe: true },
7474
)
75+
76+
onKeyStroke(
77+
'c',
78+
e => {
79+
// Allow more specific handlers to take precedence
80+
if (e.defaultPrevented) return
81+
82+
// Don't trigger if user is typing in an input
83+
const target = e.target as HTMLElement
84+
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
85+
return
86+
}
87+
88+
e.preventDefault()
89+
navigateTo('/compare')
90+
},
91+
{ dedupe: true },
92+
)
7593
</script>
7694

7795
<template>
@@ -156,10 +174,16 @@ onKeyStroke(
156174
<!-- Desktop: Compare link -->
157175
<NuxtLink
158176
to="/compare"
159-
class="hidden sm:inline-flex link-subtle font-mono text-sm items-center gap-1.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 rounded"
177+
class="hidden sm:inline-flex link-subtle font-mono text-sm items-center gap-2 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 rounded"
178+
aria-keyshortcuts="c"
160179
>
161-
<span class="i-carbon:compare w-4 h-4" aria-hidden="true" />
162180
{{ $t('nav.compare') }}
181+
<kbd
182+
class="inline-flex items-center justify-center w-5 h-5 text-xs bg-bg-muted border border-border rounded"
183+
aria-hidden="true"
184+
>
185+
c
186+
</kbd>
163187
</NuxtLink>
164188

165189
<!-- Desktop: Settings link -->

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ onKeyStroke(
338338
{ dedupe: true },
339339
)
340340
341-
onKeyStroke('c', () => {
341+
onKeyStroke('c', e => {
342342
if (pkg.value) {
343+
e.preventDefault()
343344
router.push({ path: '/compare', query: { packages: pkg.value.name } })
344345
}
345346
})

test/e2e/interactions.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,63 @@ test.describe('Search Pages', () => {
7676
await expect(headerSearchInput).toBeFocused()
7777
})
7878
})
79+
80+
test.describe('Keyboard Shortcuts', () => {
81+
test('"c" navigates to /compare', async ({ page, goto }) => {
82+
await goto('/settings', { waitUntil: 'hydration' })
83+
84+
await page.keyboard.press('c')
85+
86+
await expect(page).toHaveURL(/\/compare/)
87+
})
88+
89+
test('"c" on package page navigates to /compare with package pre-filled', async ({
90+
page,
91+
goto,
92+
}) => {
93+
await goto('/vue', { waitUntil: 'hydration' })
94+
95+
await page.keyboard.press('c')
96+
97+
// Should navigate to /compare with the package in the query
98+
await expect(page).toHaveURL(/\/compare\?packages=vue/)
99+
})
100+
101+
test('"c" does not navigate when search input is focused', async ({ page, goto }) => {
102+
await goto('/settings', { waitUntil: 'hydration' })
103+
104+
const searchInput = page.locator('#header-search')
105+
await searchInput.focus()
106+
await expect(searchInput).toBeFocused()
107+
108+
await page.keyboard.press('c')
109+
110+
// Should still be on settings, not navigated to compare
111+
await expect(page).toHaveURL(/\/settings/)
112+
// The 'c' should have been typed into the input
113+
await expect(searchInput).toHaveValue('c')
114+
})
115+
116+
test('"," navigates to /settings', async ({ page, goto }) => {
117+
await goto('/compare', { waitUntil: 'hydration' })
118+
119+
await page.keyboard.press(',')
120+
121+
await expect(page).toHaveURL(/\/settings/)
122+
})
123+
124+
test('"," does not navigate when search input is focused', async ({ page, goto }) => {
125+
await goto('/compare', { waitUntil: 'hydration' })
126+
127+
const searchInput = page.locator('#header-search')
128+
await searchInput.focus()
129+
await expect(searchInput).toBeFocused()
130+
131+
await page.keyboard.press(',')
132+
133+
// Should still be on compare, not navigated to settings
134+
await expect(page).toHaveURL(/\/compare/)
135+
// The ',' should have been typed into the input
136+
await expect(searchInput).toHaveValue(',')
137+
})
138+
})

0 commit comments

Comments
 (0)