11<script setup lang="ts">
22import { formatNumber } from ' #imports'
3+ import { onKeyDown } from ' @vueuse/core'
34import { debounce } from ' perfect-debounce'
45import { isValidNewPackageName , checkPackageExists } from ' ~/utils/package-name'
56import { isPlatformSpecificPackage } from ' ~/utils/platform-packages'
@@ -595,50 +596,22 @@ function scrollToSelectedItem() {
595596 }
596597}
597598
598- function focusSelectedItem() {
599- const suggIdx = toSuggestionIndex (unifiedSelectedIndex .value )
600- const pkgIdx = toPackageIndex (unifiedSelectedIndex .value )
601-
602- nextTick (() => {
603- if (suggIdx !== null ) {
604- const el = document .querySelector <HTMLElement >(` [data-suggestion-index="${suggIdx }"] ` )
605- el ?.focus ()
606- } else if (pkgIdx !== null ) {
607- scrollToSelectedItem ()
608- nextTick (() => {
609- const el = document .querySelector <HTMLElement >(` [data-result-index="${pkgIdx }"] ` )
610- el ?.focus ()
611- })
612- }
613- })
614- }
615-
616599function handleResultsKeydown(e : KeyboardEvent ) {
617600 if (totalSelectableCount .value <= 0 ) return
618601
619- const isFromInput = (e .target as HTMLElement ).tagName === ' INPUT'
620-
621602 if (e .key === ' ArrowDown' ) {
622603 e .preventDefault ()
623604 userHasNavigated .value = true
624605 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value + 1 )
625- if (isFromInput ) {
626- scrollToSelectedItem ()
627- } else {
628- focusSelectedItem ()
629- }
606+ scrollToSelectedItem ()
630607 return
631608 }
632609
633610 if (e .key === ' ArrowUp' ) {
634611 e .preventDefault ()
635612 userHasNavigated .value = true
636613 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value - 1 )
637- if (isFromInput ) {
638- scrollToSelectedItem ()
639- } else {
640- focusSelectedItem ()
641- }
614+ scrollToSelectedItem ()
642615 return
643616 }
644617
@@ -664,6 +637,8 @@ function handleResultsKeydown(e: KeyboardEvent) {
664637 }
665638}
666639
640+ onKeyDown ([' ArrowDown' , ' ArrowUp' , ' Enter' ], handleResultsKeydown )
641+
667642function handleSuggestionSelect(index : number ) {
668643 // Convert suggestion index to unified index
669644 unifiedSelectedIndex .value = - (suggestionCount .value - index )
@@ -688,7 +663,7 @@ defineOgImageComponent('Default', {
688663 <main class =" overflow-x-hidden" >
689664 <!-- Results area with container padding -->
690665 <div class =" container-sm py-6" >
691- <section v-if =" query" :aria-label =" $t('search.results')" @keydown = " handleResultsKeydown " >
666+ <section v-if =" query" :aria-label =" $t('search.results')" >
692667 <!-- Initial loading (only after user interaction, not during view transition) -->
693668 <LoadingSpinner v-if =" showSearching" :text =" $t('search.searching')" />
694669
0 commit comments