Skip to content
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
"rc-util": "^5.27.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@types/enzyme": "^3.10.5",
"@types/jest": "^28.1.2",
"@types/react": "^17.0.35",
Expand All @@ -84,7 +86,7 @@
"rc-animate": "^3.0.0",
"rc-dropdown": "~4.0.1",
"rc-menu": "~9.6.0",
"rc-test": "^7.0.2",
"rc-test": "^7.0.14",
"rc-tooltip": "^5.2.1",
"react": "^16.0.0",
"react-dnd": "^2.5.4",
Expand Down
4 changes: 2 additions & 2 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
}

// ================ RowSpan & ColSpan =================
const mergedColSpan = legacyCellProps?.colSpan ?? colSpan ?? additionalProps.colSpan ?? 1;
const mergedRowSpan = legacyCellProps?.rowSpan ?? rowSpan ?? additionalProps.rowSpan ?? 1;
const mergedColSpan = legacyCellProps?.colSpan ?? additionalProps.colSpan ?? colSpan ?? 1;
const mergedRowSpan = legacyCellProps?.rowSpan ?? additionalProps.rowSpan ?? rowSpan ?? 1;

// ====================== Hover =======================
const [hovering, onHover] = useHoverState(index, mergedRowSpan);
Expand Down
54 changes: 54 additions & 0 deletions tests/ColSpan.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { render } from '@testing-library/react';
import React from 'react';
import Table from '../src';

describe('Table.ColSpan', () => {
it('hover the tree table', () => {
const { container } = render(
<Table
columns={[
{
title: 'Parent',
key: 'parent',
children: [
{
title: 'name',
key: 'name',
dataIndex: 'name',
onHeaderCell: () => ({
colSpan: 2,
}),
},
{
title: 'age',
key: 'age',
dataIndex: 'age',
onHeaderCell: () => ({ colSpan: 0 }),
},
],
},
]}
data={[
{
key: '1',
name: 'Little',
age: 2,
},
]}
/>,
);

// 2 rows
expect(container.querySelector('thead').querySelectorAll('tr')).toHaveLength(2);

// one cell
const lastTr = container.querySelector('thead').querySelectorAll('tr')[1];
expect(lastTr.querySelectorAll('th')).toHaveLength(1);
expect(lastTr.querySelector('th')).toHaveAttribute('colSpan', '2');

// Data 2 cells
expect(
container.querySelector('tbody').querySelectorAll('tr')[0].querySelectorAll('td'),
).toHaveLength(2);
});
});