Skip to content

Commit 5209360

Browse files
author
Alberto Iannaccone
committed
always set the internal state value
1 parent 26a1b18 commit 5209360

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arduino-ide-extension/src/browser/dialogs/settings/settings-step-input.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
3737
return Math.min(Math.max(value, min), max);
3838
};
3939

40+
const setValidValue = (value: number): void => {
41+
const clampedValue = clamp(value, minValue, maxValue);
42+
setValueState({ currentValue: clampedValue, isEmptyString: false });
43+
setSettingsStateValue(clampedValue);
44+
};
45+
4046
const onStep = (
4147
roundingOperation: 'ceil' | 'floor',
4248
stepOperation: (a: number, b: number) => number
@@ -47,9 +53,7 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
4753
valueRoundedToScale === currentValue
4854
? stepOperation(currentValue, step)
4955
: valueRoundedToScale;
50-
const newValue = clamp(calculatedValue, minValue, maxValue);
51-
52-
setSettingsStateValue(newValue);
56+
setValidValue(calculatedValue);
5357
};
5458

5559
const onStepUp = (): void => {
@@ -87,10 +91,7 @@ const SettingsStepInput: React.FC<SettingsStepInputProps> = (
8791
}
8892

8993
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);
9495
}
9596
};
9697

0 commit comments

Comments
 (0)