diff --git a/components/home/HomeSearch.vue b/components/app/AppGlobalSearchInput.vue similarity index 86% rename from components/home/HomeSearch.vue rename to components/app/AppGlobalSearchInput.vue index ca412e76796916adea5acb35b532bcc9fe3fadaa..9495136ba2dccf78b9b16490a75a7d261c65f24c 100644 --- a/components/home/HomeSearch.vue +++ b/components/app/AppGlobalSearchInput.vue @@ -1,31 +1,37 @@ <template> - <section class="bg-gray-100 dark:bg-gray-800"> - <div class="container py-12 relative prose"> - <div class="flex justify-evenly"> - <TInputIcon - ref="search" - v-model="query" - type="search" - :placeholder="placeholder" - class="w-full" - input-class="text-2xl rounded-full" - icon="search" - icon-class="text-2xl text-blue-100 dark:text-gray-600" - @keyup.enter="search()" - /> + <div class="flex justify-evenly"> + <TInputIcon + ref="search" + v-model="query" + type="search" + :placeholder="placeholder" + class="w-full" + :input-class="inputClass" + icon="search" + :icon-class="iconClass" + @keyup.enter="search()" + /> - <t-button - class="ml-6 rounded-full text-xl" - :text="$t('search')" - @click="search()" - /> - </div> - </div> - </section> + <t-button :class="buttonClass" :text="$t('search')" @click="search()" /> + </div> </template> <script> export default { + props: { + inputClass: { + type: String, + default: 'text-2xl rounded-full', + }, + iconClass: { + type: String, + default: 'text-2xl text-blue-100 dark:text-gray-600', + }, + buttonClass: { + type: String, + default: 'text-xl ml-6 rounded-full', + }, + }, data() { return { query: null, @@ -58,7 +64,7 @@ export default { if (this.query) { this.$router.push(`/recherche?q=${this.query}`) } else { - this.$refs.search.$children[0].$el.focus() + this.$refs.search.focus() } }, typewrite(curString, curStrPos) { diff --git a/components/app/TInputIcon.vue b/components/app/TInputIcon.vue index 0620b3ff8fab622422c2ae94dd6812dec6dddcbd..293665abbd59579a194a9f35a3ce99f7be1eaa26 100644 --- a/components/app/TInputIcon.vue +++ b/components/app/TInputIcon.vue @@ -34,13 +34,18 @@ export default { type: String, default: null, }, - focus: { + hasFocus: { type: Boolean, default: false, }, }, mounted() { - if (this.focus) this.$refs.inputIcon.$el.focus() + if (this.focus) this.focus() + }, + methods: { + focus() { + this.$refs.inputIcon.$el.focus() + }, }, } </script> diff --git a/components/search/SearchContainer.vue b/components/search/SearchContainer.vue index 59d3a60563fd0bd4890bdc81982cc2961ed5156d..10d57244f212a35cd7545a1931b7cf032143dadc 100644 --- a/components/search/SearchContainer.vue +++ b/components/search/SearchContainer.vue @@ -15,7 +15,7 @@ icon="search" icon-class="text-2xl text-blue-100 dark:text-gray-600" class="flex-1" - focus + has-focus /> <slot name="search" /> </div> diff --git a/pages/index.vue b/pages/index.vue index 89b74bdf98cc8a6b99a54e2d2bb121b15672361c..88a37167c1c251323775ff720c34f3ce68d98356 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2,7 +2,12 @@ <div> <HomeHero :document="hero" /> <HomeCTA :document="cta" /> - <HomeSearch /> + + <section class="bg-gray-100 dark:bg-gray-800"> + <div class="container py-12 relative prose"> + <AppGlobalSearchInput /> + </div> + </section> <nuxt-content class="container my-12 prose dark:prose-dark" diff --git a/pages/recherche.vue b/pages/recherche.vue index 564b1c1e4a3bd76e796da9348b8c875093d7c7c9..201de5255d4061c1e744b75d8a025fb014feb07d 100644 --- a/pages/recherche.vue +++ b/pages/recherche.vue @@ -1,5 +1,6 @@ <template> <SearchContainer + ref="searchContainer" :title="$t('recherche.title')" :results="[]" :search-placeholder="$t('recherche.searchPlaceholder')" @@ -91,6 +92,14 @@ export default { ressourcesResults: [], } }, + created() { + this.$nuxt.$on('global-search', (query) => { + this.$refs.searchContainer.query = query + }) + }, + beforeDestroy() { + this.$nuxt.$off('global-search') + }, methods: { async searchFunction(query) { let results = await this.$content({ deep: true })