diff --git a/src/hooks/useColumns.tsx b/src/hooks/useColumns.tsx index 67e05bb71..4f170b6a8 100644 --- a/src/hooks/useColumns.tsx +++ b/src/hooks/useColumns.tsx @@ -175,8 +175,9 @@ function useColumns( // Insert expand column in the target position const cloneColumns = baseColumns.slice(); - cloneColumns.splice(expandColIndex, 0, expandColumn); - + if (expandColIndex >= 0) { + cloneColumns.splice(expandColIndex, 0, expandColumn); + } return cloneColumns; } return baseColumns; diff --git a/tests/ExpandRow.spec.js b/tests/ExpandRow.spec.js index 140228cd5..6452bf933 100644 --- a/tests/ExpandRow.spec.js +++ b/tests/ExpandRow.spec.js @@ -148,6 +148,19 @@ describe('Table.Expand', () => { ).toBeTruthy(); }); + // https://github.com/ant-design/ant-design/issues/24129 + it('should not render expand icon column when expandIconColumnIndex is negative', () => { + const wrapper = mount( + createTable({ + expandable: { + expandedRowRender, + expandIconColumnIndex: -1, + }, + }), + ); + expect(wrapper.find('.rc-table-row-expand-icon-cell').length).toBe(0); + }); + it('renders a custom icon', () => { function CustomExpandIcon(props) { return (