Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/InputNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const InputNumber = React.forwardRef(
};

// >>> Input
const onInternalInput: React.ChangeEventHandler<HTMLInputElement> = (e) => {
const onInternalInput: React.ChangeEventHandler<HTMLInputElement> = e => {
let inputStr = e.target.value;

// optimize for chinese input experience
Expand Down Expand Up @@ -404,12 +404,12 @@ const InputNumber = React.forwardRef(
}
};

const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (event) => {
const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = event => {
const { which } = event;
userTypingRef.current = true;

if (which === KeyCode.ENTER) {
if(!compositionRef.current) {
if (!compositionRef.current) {
userTypingRef.current = false;
}
flushInputValue();
Expand All @@ -436,6 +436,8 @@ const InputNumber = React.forwardRef(
flushInputValue();

setFocus(false);

userTypingRef.current = false;
};

// ========================== Controlled ==========================
Expand Down
20 changes: 19 additions & 1 deletion tests/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement>(null)
const inputRef = React.useRef<HTMLInputElement>(null);
return (
<InputNumber
ref={inputRef}
Expand All @@ -119,6 +119,24 @@ describe('InputNumber.Input', () => {
expect(wrapper.getInputValue()).toEqual('5');
});

it('keydown Tab, after change value should be ok', () => {
let outSetValue;

const Demo = () => {
const [value, setValue] = React.useState<string | number>(1);
outSetValue = setValue;
return <InputNumber autoFocus value={value} onChange={val => setValue(val)} />;
};

const wrapper = mount(<Demo />);
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();
Expand Down