Skip to content

Commit

Permalink
🚸 Auto-apply first random keyword on empty search
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 committed Dec 10, 2024
1 parent 3ccdb97 commit 1874fda
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
:value="searchQuery"
:placeholder="placeholderText"
@input="debouncedUpdateSearchKeyword"
@keyup.enter="handleEnter"
/>
<ButtonV2
v-if="isSearchOpen"
Expand Down Expand Up @@ -84,6 +85,7 @@ export default {
return {
isSearchOpen: false,
placeholderText: this.$t('gutenberg_search_placeholder'),
randomKeywords: [],
};
},
mounted() {
Expand Down Expand Up @@ -116,10 +118,18 @@ export default {
() => Math.random() - 0.5
);
const randomTerms = shuffled.slice(0, 3);
this.randomKeywords = randomTerms;
return randomTerms.join('');
}
return this.$t('gutenberg_search_placeholder');
},
handleEnter() {
if (!this.searchQuery || this.searchQuery.trim() === '') {
const fallbackKeyword =
this.randomKeywords?.[0] || this.$t('gutenberg_search_placeholder');
this.$emit('input', fallbackKeyword);
}
},
},
};
</script>

0 comments on commit 1874fda

Please sign in to comment.