Skip to content
Snippets Groups Projects
Commit eb4c1dbc authored by Emmanuel Salomon's avatar Emmanuel Salomon :fist:
Browse files

Refactoring search input

parent 31d980dd
No related branches found
No related tags found
No related merge requests found
<template> <template>
<section class="bg-gray-100 dark:bg-gray-800"> <div class="flex justify-evenly">
<div class="container py-12 relative prose"> <TInputIcon
<div class="flex justify-evenly"> ref="search"
<TInputIcon v-model="query"
ref="search" type="search"
v-model="query" :placeholder="placeholder"
type="search" class="w-full"
:placeholder="placeholder" :input-class="inputClass"
class="w-full" icon="search"
input-class="text-2xl rounded-full" :icon-class="iconClass"
icon="search" @keyup.enter="search()"
icon-class="text-2xl text-blue-100 dark:text-gray-600" />
@keyup.enter="search()"
/>
<t-button <t-button :class="buttonClass" :text="$t('search')" @click="search()" />
class="ml-6 rounded-full text-xl" </div>
:text="$t('search')"
@click="search()"
/>
</div>
</div>
</section>
</template> </template>
<script> <script>
export default { 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() { data() {
return { return {
query: null, query: null,
...@@ -58,7 +64,7 @@ export default { ...@@ -58,7 +64,7 @@ export default {
if (this.query) { if (this.query) {
this.$router.push(`/recherche?q=${this.query}`) this.$router.push(`/recherche?q=${this.query}`)
} else { } else {
this.$refs.search.$children[0].$el.focus() this.$refs.search.focus()
} }
}, },
typewrite(curString, curStrPos) { typewrite(curString, curStrPos) {
......
...@@ -34,13 +34,18 @@ export default { ...@@ -34,13 +34,18 @@ export default {
type: String, type: String,
default: null, default: null,
}, },
focus: { hasFocus: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
}, },
mounted() { mounted() {
if (this.focus) this.$refs.inputIcon.$el.focus() if (this.focus) this.focus()
},
methods: {
focus() {
this.$refs.inputIcon.$el.focus()
},
}, },
} }
</script> </script>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
icon="search" icon="search"
icon-class="text-2xl text-blue-100 dark:text-gray-600" icon-class="text-2xl text-blue-100 dark:text-gray-600"
class="flex-1" class="flex-1"
focus has-focus
/> />
<slot name="search" /> <slot name="search" />
</div> </div>
......
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
<div> <div>
<HomeHero :document="hero" /> <HomeHero :document="hero" />
<HomeCTA :document="cta" /> <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 <nuxt-content
class="container my-12 prose dark:prose-dark" class="container my-12 prose dark:prose-dark"
......
<template> <template>
<SearchContainer <SearchContainer
ref="searchContainer"
:title="$t('recherche.title')" :title="$t('recherche.title')"
:results="[]" :results="[]"
:search-placeholder="$t('recherche.searchPlaceholder')" :search-placeholder="$t('recherche.searchPlaceholder')"
...@@ -91,6 +92,14 @@ export default { ...@@ -91,6 +92,14 @@ export default {
ressourcesResults: [], ressourcesResults: [],
} }
}, },
created() {
this.$nuxt.$on('global-search', (query) => {
this.$refs.searchContainer.query = query
})
},
beforeDestroy() {
this.$nuxt.$off('global-search')
},
methods: { methods: {
async searchFunction(query) { async searchFunction(query) {
let results = await this.$content({ deep: true }) let results = await this.$content({ deep: true })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment