From 105dee315cbe2e0d01aaebd6ae5186fcf50766e7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 25 Mar 2021 14:56:31 +0800 Subject: [PATCH 1/3] fix: Microsoft Chinese IME input bug (#307) * fix: Microsoft Chinese IME input bug * bump beta version * fix controlled mode --- package.json | 2 +- src/index.js | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 83528e06..41791918 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-input-number", - "version": "4.5.7", + "version": "4.5.8-beta.2", "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} >
Date: Thu, 25 Mar 2021 14:57:43 +0800 Subject: [PATCH 2/3] 4.5.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 41791918..a0e01a91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-input-number", - "version": "4.5.8-beta.2", + "version": "4.5.8", "description": "React input-number component", "keywords": [ "react", From 460e668936bae97e5b19ef2f47af8983a20c1149 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 25 Mar 2021 15:45:02 +0800 Subject: [PATCH 3/3] 4.5.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a0e01a91..420d3d77 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-input-number", - "version": "4.5.8", + "version": "4.5.9", "description": "React input-number component", "keywords": [ "react",