Skip to content

Commit 5f2aa85

Browse files
committed
Move pointer if overlaps
1 parent 3e5c5a8 commit 5f2aa85

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/range_slider.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,12 @@ export default class extends Controller {
274274
this.scale.appendChild(labelContainer);
275275
labelContainer.style.width =
276276
i === this.values.range.length - 1 ? 0 : this.stepWidth + "px";
277+
277278
label.innerHTML = this.labelsValue
278279
? this.formatStr(this.values.range[i])
279280
: "";
281+
282+
label.style.whiteSpace = "nowrap";
280283
label.style.marginLeft = (label.clientWidth / 2) * -1 + "px";
281284
}
282285
}
@@ -399,18 +402,18 @@ export default class extends Controller {
399402
move(e) {
400403
if (!this.activePointer) return;
401404

402-
let coordX = e.pageX;
405+
let coordX = e.touches ? e.touches[0].pageX : e.pageX;
403406
let index = coordX - this.sliderLeft - this.pointerWidth / 2;
404407

405408
index = Math.round(index / this.stepWidth);
406409
index = Math.max(0, Math.min(index, this.values.range.length - 1));
407410

408411
if (this.isRange) {
409412
if (this.activePointer === this.pointerL) {
410-
this.values.start = index;
413+
this.values.start = Math.min(index, this.values.end);;
411414
}
412415
if (this.activePointer === this.pointerR) {
413-
this.values.end = index;
416+
this.values.end = Math.max(index, this.values.start);
414417
}
415418
} else {
416419
this.values.end = index;

0 commit comments

Comments
 (0)