Skip to content

Commit 5231272

Browse files
authored
Merge pull request #6780 from david-bezero/range-0
Do not break if mouse moves to x=0 when using rangeslider
2 parents b735a81 + 769158d commit 5231272

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

draftlogs/6780_fix.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix `Cannot read properties of undefined (reading '0')` when the mouse moves to x=0 while dragging a rangeslider [[#6780](https://github.com/plotly/plotly.js/pull/6780)], with thanks to @david-bezero for the contribution!

src/components/rangeslider/draw.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ module.exports = function(gd) {
224224
});
225225
};
226226

227+
function eventX(event) {
228+
if(typeof event.clientX === 'number') {
229+
return event.clientX;
230+
}
231+
if(event.touches && event.touches.length > 0) {
232+
return event.touches[0].clientX;
233+
}
234+
return 0;
235+
}
236+
227237
function setupDragElement(rangeSlider, gd, axisOpts, opts) {
228238
if(gd._context.staticPlot) return;
229239

@@ -234,7 +244,7 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
234244
function mouseDownHandler() {
235245
var event = d3.event;
236246
var target = event.target;
237-
var startX = event.clientX || event.touches[0].clientX;
247+
var startX = eventX(event);
238248
var offsetX = startX - rangeSlider.node().getBoundingClientRect().left;
239249
var minVal = opts.d2p(axisOpts._rl[0]);
240250
var maxVal = opts.d2p(axisOpts._rl[1]);
@@ -247,7 +257,7 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
247257
dragCover.addEventListener('mouseup', mouseUp);
248258

249259
function mouseMove(e) {
250-
var clientX = e.clientX || e.touches[0].clientX;
260+
var clientX = eventX(e);
251261
var delta = +clientX - startX;
252262
var pixelMin, pixelMax, cursor;
253263

0 commit comments

Comments
 (0)