@@ -37,6 +37,12 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
37
37
return Math . min ( Math . max ( value , min ) , max ) ;
38
38
} ;
39
39
40
+ const setValidValue = ( value : number ) : void => {
41
+ const clampedValue = clamp ( value , minValue , maxValue ) ;
42
+ setValueState ( { currentValue : clampedValue , isEmptyString : false } ) ;
43
+ setSettingsStateValue ( clampedValue ) ;
44
+ } ;
45
+
40
46
const onStep = (
41
47
roundingOperation : 'ceil' | 'floor' ,
42
48
stepOperation : ( a : number , b : number ) => number
@@ -47,9 +53,7 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
47
53
valueRoundedToScale === currentValue
48
54
? stepOperation ( currentValue , step )
49
55
: valueRoundedToScale ;
50
- const newValue = clamp ( calculatedValue , minValue , maxValue ) ;
51
-
52
- setSettingsStateValue ( newValue ) ;
56
+ setValidValue ( calculatedValue ) ;
53
57
} ;
54
58
55
59
const onStepUp = ( ) : void => {
@@ -87,10 +91,7 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
87
91
}
88
92
89
93
if ( currentValue !== initialValue ) {
90
- /* If the user input is a number, clamp it to the min and max values */
91
- const newValue = clamp ( currentValue , minValue , maxValue ) ;
92
-
93
- setSettingsStateValue ( newValue ) ;
94
+ setValidValue ( currentValue ) ;
94
95
}
95
96
} ;
96
97
0 commit comments