This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input): better mobile experience
- Loading branch information
Showing
1 changed file
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,56 @@ | ||
<template> | ||
<input type="search" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
autocomplete="off" | ||
spellcheck="false" | ||
:class="bem()" | ||
v-model="query" | ||
> | ||
<form role="search" action="" @submit.prevent="onFormSubmit"> | ||
<input type="search" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
autocomplete="off" | ||
spellcheck="false" | ||
:class="bem()" | ||
v-model="query" | ||
ref="input" | ||
:placeholder="placeholder" | ||
> | ||
</form> | ||
</template> | ||
|
||
<script> | ||
import algoliaComponent from 'vue-instantsearch-component' | ||
import algoliaComponent from 'vue-instantsearch-component'; | ||
export default { | ||
mixins: [algoliaComponent], | ||
data () { | ||
return { | ||
blockClassName: 'ais-input' | ||
} | ||
}, | ||
computed: { | ||
query: { | ||
get () { | ||
return this.searchStore.query | ||
}, | ||
set (value) { | ||
this.searchStore.stop() | ||
this.searchStore.query = value | ||
this.$emit('query', value) | ||
export default { | ||
mixins: [algoliaComponent], | ||
props: { | ||
placeholder: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
data() { | ||
return { | ||
blockClassName: 'ais-input' | ||
}; | ||
}, | ||
computed: { | ||
query: { | ||
get() { | ||
return this.searchStore.query; | ||
}, | ||
set(value) { | ||
this.searchStore.stop(); | ||
this.searchStore.query = value; | ||
this.$emit('query', value); | ||
// We here ensure we give the time to listeners to alter the store's state | ||
// without triggering in between ghost queries. | ||
this.$nextTick(function () { | ||
this.searchStore.start() | ||
}) | ||
} | ||
// We here ensure we give the time to listeners to alter the store's state | ||
// without triggering in between ghost queries. | ||
this.$nextTick(function() { | ||
this.searchStore.start(); | ||
}); | ||
} | ||
} | ||
}, | ||
methods: { | ||
onFormSubmit() { | ||
this.$refs.input.blur(); | ||
} | ||
} | ||
}; | ||
</script> |