mirror of
https://github.com/youzan/vant.git
synced 2025-10-18 01:17:15 +00:00
[new feature] Search: support input native events (#451)
This commit is contained in:
@@ -6,14 +6,12 @@
|
||||
<div class="van-search__input-wrap" v-clickoutside="onClickoutside">
|
||||
<icon name="search" />
|
||||
<input
|
||||
v-bind="$attrs"
|
||||
v-on="listeners"
|
||||
v-refocus="focusStatus"
|
||||
type="search"
|
||||
class="van-search__input"
|
||||
v-bind="$attrs"
|
||||
v-refocus="focusStatus"
|
||||
:value="value"
|
||||
@input="onInput"
|
||||
@focus="onFocus"
|
||||
@keypress.enter.prevent="onSearch"
|
||||
>
|
||||
<icon name="clear" v-show="isFocus && value" @click="onClean" />
|
||||
</div>
|
||||
@@ -59,15 +57,36 @@ export default create({
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
listeners() {
|
||||
return {
|
||||
...this.$listeners,
|
||||
focus: this.onFocus,
|
||||
input: this.onInput,
|
||||
keypress: this.onKeypress
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onFocus() {
|
||||
this.isFocus = true;
|
||||
this.$emit('focus');
|
||||
},
|
||||
|
||||
onInput(event) {
|
||||
this.$emit('input', event.target.value);
|
||||
},
|
||||
|
||||
onKeypress(event) {
|
||||
// press enter
|
||||
if (event.keyCode === 13) {
|
||||
event.preventDefault();
|
||||
this.$emit('search', this.value);
|
||||
}
|
||||
this.$emit('keypress', event);
|
||||
},
|
||||
|
||||
// refocus after click close icon
|
||||
onClean() {
|
||||
this.$emit('input', '');
|
||||
@@ -84,12 +103,6 @@ export default create({
|
||||
this.$emit('cancel');
|
||||
},
|
||||
|
||||
onSearch(e) {
|
||||
e.preventDefault();
|
||||
this.$emit('search', this.value);
|
||||
return false;
|
||||
},
|
||||
|
||||
onClickoutside() {
|
||||
this.isFocus = false;
|
||||
this.focusStatus = false;
|
||||
|
Reference in New Issue
Block a user