Skip to content

Commit ca1be35

Browse files
committed
feat: enter key open the first package when searching (#916)
1 parent 704987b commit ca1be35

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

app/pages/search.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,14 @@ function handleResultsKeydown(e: KeyboardEvent) {
566566
}
567567
568568
if (e.key === 'Enter') {
569+
// If the active element is an input and there are results, navigate to the first result
570+
if (document.activeElement?.tagName === 'INPUT' && displayResults.value?.length) {
571+
return router.push({
572+
name: 'package',
573+
params: { package: displayResults.value?.[0]?.package.name.split('/') },
574+
})
575+
}
576+
569577
// Browser handles Enter on focused links naturally, but handle for non-link elements
570578
if (document.activeElement && elements.includes(document.activeElement as HTMLElement)) {
571579
const el = document.activeElement as HTMLElement

0 commit comments

Comments
 (0)