|
1 | 1 | <template>
|
2 |
| - <input type="search" |
3 |
| - autocorrect="off" |
4 |
| - autocapitalize="off" |
5 |
| - autocomplete="off" |
6 |
| - spellcheck="false" |
7 |
| - :class="bem()" |
8 |
| - v-model="query" |
9 |
| - > |
| 2 | + <form role="search" action="" @submit.prevent="onFormSubmit"> |
| 3 | + <input type="search" |
| 4 | + autocorrect="off" |
| 5 | + autocapitalize="off" |
| 6 | + autocomplete="off" |
| 7 | + spellcheck="false" |
| 8 | + :class="bem()" |
| 9 | + v-model="query" |
| 10 | + ref="input" |
| 11 | + :placeholder="placeholder" |
| 12 | + > |
| 13 | + </form> |
10 | 14 | </template>
|
11 | 15 |
|
12 | 16 | <script>
|
13 |
| - import algoliaComponent from 'vue-instantsearch-component' |
| 17 | +import algoliaComponent from 'vue-instantsearch-component'; |
14 | 18 |
|
15 |
| - export default { |
16 |
| - mixins: [algoliaComponent], |
17 |
| - data () { |
18 |
| - return { |
19 |
| - blockClassName: 'ais-input' |
20 |
| - } |
21 |
| - }, |
22 |
| - computed: { |
23 |
| - query: { |
24 |
| - get () { |
25 |
| - return this.searchStore.query |
26 |
| - }, |
27 |
| - set (value) { |
28 |
| - this.searchStore.stop() |
29 |
| - this.searchStore.query = value |
30 |
| - this.$emit('query', value) |
| 19 | +export default { |
| 20 | + mixins: [algoliaComponent], |
| 21 | + props: { |
| 22 | + placeholder: { |
| 23 | + type: String, |
| 24 | + default: '' |
| 25 | + } |
| 26 | + }, |
| 27 | + data() { |
| 28 | + return { |
| 29 | + blockClassName: 'ais-input' |
| 30 | + }; |
| 31 | + }, |
| 32 | + computed: { |
| 33 | + query: { |
| 34 | + get() { |
| 35 | + return this.searchStore.query; |
| 36 | + }, |
| 37 | + set(value) { |
| 38 | + this.searchStore.stop(); |
| 39 | + this.searchStore.query = value; |
| 40 | + this.$emit('query', value); |
31 | 41 |
|
32 |
| - // We here ensure we give the time to listeners to alter the store's state |
33 |
| - // without triggering in between ghost queries. |
34 |
| - this.$nextTick(function () { |
35 |
| - this.searchStore.start() |
36 |
| - }) |
37 |
| - } |
| 42 | + // We here ensure we give the time to listeners to alter the store's state |
| 43 | + // without triggering in between ghost queries. |
| 44 | + this.$nextTick(function() { |
| 45 | + this.searchStore.start(); |
| 46 | + }); |
38 | 47 | }
|
39 | 48 | }
|
| 49 | + }, |
| 50 | + methods: { |
| 51 | + onFormSubmit() { |
| 52 | + this.$refs.input.blur(); |
| 53 | + } |
40 | 54 | }
|
| 55 | +}; |
41 | 56 | </script>
|
0 commit comments