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

View File

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