From e30f1a8c7cce07ed7bd9799785a0fd7610befa8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 10 Mar 2025 17:26:06 +0800 Subject: [PATCH 1/5] chore: fix logical position --- src/Table.tsx | 6 ++---- src/hooks/useColumns/index.tsx | 32 ++++++-------------------------- tests/Table.spec.jsx | 1 + 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/Table.tsx b/src/Table.tsx index ef2480e48..e40a0d23e 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -775,10 +775,8 @@ function Table( /** No used but for compatible */ [`${prefixCls}-fixed-column`]: fixColumn, [`${prefixCls}-scroll-horizontal`]: horizonScroll, - [`${prefixCls}-has-fix-left`]: flattenColumns[0] && flattenColumns[0].fixed, - [`${prefixCls}-has-fix-right`]: - flattenColumns[flattenColumns.length - 1] && - flattenColumns[flattenColumns.length - 1].fixed === 'right', + [`${prefixCls}-has-fix-start`]: flattenColumns[0]?.fixed, + [`${prefixCls}-has-fix-end`]: flattenColumns[flattenColumns.length - 1]?.fixed === 'end', })} style={style} id={id} diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index c6792b9a4..715294d83 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -63,8 +63,8 @@ function flatColumns( .filter(column => column && typeof column === 'object') .reduce((list, column, index) => { const { fixed } = column; - // Convert `fixed='true'` to `fixed='left'` instead - const parsedFixed = fixed === true ? 'left' : fixed; + const parsedFixed = + fixed === true || fixed === 'left' ? 'start' : fixed === 'right' ? 'end' : fixed; const mergedKey = `${parentKey}-${index}`; const subColumns = (column as ColumnGroupType).children; @@ -88,24 +88,6 @@ function flatColumns( }, []); } -function revertForRtl(columns: ColumnsType): ColumnsType { - return columns.map(column => { - const { fixed, ...restProps } = column; - - // Convert `fixed='left'` to `fixed='right'` instead - let parsedFixed = fixed; - if (fixed === 'left') { - parsedFixed = 'right'; - } else if (fixed === 'right') { - parsedFixed = 'left'; - } - return { - fixed: parsedFixed, - ...restProps, - }; - }); -} - /** * Parse `columns` & `children` into `columns`. */ @@ -266,13 +248,11 @@ function useColumns( }, [transformColumns, withExpandColumns, direction]); // ========================== Flatten ========================= - const flattenColumns = React.useMemo(() => { - if (direction === 'rtl') { - return revertForRtl(flatColumns(mergedColumns)); - } - return flatColumns(mergedColumns); + const flattenColumns = React.useMemo( + () => flatColumns(mergedColumns), // eslint-disable-next-line react-hooks/exhaustive-deps - }, [mergedColumns, direction, scrollWidth]); + [mergedColumns, direction, scrollWidth], + ); // ========================= FillWidth ======================== const [filledColumns, realScrollWidth] = useWidthColumns( diff --git a/tests/Table.spec.jsx b/tests/Table.spec.jsx index a0be920b4..6417fee5d 100644 --- a/tests/Table.spec.jsx +++ b/tests/Table.spec.jsx @@ -619,6 +619,7 @@ describe('Table.Basic', () => { scroll: { x: 100, y: 100 }, }), ); + console.log(container.innerHTML); expect(container.firstChild).toMatchSnapshot(); }); From 17cd472ea183741b6afc4c3ec5f0a54274206de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 10 Mar 2025 17:26:22 +0800 Subject: [PATCH 2/5] test: update snapshot --- tests/__snapshots__/Table.spec.jsx.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/__snapshots__/Table.spec.jsx.snap b/tests/__snapshots__/Table.spec.jsx.snap index dcee6c815..d69946a3b 100644 --- a/tests/__snapshots__/Table.spec.jsx.snap +++ b/tests/__snapshots__/Table.spec.jsx.snap @@ -76,7 +76,7 @@ exports[`Table.Basic > custom components > renders correctly 1`] = ` exports[`Table.Basic > custom components > renders fixed column and header correctly 1`] = `
Date: Mon, 10 Mar 2025 17:39:47 +0800 Subject: [PATCH 3/5] chore: fix default fixed type --- src/Table.tsx | 2 +- src/hooks/useColumns/index.tsx | 7 +++++-- src/utils/fixUtil.ts | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Table.tsx b/src/Table.tsx index e40a0d23e..45fc7f398 100644 --- a/src/Table.tsx +++ b/src/Table.tsx @@ -827,7 +827,7 @@ function Table( onTriggerExpand, expandIconColumnIndex: expandableConfig.expandIconColumnIndex, indentSize: expandableConfig.indentSize, - allColumnsFixedLeft: flattenColumns.every(col => col.fixed === 'left'), + allColumnsFixedLeft: flattenColumns.every(col => col.fixed === 'start'), emptyNode, // Column diff --git a/src/hooks/useColumns/index.tsx b/src/hooks/useColumns/index.tsx index 715294d83..aa9f7bcac 100644 --- a/src/hooks/useColumns/index.tsx +++ b/src/hooks/useColumns/index.tsx @@ -157,10 +157,13 @@ function useColumns( // >>> Insert expand column if not exist if (!cloneColumns.includes(EXPAND_COLUMN)) { const expandColIndex = expandIconColumnIndex || 0; - if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) { + if ( + expandColIndex >= 0 && + (expandColIndex || fixed === 'left' || fixed === 'start' || !fixed) + ) { cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN); } - if (fixed === 'right') { + if (fixed === 'right' || fixed === 'end') { cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN); } } diff --git a/src/utils/fixUtil.ts b/src/utils/fixUtil.ts index 74d4062c1..8be767e28 100644 --- a/src/utils/fixUtil.ts +++ b/src/utils/fixUtil.ts @@ -16,10 +16,10 @@ export interface FixedInfo { } function isFixedStart(column: { fixed?: FixedType }) { - return column.fixed === 'left' || column.fixed === 'start'; + return column.fixed === 'start'; } function isFixedEnd(column: { fixed?: FixedType }) { - return column.fixed === 'right' || column.fixed === 'end'; + return column.fixed === 'end'; } export function getCellFixedInfo( From 1756eeed8b3e93d47422afe96902c9b6bce16cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Mon, 10 Mar 2025 17:45:55 +0800 Subject: [PATCH 4/5] test: update snapshot --- tests/__snapshots__/FixedColumn.spec.tsx.snap | 208 +++++++++++------- 1 file changed, 124 insertions(+), 84 deletions(-) diff --git a/tests/__snapshots__/FixedColumn.spec.tsx.snap b/tests/__snapshots__/FixedColumn.spec.tsx.snap index 54dab8627..a467e7062 100644 --- a/tests/__snapshots__/FixedColumn.spec.tsx.snap +++ b/tests/__snapshots__/FixedColumn.spec.tsx.snap @@ -2,7 +2,7 @@ exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = `
fixed column renders correctly RTL 1`] = ` > title1 - title2 + + title2 + fixed column renders correctly RTL 1`] = ` title11 title12 @@ -238,18 +242,22 @@ exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = ` data-row-key="1" > 123 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` xxxxxxxx xxxxxxxx @@ -307,18 +315,22 @@ exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = ` data-row-key="2" > cdd - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` edd12221 edd12221 @@ -376,18 +388,22 @@ exports[`Table.FixedColumn > fixed column renders correctly RTL 1`] = ` data-row-key="3" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="4" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="5" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="6" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="7" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="8" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> fixed column renders correctly RTL 1`] = ` data-row-key="9" > 133 - - 1111 + + + 1111 + fixed column renders correctly RTL 1`] = ` class="rc-table-cell" /> @@ -753,7 +793,7 @@ exports[`Table.FixedColumn > renders correctly > all column has width should use exports[`Table.FixedColumn > renders correctly > scrollX - with data 1`] = `
renders correctly > scrollX - with data 1`] = ` exports[`Table.FixedColumn > renders correctly > scrollX - without data 1`] = `
renders correctly > scrollX - without data 1`] = ` exports[`Table.FixedColumn > renders correctly > scrollXY - with data 1`] = `
renders correctly > scrollXY - with data 1`] = ` exports[`Table.FixedColumn > renders correctly > scrollXY - without data 1`] = `
Date: Mon, 10 Mar 2025 17:55:16 +0800 Subject: [PATCH 5/5] test: fix test case --- tests/ExpandRow.spec.jsx | 4 ++-- tests/__snapshots__/ExpandRow.spec.jsx.snap | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/ExpandRow.spec.jsx b/tests/ExpandRow.spec.jsx index ff888ddae..fb3f8a9db 100644 --- a/tests/ExpandRow.spec.jsx +++ b/tests/ExpandRow.spec.jsx @@ -265,8 +265,8 @@ describe('Table.Expand', () => { expandable: { expandedRowRender, fixed: 'right' }, }), ); - expect(container.querySelectorAll('.rc-table-has-fix-left').length).toBe(1); - expect(container2.querySelectorAll('.rc-table-has-fix-right').length).toBe(1); + expect(container.querySelector('.rc-table-has-fix-start')).toBeTruthy(); + expect(container2.querySelector('.rc-table-has-fix-end')).toBeTruthy(); }); describe('config expand column index', () => { diff --git a/tests/__snapshots__/ExpandRow.spec.jsx.snap b/tests/__snapshots__/ExpandRow.spec.jsx.snap index c7c405d5e..71d1f8f9d 100644 --- a/tests/__snapshots__/ExpandRow.spec.jsx.snap +++ b/tests/__snapshots__/ExpandRow.spec.jsx.snap @@ -438,7 +438,7 @@ exports[`Table.Expand > not use nest when children is invalidate 1`] = ` exports[`Table.Expand > renders fixed column correctly > work 1`] = `