Input / Select: shouldn't fire input event during composition (#10517)

pull/10525/head
杨奕 2018-04-02 18:12:56 +08:00 committed by GitHub
parent c8ff3ad606
commit 0b7e9dae5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -29,6 +29,9 @@
:autocomplete="autoComplete"
:value="currentValue"
ref="input"
@compositionstart="handleComposition"
@compositionupdate="handleComposition"
@compositionend="handleComposition"
@input="handleInput"
@focus="handleFocus"
@blur="handleBlur"
@ -76,6 +79,9 @@
:tabindex="tabindex"
class="el-textarea__inner"
:value="currentValue"
@compositionstart="handleComposition"
@compositionupdate="handleComposition"
@compositionend="handleComposition"
@input="handleInput"
ref="textarea"
v-bind="$attrs"
@ -120,7 +126,8 @@
prefixOffset: null,
suffixOffset: null,
hovering: false,
focused: false
focused: false,
isOnComposition: false
};
},
@ -243,7 +250,16 @@
this.focused = true;
this.$emit('focus', event);
},
handleComposition(event) {
if (event.type === 'compositionend') {
this.isOnComposition = false;
this.handleInput(event);
} else {
this.isOnComposition = true;
}
},
handleInput(event) {
if (this.isOnComposition) return;
const value = event.target.value;
this.$emit('input', value);
this.setCurrentValue(value);

View File

@ -57,6 +57,9 @@
@keydown.enter.prevent="selectOption"
@keydown.esc.stop.prevent="visible = false"
@keydown.delete="deletePrevTag"
@compositionstart="handleComposition"
@compositionupdate="handleComposition"
@compositionend="handleComposition"
v-model="query"
@input="e => handleQueryChange(e.target.value)"
:debounce="remote ? 300 : 0"
@ -304,7 +307,8 @@
query: '',
previousQuery: null,
inputHovering: false,
currentPlaceholder: ''
currentPlaceholder: '',
isOnComposition: false
};
},
@ -407,8 +411,16 @@
},
methods: {
handleComposition(event) {
if (event.type === 'compositionend') {
this.isOnComposition = false;
this.handleQueryChange(event.target.value);
} else {
this.isOnComposition = true;
}
},
handleQueryChange(val) {
if (this.previousQuery === val) return;
if (this.previousQuery === val || this.isOnComposition) return;
if (
this.previousQuery === null &&
(typeof this.filterMethod === 'function' || typeof this.remoteMethod === 'function')