Skip to content

Commit 1aa2e67

Browse files
authored
fix: Table rtl related className (#1245)
* chore: fix logical position * test: update snapshot * chore: fix default fixed type * test: update snapshot * test: fix test case
1 parent 68e6975 commit 1aa2e67

File tree

8 files changed

+145
-123
lines changed

8 files changed

+145
-123
lines changed

src/Table.tsx

+3-5
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,8 @@ function Table<RecordType extends DefaultRecordType>(
775775
/** No used but for compatible */
776776
[`${prefixCls}-fixed-column`]: fixColumn,
777777
[`${prefixCls}-scroll-horizontal`]: horizonScroll,
778-
[`${prefixCls}-has-fix-left`]: flattenColumns[0] && flattenColumns[0].fixed,
779-
[`${prefixCls}-has-fix-right`]:
780-
flattenColumns[flattenColumns.length - 1] &&
781-
flattenColumns[flattenColumns.length - 1].fixed === 'right',
778+
[`${prefixCls}-has-fix-start`]: flattenColumns[0]?.fixed,
779+
[`${prefixCls}-has-fix-end`]: flattenColumns[flattenColumns.length - 1]?.fixed === 'end',
782780
})}
783781
style={style}
784782
id={id}
@@ -829,7 +827,7 @@ function Table<RecordType extends DefaultRecordType>(
829827
onTriggerExpand,
830828
expandIconColumnIndex: expandableConfig.expandIconColumnIndex,
831829
indentSize: expandableConfig.indentSize,
832-
allColumnsFixedLeft: flattenColumns.every(col => col.fixed === 'left'),
830+
allColumnsFixedLeft: flattenColumns.every(col => col.fixed === 'start'),
833831
emptyNode,
834832

835833
// Column

src/hooks/useColumns/index.tsx

+11-28
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function flatColumns<RecordType>(
6363
.filter(column => column && typeof column === 'object')
6464
.reduce((list, column, index) => {
6565
const { fixed } = column;
66-
// Convert `fixed='true'` to `fixed='left'` instead
67-
const parsedFixed = fixed === true ? 'left' : fixed;
66+
const parsedFixed =
67+
fixed === true || fixed === 'left' ? 'start' : fixed === 'right' ? 'end' : fixed;
6868
const mergedKey = `${parentKey}-${index}`;
6969

7070
const subColumns = (column as ColumnGroupType<RecordType>).children;
@@ -88,24 +88,6 @@ function flatColumns<RecordType>(
8888
}, []);
8989
}
9090

91-
function revertForRtl<RecordType>(columns: ColumnsType<RecordType>): ColumnsType<RecordType> {
92-
return columns.map(column => {
93-
const { fixed, ...restProps } = column;
94-
95-
// Convert `fixed='left'` to `fixed='right'` instead
96-
let parsedFixed = fixed;
97-
if (fixed === 'left') {
98-
parsedFixed = 'right';
99-
} else if (fixed === 'right') {
100-
parsedFixed = 'left';
101-
}
102-
return {
103-
fixed: parsedFixed,
104-
...restProps,
105-
};
106-
});
107-
}
108-
10991
/**
11092
* Parse `columns` & `children` into `columns`.
11193
*/
@@ -175,10 +157,13 @@ function useColumns<RecordType>(
175157
// >>> Insert expand column if not exist
176158
if (!cloneColumns.includes(EXPAND_COLUMN)) {
177159
const expandColIndex = expandIconColumnIndex || 0;
178-
if (expandColIndex >= 0 && (expandColIndex || fixed === 'left' || !fixed)) {
160+
if (
161+
expandColIndex >= 0 &&
162+
(expandColIndex || fixed === 'left' || fixed === 'start' || !fixed)
163+
) {
179164
cloneColumns.splice(expandColIndex, 0, EXPAND_COLUMN);
180165
}
181-
if (fixed === 'right') {
166+
if (fixed === 'right' || fixed === 'end') {
182167
cloneColumns.splice(baseColumns.length, 0, EXPAND_COLUMN);
183168
}
184169
}
@@ -266,13 +251,11 @@ function useColumns<RecordType>(
266251
}, [transformColumns, withExpandColumns, direction]);
267252

268253
// ========================== Flatten =========================
269-
const flattenColumns = React.useMemo(() => {
270-
if (direction === 'rtl') {
271-
return revertForRtl(flatColumns(mergedColumns));
272-
}
273-
return flatColumns(mergedColumns);
254+
const flattenColumns = React.useMemo(
255+
() => flatColumns(mergedColumns),
274256
// eslint-disable-next-line react-hooks/exhaustive-deps
275-
}, [mergedColumns, direction, scrollWidth]);
257+
[mergedColumns, direction, scrollWidth],
258+
);
276259

277260
// ========================= FillWidth ========================
278261
const [filledColumns, realScrollWidth] = useWidthColumns(

src/utils/fixUtil.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export interface FixedInfo {
1616
}
1717

1818
function isFixedStart(column: { fixed?: FixedType }) {
19-
return column.fixed === 'left' || column.fixed === 'start';
19+
return column.fixed === 'start';
2020
}
2121
function isFixedEnd(column: { fixed?: FixedType }) {
22-
return column.fixed === 'right' || column.fixed === 'end';
22+
return column.fixed === 'end';
2323
}
2424

2525
export function getCellFixedInfo(

tests/ExpandRow.spec.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ describe('Table.Expand', () => {
265265
expandable: { expandedRowRender, fixed: 'right' },
266266
}),
267267
);
268-
expect(container.querySelectorAll('.rc-table-has-fix-left').length).toBe(1);
269-
expect(container2.querySelectorAll('.rc-table-has-fix-right').length).toBe(1);
268+
expect(container.querySelector('.rc-table-has-fix-start')).toBeTruthy();
269+
expect(container2.querySelector('.rc-table-has-fix-end')).toBeTruthy();
270270
});
271271

272272
describe('config expand column index', () => {

tests/Table.spec.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ describe('Table.Basic', () => {
619619
scroll: { x: 100, y: 100 },
620620
}),
621621
);
622+
console.log(container.innerHTML);
622623
expect(container.firstChild).toMatchSnapshot();
623624
});
624625

tests/__snapshots__/ExpandRow.spec.jsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ exports[`Table.Expand > not use nest when children is invalidate 1`] = `
438438

439439
exports[`Table.Expand > renders fixed column correctly > work 1`] = `
440440
<div
441-
class="rc-table rc-table-fix-start-shadow rc-table-fix-end-shadow rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-left rc-table-has-fix-right"
441+
class="rc-table rc-table-fix-start-shadow rc-table-fix-end-shadow rc-table-fixed-column rc-table-scroll-horizontal rc-table-has-fix-start rc-table-has-fix-end"
442442
>
443443
<div
444444
class="rc-table-container"

0 commit comments

Comments
 (0)