Input / Select: fix Korean IME composition bug (#10648)

* Input: fix cursor goes to the end of the text(#10611)

* Input: fix cursor goes to the end of the text(#10611)

* Update input.vue

* Update select.vue

* Update input.vue
pull/10716/head
Hyuni 2018-04-15 15:57:35 +08:00 committed by 杨奕
parent 769db14516
commit 783cb2691f
3 changed files with 13 additions and 3 deletions

View File

@ -100,6 +100,7 @@
import Migrating from 'element-ui/src/mixins/migrating'; import Migrating from 'element-ui/src/mixins/migrating';
import calcTextareaHeight from './calcTextareaHeight'; import calcTextareaHeight from './calcTextareaHeight';
import merge from 'element-ui/src/utils/merge'; import merge from 'element-ui/src/utils/merge';
import { isKorean } from 'element-ui/src/utils/shared';
export default { export default {
name: 'ElInput', name: 'ElInput',
@ -255,7 +256,9 @@
this.isOnComposition = false; this.isOnComposition = false;
this.handleInput(event); this.handleInput(event);
} else { } else {
this.isOnComposition = true; const text = event.target.value;
const lastCharacter = text[text.length - 1] || '';
this.isOnComposition = !isKorean(lastCharacter);
} }
}, },
handleInput(event) { handleInput(event) {

View File

@ -147,6 +147,7 @@
import { getValueByPath } from 'element-ui/src/utils/util'; import { getValueByPath } from 'element-ui/src/utils/util';
import { valueEquals } from 'element-ui/src/utils/util'; import { valueEquals } from 'element-ui/src/utils/util';
import NavigationMixin from './navigation-mixin'; import NavigationMixin from './navigation-mixin';
import { isKorean } from 'element-ui/src/utils/shared';
const sizeMap = { const sizeMap = {
'medium': 36, 'medium': 36,
@ -412,11 +413,13 @@
methods: { methods: {
handleComposition(event) { handleComposition(event) {
const text = event.target.value;
if (event.type === 'compositionend') { if (event.type === 'compositionend') {
this.isOnComposition = false; this.isOnComposition = false;
this.handleQueryChange(event.target.value); this.handleQueryChange(text);
} else { } else {
this.isOnComposition = true; const lastCharacter = text[text.length - 1] || '';
this.isOnComposition = !isKorean(lastCharacter);
} }
}, },
handleQueryChange(val) { handleQueryChange(val) {

View File

@ -1,3 +1,7 @@
export function isDef(val) { export function isDef(val) {
return val !== undefined && val !== null; return val !== undefined && val !== null;
} }
export function isKorean(text) {
const reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi;
return reg.test(text);
}