File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,8 @@ const InputNumber = React.forwardRef(
141141
142142 const userTypingRef = React . useRef ( false ) ;
143143 const compositionRef = React . useRef ( false ) ;
144+ const keydownRef = React . useRef ( false ) ;
145+ const onChangeRef = React . useRef < ( ) => void > ( ) ;
144146
145147 // ============================ Value =============================
146148 // Real value control
@@ -401,6 +403,13 @@ const InputNumber = React.forwardRef(
401403
402404 // >>> Input
403405 const onInternalInput : React . ChangeEventHandler < HTMLInputElement > = ( e ) => {
406+ if ( ! keydownRef . current ) {
407+ const v = e . target . value ;
408+ onChangeRef . current = ( ) => {
409+ collectInputValue ( v ) ;
410+ } ;
411+ return ;
412+ }
404413 collectInputValue ( e . target . value ) ;
405414 } ;
406415
@@ -469,6 +478,12 @@ const InputNumber = React.forwardRef(
469478 onPressEnter ?.( event ) ;
470479 }
471480
481+ keydownRef . current = true ;
482+ if ( onChangeRef . current ) {
483+ onChangeRef . current ( ) ;
484+ onChangeRef . current = undefined ;
485+ }
486+
472487 if ( keyboard === false ) {
473488 return ;
474489 }
@@ -482,6 +497,7 @@ const InputNumber = React.forwardRef(
482497
483498 const onKeyUp = ( ) => {
484499 userTypingRef . current = false ;
500+ keydownRef . current = false ;
485501 } ;
486502
487503 // >>> Focus & Blur
Original file line number Diff line number Diff line change @@ -458,10 +458,12 @@ describe('InputNumber.Github', () => {
458458 wrapper
459459 . find ( 'input' )
460460 . last ( )
461+ . simulate ( 'keyDown' )
461462 . simulate ( 'change' , { target : { value : '1.23' } } ) ;
462463 wrapper
463464 . find ( 'input' )
464465 . first ( )
466+ . simulate ( 'keyDown' )
465467 . simulate ( 'change' , { target : { value : '0' } } ) ;
466468
467469 expect ( wrapper . find ( 'input' ) . last ( ) . props ( ) . value ) . toEqual ( '1' ) ;
Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ describe('InputNumber.Keyboard', () => {
3535 const onChange = jest . fn ( ) ;
3636 const wrapper = mount ( < InputNumber precision = { 0 } onChange = { onChange } /> ) ;
3737
38- wrapper . find ( 'input' ) . simulate ( 'change' , { target : { value : '2.3333' } } ) ;
38+ wrapper
39+ . find ( 'input' )
40+ . simulate ( 'keyDown' )
41+ . simulate ( 'change' , { target : { value : '2.3333' } } ) ;
3942 expect ( onChange ) . toHaveBeenCalledWith ( 2.3333 ) ;
4043 onChange . mockReset ( ) ;
4144
You can’t perform that action at this time.
0 commit comments