diff --git a/src/InputNumber.tsx b/src/InputNumber.tsx index 7c541e27..c956f10c 100644 --- a/src/InputNumber.tsx +++ b/src/InputNumber.tsx @@ -336,7 +336,7 @@ const InputNumber = React.forwardRef( }; // >>> Input - const onInternalInput: React.ChangeEventHandler = (e) => { + const onInternalInput: React.ChangeEventHandler = e => { let inputStr = e.target.value; // optimize for chinese input experience @@ -404,12 +404,12 @@ const InputNumber = React.forwardRef( } }; - const onKeyDown: React.KeyboardEventHandler = (event) => { + const onKeyDown: React.KeyboardEventHandler = event => { const { which } = event; userTypingRef.current = true; if (which === KeyCode.ENTER) { - if(!compositionRef.current) { + if (!compositionRef.current) { userTypingRef.current = false; } flushInputValue(); @@ -436,6 +436,8 @@ const InputNumber = React.forwardRef( flushInputValue(); setFocus(false); + + userTypingRef.current = false; }; // ========================== Controlled ========================== diff --git a/tests/input.test.tsx b/tests/input.test.tsx index d8f8d859..346daddd 100644 --- a/tests/input.test.tsx +++ b/tests/input.test.tsx @@ -97,7 +97,7 @@ describe('InputNumber.Input', () => { it('pressEnter value should be ok', () => { const Demo = () => { const [value, setValue] = React.useState(1); - const inputRef = React.useRef(null) + const inputRef = React.useRef(null); return ( { expect(wrapper.getInputValue()).toEqual('5'); }); + it('keydown Tab, after change value should be ok', () => { + let outSetValue; + + const Demo = () => { + const [value, setValue] = React.useState(1); + outSetValue = setValue; + return setValue(val)} />; + }; + + const wrapper = mount(); + wrapper.findInput().simulate('keyDown', { which: KeyCode.TAB }); + wrapper.blurInput(); + expect(wrapper.getInputValue()).toEqual('1'); + outSetValue(5); + wrapper.focusInput(); + expect(wrapper.getInputValue()).toEqual('5'); + }); + describe('empty on blur should trigger null', () => { it('basic', () => { const onChange = jest.fn();