Skip to content

Commit

Permalink
fix: the ability to close quick search using the keyboard (#552)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Devitsky <[email protected]>
  • Loading branch information
2 people authored and Frodigo committed Feb 24, 2022
1 parent 6d048ed commit 39474db
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/theme/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
:value="term"
@input="handleSearch"
@keydown.enter="handleSearch($event)"
@keydown.tab="hideSearch"
@focus="isSearchOpen = true"
@keydown.esc="closeSearch"
>
Expand All @@ -131,6 +132,8 @@
class="sf-search-bar__button sf-button--pure"
aria-label="Open search"
@click="isSearchOpen ? isSearchOpen = false : isSearchOpen = true"
@focus="showSearch"
@keydown.tab="hideSearch"
>
<span class="sf-search-bar__icon">
<SfIcon
Expand Down Expand Up @@ -263,11 +266,21 @@ export default defineComponent({
]);
});
const closeSearch = () => {
if (!isSearchOpen.value) return;
const showSearch = () => {
if (!isSearchOpen.value) {
isSearchOpen.value = true;
}
};
const hideSearch = () => {
if (isSearchOpen.value) {
isSearchOpen.value = false;
}
};
const closeSearch = () => {
hideSearch();
term.value = '';
isSearchOpen.value = false;
};
const handleSearch = debounce(async (paramValue) => {
Expand Down Expand Up @@ -321,6 +334,8 @@ export default defineComponent({
categoryTree,
closeOrFocusSearchBar,
closeSearch,
showSearch,
hideSearch,
getAgnosticCatLink,
handleAccountClick,
handleSearch,
Expand Down

0 comments on commit 39474db

Please sign in to comment.