From 825ccb389b5d15b58eeebf40d046179b14a6ccfe Mon Sep 17 00:00:00 2001 From: melloware Date: Fri, 11 Nov 2022 11:26:34 -0500 Subject: [PATCH] Fix #2871: InputNumber duplicating suffix when using decimals --- components/lib/inputnumber/InputNumber.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/lib/inputnumber/InputNumber.js b/components/lib/inputnumber/InputNumber.js index ee0b4cf8d3..e51a443d0d 100644 --- a/components/lib/inputnumber/InputNumber.js +++ b/components/lib/inputnumber/InputNumber.js @@ -889,9 +889,13 @@ export const InputNumber = React.memo( if (val1 && val2) { let decimalCharIndex = val2.search(_decimal.current); + if (decimalCharIndex === -1) { + return val1; + } + _decimal.current.lastIndex = 0; - return decimalCharIndex !== -1 ? val1.split(_decimal.current)[0] + val2.slice(decimalCharIndex) : val1; + return decimalCharIndex !== -1 ? replaceSuffix(val1.split(_decimal.current)[0]) + val2.slice(decimalCharIndex) : val1; } return val1; @@ -902,13 +906,21 @@ export const InputNumber = React.memo( const valueSplit = value.split(_decimal.current); if (valueSplit.length === 2) { - return valueSplit[1].replace(_suffix.current, '').trim().replace(/\s/g, '').replace(_currency.current, '').length; + return replaceSuffix(valueSplit[1]).length; } } return 0; }; + const replaceSuffix = (value) => { + if (!value) { + return value; + } + + return value.replace(_suffix.current, '').trim().replace(/\s/g, '').replace(_currency.current, ''); + }; + const updateModel = (event, value) => { if (props.onValueChange) { props.onValueChange({