diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index 541be08f..43ee2830 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -139,6 +139,8 @@ const InputNumber = React.forwardRef( const [focus, setFocus] = React.useState(false); + const [illegalData, setIllegalData] = React.useState(false); + const userTypingRef = React.useRef(false); const compositionRef = React.useRef(false); @@ -399,8 +401,13 @@ const InputNumber = React.forwardRef( collectInputValue(inputRef.current.value); }; + const judgeData = (inputNumberValue: string) => { + return (isNaN(Number(inputNumberValue)) && inputNumberValue !== '-') || (max && inputNumberValue > max) || (min && inputNumberValue < min) + } + // >>> Input const onInternalInput: React.ChangeEventHandler = (e) => { + setIllegalData(judgeData(e.target.value)) collectInputValue(e.target.value); }; @@ -487,6 +494,8 @@ const InputNumber = React.forwardRef( // >>> Focus & Blur const onBlur = () => { flushInputValue(false); + + setIllegalData(false) setFocus(false); @@ -531,7 +540,7 @@ const InputNumber = React.forwardRef( [`${prefixCls}-disabled`]: disabled, [`${prefixCls}-readonly`]: readOnly, [`${prefixCls}-not-a-number`]: decimalValue.isNaN(), - [`${prefixCls}-out-of-range`]: !decimalValue.isInvalidate() && !isInRange(decimalValue), + [`${prefixCls}-out-of-range`]: (!decimalValue.isInvalidate() && !isInRange(decimalValue)) || illegalData, })} style={style} onFocus={() => {