Skip to content

Commit

Permalink
test: update test
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Jan 30, 2024
1 parent e857125 commit 362a520
Show file tree
Hide file tree
Showing 4 changed files with 3,160 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/examples/fixedColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ interface RecordType {

const columns: ColumnType<RecordType>[] = [
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100, ellipsis: true },
{ title: 'title3', dataIndex: 'c', key: 'c', fixed: 'left' },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left', ellipsis: true },
{ title: 'title3', dataIndex: 'c', key: 'c' },
{ title: 'title4', dataIndex: 'b', key: 'd' },
{ title: 'title5', dataIndex: 'b', key: 'e' },
{ title: 'title6', dataIndex: 'b', key: 'f' },
Expand All @@ -33,7 +33,7 @@ const columns: ColumnType<RecordType>[] = [
},
{ title: 'title8', dataIndex: 'b', key: 'h' },
{ title: 'title9', dataIndex: 'b', key: 'i' },
{ title: 'title10', dataIndex: 'b', key: 'j', fixed: 'right' },
{ title: 'title10', dataIndex: 'b', key: 'j' },
{ title: 'title11', dataIndex: 'b', key: 'k', width: 50 },
{ title: 'title12', dataIndex: 'b', key: 'l', width: 100, fixed: 'right' },
];
Expand Down
4 changes: 2 additions & 2 deletions src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function Table<RecordType extends DefaultRecordType>(
const scrollX = scroll?.x;
const [componentWidth, setComponentWidth] = React.useState(0);

const [columns, flattenColumns, flattenScrollX, gapFixed] = useColumns(
const [columns, flattenColumns, flattenScrollX, hasGapFixed] = useColumns(
{
...props,
...expandableConfig,
Expand Down Expand Up @@ -750,7 +750,7 @@ function Table<RecordType extends DefaultRecordType>(
[`${prefixCls}-fixed-header`]: fixHeader,
/** No used but for compatible */
[`${prefixCls}-fixed-column`]: fixColumn,
[`${prefixCls}-fixed-column-gapped`]: fixColumn && gapFixed,
[`${prefixCls}-fixed-column-gapped`]: fixColumn && hasGapFixed,
[`${prefixCls}-scroll-horizontal`]: horizonScroll,
[`${prefixCls}-has-fix-left`]: flattenColumns[0] && flattenColumns[0].fixed,
[`${prefixCls}-has-fix-right`]:
Expand Down
14 changes: 10 additions & 4 deletions src/hooks/useColumns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@ function useColumns<RecordType>(

// ========================= Gap Fixed ========================
const hasGapFixed = React.useMemo(() => {
// Fixed: left
const lastLeftIndex = flattenColumns.findLastIndex(
({ fixed: colFixed }) => colFixed === 'left' || colFixed === true,
);
// Fixed: left, since old browser not support `findLastIndex`, we should use reverse loop
let lastLeftIndex = -1;
for (let i = flattenColumns.length - 1; i >= 0; i -= 1) {
const colFixed = flattenColumns[i].fixed;
if (colFixed === 'left' || colFixed === true) {
lastLeftIndex = i;
break;
}
}

if (lastLeftIndex >= 0) {
for (let i = 0; i <= lastLeftIndex; i += 1) {
const colFixed = flattenColumns[i].fixed;
Expand Down
Loading

0 comments on commit 362a520

Please sign in to comment.