Skip to content

Commit

Permalink
fix(theme/a11y): don't select search result unless mouse is actually …
Browse files Browse the repository at this point in the history
…moved

closes #4297
  • Loading branch information
brc-dd committed Oct 17, 2024
1 parent fcae4d5 commit e638d85
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/client/theme-default/components/VPLocalSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function onSearchBarClick(event: PointerEvent) {
/* Search keyboard selection */
const selectedIndex = ref(-1)
const disableMouseOver = ref(false)
const disableMouseOver = ref(true)
watch(results, (r) => {
selectedIndex.value = r.length ? 0 : -1
Expand Down Expand Up @@ -400,6 +400,16 @@ function formMarkRegex(terms: Set<string>) {
'gi'
)
}
function onMouseMove(e: MouseEvent) {
if (!disableMouseOver.value) return
const el = (e.target as HTMLElement)?.closest<HTMLAnchorElement>('.result')
const index = Number.parseInt(el?.dataset.index!)
if (index >= 0 && index !== selectedIndex.value) {
selectedIndex.value = index
}
disableMouseOver.value = false
}
</script>

<template>
Expand Down Expand Up @@ -487,7 +497,7 @@ function formMarkRegex(terms: Set<string>) {
:role="results?.length ? 'listbox' : undefined"
:aria-labelledby="results?.length ? 'localsearch-label' : undefined"
class="results"
@mousemove="disableMouseOver = false"
@mousemove="onMouseMove"
>
<li
v-for="(p, index) in results"
Expand All @@ -506,6 +516,7 @@ function formMarkRegex(terms: Set<string>) {
@mouseenter="!disableMouseOver && (selectedIndex = index)"
@focusin="selectedIndex = index"
@click="$emit('close')"
:data-index="index"
>
<div>
<div class="titles">
Expand Down

0 comments on commit e638d85

Please sign in to comment.