Skip to content

Commit

Permalink
[color-slider] Correctly handle spinner properties when showing progress
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
DmitrySharabin committed Jun 5, 2024
1 parent f0196b1 commit 8549e0f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/color-slider/color-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ const Self = class ColorSlider extends NudeElement {
}

propChangedCallback ({name, prop, detail: change}) {
// Spinner values when tooltip is "progress"
let values = { min: 1, max: 100, step: 1, value: +(this.progress * 100).toPrecision(4) };
values["defaultValue"] = values.value;

if (["min", "max", "step", "value", "defaultValue"].includes(name)) {
prop.applyChange(this._el.slider, change);

let value = change.value;
if (this.tooltip === "progress" && (name === "value" || name === "defaultValue")) {
value = +(this.progress * 100).toPrecision(4);
}
let value = this.tooltip === "progress" ? values[name] : change.value;
prop.applyChange(this._el.spinner, {...change, value});
}

Expand Down Expand Up @@ -130,6 +131,13 @@ const Self = class ColorSlider extends NudeElement {
this._el.spinner.style.setProperty("--value-length", valueStr.length);
}
}
else if (name === "tooltip") {
if (change.value === "progress") {
["min", "max", "step", "value"].forEach(name => {
this._el.spinner[name] = values[name];
});
}
}
}

tessellateStops (options = {}) {
Expand Down

0 comments on commit 8549e0f

Please sign in to comment.