Skip to content

Commit 2166c92

Browse files
authored
refactor: enter will trigger onChange (#357)
1 parent c4ae6f8 commit 2166c92

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/InputNumber.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ const InputNumber = React.forwardRef(
428428
if (!compositionRef.current) {
429429
userTypingRef.current = false;
430430
}
431-
flushInputValue(true);
431+
flushInputValue(false);
432432
onPressEnter?.(event);
433433
}
434434

tests/keyboard.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,16 @@ describe('InputNumber.Keyboard', () => {
3030
wrapper.find('input').simulate('keyDown', { which: KeyCode.DOWN });
3131
expect(onChange).not.toHaveBeenCalled();
3232
});
33+
34+
it('enter to trigger onChange with precision', () => {
35+
const onChange = jest.fn();
36+
const wrapper = mount(<InputNumber precision={0} onChange={onChange} />);
37+
38+
wrapper.find('input').simulate('change', { target: { value: '2.3333' } });
39+
expect(onChange).toHaveBeenCalledWith(2.3333);
40+
onChange.mockReset();
41+
42+
wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
43+
expect(onChange).toHaveBeenCalledWith(2);
44+
});
3345
});

0 commit comments

Comments
 (0)