From 0ed521a335ceb6e6271877c962e05ec12acf111e Mon Sep 17 00:00:00 2001 From: liwenbo Date: Wed, 4 Dec 2024 14:58:54 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E8=A1=8C=E9=AB=98=E5=8F=97rowCell=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/__tests__/bugs/issue-2905-spec.ts | 84 +++++++++++++++++++ .../__tests__/data/data-issue-2905.json | 16 ++++ .../src/interaction/row-column-resize.ts | 4 +- 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 packages/s2-core/__tests__/bugs/issue-2905-spec.ts create mode 100644 packages/s2-core/__tests__/data/data-issue-2905.json diff --git a/packages/s2-core/__tests__/bugs/issue-2905-spec.ts b/packages/s2-core/__tests__/bugs/issue-2905-spec.ts new file mode 100644 index 0000000000..6361e86649 --- /dev/null +++ b/packages/s2-core/__tests__/bugs/issue-2905-spec.ts @@ -0,0 +1,84 @@ +/** + * 明细表设置rowCell pedding后,row-column-resize交互计算高度计算错误 + * @description spec for issue #2905 + * https://github.com/antvis/S2/issues/2905 + */ +import * as mockDataConfig from '../data/data-issue-2905.json'; +import { getContainer } from '../util/helpers'; +import { + TableSheet, + ResizeAreaEffect, + ResizeDirectionType, + type ResizeInfo, + RowColumnResize, + S2Event, + type S2Theme, + type S2Options, +} from '@/index'; + +const s2Options: S2Options = { + width: 600, + height: 480, +}; +const s2Theme: S2Theme = { + rowCell: { + cell: { + padding: { + top: 8, + bottom: 8, + }, + }, + }, +}; + +describe('TableSheet Resize With RowCell Padding Tests', () => { + let rowColumnResizeInstance: RowColumnResize; + + const emitResizeEvent = ( + type: S2Event, + event: Partial, + resizeInfo?: ResizeInfo, + ) => { + rowColumnResizeInstance.spreadsheet.emit(type, { + originalEvent: event, + preventDefault() {}, + target: { + attr: () => ({ + ...resizeInfo, + isResizeArea: true, + }), + }, + } as any); + }; + + test('should update table sheet cell height without padding effect', () => { + const s2 = new TableSheet(getContainer(), mockDataConfig, s2Options); + s2.setTheme(s2Theme); + s2.render(); + + rowColumnResizeInstance = new RowColumnResize(s2); + + const resizeInfo = { + theme: {}, + type: ResizeDirectionType.Vertical, + offsetX: 0, + offsetY: 32, + width: 5, + height: 32, + isResizeArea: true, + effect: ResizeAreaEffect.Cell, + id: '0', + resizedWidth: 0, + resizedHeight: 32, + } as ResizeInfo; + + emitResizeEvent(S2Event.LAYOUT_RESIZE_MOUSE_DOWN, {}, resizeInfo); + emitResizeEvent(S2Event.GLOBAL_MOUSE_UP, {}, resizeInfo); + expect(s2.options.style.cellCfg.height).toBe(32); + + resizeInfo.height = 16; + emitResizeEvent(S2Event.LAYOUT_RESIZE_MOUSE_DOWN, {}, resizeInfo); + emitResizeEvent(S2Event.GLOBAL_MOUSE_UP, {}, resizeInfo); + expect(s2.options.style.cellCfg.height).toBe(16); + }); +}); diff --git a/packages/s2-core/__tests__/data/data-issue-2905.json b/packages/s2-core/__tests__/data/data-issue-2905.json new file mode 100644 index 0000000000..1ab148a3c7 --- /dev/null +++ b/packages/s2-core/__tests__/data/data-issue-2905.json @@ -0,0 +1,16 @@ +{ + "fields": { + "columns": ["row"] + }, + "data": [ + { + "row": 1 + }, + { + "row": 2 + }, + { + "row": 3 + } + ] +} diff --git a/packages/s2-core/src/interaction/row-column-resize.ts b/packages/s2-core/src/interaction/row-column-resize.ts index a249b8394d..ef6d596e0a 100644 --- a/packages/s2-core/src/interaction/row-column-resize.ts +++ b/packages/s2-core/src/interaction/row-column-resize.ts @@ -296,7 +296,9 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement { const { padding: rowCellPadding } = this.spreadsheet.theme.rowCell.cell; const resizeInfo = this.getResizeInfo(); const { displayHeight } = this.getDisAllowResizeInfo(); - const height = displayHeight - rowCellPadding.top - rowCellPadding.bottom; + const height = this.spreadsheet.isPivotMode() + ? displayHeight - rowCellPadding.top - rowCellPadding.bottom + : displayHeight; let rowCellStyle: Style; switch (resizeInfo.effect) {