Skip to content

Commit 5daef26

Browse files
committed
fix: untrap search focus when clicking outside
- show search dropdown scrollbar See: FE-142
1 parent 8e8a814 commit 5daef26

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

frontend/layers/base/app/components/BaseSearchInput.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts" generic="SearchResultType extends Record<string, any>">
2+
import type { PointerDownOutsideEvent } from 'reka-ui'
3+
24
type GroupBy = keyof SearchResultType
35
46
const {
@@ -48,6 +50,14 @@ const groupedResults = computed(() => {
4850
4951
return Object.entries(groupedResults) as [SearchResultType[GroupBy], SearchResultType[]][]
5052
})
53+
54+
const searchInput = useTemplateRef('search-input')
55+
const handleClickOutside = (e: PointerDownOutsideEvent) => {
56+
if (e.target === searchInput.value?.$el) return
57+
58+
input.value = ''
59+
hasSearched.value = false
60+
}
5161
</script>
5262

5363
<template>
@@ -69,6 +79,7 @@ const groupedResults = computed(() => {
6979
</RkLabel>
7080
<RkComboboxInput
7181
id="search-input"
82+
ref="search-input"
7283
v-model.trim="input"
7384
type="search"
7485
auto-focus
@@ -82,12 +93,17 @@ const groupedResults = computed(() => {
8293

8394
<RkComboboxContent
8495
class="absolute z-10 dark:bg-gray-950 mt-xl rounded-xl w-full max-h-[400px]"
96+
@pointer-down-outside="handleClickOutside"
8597
>
8698
<template v-if="$slots['dropdown-fixed-header']">
8799
<slot name="dropdown-fixed-header" />
88100
</template>
89101

90-
<RkComboboxViewport tabindex="-1">
102+
<div
103+
role="presentation"
104+
class="overflow-y-auto"
105+
tabindex="-1"
106+
>
91107
<div class="py-lg">
92108
<slot
93109
v-if="isLoading"
@@ -156,7 +172,7 @@ const groupedResults = computed(() => {
156172
</RkComboboxItem>
157173
</template>
158174
</div>
159-
</RkComboboxViewport>
175+
</div>
160176
</RkComboboxContent>
161177
</RkComboboxRoot>
162178
</form>

0 commit comments

Comments
 (0)