Skip to content

Commit 8f5de3f

Browse files
committed
chore: adjust logic
1 parent 150bd00 commit 8f5de3f

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/InputNumber.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BaseInput } from '@rc-component/input';
12
import getMiniDecimal, {
23
DecimalClass,
34
getNumberPrecision,
@@ -6,20 +7,20 @@ import getMiniDecimal, {
67
validateNumber,
78
ValueType,
89
} from '@rc-component/mini-decimal';
9-
import { clsx } from 'clsx';
10-
import { BaseInput } from '@rc-component/input';
1110
import { useLayoutUpdateEffect } from '@rc-component/util/lib/hooks/useLayoutEffect';
1211
import proxyObject from '@rc-component/util/lib/proxyObject';
1312
import { composeRef } from '@rc-component/util/lib/ref';
13+
import { clsx } from 'clsx';
1414
import * as React from 'react';
1515
import useCursor from './hooks/useCursor';
16+
import SemanticContext from './SemanticContext';
1617
import StepHandler from './StepHandler';
1718
import { getDecupleSteps } from './utils/numberUtil';
18-
import SemanticContext from './SemanticContext';
1919

2020
import type { HolderRef } from '@rc-component/input/lib/BaseInput';
2121
import { BaseInputProps } from '@rc-component/input/lib/interface';
2222
import { InputFocusOptions, triggerFocus } from '@rc-component/input/lib/utils/commonUtils';
23+
import { useEvent } from '@rc-component/util';
2324
import useFrame from './hooks/useFrame';
2425

2526
export type { ValueType };
@@ -440,7 +441,7 @@ const InternalInputNumber = React.forwardRef(
440441
};
441442

442443
// ============================= Step =============================
443-
const onInternalStep = (up: boolean, emitter: 'handler' | 'keyboard' | 'wheel') => {
444+
const onInternalStep = useEvent((up: boolean, emitter: 'handler' | 'keyboard' | 'wheel') => {
444445
// Ignore step since out of range
445446
if ((up && upDisabled) || (!up && downDisabled)) {
446447
return;
@@ -466,7 +467,7 @@ const InternalInputNumber = React.forwardRef(
466467
});
467468

468469
inputRef.current?.focus();
469-
};
470+
});
470471

471472
// ============================ Flush =============================
472473
/**
@@ -591,6 +592,7 @@ const InternalInputNumber = React.forwardRef(
591592
}, [inputValue]);
592593

593594
// ============================ Render ============================
595+
// >>>>>> Handler
594596
const upNode = (
595597
<StepHandler action="up" prefixCls={prefixCls} disabled={upDisabled} onStep={onInternalStep}>
596598
{upHandler}
@@ -608,6 +610,7 @@ const InternalInputNumber = React.forwardRef(
608610
</StepHandler>
609611
);
610612

613+
// >>>>>> Render
611614
return (
612615
<div
613616
ref={domRef}

src/StepHandler.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable react/no-unknown-property */
2-
import * as React from 'react';
3-
import { clsx } from 'clsx';
42
import raf from '@rc-component/util/lib/raf';
3+
import { clsx } from 'clsx';
4+
import * as React from 'react';
55

66
/**
77
* When click and hold on a button - the speed of auto changing the value.
@@ -28,13 +28,13 @@ export default function StepHandler({
2828
disabled,
2929
onStep,
3030
}: StepHandlerProps) {
31+
// ======================== MISC ========================
32+
const isUpAction = action === 'up';
33+
3134
// ======================== Step ========================
3235
const stepTimeoutRef = React.useRef<any>();
3336
const frameIds = React.useRef<number[]>([]);
3437

35-
const onStepRef = React.useRef<StepHandlerProps['onStep']>();
36-
onStepRef.current = onStep;
37-
3838
const onStopStep = () => {
3939
clearTimeout(stepTimeoutRef.current);
4040
};
@@ -44,11 +44,11 @@ export default function StepHandler({
4444
e.preventDefault();
4545
onStopStep();
4646

47-
onStepRef.current(action === 'up', 'handler');
47+
onStep(isUpAction, 'handler');
4848

4949
// Loop step for interval
5050
function loopStep() {
51-
onStepRef.current(action === 'up', 'handler');
51+
onStep(isUpAction, 'handler');
5252

5353
stepTimeoutRef.current = setTimeout(loopStep, STEP_INTERVAL);
5454
}
@@ -94,7 +94,7 @@ export default function StepHandler({
9494
onMouseDown={(e) => {
9595
onStepMouseDown(e);
9696
}}
97-
aria-label={action === 'up' ? 'Increase Value' : 'Decrease Value'}
97+
aria-label={isUpAction ? 'Increase Value' : 'Decrease Value'}
9898
aria-disabled={disabled}
9999
className={className}
100100
>

0 commit comments

Comments
 (0)