Skip to content

Commit de66b04

Browse files
committed
fix: add clear button in search field (mobile view) - #1881
1 parent de28051 commit de66b04

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

app/components/Header/SearchBox.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ const showSearchBar = computed(() => {
1717
})
1818
1919
const { model: searchQuery, startSearch } = useGlobalSearch('header')
20+
const hasSearchQuery = computed(() => searchQuery.value.trim().length > 0)
2021
2122
function handleSubmit() {
2223
startSearch()
2324
}
2425
26+
function clearSearch() {
27+
searchQuery.value = ''
28+
inputRef.value?.focus()
29+
}
30+
2531
// Expose focus method for parent components
2632
const inputRef = useTemplateRef('inputRef')
2733
function focus() {
@@ -52,14 +58,23 @@ defineExpose({ focus })
5258
name="q"
5359
:placeholder="$t('search.placeholder')"
5460
no-correct
55-
class="w-full min-w-25 ps-7"
61+
class="w-full min-w-25 ps-7 pe-8"
5662
@focus="isSearchFocused = true"
5763
@blur="isSearchFocused = false"
5864
size="small"
5965
/>
66+
<button
67+
v-if="hasSearchQuery"
68+
type="button"
69+
:aria-label="$t('common.close')"
70+
class="absolute inset-ie-2 inline-flex h-6 w-6 items-center justify-center rounded text-fg-muted hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"
71+
@click="clearSearch"
72+
>
73+
<span class="i-lucide:circle-x h-4 w-4" aria-hidden="true" />
74+
</button>
6075
<button type="submit" class="sr-only">{{ $t('search.button') }}</button>
6176
</div>
6277
</div>
6378
</form>
6479
</search>
65-
</template>
80+
</template>

0 commit comments

Comments
 (0)