Skip to content

Commit a246380

Browse files
authored
refactor: re-order that onHeadCell props has higher priority (#957)
1 parent 5e68e43 commit a246380

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
"rc-util": "^5.27.1"
6161
},
6262
"devDependencies": {
63+
"@testing-library/jest-dom": "^5.16.5",
64+
"@testing-library/react": "^12.1.5",
6365
"@types/enzyme": "^3.10.5",
6466
"@types/jest": "^28.1.2",
6567
"@types/react": "^17.0.35",
@@ -84,7 +86,7 @@
8486
"rc-animate": "^3.0.0",
8587
"rc-dropdown": "~4.0.1",
8688
"rc-menu": "~9.6.0",
87-
"rc-test": "^7.0.2",
89+
"rc-test": "^7.0.14",
8890
"rc-tooltip": "^5.2.1",
8991
"react": "^16.0.0",
9092
"react-dnd": "^2.5.4",

src/Cell/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
148148
}
149149

150150
// ================ RowSpan & ColSpan =================
151-
const mergedColSpan = legacyCellProps?.colSpan ?? colSpan ?? additionalProps.colSpan ?? 1;
152-
const mergedRowSpan = legacyCellProps?.rowSpan ?? rowSpan ?? additionalProps.rowSpan ?? 1;
151+
const mergedColSpan = legacyCellProps?.colSpan ?? additionalProps.colSpan ?? colSpan ?? 1;
152+
const mergedRowSpan = legacyCellProps?.rowSpan ?? additionalProps.rowSpan ?? rowSpan ?? 1;
153153

154154
// ====================== Hover =======================
155155
const [hovering, onHover] = useHoverState(index, mergedRowSpan);

tests/ColSpan.spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
import Table from '../src';
4+
5+
describe('Table.ColSpan', () => {
6+
it('hover the tree table', () => {
7+
const { container } = render(
8+
<Table
9+
columns={[
10+
{
11+
title: 'Parent',
12+
key: 'parent',
13+
children: [
14+
{
15+
title: 'name',
16+
key: 'name',
17+
dataIndex: 'name',
18+
onHeaderCell: () => ({
19+
colSpan: 2,
20+
}),
21+
},
22+
{
23+
title: 'age',
24+
key: 'age',
25+
dataIndex: 'age',
26+
onHeaderCell: () => ({ colSpan: 0 }),
27+
},
28+
],
29+
},
30+
]}
31+
data={[
32+
{
33+
key: '1',
34+
name: 'Little',
35+
age: 2,
36+
},
37+
]}
38+
/>,
39+
);
40+
41+
// 2 rows
42+
expect(container.querySelector('thead').querySelectorAll('tr')).toHaveLength(2);
43+
44+
// one cell
45+
const lastTr = container.querySelector('thead').querySelectorAll('tr')[1];
46+
expect(lastTr.querySelectorAll('th')).toHaveLength(1);
47+
expect(lastTr.querySelector('th')).toHaveAttribute('colSpan', '2');
48+
49+
// Data 2 cells
50+
expect(
51+
container.querySelector('tbody').querySelectorAll('tr')[0].querySelectorAll('td'),
52+
).toHaveLength(2);
53+
});
54+
});

0 commit comments

Comments
 (0)