Skip to content

Commit

Permalink
Merge branch 'master' into chore-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
wjgogogo authored May 16, 2023
2 parents e9b6e60 + 740462f commit 6a8f1d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
34 changes: 31 additions & 3 deletions packages/s2-core/__tests__/spreadsheet/scroll-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ describe('Scroll Tests', () => {
).toBeFalsy();
});

test('should scroll horizontally when shift key is held', async () => {
test('should scroll horizontally when shift key is held on Windows', async () => {
s2.setOptions({
frozenRowHeader: true,
style: {
Expand Down Expand Up @@ -671,13 +671,41 @@ describe('Scroll Tests', () => {
shiftKey: true,
});

canvas.dispatchEvent(wheelEvent);
Object.defineProperty(window.navigator, 'userAgent', {
value: 'Windows',
configurable: true,
writable: true,
});

canvas.dispatchEvent(wheelEvent);
await sleep(200);

expect(onScroll).toHaveBeenCalled();
});

test('should not scroll horizontally when shift key is held on macOS', async () => {
const onScroll = jest.fn((...args) => {
expect(args[0].rowHeaderScrollX).toBeGreaterThan(0);
expect(args[0].scrollX).toBe(0);
expect(args[0].scrollY).toBe(0);
});

const wheelEvent = new WheelEvent('wheel', {
deltaX: 0,
deltaY: 20,
shiftKey: true,
});

Object.defineProperty(window.navigator, 'userAgent', {
value: 'Mac OS',
configurable: true,
writable: true,
});

canvas.dispatchEvent(wheelEvent);
await sleep(200);
expect(onScroll).not.toHaveBeenCalled();
});

it('should not change init body overscrollBehavior style when render and destroyed', () => {
document.body.style.overscrollBehavior = 'none';

Expand Down
7 changes: 4 additions & 3 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { getAdjustedRowScrollX, getAdjustedScrollOffset } from '../utils/facet';
import { getAllChildCells } from '../utils/get-all-child-cells';
import { getColsForGrid, getRowsForGrid } from '../utils/grid';
import { diffPanelIndexes, type PanelIndexes } from '../utils/indexes';
import { isMobile } from '../utils/is-mobile';
import { isMobile, isWindows } from '../utils/is-mobile';
import { DEFAULT_PAGE_INDEX } from '../common/constant/pagination';
import { CornerBBox } from './bbox/cornerBBox';
import { PanelBBox } from './bbox/panelBBox';
Expand Down Expand Up @@ -939,8 +939,9 @@ export abstract class BaseFacet {
let { deltaX, deltaY, offsetX, offsetY } = event;
const { shiftKey } = event;

// 按住shift时,固定为水平方向滚动
if (shiftKey) {
// Windows 环境,按住 shift 时,固定为水平方向滚动,macOS 环境默认有该行为
// see https://github.com/antvis/S2/issues/2198
if (shiftKey && isWindows()) {
offsetX = offsetX - deltaX + deltaY;
deltaX = deltaY;
offsetY -= deltaY;
Expand Down

0 comments on commit 6a8f1d9

Please sign in to comment.