From a04fb2133577450ad51ed5eb0c713302df373f85 Mon Sep 17 00:00:00 2001 From: "Ghislain B." Date: Sat, 11 Jan 2025 17:03:40 -0500 Subject: [PATCH] fix: shift+mousewheel should scroll horizontally (#1792) --- packages/common/src/core/__tests__/slickGrid.spec.ts | 1 + packages/common/src/core/slickGrid.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/common/src/core/__tests__/slickGrid.spec.ts b/packages/common/src/core/__tests__/slickGrid.spec.ts index e1847be71..2ab623df3 100644 --- a/packages/common/src/core/__tests__/slickGrid.spec.ts +++ b/packages/common/src/core/__tests__/slickGrid.spec.ts @@ -4015,6 +4015,7 @@ describe('SlickGrid core file', () => { grid.scrollCellIntoView(1, 2, true); const mouseEvent = new Event('mousewheel'); + Object.defineProperty(mouseEvent, 'shiftKey', { writable: true, value: true }); const mousePreventSpy = vi.spyOn(mouseEvent, 'preventDefault'); const onViewportChangedSpy = vi.spyOn(grid.onViewportChanged, 'notify'); const viewportTopLeftElm = container.querySelector('.slick-viewport-top.slick-viewport-left') as HTMLDivElement; diff --git a/packages/common/src/core/slickGrid.ts b/packages/common/src/core/slickGrid.ts index a31509ca4..ef4a6f4d2 100755 --- a/packages/common/src/core/slickGrid.ts +++ b/packages/common/src/core/slickGrid.ts @@ -5133,8 +5133,12 @@ export class SlickGrid = Column, O e protected handleMouseWheel(e: MouseEvent, _delta: number, deltaX: number, deltaY: number): void { this.scrollHeight = this._viewportScrollContainerY.scrollHeight; - this.scrollTop = Math.max(0, this._viewportScrollContainerY.scrollTop - deltaY * this._options.rowHeight!); - this.scrollLeft = this._viewportScrollContainerX.scrollLeft + deltaX * 10; + if (e.shiftKey) { + this.scrollLeft = this._viewportScrollContainerX.scrollLeft + deltaX * 10; + } else { + this.scrollTop = Math.max(0, this._viewportScrollContainerY.scrollTop - deltaY * this._options.rowHeight!); + this.scrollLeft = this._viewportScrollContainerX.scrollLeft + deltaX * 10; + } const handled = this._handleScroll('mousewheel'); if (handled) { e.preventDefault();