We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3ce9c1 commit 7d72159Copy full SHA for 7d72159
src/range_slider.js
@@ -431,10 +431,11 @@ export default class extends Controller {
431
onClickPiece(e) {
432
if (this.isDisabled) return;
433
434
- var idx = Math.round((e.clientX - this.sliderLeft) / this.stepWidth);
+ let relativePosition = e.clientX - this.sliderLeft;
435
+ let percentage = relativePosition / this.sliderWidth;
436
+ let idx = Math.round(percentage * (this.values.range.length - 1));
437
- if (idx > this.values.range.length - 1) idx = this.values.range.length - 1;
- if (idx < 0) idx = 0;
438
+ idx = Math.max(0, Math.min(idx, this.values.range.length - 1));
439
440
if (this.isRange) {
441
if (idx - this.values.start <= this.values.end - idx) {
0 commit comments