Skip to content

Commit cfc8c2c

Browse files
authored
Merge pull request #5051 from ManelBH/fix
Improved browser compatibility for table scroll
2 parents ad1e8ff + 32d4fed commit cfc8c2c

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/traces/table/plot.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ module.exports = function plot(gd, wrappedTraceHolders) {
5757
.classed(c.cn.tableControlView, true)
5858
.style('box-sizing', 'content-box');
5959
if(dynamic) {
60+
var wheelEvent = 'onwheel' in document ? 'wheel' : 'mousewheel';
6061
cvEnter
6162
.on('mousemove', function(d) {
6263
tableControlView
6364
.filter(function(dd) {return d === dd;})
6465
.call(renderScrollbarKit, gd);
6566
})
66-
.on('mousewheel', function(d) {
67+
.on(wheelEvent, function(d) {
6768
if(d.scrollbarState.wheeling) return;
6869
d.scrollbarState.wheeling = true;
6970
var newY = d.scrollY + d3.event.deltaY;

test/jasmine/assets/mouse_event.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ module.exports = function(type, x, y, opts) {
3636
var el = (opts && opts.element) || document.elementFromPoint(x, y);
3737
var ev;
3838

39-
if(type === 'scroll' || type === 'mousewheel') {
40-
// somehow table needs this to be mouswheel but others need wheel.
41-
// yet they all work the same in the browser?
42-
type = (type === 'scroll') ? 'wheel' : 'mousewheel';
39+
if(type === 'scroll' || type === 'wheel') {
40+
type = 'wheel';
4341
ev = new window.WheelEvent(type, Lib.extendFlat({}, fullOpts, opts));
4442
} else {
4543
ev = new window.MouseEvent(type, fullOpts);

test/jasmine/tests/table_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ describe('table', function() {
415415
gdWheelEventCount = 0;
416416
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
417417
.then(function() {
418-
gd.addEventListener('mousewheel', function(evt) {
418+
gd.addEventListener('wheel', function(evt) {
419419
gdWheelEventCount++;
420420
// make sure we don't *really* scroll the page.
421421
// that would be annoying!
@@ -440,7 +440,7 @@ describe('table', function() {
440440

441441
function scroll(pos, dy) {
442442
mouseEvent('mousemove', pos.x, pos.y);
443-
mouseEvent('mousewheel', pos.x, pos.y, {deltaX: 0, deltaY: dy});
443+
mouseEvent('wheel', pos.x, pos.y, {deltaX: 0, deltaY: dy});
444444
}
445445

446446
it('bubbles scroll events iff they did not scroll a table', function() {

0 commit comments

Comments
 (0)