From 009b298fdb663180d4bc8c9ed7355f9e96e42c6b Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 23 Jun 2020 20:41:43 -0500 Subject: [PATCH] fix: number validation and shift inc --- src/client/types/number.type-renderer.jsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/client/types/number.type-renderer.jsx b/src/client/types/number.type-renderer.jsx index a3d60d5..9ce9921 100644 --- a/src/client/types/number.type-renderer.jsx +++ b/src/client/types/number.type-renderer.jsx @@ -14,6 +14,7 @@ const Number = ({ options, value, }) => { + const [whole, fraction = 0] = `${value}`.split('.'); const inputRef = useRef(null); return ( @@ -32,24 +33,30 @@ const Number = ({ onChange={(event) => { const {value: number} = event.target; // eslint-disable-next-line no-restricted-globals - if (!isNaN(number)) { - onChange('' === number ? 0 : parseInt(number, 10), event); + if (number.match(/^(?:[0-9]+)?\.?(?:[0-9]+)?$/)) { + onChange('' === number ? 0 : parseFloat(number), event); } }} // onWheel={(e) => (e.preventDefault(), false)} ref={inputRef} type="text" - value={value} + value={`${whole}.${fraction}`} />