Skip to content

Commit e9953c1

Browse files
committed
Added touchmove support to slider component
See #5855
1 parent bbeeda9 commit e9953c1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

draftlogs/5856_add.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Add touch support to slider [[#5856](https://github.com/plotly/plotly.js/pull/5856)]

src/components/sliders/draw.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ function attachGripEvents(item, gd, sliderGroup) {
461461
return sliderGroup.data()[0];
462462
}
463463

464-
item.on('mousedown', function() {
464+
function mouseDownHandler() {
465465
var sliderOpts = getSliderOpts();
466466
gd.emit('plotly_sliderstart', {slider: sliderOpts});
467467

@@ -475,25 +475,36 @@ function attachGripEvents(item, gd, sliderGroup) {
475475
handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, true);
476476
sliderOpts._dragging = true;
477477

478-
$gd.on('mousemove', function() {
478+
function mouseMoveHandler() {
479479
var sliderOpts = getSliderOpts();
480480
var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);
481481
handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, false);
482-
});
482+
}
483+
484+
$gd.on('mousemove', mouseMoveHandler);
485+
$gd.on('touchmove', mouseMoveHandler);
483486

484-
$gd.on('mouseup', function() {
487+
function mouseUpHandler() {
485488
var sliderOpts = getSliderOpts();
486489
sliderOpts._dragging = false;
487490
grip.call(Color.fill, sliderOpts.bgcolor);
488491
$gd.on('mouseup', null);
489492
$gd.on('mousemove', null);
493+
$gd.on('touchend', null);
494+
$gd.on('touchmove', null);
490495

491496
gd.emit('plotly_sliderend', {
492497
slider: sliderOpts,
493498
step: sliderOpts.steps[sliderOpts.active]
494499
});
495-
});
496-
});
500+
}
501+
502+
$gd.on('mouseup', mouseUpHandler);
503+
$gd.on('touchend', mouseUpHandler);
504+
}
505+
506+
item.on('mousedown', mouseDownHandler);
507+
item.on('touchstart', mouseDownHandler);
497508
}
498509

499510
function drawTicks(sliderGroup, sliderOpts) {

0 commit comments

Comments
 (0)