mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
[improvement] Field: add clear event (#1944)
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
v-if="showClear"
|
||||
name="clear"
|
||||
:class="b('clear')"
|
||||
@touchstart.prevent="$emit('input', '')"
|
||||
@touchstart.prevent="onClear"
|
||||
/>
|
||||
<div v-if="$slots.icon || icon" :class="b('icon')" @click="onClickIcon">
|
||||
<slot name="icon">
|
||||
@@ -152,6 +152,7 @@ export default create({
|
||||
this.$emit('focus', event);
|
||||
|
||||
// hack for safari
|
||||
/* istanbul ignore if */
|
||||
if (this.readonly) {
|
||||
this.blur();
|
||||
}
|
||||
@@ -167,6 +168,11 @@ export default create({
|
||||
this.onIconClick && this.onIconClick();
|
||||
},
|
||||
|
||||
onClear() {
|
||||
this.$emit('input', '');
|
||||
this.$emit('clear');
|
||||
},
|
||||
|
||||
onKeypress(event) {
|
||||
if (this.type === 'number') {
|
||||
const { keyCode } = event;
|
||||
@@ -177,6 +183,8 @@ export default create({
|
||||
}
|
||||
}
|
||||
|
||||
// trigger blur after click keyboard search button
|
||||
/* istanbul ignore next */
|
||||
if (this.type === 'search' && event.keyCode === 13) {
|
||||
this.blur();
|
||||
}
|
||||
|
Reference in New Issue
Block a user