diff --git a/package.json b/package.json index 83528e06..420d3d77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-input-number", - "version": "4.5.7", + "version": "4.5.9", "description": "React input-number component", "keywords": [ "react", diff --git a/src/index.js b/src/index.js index 4d45f397..92141057 100644 --- a/src/index.js +++ b/src/index.js @@ -270,16 +270,17 @@ export default class InputNumber extends React.Component { } onChange = (e) => { - const { - onChange, - } = this.props; - + const { onChange } = this.props; if (this.state.focused) { this.inputting = true; } this.rawInput = this.props.parser(this.getValueFromEvent(e)); - this.setState({ inputValue: this.rawInput }); - onChange(this.toNumber(this.rawInput)); // valid number or invalid string + if (this.composing) { + this.setState({ inputValue: this.getValueFromEvent(e) }); + } else { + this.setState({ inputValue: this.rawInput }); + onChange(this.toNumber(this.rawInput)); // valid number or invalid string + } } onMouseUp = (...args) => { @@ -317,6 +318,15 @@ export default class InputNumber extends React.Component { } } + onComposition = (e) => { + if (e.type === 'compositionstart') { + this.composing = true; + } else if (e.type === 'compositionend') { + this.composing = false; + this.onChange(e); + } + } + getCurrentValidValue(value) { let val = value; if (val === '') { @@ -679,7 +689,7 @@ export default class InputNumber extends React.Component { }); let upDisabledClass = ''; let downDisabledClass = ''; - const { value } = this.state; + const { value, inputValue } = this.state; if (value || value === 0) { if (!isNaN(value)) { const val = Number(value); @@ -713,7 +723,7 @@ export default class InputNumber extends React.Component { // focus state, show input value // unfocus state, show valid value - const inputDisplayValue = this.getInputDisplayValue(); + const inputDisplayValue = this.composing ? inputValue : this.getInputDisplayValue(); let upEvents; let downEvents; @@ -751,6 +761,8 @@ export default class InputNumber extends React.Component { onMouseLeave={props.onMouseLeave} onMouseOver={props.onMouseOver} onMouseOut={props.onMouseOut} + onCompositionStart={this.onComposition} + onCompositionEnd={this.onComposition} >