Skip to content

Commit 7d72159

Browse files
committed
Consistent updates onClickPiece
1 parent f3ce9c1 commit 7d72159

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/range_slider.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,11 @@ export default class extends Controller {
431431
onClickPiece(e) {
432432
if (this.isDisabled) return;
433433

434-
var idx = Math.round((e.clientX - this.sliderLeft) / this.stepWidth);
434+
let relativePosition = e.clientX - this.sliderLeft;
435+
let percentage = relativePosition / this.sliderWidth;
436+
let idx = Math.round(percentage * (this.values.range.length - 1));
435437

436-
if (idx > this.values.range.length - 1) idx = this.values.range.length - 1;
437-
if (idx < 0) idx = 0;
438+
idx = Math.max(0, Math.min(idx, this.values.range.length - 1));
438439

439440
if (this.isRange) {
440441
if (idx - this.values.start <= this.values.end - idx) {

0 commit comments

Comments
 (0)