Skip to content

Commit e42fff4

Browse files
SahulKolaautofix-ci[bot]ghostdevvknowler
authored
feat: add clear button in search input (#1895)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Willow (GHOST) <git@willow.sh> Co-authored-by: Willow (GHOST) <ghostdevbusiness@gmail.com> Co-authored-by: Nathan Knowler <nathan@knowler.dev>
1 parent e69428d commit e42fff4

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

app/components/Header/SearchBox.vue

Lines changed: 17 additions & 1 deletion
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,11 +58,21 @@ 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+
class="absolute inset-ie-2 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 group-focus-within:flex group-hover:inline-flex hidden"
70+
@click="clearSearch"
71+
aria-hidden="true"
72+
tabindex="-1"
73+
>
74+
<span class="i-lucide:circle-x h-4 w-4" />
75+
</button>
6076
<button type="submit" class="sr-only">{{ $t('search.button') }}</button>
6177
</div>
6278
</div>

0 commit comments

Comments
 (0)