Skip to content

Commit

Permalink
improve event order to fix ant-design/ant-design#4265
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 15, 2016
1 parent 2ef0f04 commit 9fcfd5f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ export default {
focused: false,
});
const value = this.getCurrentValidValue(this.getValueFromEvent(e).trim());
this.setValue(value);
this.props.onBlur(e, ...args);
this.setValue(value, () => {
this.props.onBlur(e, ...args);
});
},

getCurrentValidValue(value) {
Expand All @@ -95,20 +96,20 @@ export default {
return this.toNumber(val);
},

setValue(v) {
setValue(v, callback) {
// trigger onChange
const newValue = isNaN(v) || v === '' ? undefined : v;
const changed = newValue !== this.state.value;
if (!('value' in this.props)) {
this.setState({
value: v,
inputValue: this.toPrecisionAsStep(v),
});
}, callback);
} else {
// always set input value same as value
this.setState({
inputValue: this.toPrecisionAsStep(this.state.value),
});
}, callback);
}
if (changed) {
this.props.onChange(newValue);
Expand Down

0 comments on commit 9fcfd5f

Please sign in to comment.