mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
fix: Table should not crash with empty column children (#20703)
This commit is contained in:
parent
c5a40fc683
commit
1c1a4a773d
@ -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…
Reference in New Issue
Block a user