@@ -126,7 +126,7 @@ const InputNumber = React.forwardRef(
126126 /**
127127 * `precision` is used for formatter & onChange.
128128 * It will auto generate by `value` & `step`.
129- * But it will not block user typing when auto generated .
129+ * But it will not block user typing.
130130 *
131131 * Note: Auto generate `precision` is used for legacy logic.
132132 * We should remove this since we already support high precision with BigInt.
@@ -136,14 +136,14 @@ const InputNumber = React.forwardRef(
136136 */
137137 const getPrecision = React . useCallback (
138138 ( numStr : string , userTyping : boolean ) => {
139- if ( precision >= 0 ) {
140- return precision ;
141- }
142-
143139 if ( userTyping ) {
144140 return undefined ;
145141 }
146142
143+ if ( precision >= 0 ) {
144+ return precision ;
145+ }
146+
147147 return Math . max ( getNumberPrecision ( numStr ) , getNumberPrecision ( step ) ) ;
148148 } ,
149149 [ precision , step ] ,
@@ -215,7 +215,15 @@ const InputNumber = React.forwardRef(
215215
216216 // Should always be string
217217 function setInputValue ( newValue : DecimalClass , userTyping : boolean ) {
218- setInternalInputValue ( mergedFormatter ( newValue . toString ( false ) , userTyping ) ) ;
218+ setInternalInputValue (
219+ mergedFormatter (
220+ // Invalidate number is sometime passed by external control, we should let it go
221+ // Otherwise is controlled by internal interactive logic which check by userTyping
222+ // You can ref 'show limited value when input is not focused' test for more info.
223+ newValue . isInvalidate ( ) ? newValue . toString ( false ) : newValue . toString ( ! userTyping ) ,
224+ userTyping ,
225+ ) ,
226+ ) ;
219227 }
220228
221229 // >>> Max & Min limit
@@ -336,7 +344,7 @@ const InputNumber = React.forwardRef(
336344 } ;
337345
338346 // >>> Input
339- const onInternalInput : React . ChangeEventHandler < HTMLInputElement > = e => {
347+ const onInternalInput : React . ChangeEventHandler < HTMLInputElement > = ( e ) => {
340348 let inputStr = e . target . value ;
341349
342350 // optimize for chinese input experience
@@ -383,14 +391,14 @@ const InputNumber = React.forwardRef(
383391 /**
384392 * Flush current input content to trigger value change & re-formatter input if needed
385393 */
386- const flushInputValue = ( ) => {
394+ const flushInputValue = ( userTyping : boolean ) => {
387395 const parsedValue = getMiniDecimal ( mergedParser ( inputValue ) ) ;
388396 let formatValue : DecimalClass = parsedValue ;
389397
390398 if ( ! parsedValue . isNaN ( ) ) {
391399 // Only validate value or empty value can be re-fill to inputValue
392400 // Reassign the formatValue within ranged of trigger control
393- formatValue = triggerValueUpdate ( parsedValue , true ) ;
401+ formatValue = triggerValueUpdate ( parsedValue , userTyping ) ;
394402 } else {
395403 formatValue = decimalValue ;
396404 }
@@ -404,15 +412,15 @@ const InputNumber = React.forwardRef(
404412 }
405413 } ;
406414
407- const onKeyDown : React . KeyboardEventHandler < HTMLInputElement > = event => {
415+ const onKeyDown : React . KeyboardEventHandler < HTMLInputElement > = ( event ) => {
408416 const { which } = event ;
409417 userTypingRef . current = true ;
410418
411419 if ( which === KeyCode . ENTER ) {
412420 if ( ! compositionRef . current ) {
413421 userTypingRef . current = false ;
414422 }
415- flushInputValue ( ) ;
423+ flushInputValue ( true ) ;
416424 onPressEnter ?.( event ) ;
417425 }
418426
@@ -433,7 +441,7 @@ const InputNumber = React.forwardRef(
433441
434442 // >>> Focus & Blur
435443 const onBlur = ( ) => {
436- flushInputValue ( ) ;
444+ flushInputValue ( false ) ;
437445
438446 setFocus ( false ) ;
439447
0 commit comments