fix: Table should not crash with empty column children (#20703)

pull/20705/head
二货机器人 5 years ago committed by GitHub
parent c5a40fc683
commit 1c1a4a773d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -142,4 +142,18 @@ describe('Table', () => {
wrapper.find('th').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should not crash when column children is empty', () => {
mount(
<Table
columns={[
{
dataIndex: 'name',
children: undefined,
},
]}
dataSource={[]}
/>,
);
});
});

@ -27,7 +27,7 @@ function collectFilterStates<RecordType>(
): FilterState<RecordType>[] {
let filterStates: FilterState<RecordType>[] = [];
columns.forEach((column, index) => {
(columns || []).forEach((column, index) => {
const columnPos = getColumnPos(index, pos);
if ('children' in column) {

@ -54,7 +54,7 @@ function collectSortStates<RecordType>(
): SortState<RecordType>[] {
let sortStates: SortState<RecordType>[] = [];
columns.forEach((column, index) => {
(columns || []).forEach((column, index) => {
const columnPos = getColumnPos(index, pos);
if ('children' in column) {
@ -91,7 +91,7 @@ function injectSorter<RecordType>(
defaultSortDirections: SortOrder[],
pos?: string,
): ColumnsType<RecordType> {
return columns.map((column, index) => {
return (columns || []).map((column, index) => {
const columnPos = getColumnPos(index, pos);
let newColumn: ColumnsType<RecordType>[number] = column;

@ -63,7 +63,6 @@ export interface ColumnType<RecordType> extends RcColumnType<RecordType> {
title?: ColumnTitle<RecordType>;
// Sorter
// TODO: Doc this update
sorter?:
| boolean
| CompareFn<RecordType>

Loading…
Cancel
Save