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: 修复表格拖拽行高受rowCell影响问题 close #2905 #3015

Merged
merged 1 commit into from
Dec 5, 2024
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
84 changes: 84 additions & 0 deletions packages/s2-core/__tests__/bugs/issue-2905-spec.ts
Original file line number Diff line number Diff line change
@@ -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<MouseEvent>,
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);
});
});
16 changes: 16 additions & 0 deletions packages/s2-core/__tests__/data/data-issue-2905.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"fields": {
"columns": ["row"]
},
"data": [
{
"row": 1
},
{
"row": 2
},
{
"row": 3
}
]
}
4 changes: 3 additions & 1 deletion packages/s2-core/src/interaction/row-column-resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading