From 685971fa09deada33e65a57ad0a094fc2b1f43ef Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 16 Nov 2020 16:35:03 +0100 Subject: [PATCH] Max length for InputNumber (equal to allowed digits) (#4034) * Max length for InputNumber (equal to allowed digits) * Description on length check --- packages/react-components/src/InputNumber.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/react-components/src/InputNumber.tsx b/packages/react-components/src/InputNumber.tsx index fc94aff48f..de6ec71015 100644 --- a/packages/react-components/src/InputNumber.tsx +++ b/packages/react-components/src/InputNumber.tsx @@ -243,7 +243,10 @@ function InputNumber ({ autoFocus, bitLength = DEFAULT_BITLENGTH, children, clas [_onChangeWithSi, value] ); - const maxValueLength = getGlobalMaxValue(bitLength).toString().length - 1; + // Same as the number of digits, which means it can still overflow, i.e. + // for u8 we allow 3, which could be 999 (however 2 digits will limit to only 99, + // so this is more-or-less the lesser of evils without a max-value check) + const maxValueLength = getGlobalMaxValue(bitLength).toString().length; return (