Skip to content

Commit

Permalink
Merge pull request #5051 from ManelBH/fix
Browse files Browse the repository at this point in the history
Improved browser compatibility for table scroll
  • Loading branch information
archmoj authored Aug 11, 2020
2 parents ad1e8ff + 32d4fed commit cfc8c2c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/traces/table/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ module.exports = function plot(gd, wrappedTraceHolders) {
.classed(c.cn.tableControlView, true)
.style('box-sizing', 'content-box');
if(dynamic) {
var wheelEvent = 'onwheel' in document ? 'wheel' : 'mousewheel';
cvEnter
.on('mousemove', function(d) {
tableControlView
.filter(function(dd) {return d === dd;})
.call(renderScrollbarKit, gd);
})
.on('mousewheel', function(d) {
.on(wheelEvent, function(d) {
if(d.scrollbarState.wheeling) return;
d.scrollbarState.wheeling = true;
var newY = d.scrollY + d3.event.deltaY;
Expand Down
6 changes: 2 additions & 4 deletions test/jasmine/assets/mouse_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ module.exports = function(type, x, y, opts) {
var el = (opts && opts.element) || document.elementFromPoint(x, y);
var ev;

if(type === 'scroll' || type === 'mousewheel') {
// somehow table needs this to be mouswheel but others need wheel.
// yet they all work the same in the browser?
type = (type === 'scroll') ? 'wheel' : 'mousewheel';
if(type === 'scroll' || type === 'wheel') {
type = 'wheel';
ev = new window.WheelEvent(type, Lib.extendFlat({}, fullOpts, opts));
} else {
ev = new window.MouseEvent(type, fullOpts);
Expand Down
4 changes: 2 additions & 2 deletions test/jasmine/tests/table_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('table', function() {
gdWheelEventCount = 0;
Plotly.plot(gd, mockCopy.data, mockCopy.layout)
.then(function() {
gd.addEventListener('mousewheel', function(evt) {
gd.addEventListener('wheel', function(evt) {
gdWheelEventCount++;
// make sure we don't *really* scroll the page.
// that would be annoying!
Expand All @@ -440,7 +440,7 @@ describe('table', function() {

function scroll(pos, dy) {
mouseEvent('mousemove', pos.x, pos.y);
mouseEvent('mousewheel', pos.x, pos.y, {deltaX: 0, deltaY: dy});
mouseEvent('wheel', pos.x, pos.y, {deltaX: 0, deltaY: dy});
}

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

0 comments on commit cfc8c2c

Please sign in to comment.