Skip to content

Commit 405372b

Browse files
committed
fix: number is duplicate when input number by keyboard's numeric keypad in Chrome
1 parent 4470642 commit 405372b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: src/InputNumber.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const InternalInputNumber = React.forwardRef(
160160
const userTypingRef = React.useRef(false);
161161
const compositionRef = React.useRef(false);
162162
const shiftKeyRef = React.useRef(false);
163+
const imeCompositionRef = React.useRef(false);
163164

164165
// ============================ Value =============================
165166
// Real value control
@@ -428,6 +429,9 @@ const InternalInputNumber = React.forwardRef(
428429

429430
// >>> Input
430431
const onInternalInput: React.ChangeEventHandler<HTMLInputElement> = (e) => {
432+
if (imeCompositionRef.current && !compositionRef.current) {
433+
return;
434+
}
431435
collectInputValue(e.target.value);
432436
};
433437

@@ -498,6 +502,12 @@ const InternalInputNumber = React.forwardRef(
498502

499503
shiftKeyRef.current = shiftKey;
500504

505+
if ((event.key === 'Process' && event.code !== 'NumpadEnter' && event.code !== 'Enter') || compositionRef.current) {
506+
imeCompositionRef.current = true;
507+
} else {
508+
imeCompositionRef.current = false;
509+
}
510+
501511
if (key === 'Enter') {
502512
if (!compositionRef.current) {
503513
userTypingRef.current = false;
@@ -543,6 +553,8 @@ const InternalInputNumber = React.forwardRef(
543553

544554
// >>> Focus & Blur
545555
const onBlur = () => {
556+
imeCompositionRef.current = false;
557+
546558
if (changeOnBlur) {
547559
flushInputValue(false);
548560
}

0 commit comments

Comments
 (0)