[improvement] Field: add clear event (#1944)

This commit is contained in:
neverland
2018-10-17 13:14:07 +08:00
committed by GitHub
parent fcd5a53cf7
commit 995ae8c300
5 changed files with 65 additions and 1 deletions

View File

@@ -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();
}