Skip to content

Commit

Permalink
Input / Select: fix Korean IME composition bug (ElemeFE#10648)
Browse files Browse the repository at this point in the history
* Input: fix cursor goes to the end of the text(ElemeFE#10611)

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

* Update input.vue

* Update select.vue

* Update input.vue
  • Loading branch information
xuzaixian authored and Leopoldthecoder committed Apr 15, 2018
1 parent 769db14 commit 783cb26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/input/src/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import Migrating from 'element-ui/src/mixins/migrating';
import calcTextareaHeight from './calcTextareaHeight';
import merge from 'element-ui/src/utils/merge';
import { isKorean } from 'element-ui/src/utils/shared';
export default {
name: 'ElInput',
Expand Down Expand Up @@ -255,7 +256,9 @@
this.isOnComposition = false;
this.handleInput(event);
} else {
this.isOnComposition = true;
const text = event.target.value;
const lastCharacter = text[text.length - 1] || '';
this.isOnComposition = !isKorean(lastCharacter);
}
},
handleInput(event) {
Expand Down
7 changes: 5 additions & 2 deletions packages/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
import { getValueByPath } from 'element-ui/src/utils/util';
import { valueEquals } from 'element-ui/src/utils/util';
import NavigationMixin from './navigation-mixin';
import { isKorean } from 'element-ui/src/utils/shared';
const sizeMap = {
'medium': 36,
Expand Down Expand Up @@ -412,11 +413,13 @@
methods: {
handleComposition(event) {
const text = event.target.value;
if (event.type === 'compositionend') {
this.isOnComposition = false;
this.handleQueryChange(event.target.value);
this.handleQueryChange(text);
} else {
this.isOnComposition = true;
const lastCharacter = text[text.length - 1] || '';
this.isOnComposition = !isKorean(lastCharacter);
}
},
handleQueryChange(val) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/shared.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function isDef(val) {
return val !== undefined && val !== null;
}
export function isKorean(text) {
const reg = /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi;
return reg.test(text);
}

0 comments on commit 783cb26

Please sign in to comment.