@@ -2,9 +2,15 @@ import * as React from 'react';
22import  classNames  from  'classnames' ; 
33import  KeyCode  from  'rc-util/lib/KeyCode' ; 
44import  {  composeRef  }  from  'rc-util/lib/ref' ; 
5- import  getMiniDecimal ,  {  DecimalClass ,  toFixed ,  ValueType  }  from  './utils/MiniDecimal' ; 
5+ import  getMiniDecimal ,  { 
6+   DecimalClass , 
7+   roundDownUnsignedDecimal , 
8+   roundUpUnsignedDecimal , 
9+   toFixed , 
10+   ValueType 
11+ }  from  './utils/MiniDecimal' ; 
612import  StepHandler  from  './StepHandler' ; 
7- import  {   getNumberPrecision ,  num2str ,  validateNumber   }  from  './utils/numberUtil' ; 
13+ import  { getNumberPrecision ,  num2str ,  trimNumber ,   validateNumber }  from  './utils/numberUtil' ; 
814import  useCursor  from  './hooks/useCursor' ; 
915import  useUpdateEffect  from  './hooks/useUpdateEffect' ; 
1016import  useFrame  from  './hooks/useFrame' ; 
@@ -20,9 +26,32 @@ const getDecimalValue = (stringMode: boolean, decimalValue: DecimalClass) => {
2026  return  decimalValue . toNumber ( ) ; 
2127} ; 
2228
23- const  getDecimalIfValidate  =  ( value : ValueType )  =>  { 
29+ /** 
30+  * format max or min value 
31+  * 1. if isInvalid return null 
32+  * 2. if precision is undefined, return decimal 
33+  * 3. format with precision 
34+  *    I. if max > 0, round down with precision. Example: max= 3.5, precision=0  afterFormat: 3 
35+  *    II. if max < 0, round up with precision. Example: max= -3.5, precision=0  afterFormat: -4 
36+  *    III. if min > 0, round up with precision. Example: min= 3.5, precision=0  afterFormat: 4 
37+  *    IV. if min < 0, round down with precision. Example: max= -3.5, precision=0  afterFormat: -3 
38+  */ 
39+ const  getDecimalIfValidate  =  ( value : ValueType ,  precision : number  |  undefined ,  isMax ?: boolean )  =>  { 
2440  const  decimal  =  getMiniDecimal ( value ) ; 
25-   return  decimal . isInvalidate ( )  ? null  : decimal ; 
41+   if  ( decimal . isInvalidate ( ) )  { 
42+     return  null ; 
43+   } 
44+   if  ( precision  ===  undefined )  { 
45+     return  decimal ; 
46+   } 
47+   const  { negative,  integerStr,  decimalStr,  negativeStr}  =  trimNumber ( decimal . toString ( ) ) 
48+ 
49+   const  unSignedNumberStr  =  integerStr  + '.'  +   decimalStr 
50+   if  ( ( isMax  &&  ! negative )  ||  ( ! isMax  &&  negative ) )  { 
51+     return  getMiniDecimal ( negativeStr  +   roundDownUnsignedDecimal ( unSignedNumberStr ,  precision ) ) 
52+   }  else  { 
53+     return  getMiniDecimal ( negativeStr  +   roundUpUnsignedDecimal ( unSignedNumberStr ,  precision ) ) 
54+   } 
2655} ; 
2756
2857export  interface  InputNumberProps < T  extends  ValueType  =  ValueType > 
@@ -232,8 +261,8 @@ const InputNumber = React.forwardRef(
232261    } 
233262
234263    // >>> Max & Min limit 
235-     const  maxDecimal  =  React . useMemo ( ( )  =>  getDecimalIfValidate ( max ) ,  [ max ] ) ; 
236-     const  minDecimal  =  React . useMemo ( ( )  =>  getDecimalIfValidate ( min ) ,  [ min ] ) ; 
264+     const  maxDecimal  =  React . useMemo ( ( )  =>  getDecimalIfValidate ( max ,   precision ,   true ) ,  [ max ,   precision ] ) ; 
265+     const  minDecimal  =  React . useMemo ( ( )  =>  getDecimalIfValidate ( min ,   precision ,   false ) ,  [ min ,   precision ] ) ; 
237266
238267    const  upDisabled  =  React . useMemo ( ( )  =>  { 
239268      if  ( ! maxDecimal  ||  ! decimalValue  ||  decimalValue . isInvalidate ( ) )  { 
@@ -504,7 +533,7 @@ const InputNumber = React.forwardRef(
504533          [ `${ prefixCls }  ] : decimalValue . isNaN ( ) , 
505534          [ `${ prefixCls }  ] : ! decimalValue . isInvalidate ( )  &&  ! isInRange ( decimalValue ) , 
506535        } ) } 
507-         style = { style } 
536+         style = { { ... style ,   color :  'red' } } 
508537        onFocus = { ( )  =>  { 
509538          setFocus ( true ) ; 
510539        } } 
0 commit comments