11<script setup lang="ts">
22import { formatNumber } from ' #imports'
33import type { FilterChip , SortOption } from ' #shared/types/preferences'
4+ import { onKeyDown } from ' @vueuse/core'
45import { debounce } from ' perfect-debounce'
56import { isValidNewPackageName , checkPackageExists } from ' ~/utils/package-name'
67import { isPlatformSpecificPackage } from ' ~/utils/platform-packages'
@@ -638,50 +639,22 @@ function scrollToSelectedItem() {
638639 }
639640}
640641
641- function focusSelectedItem() {
642- const suggIdx = toSuggestionIndex (unifiedSelectedIndex .value )
643- const pkgIdx = toPackageIndex (unifiedSelectedIndex .value )
644-
645- nextTick (() => {
646- if (suggIdx !== null ) {
647- const el = document .querySelector <HTMLElement >(` [data-suggestion-index="${suggIdx }"] ` )
648- el ?.focus ()
649- } else if (pkgIdx !== null ) {
650- scrollToSelectedItem ()
651- nextTick (() => {
652- const el = document .querySelector <HTMLElement >(` [data-result-index="${pkgIdx }"] ` )
653- el ?.focus ()
654- })
655- }
656- })
657- }
658-
659642function handleResultsKeydown(e : KeyboardEvent ) {
660643 if (totalSelectableCount .value <= 0 ) return
661644
662- const isFromInput = (e .target as HTMLElement ).tagName === ' INPUT'
663-
664645 if (e .key === ' ArrowDown' ) {
665646 e .preventDefault ()
666647 userHasNavigated .value = true
667648 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value + 1 )
668- if (isFromInput ) {
669- scrollToSelectedItem ()
670- } else {
671- focusSelectedItem ()
672- }
649+ scrollToSelectedItem ()
673650 return
674651 }
675652
676653 if (e .key === ' ArrowUp' ) {
677654 e .preventDefault ()
678655 userHasNavigated .value = true
679656 unifiedSelectedIndex .value = clampUnifiedIndex (unifiedSelectedIndex .value - 1 )
680- if (isFromInput ) {
681- scrollToSelectedItem ()
682- } else {
683- focusSelectedItem ()
684- }
657+ scrollToSelectedItem ()
685658 return
686659 }
687660
@@ -707,6 +680,8 @@ function handleResultsKeydown(e: KeyboardEvent) {
707680 }
708681}
709682
683+ onKeyDown ([' ArrowDown' , ' ArrowUp' , ' Enter' ], handleResultsKeydown )
684+
710685function handleSuggestionSelect(index : number ) {
711686 // Convert suggestion index to unified index
712687 unifiedSelectedIndex .value = - (suggestionCount .value - index )
@@ -731,7 +706,7 @@ defineOgImageComponent('Default', {
731706 <main class =" overflow-x-hidden" >
732707 <!-- Results area with container padding -->
733708 <div class =" container-sm py-6" >
734- <section v-if =" query" :aria-label =" $t('search.results')" @keydown = " handleResultsKeydown " >
709+ <section v-if =" query" :aria-label =" $t('search.results')" >
735710 <!-- Initial loading (only after user interaction, not during view transition) -->
736711 <LoadingSpinner v-if =" showSearching" :text =" $t('search.searching')" />
737712
0 commit comments