Skip to content

Commit 2dd8876

Browse files
committed
fix: 修复拖拽列宽后, 默认的自定义列宽失效 close #2910
1 parent c35bc03 commit 2dd8876

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed

packages/s2-core/__tests__/unit/interaction/__snapshots__/row-column-resize-spec.ts.snap

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Object {
2020
"heightByField": null,
2121
"maxLines": 1,
2222
"textOverflow": "ellipsis",
23-
"width": null,
23+
"width": undefined,
2424
"widthByField": Object {
2525
"testFieldId": 5,
2626
},
@@ -34,7 +34,7 @@ Object {
3434
"heightByField": null,
3535
"maxLines": 1,
3636
"textOverflow": "ellipsis",
37-
"width": null,
37+
"width": undefined,
3838
"widthByField": Object {
3939
"testField": 5,
4040
},
@@ -48,9 +48,10 @@ Object {
4848
"heightByField": null,
4949
"maxLines": 1,
5050
"textOverflow": "ellipsis",
51-
"width": null,
51+
"width": undefined,
5252
"widthByField": Object {
53-
"testFieldId": 5,
53+
"test-cell-a": 5,
54+
"test-cell-b": 5,
5455
},
5556
"wordWrap": true,
5657
}
@@ -62,7 +63,7 @@ Object {
6263
"heightByField": null,
6364
"maxLines": 1,
6465
"textOverflow": "ellipsis",
65-
"width": null,
66+
"width": undefined,
6667
"widthByField": Object {
6768
"test-cell-a": 5,
6869
"test-cell-b": 5,
@@ -73,7 +74,7 @@ Object {
7374

7475
exports[`Interaction Row Column Resize Tests should get multiple vertical filed resize style by field for selected resize type 1`] = `
7576
Object {
76-
"height": null,
77+
"height": undefined,
7778
"heightByField": Object {
7879
"test-cell-a": 2,
7980
"test-cell-b": 2,
@@ -123,7 +124,7 @@ Object {
123124

124125
exports[`Interaction Row Column Resize Tests should get vertical filed resize style by field for current resize type 1`] = `
125126
Object {
126-
"height": null,
127+
"height": undefined,
127128
"heightByField": Object {
128129
"testFieldId": 2,
129130
},
@@ -137,9 +138,10 @@ Object {
137138

138139
exports[`Interaction Row Column Resize Tests should get vertical filed resize style by field for selected resize type 1`] = `
139140
Object {
140-
"height": null,
141+
"height": undefined,
141142
"heightByField": Object {
142-
"testFieldId": 2,
143+
"test-cell-a": 2,
144+
"test-cell-b": 2,
143145
},
144146
"maxLines": 1,
145147
"showTreeLeafNodeAlignDot": false,
@@ -163,6 +165,20 @@ Object {
163165
}
164166
`;
165167

168+
exports[`Interaction Row Column Resize Tests should not effect default resize style by field for selected resize type 1`] = `
169+
Object {
170+
"height": 30,
171+
"heightByField": null,
172+
"maxLines": 1,
173+
"textOverflow": "ellipsis",
174+
"width": 50,
175+
"widthByField": Object {
176+
"testFieldId": 5,
177+
},
178+
"wordWrap": true,
179+
}
180+
`;
181+
166182
exports[`Interaction Row Column Resize Tests should rerender by resize col cell 1`] = `
167183
Object {
168184
"height": 30,

packages/s2-core/__tests__/unit/interaction/row-column-resize-spec.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ describe('Interaction Row Column Resize Tests', () => {
160160
s2.hideTooltip = jest.fn();
161161
s2.interaction.reset = jest.fn();
162162
s2.interaction.getActiveRowCells = () => [
163-
createMockCellInfo('test-row-cell').mockCell,
163+
createMockCellInfo('test-row-cell-a').mockCell,
164+
createMockCellInfo('test-row-cell-b').mockCell,
164165
];
165166
s2.interaction.getActiveColCells = () => [
166-
createMockCellInfo('test-col-cell').mockCell,
167+
createMockCellInfo('test-col-cell-a').mockCell,
168+
createMockCellInfo('test-col-cell-b').mockCell,
167169
];
168170

169171
// 模拟多选
@@ -823,6 +825,10 @@ describe('Interaction Row Column Resize Tests', () => {
823825
},
824826
});
825827

828+
jest
829+
.spyOn(s2.interaction, 'isSelectedState')
830+
.mockImplementationOnce(() => true);
831+
826832
emitResize(ResizeDirectionType.Horizontal, ResizeAreaEffect.Cell);
827833

828834
expect(s2.options.style!.colCell).toMatchSnapshot();
@@ -839,6 +845,10 @@ describe('Interaction Row Column Resize Tests', () => {
839845
},
840846
});
841847

848+
jest
849+
.spyOn(s2.interaction, 'isSelectedState')
850+
.mockImplementationOnce(() => true);
851+
842852
emitResize(ResizeDirectionType.Vertical, ResizeAreaEffect.Cell);
843853

844854
expect(s2.options.style!.rowCell).toMatchSnapshot();
@@ -895,4 +905,25 @@ describe('Interaction Row Column Resize Tests', () => {
895905

896906
expect(s2.options.style!.colCell).toMatchSnapshot();
897907
});
908+
909+
// https://github.com/antvis/S2/issues/2910
910+
test('should not effect default resize style by field for selected resize type', () => {
911+
s2.setOptions({
912+
style: {
913+
colCell: {
914+
width: 50,
915+
},
916+
},
917+
interaction: {
918+
resize: {
919+
rowResizeType: ResizeType.CURRENT,
920+
colResizeType: ResizeType.CURRENT,
921+
},
922+
},
923+
});
924+
925+
emitResize(ResizeDirectionType.Horizontal, ResizeAreaEffect.Cell);
926+
927+
expect(s2.options.style!.colCell).toMatchSnapshot();
928+
});
898929
});

packages/s2-core/src/interaction/row-column-resize.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
303303

304304
// 非多选: 正常设置即可
305305
if (
306-
!this.isEffectRowOf(ResizeType.SELECTED) ||
307-
!this.isEffectColOf(ResizeType.SELECTED) ||
306+
(!this.isEffectRowOf(ResizeType.SELECTED) &&
307+
!this.isEffectColOf(ResizeType.SELECTED)) ||
308308
!isMultiSelected
309309
) {
310310
return {
@@ -360,7 +360,9 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
360360
eventType: S2Event.LAYOUT_RESIZE_COL_WIDTH,
361361
style: {
362362
colCell: {
363-
width: !this.isEffectColOf(ResizeType.ALL) ? null : displayWidth,
363+
width: !this.isEffectColOf(ResizeType.ALL)
364+
? undefined
365+
: displayWidth,
364366
widthByField: this.getCellStyleByField(displayWidth),
365367
},
366368
},
@@ -398,7 +400,7 @@ export class RowColumnResize extends BaseEvent implements BaseEventImplement {
398400
style: {
399401
rowCell: {
400402
height: !this.isEffectRowOf(ResizeType.ALL)
401-
? null
403+
? undefined
402404
: displayHeight,
403405
heightByField: this.getCellStyleByField(displayHeight),
404406
},

s2-site/docs/common/interaction.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ interface ScrollSpeedRatio {
6868
| cornerCellHorizontal | 是否开启角头水平方向 resize 热区 | `boolean` | true | |
6969
| colCellHorizontal | 是否开启列头水平方向 resize 热区 | `boolean` | true | |
7070
| colCellVertical | 是否开启列头垂直方向 resize 热区 (列头隐藏时该配置无效) | `boolean` | true | |
71-
| rowResizeType | 用于控制行高 resize 时的生效范围 <br/> 1. `all`: 对所有单元格生效,2. `current`: 对当前单元格生效,3. `selected`: 对当前单元格生效,如果单元格是多选状态,调整任意选中单元格,对所有选中的生效。| `all`\| `current` \| `selected` | `current` | |
72-
| colResizeType | 用于控制列宽 resize 时的生效范围 <br/> 1. `all`: 对所有单元格生效,2. `current`: 对当前单元格生效,3. `selected`: 对当前单元格生效,如果单元格是多选状态,调整任意选中单元格,对所有选中的生效。| `all`\| `current` \| `selected` | `current` | |
71+
| rowResizeType | 用于控制行高 resize 时的生效范围 <br/> 1. `all`: 对所有单元格生效(会覆盖默认的行高配置),2. `current`: 对当前单元格生效,3. `selected`: 对当前单元格生效,如果单元格是多选状态,调整任意选中单元格,对所有选中的生效。| `all`\| `current` \| `selected` | `current` | |
72+
| colResizeType | 用于控制列宽 resize 时的生效范围 <br/> 1. `all`: 对所有单元格生效(会覆盖默认的列宽配置),2. `current`: 对当前单元格生效,3. `selected`: 对当前单元格生效,如果单元格是多选状态,调整任意选中单元格,对所有选中的生效。| `all`\| `current` \| `selected` | `current` | |
7373
| disable | 用于控制行高 resize 是否生效。[查看示例](/examples/interaction/advanced/#resize-disable) | (resizeInfo: [S2CellType](/docs/api/components/sheet-component#resizeinfo)) => boolean | | |
7474
| visible | 自定义当前单元格是否显示 resize 热区 | (cell: [S2CellType](/docs/api/basic-class/base-cell)) => boolean | | |
7575
| minCellWidth | 单元格可拖拽最小宽度 | `number`| 20 | |

0 commit comments

Comments
 (0)