Skip to content

Commit

Permalink
fix: 修复非滚动引起的渲染也会触发滚动事件的问题 (#2692)
Browse files Browse the repository at this point in the history
* fix: 修复非滚动引起的渲染也会触发滚动事件的问题

* chore: 还原
  • Loading branch information
lijinke666 committed Apr 30, 2024
1 parent 2f52f3b commit 0cc2839
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
29 changes: 28 additions & 1 deletion packages/s2-core/__tests__/spreadsheet/scroll-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable jest/expect-expect */
/* eslint-disable jest/no-conditional-expect */
import * as mockDataConfig from 'tests/data/simple-data.json';
import { createMockCellInfo, getContainer, sleep } from 'tests/util/helpers';
import { get } from 'lodash';
import { cloneDeep, get } from 'lodash';
import { ScrollBar, ScrollType } from '../../src/ui/scrollbar';
import type { CellScrollPosition } from './../../src/common/interface/scroll';
import { PivotSheet, SpreadSheet } from '@/sheet-type';
Expand Down Expand Up @@ -941,4 +942,30 @@ describe('Scroll Tests', () => {
isMatchElementSpy.mockClear();
},
);

test('should not trigger scroll event when first rendered', () => {
const expectScroll = getScrollExpect();

expectScroll();
});

test('should not trigger scroll event when options changed', () => {
const expectScroll = getScrollExpect();

s2.setOptions({
hierarchyType: 'tree',
});
s2.render();

expectScroll();
});

test('should not trigger scroll event when data config changed', () => {
const expectScroll = getScrollExpect();

s2.setDataCfg(cloneDeep(mockDataConfig));
s2.render();

expectScroll();
});
});
14 changes: 7 additions & 7 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export abstract class BaseFacet {
this.renderHeaders();
this.renderScrollBars();
this.renderBackground();
this.dynamicRenderCell();
this.dynamicRenderCell(true);
}

/**
Expand Down Expand Up @@ -919,25 +919,25 @@ export abstract class BaseFacet {
ScrollType.ScrollChange,
({ offset }: ScrollChangeParams) => {
const newOffset = this.getValidScrollBarOffset(offset, maxOffset);
const rowHeaderScrollX = floor(newOffset);
const newRowHeaderScrollX = floor(newOffset);

this.setScrollOffset({ rowHeaderScrollX });
this.setScrollOffset({ rowHeaderScrollX: newRowHeaderScrollX });

this.rowHeader?.onRowScrollX(
rowHeaderScrollX,
newRowHeaderScrollX,
KEY_GROUP_ROW_RESIZE_AREA,
);
this.seriesNumberHeader?.onRowScrollX(
rowHeaderScrollX,
newRowHeaderScrollX,
KEY_GROUP_ROW_INDEX_RESIZE_AREA,
);
this.cornerHeader.onRowScrollX(
rowHeaderScrollX,
newRowHeaderScrollX,
KEY_GROUP_CORNER_RESIZE_AREA,
);

const scrollBarOffsetX = this.getScrollBarOffset(
rowHeaderScrollX,
newRowHeaderScrollX,
this.hRowScrollBar,
);

Expand Down

0 comments on commit 0cc2839

Please sign in to comment.