From f49dd25407efead20a43ade0aea737d18bd3119b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=91=E6=B8=85?= Date: Sat, 21 Sep 2024 17:10:49 +0800 Subject: [PATCH 1/4] fix: The fixed attribute does not take effect --- src/hooks/useColumns/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index 99490db32..3dc679d8e 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -176,9 +176,12 @@ function useColumns( // >>> Insert expand column if not exist if (!cloneColumns.includes(EXPAND_COLUMN)) { const expandColIndex = expandIconColumnIndex || 0; - if (expandColIndex >= 0) { + if ((expandColIndex && expandColIndex >= 0) || fixed === 'left' || !fixed) { cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN); } + if (fixed === 'right') { + cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN); + } } // >>> Deduplicate additional expand column @@ -197,10 +200,8 @@ function useColumns( const prevColumn = baseColumns[expandColumnIndex]; let fixedColumn: FixedType | null; - if ((fixed === 'left' || fixed) && !expandIconColumnIndex) { - fixedColumn = 'left'; - } else if ((fixed === 'right' || fixed) && expandIconColumnIndex === baseColumns.length) { - fixedColumn = 'right'; + if (fixed) { + fixedColumn = fixed; } else { fixedColumn = prevColumn ? prevColumn.fixed : null; } From c3c5bfe582cb74cf5cf086cdd5204134e892ef33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=91=E6=B8=85?= Date: Sun, 22 Sep 2024 00:00:29 +0800 Subject: [PATCH 2/4] fix: Rectify the case that expandIconColumnIndex is smaller than 0 --- src/hooks/useColumns/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index 3dc679d8e..fcc007ab0 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -176,7 +176,8 @@ function useColumns( // >>> Insert expand column if not exist if (!cloneColumns.includes(EXPAND_COLUMN)) { const expandColIndex = expandIconColumnIndex || 0; - if ((expandColIndex && expandColIndex >= 0) || fixed === 'left' || !fixed) { + console.log(expandColIndex); + if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) { cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN); } if (fixed === 'right') { From 3030cbbf3dbb2222e16a9138e8b6e6ea0295c7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=91=E6=B8=85?= Date: Sun, 22 Sep 2024 17:46:25 +0800 Subject: [PATCH 3/4] fix: update Table.Expand snapshoot --- tests/__snapshots__/ExpandRow.spec.jsx.snap | 131 +++----------------- 1 file changed, 16 insertions(+), 115 deletions(-) diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index 72dfbbe21..f10c8e2b3 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":
- - - + - -
- -
-   -
-
- - @@ -260,14 +235,6 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > - - - @@ -323,7 +290,7 @@ LoadedCheerio { exports[`Table.Expand > does not crash if scroll is not set 2`] = ` LoadedCheerio { "0":
- - - + - -
- -
-   -
-
- - @@ -445,14 +387,6 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > - - - @@ -1183,7 +1117,7 @@ LoadedCheerio { exports[`Table.Expand > work in expandable fix 1`] = ` LoadedCheerio { "0":
- - - + - - @@ -1481,8 +1382,8 @@ LoadedCheerio { F
- -
-   -
-
- - @@ -1305,14 +1214,6 @@ LoadedCheerio { class="rc-table-row rc-table-row-level-0" data-row-key="1" > - - - @@ -1368,7 +1269,7 @@ LoadedCheerio { exports[`Table.Expand > work in expandable fix 2`] = ` LoadedCheerio { "0":
Date: Mon, 28 Oct 2024 23:04:44 +0800 Subject: [PATCH 4/4] fix: supplementary test cases --- src/hooks/useColumns/index.tsx | 4 +++- tests/ExpandRow.spec.jsx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index fcc007ab0..573a44af3 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -176,7 +176,6 @@ function useColumns( // >>> Insert expand column if not exist if (!cloneColumns.includes(EXPAND_COLUMN)) { const expandColIndex = expandIconColumnIndex || 0; - console.log(expandColIndex); if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) { cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN); } @@ -245,6 +244,7 @@ function useColumns( } return baseColumns.filter(col => col !== EXPAND_COLUMN); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [expandable, baseColumns, getRowKey, expandedKeys, expandIcon, direction]); // ========================= Transform ======================== @@ -263,6 +263,7 @@ function useColumns( ]; } return finalColumns; + // eslint-disable-next-line react-hooks/exhaustive-deps }, [transformColumns, withExpandColumns, direction]); // ========================== Flatten ========================= @@ -271,6 +272,7 @@ function useColumns( return revertForRtl(flatColumns(mergedColumns)); } return flatColumns(mergedColumns); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [mergedColumns, direction, scrollWidth]); // ========================= Gap Fixed ======================== diff --git a/tests/ExpandRow.spec.jsx b/tests/ExpandRow.spec.jsx index 93c0bed35..5a44fa1a0 100644 --- a/tests/ExpandRow.spec.jsx +++ b/tests/ExpandRow.spec.jsx @@ -230,6 +230,36 @@ describe('Table.Expand', () => { expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(0); }); + it('fixed in expandable Fixed in expandable', () => { + const columns = [ + { title: 'Name', dataIndex: 'name', key: 'name' }, + { title: 'Age', dataIndex: 'age', key: 'age' }, + { title: 'Gender', dataIndex: 'gender', key: 'gender' }, + ]; + const data = [ + { key: 0, name: 'Lucy', age: 27, gender: 'F' }, + { key: 1, name: 'Jack', age: 28, gender: 'M' }, + ]; + const wrapper = mount( + createTable({ + columns, + data, + scroll: { x: 903 }, + expandable: { expandedRowRender, fixed: 'left' }, + }), + ); + const wrapper2 = mount( + createTable({ + columns, + data, + scroll: { x: 903 }, + expandable: { expandedRowRender, fixed: 'right' }, + }), + ); + expect(wrapper.find('.rc-table-has-fix-left').length).toBe(1); + expect(wrapper2.find('.rc-table-has-fix-right').length).toBe(1); + }); + describe('config expand column index', () => { it('not show EXPAND_COLUMN if expandable is false', () => { resetWarned();