diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index fe98a2045e..7a8c08a3d9 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -142,4 +142,18 @@ describe('Table', () => { wrapper.find('th').simulate('click'); expect(onClick).toHaveBeenCalled(); }); + + it('should not crash when column children is empty', () => { + mount( + , + ); + }); }); diff --git a/components/table/hooks/useFilter/index.tsx b/components/table/hooks/useFilter/index.tsx index f20341d86f..874b8fac8b 100644 --- a/components/table/hooks/useFilter/index.tsx +++ b/components/table/hooks/useFilter/index.tsx @@ -27,7 +27,7 @@ function collectFilterStates( ): FilterState[] { let filterStates: FilterState[] = []; - columns.forEach((column, index) => { + (columns || []).forEach((column, index) => { const columnPos = getColumnPos(index, pos); if ('children' in column) { diff --git a/components/table/hooks/useSorter.tsx b/components/table/hooks/useSorter.tsx index 4db160c331..689e96a173 100644 --- a/components/table/hooks/useSorter.tsx +++ b/components/table/hooks/useSorter.tsx @@ -54,7 +54,7 @@ function collectSortStates( ): SortState[] { let sortStates: SortState[] = []; - columns.forEach((column, index) => { + (columns || []).forEach((column, index) => { const columnPos = getColumnPos(index, pos); if ('children' in column) { @@ -91,7 +91,7 @@ function injectSorter( defaultSortDirections: SortOrder[], pos?: string, ): ColumnsType { - return columns.map((column, index) => { + return (columns || []).map((column, index) => { const columnPos = getColumnPos(index, pos); let newColumn: ColumnsType[number] = column; diff --git a/components/table/interface.tsx b/components/table/interface.tsx index 9206fa5c39..c2bb7bdfb5 100644 --- a/components/table/interface.tsx +++ b/components/table/interface.tsx @@ -63,7 +63,6 @@ export interface ColumnType extends RcColumnType { title?: ColumnTitle; // Sorter - // TODO: Doc this update sorter?: | boolean | CompareFn