From 837bd6b2f1a05ef6aedec23ae6e3a321c0204946 Mon Sep 17 00:00:00 2001 From: Lodato L Date: Fri, 3 Feb 2023 16:03:58 +0100 Subject: [PATCH] not changing local state when parsed value is the same of the previous we did this small change to address the user input like 0.01 with the current implementation this is not possible as 0.00 would be resetted to 0. Since 1.01 is equal to 1.0100 just skipping the state update when the real values are the same is enough. In addition I forwarded the original text to the change handler as second parameter, this may be useful for additional logic and would not impact the currents implementations that expect a real number as first parameter of the onChange --- NumericInput/NumericInput.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NumericInput/NumericInput.js b/NumericInput/NumericInput.js index 29255483..75e480b1 100644 --- a/NumericInput/NumericInput.js +++ b/NumericInput/NumericInput.js @@ -115,10 +115,10 @@ export default class NumericInput extends Component { this.setState({ stringValue: value }) let parsedValue = this.props.valueType === 'real' ? parseFloat(value) : parseInt(value) parsedValue = isNaN(parsedValue) ? 0 : parsedValue - if (parsedValue !== this.props.value) - this.props.onChange && this.props.onChange(parsedValue) - this.setState({ value: parsedValue, legal, stringValue: parsedValue.toString() }) - + if (parsedValue !== this.props.value) { + this.props.onChange && this.props.onChange(parsedValue, value) + this.setState({ value: parsedValue, legal, stringValue: parsedValue.toString() }) + } } } onBlur = () => {