@@ -37,10 +37,11 @@ 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 ) ;
40
+ const resetToInitialState = ( ) : void => {
41
+ setValueState ( {
42
+ currentValue : initialValue ,
43
+ isEmptyString : false ,
44
+ } ) ;
44
45
} ;
45
46
46
47
const onStep = (
@@ -53,7 +54,9 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
53
54
valueRoundedToScale === currentValue
54
55
? stepOperation ( currentValue , step )
55
56
: valueRoundedToScale ;
56
- setValidValue ( calculatedValue ) ;
57
+ const newValue = clamp ( calculatedValue , minValue , maxValue ) ;
58
+
59
+ setSettingsStateValue ( newValue ) ;
57
60
} ;
58
61
59
62
const onStepUp = ( ) : void => {
@@ -74,25 +77,20 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
74
77
75
78
/* Prevent the user from entering invalid values */
76
79
const onBlur = ( event : React . FocusEvent ) : void => {
77
- if ( event . currentTarget . contains ( event . relatedTarget as Node ) ) {
78
- return ;
79
- }
80
-
81
80
if (
82
- ( currentValue === 0 && minValue > 0 ) ||
83
- isNaN ( currentValue ) ||
84
- isEmptyString
81
+ ( currentValue === initialValue && ! isEmptyString ) ||
82
+ event . currentTarget . contains ( event . relatedTarget as Node )
85
83
) {
86
- setValueState ( {
87
- currentValue : initialValue ,
88
- isEmptyString : false ,
89
- } ) ;
90
84
return ;
91
85
}
92
86
93
- if ( currentValue !== initialValue ) {
94
- setValidValue ( currentValue ) ;
87
+ const clampedValue = clamp ( currentValue , minValue , maxValue ) ;
88
+ if ( clampedValue === initialValue || isNaN ( currentValue ) || isEmptyString ) {
89
+ resetToInitialState ( ) ;
90
+ return ;
95
91
}
92
+
93
+ setSettingsStateValue ( clampedValue ) ;
96
94
} ;
97
95
98
96
const valueIsNotWithinRange =
0 commit comments