From d02424ee2fcbfb32bfd89f8bfca87dc1978830bb Mon Sep 17 00:00:00 2001 From: inottn Date: Mon, 25 Aug 2025 03:23:49 +0000 Subject: [PATCH] fix: expand column not visible when expandable.fixed is true --- src/hooks/useColumns/index.tsx | 9 +- tests/ExpandRow.spec.jsx | 24 +++- tests/__snapshots__/ExpandRow.spec.jsx.snap | 117 ++++++++++++++++++-- 3 files changed, 133 insertions(+), 17 deletions(-) diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index 64542696f..070aa3031 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -178,11 +178,10 @@ function useColumns( // >>> Insert expand column if not exist if (!cloneColumns.includes(EXPAND_COLUMN)) { const expandColIndex = expandIconColumnIndex || 0; - if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) { - cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN); - } - if (fixed === 'right') { - cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN); + const insertIndex = + expandColIndex === 0 && fixed === 'right' ? baseColumns.length : expandColIndex; + if (insertIndex >= 0) { + cloneColumns.splice(insertIndex, 0, EXPAND_COLUMN); } } diff --git a/tests/ExpandRow.spec.jsx b/tests/ExpandRow.spec.jsx index 5a44fa1a0..058e057e2 100644 --- a/tests/ExpandRow.spec.jsx +++ b/tests/ExpandRow.spec.jsx @@ -219,6 +219,14 @@ describe('Table.Expand', () => { }), ); const wrapper2 = mount( + createTable({ + columns, + data, + scroll: { x: 903 }, + expandable: { expandedRowRender, fixed: true, expandIconColumnIndex: 1 }, + }), + ); + const wrapper3 = mount( createTable({ columns, data, @@ -227,10 +235,11 @@ describe('Table.Expand', () => { }), ); expect(wrapper.find('.rc-table-has-fix-left').length).toBe(0); - expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(0); + expect(wrapper2.find('.rc-table-has-fix-left').length).toBe(0); + expect(wrapper3.find('.rc-table-has-fix-right').length).toBe(0); }); - it('fixed in expandable Fixed in expandable', () => { + it('fixed in expandable', () => { const columns = [ { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Age', dataIndex: 'age', key: 'age' }, @@ -249,6 +258,14 @@ describe('Table.Expand', () => { }), ); const wrapper2 = mount( + createTable({ + columns, + data, + scroll: { x: 903 }, + expandable: { expandedRowRender, fixed: true }, + }), + ); + const wrapper3 = mount( createTable({ columns, data, @@ -257,7 +274,8 @@ describe('Table.Expand', () => { }), ); expect(wrapper.find('.rc-table-has-fix-left').length).toBe(1); - expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(1); + expect(wrapper2.find('.rc-table-has-fix-left').length).toBe(1); + expect(wrapper3.find('.rc-table-has-fix-right').length).toBe(1); }); describe('config expand column index', () => { diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index 5a59716b0..9ee888bc2 100644 --- a/tests/__snapshots__/ExpandRow.spec.jsx.snap +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -138,7 +138,7 @@ LoadedCheerio { exports[`Table.Expand > does not crash if scroll is not set 1`] = ` LoadedCheerio { "0":
- + + + + +
+ +
+   +
+
+ + @@ -235,6 +260,14 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > + + + @@ -290,7 +323,7 @@ LoadedCheerio { exports[`Table.Expand > does not crash if scroll is not set 2`] = ` LoadedCheerio { "0":
- + + + + +
+ +
+   +
+
+ + @@ -387,6 +445,14 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > + + + @@ -1117,7 +1183,7 @@ LoadedCheerio { exports[`Table.Expand > work in expandable fix 1`] = ` LoadedCheerio { "0":
- + + + + +
+ +
+   +
+
+ + @@ -1214,6 +1305,14 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > + + +