From 3c8f18d1794b0e45914357fa745273f60bb70bb4 Mon Sep 17 00:00:00 2001 From: "owen.wjh" Date: Thu, 21 Jul 2022 21:36:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E6=9C=89=E5=86=BB=E7=BB=93=E8=A1=8C?= =?UTF-8?q?=E4=B8=94=E6=9C=89=E5=9E=82=E7=9B=B4scrollWidth=E6=97=B6?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E8=88=AA=E6=97=A0=E6=B3=95resize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/s2-core/src/cell/table-col-cell.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/s2-core/src/cell/table-col-cell.ts b/packages/s2-core/src/cell/table-col-cell.ts index 9690b58f06..cca18dc72f 100644 --- a/packages/s2-core/src/cell/table-col-cell.ts +++ b/packages/s2-core/src/cell/table-col-cell.ts @@ -49,6 +49,28 @@ export class TableColCell extends ColCell { this.spreadsheet.dataSet.getFieldName(this.meta.label), ); } + + protected shouldAddVerticalResizeArea() { + if (this.isFrozenCell()) return true + else return super.shouldAddVerticalResizeArea() + } + + 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(); From d824e8cc25193e74d6ca4d1e4f408ec5d6161cca Mon Sep 17 00:00:00 2001 From: "owen.wjh" Date: Fri, 22 Jul 2022 18:03:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=9C=89=E5=86=BB=E7=BB=93=E8=A1=8C?= =?UTF-8?q?=E4=B8=94=E6=9C=89=E5=9E=82=E7=9B=B4scrollWidth=E6=97=B6?= =?UTF-8?q?=E5=86=BB=E7=BB=93=E8=88=AA=E6=97=A0=E6=B3=95resize?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spreadsheet/hidden-columns-spec.ts | 12 ++++---- .../__tests__/spreadsheet/table-sheet-spec.ts | 29 +++++++++++++++++++ packages/s2-core/src/cell/table-col-cell.ts | 9 ++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index 40001ad256..e44d42f5bd 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -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); @@ -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); @@ -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); @@ -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, @@ -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); @@ -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); diff --git a/packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts b/packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts index 9cc3fbf499..c61f81c780 100644 --- a/packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts @@ -4,6 +4,7 @@ import { type S2Options, type S2DataConfig, ResizeType, + ColCell, } from '@/index'; const data = getMockData( @@ -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 }) + }); + }); diff --git a/packages/s2-core/src/cell/table-col-cell.ts b/packages/s2-core/src/cell/table-col-cell.ts index cca18dc72f..03aeadea71 100644 --- a/packages/s2-core/src/cell/table-col-cell.ts +++ b/packages/s2-core/src/cell/table-col-cell.ts @@ -49,10 +49,10 @@ export class TableColCell extends ColCell { this.spreadsheet.dataSet.getFieldName(this.meta.label), ); } - + protected shouldAddVerticalResizeArea() { if (this.isFrozenCell()) return true - else return super.shouldAddVerticalResizeArea() + return super.shouldAddVerticalResizeArea() } protected getVerticalResizeAreaOffset() { @@ -74,10 +74,7 @@ export class TableColCell extends ColCell { protected getColResizeArea() { const isFrozenCell = this.isFrozenCell(); - - if (!isFrozenCell) { - return super.getColResizeArea(); - } + if (!isFrozenCell) return super.getColResizeArea(); return getOrCreateResizeAreaGroupById( this.spreadsheet, KEY_GROUP_FROZEN_COL_RESIZE_AREA,