Skip to content

Commit

Permalink
refactor: enter will trigger onChange (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Sep 16, 2021
1 parent c4ae6f8 commit 2166c92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ const InputNumber = React.forwardRef(
if (!compositionRef.current) {
userTypingRef.current = false;
}
flushInputValue(true);
flushInputValue(false);
onPressEnter?.(event);
}

Expand Down
12 changes: 12 additions & 0 deletions tests/keyboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ describe('InputNumber.Keyboard', () => {
wrapper.find('input').simulate('keyDown', { which: KeyCode.DOWN });
expect(onChange).not.toHaveBeenCalled();
});

it('enter to trigger onChange with precision', () => {
const onChange = jest.fn();
const wrapper = mount(<InputNumber precision={0} onChange={onChange} />);

wrapper.find('input').simulate('change', { target: { value: '2.3333' } });
expect(onChange).toHaveBeenCalledWith(2.3333);
onChange.mockReset();

wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
expect(onChange).toHaveBeenCalledWith(2);
});
});

1 comment on commit 2166c92

@vercel
Copy link

@vercel vercel bot commented on 2166c92 Sep 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.