Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block the wheel -> scrollTop/scrollLeft assignment when window is the instance's scrollable container. #10996

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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