Skip to content

Commit

Permalink
fix: 有冻结行且有垂直scrollWidth时冻结行无法 resize (#1594)
Browse files Browse the repository at this point in the history
* fix: 有冻结行且有垂直scrollWidth时冻结航无法resize

* fix: 有冻结行且有垂直scrollWidth时冻结航无法resize

Co-authored-by: owen.wjh <[email protected]>
  • Loading branch information
serializedowen and owen.wjh authored Jul 22, 2022
1 parent 6b76c4e commit bcdcbe1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
).toEqual(mockTableDataConfig.fields.columns);
});

test('should hidden column correctly', () => {
test('should hide column correctly', () => {
const hiddenColumns = ['cost'];

tableSheet.interaction.hideColumns(hiddenColumns);
Expand All @@ -62,7 +62,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(costDetail.hideColumnNodes[0].field).toEqual('cost');
});

test('should hidden multiple columns correctly', () => {
test('should hide multiple columns correctly', () => {
const hiddenColumns = ['price', 'city'];

tableSheet.interaction.hideColumns(hiddenColumns);
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(cityDetail.hideColumnNodes[0].field).toEqual('city');
});

test('should hidden closer group columns correctly', () => {
test('should hide closer group columns correctly', () => {
const hiddenColumns = ['cost', 'province'];

tableSheet.interaction.hideColumns(hiddenColumns);
Expand All @@ -125,7 +125,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(groupDetail.hideColumnNodes[1].field).toEqual('province');
});

test('should default hidden columns by interaction hiddenColumnFields config', () => {
test('should hide columns by interaction hiddenColumnFields config by default', () => {
const hiddenColumns = ['cost'];
const sheet = new TableSheet(getContainer(), mockTableDataConfig, {
...s2Options,
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
).toEqual([typePriceColumnId, cityPriceColumnId]);
});

test('should hidden column correctly', () => {
test('should hide column correctly', () => {
const hiddenColumns = [typePriceColumnId];

pivotSheet.interaction.hideColumns(hiddenColumns);
Expand All @@ -207,7 +207,7 @@ describe('SpreadSheet Hidden Columns Tests', () => {
expect(priceDetail.hideColumnNodes[0].id).toEqual(typePriceColumnId);
});

test('should hidden multiple columns correctly', () => {
test('should hide multiple columns correctly', () => {
const hiddenColumns = [typePriceColumnId, cityPriceColumnId];

pivotSheet.interaction.hideColumns(hiddenColumns);
Expand Down
29 changes: 29 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type S2Options,
type S2DataConfig,
ResizeType,
ColCell,
} from '@/index';

const data = getMockData(
Expand Down Expand Up @@ -123,5 +124,33 @@ describe('TableSheet normal spec', () => {
hRowScrollX: 0,
});
expect(onScrollFinish).toBeCalled();

s2.destroy();
});

test('should be able to resize frozen col when there is a vertical scroll width', async () => {
const s2 = new TableSheet(getContainer(), dataCfg, options);
s2.render();

const onScrollFinish = jest.fn();
s2.facet.scrollWithAnimation(
{
offsetX: {
value: 100,
animate: true,
},
},
10,
onScrollFinish,
);
await sleep(30);


const firstColCell = s2.getColumnNodes()[1].belongsCell as any

expect(firstColCell.shouldAddVerticalResizeArea()).toBe(true)
expect(firstColCell.getVerticalResizeAreaOffset()).toEqual({ x: 80, y: 0 })

});

});
27 changes: 23 additions & 4 deletions packages/s2-core/src/cell/table-col-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,31 @@ export class TableColCell extends ColCell {
);
}

protected getColResizeArea() {
const isFrozenCell = this.isFrozenCell();
protected shouldAddVerticalResizeArea() {
if (this.isFrozenCell()) return true
return super.shouldAddVerticalResizeArea()
}

if (!isFrozenCell) {
return super.getColResizeArea();
protected getVerticalResizeAreaOffset() {
const { x, y } = this.meta;
const { scrollX, position } = this.headerConfig;

if (this.isFrozenCell()) {
return {
x,
y,
};
}
return {
x: position.x + x - scrollX,
y: position.y + y,
};
}


protected getColResizeArea() {
const isFrozenCell = this.isFrozenCell();
if (!isFrozenCell) return super.getColResizeArea();
return getOrCreateResizeAreaGroupById(
this.spreadsheet,
KEY_GROUP_FROZEN_COL_RESIZE_AREA,
Expand Down

0 comments on commit bcdcbe1

Please sign in to comment.