Skip to content

Commit

Permalink
Block the wheel -> scrollTop/scrollLeft assignment when window
Browse files Browse the repository at this point in the history
…is the instance's scrollable container. (#10996)

* Block the scrollTop/scrollLeft assignment when window is the scrollable container.

* Add the changelog entry.
  • Loading branch information
jansiegel committed May 27, 2024
1 parent 926dcbe commit a97e5da
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changelogs/10996.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"issuesOrigin": "private",
"title": "Fixed a problem where clicking and dragging on cells on a window-controlled scrolled instances would end up in unpredictable results.",
"type": "fixed",
"issueOrPR": 10996,
"breaking": false,
"framework": "none"
}
6 changes: 5 additions & 1 deletion handsontable/src/3rdparty/walkontable/src/overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ class Overlays {
const shouldNotWheelHorizontally = masterHorizontal !== rootWindow &&
target !== rootWindow && !target.contains(masterHorizontal);

if (this.keyPressed && (shouldNotWheelVertically || shouldNotWheelHorizontally)) {
if (
(this.keyPressed && (shouldNotWheelVertically || shouldNotWheelHorizontally))
||
this.scrollableElement === rootWindow
) {
return;
}

Expand Down
29 changes: 29 additions & 0 deletions handsontable/src/3rdparty/walkontable/test/spec/scroll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,35 @@ describe('WalkontableScroll', () => {
bottomHolder.removeEventListener('scroll', bottomCallback);
leftHolder.removeEventListener('scroll', leftCallback);
});

it('should not try to set the window\'s `scrollTop`/`scrollLeft` and `scrollY`/`scrollX` properties ' +
'when the window-scrolled table is scrolled', async() => {
spec().$wrapper.eq(0).css({ overflow: '', height: '', width: '' });

const wt = walkontable({
data: getData,
totalRows: getTotalRows,
totalColumns: getTotalColumns,
});

spyOn(wt.wtOverlays, 'scrollVertically').and.callThrough();
spyOn(wt.wtOverlays, 'scrollHorizontally').and.callThrough();

wt.draw();

const masterRootElement = wt.wtTable.wtRootElement;

wheelOnElement(masterRootElement, 400);
wt.draw();

await sleep(200);

expect(window.scrollTop).toEqual(undefined);
expect(window.scrollLeft).toEqual(undefined);

expect(wt.wtOverlays.scrollVertically).not.toHaveBeenCalled();
expect(wt.wtOverlays.scrollHorizontally).not.toHaveBeenCalled();
});
});

describe('horizontal scroll', () => {
Expand Down
2 changes: 1 addition & 1 deletion handsontable/src/plugins/dragToScroll/dragToScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class DragToScroll extends BasePlugin {
}

/**
* Sets the value of the visible element.
* Sets the boundaries/dimensions of the scrollable viewport.
*
* @param {DOMRect|{left: number, right: number, top: number, bottom: number}} [boundaries] An object with
* coordinates. Contains the window boundaries by default. The object is compatible with DOMRect.
Expand Down

0 comments on commit a97e5da

Please sign in to comment.