Skip to content

Commit 9eeefaa

Browse files
authored
Fix NumberInput widget not being reactive to changes to the unit (#2080)
Svelte watch unit
1 parent c27d8dc commit 9eeefaa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

frontend/src/components/widgets/inputs/NumberInput.svelte

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
5959
let self: FieldInput | undefined;
6060
let inputRangeElement: HTMLInputElement | undefined;
61-
let text = displayText(value);
61+
let text = displayText(value, unit);
6262
let editing = false;
6363
// Stays in sync with a binding to the actual input range slider element.
6464
let rangeSliderValue = value !== undefined ? value : 0;
@@ -78,7 +78,7 @@
7878
// Track whether the Ctrl key is currently held down.
7979
let ctrlKeyDown = false;
8080
81-
$: watchValue(value);
81+
$: watchValue(value, unit);
8282
8383
$: sliderStepValue = isInteger ? (step === undefined ? 1 : step) : "any";
8484
$: styles = {
@@ -104,7 +104,7 @@
104104
// ===============================
105105
106106
// Called only when `value` is changed from outside this component.
107-
function watchValue(value: number | undefined) {
107+
function watchValue(value: number | undefined, unit: string) {
108108
// Don't update if the slider is currently being dragged (we don't want the backend fighting with the user's drag)
109109
if (rangeSliderClickDragState === "Dragging") return;
110110
@@ -123,7 +123,7 @@
123123
if (typeof min === "number") sanitized = Math.max(sanitized, min);
124124
if (typeof max === "number") sanitized = Math.min(sanitized, max);
125125
126-
text = displayText(sanitized);
126+
text = displayText(sanitized, unit);
127127
}
128128
129129
// Called internally to update the value indirectly by informing the parent component of the new value,
@@ -143,7 +143,7 @@
143143
rangeSliderValueAsRendered = newValueValidated;
144144
}
145145
146-
text = displayText(newValueValidated);
146+
text = displayText(newValueValidated, unit);
147147
148148
if (newValue !== undefined) dispatch("value", newValueValidated);
149149
@@ -156,7 +156,7 @@
156156
// ================
157157
158158
// Calculates the string to display when the field is not being edited.
159-
function displayText(displayValue: number | undefined): string {
159+
function displayText(displayValue: number | undefined, unit: string): string {
160160
if (displayValue === undefined) return "-";
161161
162162
const roundingPower = 10 ** Math.max(displayDecimalPlaces, 0);

0 commit comments

Comments
 (0)