Skip to content

Commit 401709c

Browse files
fix: Input box does not need to be verified until Chinese input is completed
1 parent 4218f19 commit 401709c

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

components/input/Input.jsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default {
3939
const { value, defaultValue } = this.$props;
4040
return {
4141
stateValue: !hasProp(this, 'value') ? defaultValue : value,
42+
isComposing: false
4243
};
4344
},
4445
watch: {
@@ -83,6 +84,9 @@ export default {
8384
},
8485

8586
setValue(value, e) {
87+
if (this.isComposing) {
88+
return;
89+
}
8690
// https://github.com/vueComponent/ant-design-vue/issues/92
8791
if (isIE && !isIE9 && this.stateValue === value) {
8892
return;
@@ -121,7 +125,14 @@ export default {
121125
handleChange(e) {
122126
this.setValue(e.target.value, e);
123127
},
124-
128+
handleComposition(e) {
129+
if (e.type === 'compositionstart') {
130+
this.isComposing = true;
131+
}else if (e.type === 'compositionend') {
132+
this.isComposing = false;
133+
this.handleChange(e);
134+
}
135+
},
125136
renderClearIcon(prefixCls) {
126137
const { allowClear } = this.$props;
127138
const { stateValue } = this;
@@ -224,7 +235,7 @@ export default {
224235
'value',
225236
'defaultValue',
226237
]);
227-
const { stateValue, getInputClassName, handleKeyDown, handleChange, $listeners } = this;
238+
const { stateValue, getInputClassName, handleKeyDown, handleChange, handleComposition, $listeners } = this;
228239
const inputProps = {
229240
domProps: {
230241
value: fixControlledValue(stateValue),
@@ -235,6 +246,8 @@ export default {
235246
keydown: handleKeyDown,
236247
input: handleChange,
237248
change: noop,
249+
compositionstart: handleComposition,
250+
compositionend: handleComposition
238251
},
239252
class: getInputClassName(prefixCls),
240253
ref: 'input',
@@ -248,14 +261,16 @@ export default {
248261
},
249262
render() {
250263
if (this.$props.type === 'textarea') {
251-
const { $listeners } = this;
264+
const { $listeners, handleChange, handleKeyDown, handleComposition } = this;
252265
const textareaProps = {
253266
props: this.$props,
254267
attrs: this.$attrs,
255268
on: {
256269
...$listeners,
257-
change: this.handleChange,
258-
keydown: this.handleKeyDown,
270+
change: handleChange,
271+
keydown: handleKeyDown,
272+
compositionstart: handleComposition,
273+
compositionend: handleComposition
259274
},
260275
directives: [
261276
{

0 commit comments

Comments
 (0)