Skip to content

Commit

Permalink
fix: table warning message when columns=[]
Browse files Browse the repository at this point in the history
  • Loading branch information
Francoshum95 committed Mar 12, 2023
1 parent 3d731c4 commit 659bc01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,12 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
if (typeof colWidth === 'number' && !Number.isNaN(colWidth)) {
return colWidth;
}
warning(
false,
'When use `components.body` with render props. Each column should have a fixed `width` value.',
);

if (props.columns.length > 0) {
warning(
false,
'When use `components.body` with render props. Each column should have a fixed `width` value.',
);
}
return 0;
}) as number[];
} else {
Expand All @@ -599,7 +600,11 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
{bodyColGroup}
{bodyTable}
{!fixFooter && summaryNode && (
<Footer stickyOffsets={stickyOffsets} flattenColumns={flattenColumns} columns={columns}>
<Footer
stickyOffsets={stickyOffsets}
flattenColumns={flattenColumns}
columns={columns}
>
{summaryNode}
</Footer>
)}
Expand Down
18 changes: 18 additions & 0 deletions tests/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,24 @@ describe('Table.Basic', () => {
});
});

it('without warning - columns is emplty', () => {
resetWarned();
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mount(
createTable({
columns: [],
components: {
body: () => <h1>Bamboo</h1>,
},
scroll: { x: 100, y: 100 },
}),
);
expect(errSpy).not.toHaveBeenCalledWith(
'Warning: When use `components.body` with render props. Each column should have a fixed `width` value.',
);
errSpy.mockRestore();
});

it('not crash', () => {
const Looper = React.forwardRef(() => <td />);
Looper.looper = Looper;
Expand Down

0 comments on commit 659bc01

Please sign in to comment.