Skip to content

Commit 12b0588

Browse files
committed
Update Direction type
1 parent 89310d8 commit 12b0588

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

packages/mui-base/src/unstable_useNumberInput/numberInputReducer.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import {
22
NumberInputActionContext,
33
NumberInputReducerAction,
44
NumberInputState,
5-
StepDirection,
65
} from './useNumberInput.types';
76
import { NumberInputActionTypes } from './numberInputAction.types';
87
import { clamp, isNumber } from './utils';
98

9+
type Direction = '+' | '-';
10+
1011
// extracted from handleValueChange
1112
function getClampedValues(rawValue: number | undefined, context: NumberInputActionContext) {
1213
const { min, max, step } = context;
@@ -24,22 +25,22 @@ function getClampedValues(rawValue: number | undefined, context: NumberInputActi
2425
function stepValue(
2526
state: NumberInputState,
2627
context: NumberInputActionContext,
27-
direction: StepDirection,
28+
direction: Direction,
2829
multiplier: number,
2930
) {
3031
const { value } = state;
3132
const { step = 1, min, max } = context;
3233

3334
if (isNumber(value)) {
3435
return {
35-
up: value + (step ?? 1) * multiplier,
36-
down: value - (step ?? 1) * multiplier,
36+
'+': value + (step ?? 1) * multiplier,
37+
'-': value - (step ?? 1) * multiplier,
3738
}[direction];
3839
}
3940

4041
return {
41-
up: min ?? 0,
42-
down: max ?? 0,
42+
'+': min ?? 0,
43+
'-': max ?? 0,
4344
}[direction];
4445
}
4546

@@ -98,8 +99,8 @@ function handleInputChange<State extends NumberInputState>(
9899
function handleStep<State extends NumberInputState>(
99100
state: State,
100101
context: NumberInputActionContext,
102+
direction: Direction,
101103
applyMultiplier: boolean,
102-
direction: StepDirection,
103104
) {
104105
const multiplier = applyMultiplier ? context.shiftMultiplier : 1;
105106

@@ -143,9 +144,9 @@ export function numberInputReducer(
143144
case NumberInputActionTypes.inputChange:
144145
return handleInputChange(state, context, action.inputValue);
145146
case NumberInputActionTypes.increment:
146-
return handleStep(state, context, action.applyMultiplier, 'up');
147+
return handleStep(state, context, '+', action.applyMultiplier);
147148
case NumberInputActionTypes.decrement:
148-
return handleStep(state, context, action.applyMultiplier, 'down');
149+
return handleStep(state, context, '-', action.applyMultiplier);
149150
case NumberInputActionTypes.incrementToMax:
150151
return handleToMinOrMax(state, context, 'max');
151152
case NumberInputActionTypes.decrementToMin:

0 commit comments

Comments
 (0)