|
58 | 58 |
|
59 | 59 | let self: FieldInput | undefined;
|
60 | 60 | let inputRangeElement: HTMLInputElement | undefined;
|
61 |
| - let text = displayText(value); |
| 61 | + let text = displayText(value, unit); |
62 | 62 | let editing = false;
|
63 | 63 | // Stays in sync with a binding to the actual input range slider element.
|
64 | 64 | let rangeSliderValue = value !== undefined ? value : 0;
|
|
78 | 78 | // Track whether the Ctrl key is currently held down.
|
79 | 79 | let ctrlKeyDown = false;
|
80 | 80 |
|
81 |
| - $: watchValue(value); |
| 81 | + $: watchValue(value, unit); |
82 | 82 |
|
83 | 83 | $: sliderStepValue = isInteger ? (step === undefined ? 1 : step) : "any";
|
84 | 84 | $: styles = {
|
|
104 | 104 | // ===============================
|
105 | 105 |
|
106 | 106 | // Called only when `value` is changed from outside this component.
|
107 |
| - function watchValue(value: number | undefined) { |
| 107 | + function watchValue(value: number | undefined, unit: string) { |
108 | 108 | // Don't update if the slider is currently being dragged (we don't want the backend fighting with the user's drag)
|
109 | 109 | if (rangeSliderClickDragState === "Dragging") return;
|
110 | 110 |
|
|
123 | 123 | if (typeof min === "number") sanitized = Math.max(sanitized, min);
|
124 | 124 | if (typeof max === "number") sanitized = Math.min(sanitized, max);
|
125 | 125 |
|
126 |
| - text = displayText(sanitized); |
| 126 | + text = displayText(sanitized, unit); |
127 | 127 | }
|
128 | 128 |
|
129 | 129 | // Called internally to update the value indirectly by informing the parent component of the new value,
|
|
143 | 143 | rangeSliderValueAsRendered = newValueValidated;
|
144 | 144 | }
|
145 | 145 |
|
146 |
| - text = displayText(newValueValidated); |
| 146 | + text = displayText(newValueValidated, unit); |
147 | 147 |
|
148 | 148 | if (newValue !== undefined) dispatch("value", newValueValidated);
|
149 | 149 |
|
|
156 | 156 | // ================
|
157 | 157 |
|
158 | 158 | // 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 { |
160 | 160 | if (displayValue === undefined) return "-";
|
161 | 161 |
|
162 | 162 | const roundingPower = 10 ** Math.max(displayDecimalPlaces, 0);
|
|
0 commit comments