Skip to content

Commit ae3bc5b

Browse files
authored
fix: table warning message when columns=[] (#966)
1 parent 3d731c4 commit ae3bc5b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/Table.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,12 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
570570
if (typeof colWidth === 'number' && !Number.isNaN(colWidth)) {
571571
return colWidth;
572572
}
573-
warning(
574-
false,
575-
'When use `components.body` with render props. Each column should have a fixed `width` value.',
576-
);
577-
573+
if (props.columns.length > 0) {
574+
warning(
575+
false,
576+
'When use `components.body` with render props. Each column should have a fixed `width` value.',
577+
);
578+
}
578579
return 0;
579580
}) as number[];
580581
} else {
@@ -599,7 +600,11 @@ function Table<RecordType extends DefaultRecordType>(tableProps: TableProps<Reco
599600
{bodyColGroup}
600601
{bodyTable}
601602
{!fixFooter && summaryNode && (
602-
<Footer stickyOffsets={stickyOffsets} flattenColumns={flattenColumns} columns={columns}>
603+
<Footer
604+
stickyOffsets={stickyOffsets}
605+
flattenColumns={flattenColumns}
606+
columns={columns}
607+
>
603608
{summaryNode}
604609
</Footer>
605610
)}

tests/Table.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,24 @@ describe('Table.Basic', () => {
701701
});
702702
});
703703

704+
it('without warning - columns is emplty', () => {
705+
resetWarned();
706+
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
707+
mount(
708+
createTable({
709+
columns: [],
710+
components: {
711+
body: () => <h1>Bamboo</h1>,
712+
},
713+
scroll: { x: 100, y: 100 },
714+
}),
715+
);
716+
expect(errSpy).not.toHaveBeenCalledWith(
717+
'Warning: When use `components.body` with render props. Each column should have a fixed `width` value.',
718+
);
719+
errSpy.mockRestore();
720+
});
721+
704722
it('not crash', () => {
705723
const Looper = React.forwardRef(() => <td />);
706724
Looper.looper = Looper;

0 commit comments

Comments
 (0)