Skip to content

Commit f3ce9c1

Browse files
committed
Fix pointer alignment if range of numbers too big
1 parent 5f2aa85 commit f3ce9c1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/range_slider.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ export default class extends Controller {
403403
if (!this.activePointer) return;
404404

405405
let coordX = e.touches ? e.touches[0].pageX : e.pageX;
406-
let index = coordX - this.sliderLeft - this.pointerWidth / 2;
406+
let relativePosition = coordX - this.sliderLeft;
407+
let percentage = relativePosition / this.sliderWidth;
408+
let index = Math.round(percentage * (this.values.range.length - 1));
407409

408-
index = Math.round(index / this.stepWidth);
410+
// Ensure index is within valid range
409411
index = Math.max(0, Math.min(index, this.values.range.length - 1));
410412

411413
if (this.isRange) {

0 commit comments

Comments
 (0)