Skip to content

Commit efb6506

Browse files
AlexanderDevitskyAlexander Devitsky
authored andcommitted
fix: the ability to close quick search using the keyboard (#552)
Co-authored-by: Alexander Devitsky <[email protected]>
1 parent e80aecb commit efb6506

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/theme/components/AppHeader.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
:value="term"
109109
@input="handleSearch"
110110
@keydown.enter="handleSearch($event)"
111+
@keydown.tab="hideSearch"
111112
@focus="isSearchOpen = true"
112113
@keydown.esc="closeSearch"
113114
>
@@ -131,6 +132,8 @@
131132
class="sf-search-bar__button sf-button--pure"
132133
aria-label="Open search"
133134
@click="isSearchOpen ? isSearchOpen = false : isSearchOpen = true"
135+
@focus="showSearch"
136+
@keydown.tab="hideSearch"
134137
>
135138
<span class="sf-search-bar__icon">
136139
<SfIcon
@@ -263,11 +266,21 @@ export default defineComponent({
263266
]);
264267
});
265268
266-
const closeSearch = () => {
267-
if (!isSearchOpen.value) return;
269+
const showSearch = () => {
270+
if (!isSearchOpen.value) {
271+
isSearchOpen.value = true;
272+
}
273+
};
268274
275+
const hideSearch = () => {
276+
if (isSearchOpen.value) {
277+
isSearchOpen.value = false;
278+
}
279+
};
280+
281+
const closeSearch = () => {
282+
hideSearch();
269283
term.value = '';
270-
isSearchOpen.value = false;
271284
};
272285
273286
const handleSearch = debounce(async (paramValue) => {
@@ -321,6 +334,8 @@ export default defineComponent({
321334
categoryTree,
322335
closeOrFocusSearchBar,
323336
closeSearch,
337+
showSearch,
338+
hideSearch,
324339
getAgnosticCatLink,
325340
handleAccountClick,
326341
handleSearch,

0 commit comments

Comments
 (0)