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

fix: 有冻结行且有垂直 scrollWidth 时冻结行无法 resize #1594

Merged
merged 2 commits into from
Jul 22, 2022
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
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