Browse Source

fix: update unit in cfg menu input labels on slider change

Sv443 3 days ago
parent
commit
52da226a6b
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/menu/menu_old.ts

+ 4 - 4
src/menu/menu_old.ts

@@ -599,12 +599,12 @@ async function mountCfgMenu() {
             if(type === "toggle" && typeof initialVal !== "undefined")
               inputElem.checked = Boolean(initialVal);
 
-            const unitTxt = (
+            const getUnitTxt = (val: Stringifiable) => (
               "unit" in ftInfo && typeof ftInfo.unit === "string"
                 ? ftInfo.unit
                 : (
                   "unit" in ftInfo && typeof ftInfo.unit === "function"
-                    ? ftInfo.unit(Number(inputElem.value))
+                    ? ftInfo.unit(Number(val))
                     : ""
                 )
             );
@@ -614,11 +614,11 @@ async function mountCfgMenu() {
             if(type === "slider") {
               labelElem = document.createElement("label");
               labelElem.classList.add("bytm-ftconf-label", "bytm-slider-label");
-              labelElem.textContent = `${fmtVal(initialVal, featKey as FeatureKey)}${unitTxt}`;
+              labelElem.textContent = `${fmtVal(initialVal, featKey as FeatureKey)}${getUnitTxt(inputElem.value)}`;
 
               inputElem.addEventListener("input", () => {
                 if(labelElem && lastDisplayedVal !== inputElem.value) {
-                  labelElem.textContent = `${fmtVal(inputElem.value, featKey as FeatureKey)}${unitTxt}`;
+                  labelElem.textContent = `${fmtVal(inputElem.value, featKey as FeatureKey)}${getUnitTxt(inputElem.value)}`;
                   lastDisplayedVal = inputElem.value;
                 }
               });