Skip to content

Commit c7f774c

Browse files
authored
fix: stack case (#1247)
1 parent 2e6d4f2 commit c7f774c

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

docs/examples/scrollXY.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import Table from 'rc-table';
44
import '../../assets/index.less';
55

66
const columns: TableProps['columns'] = [
7-
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'start' },
8-
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
9-
{ title: 'title3', dataIndex: 'c', key: 'c', width: 100, fixed: 'start' },
10-
{ title: 'title4', dataIndex: 'b', key: 'd', width: 100 },
11-
{ title: 'title5', dataIndex: 'b', key: 'e', width: 100 },
12-
{ title: 'title6', dataIndex: 'b', key: 'f', width: 100 },
7+
{ title: 'title1', dataIndex: 'a', key: 'a', width: 60, fixed: 'start' },
8+
{ title: 'title2', dataIndex: 'b', key: 'b', width: 80, fixed: 'start' },
9+
{ title: 'title3', dataIndex: 'c', key: 'c', width: 120 },
10+
{ title: 'title4', dataIndex: 'b', key: 'd', width: 100, fixed: 'start' },
11+
{ title: 'title5', dataIndex: 'b', key: 'e' },
12+
{ title: 'title6', dataIndex: 'b', key: 'f' },
1313
{ title: 'title7', dataIndex: 'b', key: 'g', width: 100 },
1414
{ title: 'title8', dataIndex: 'b', key: 'h', width: 100 },
1515
{ title: 'title9', dataIndex: 'b', key: 'i', width: 100 },

src/Cell/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export interface CellProps<RecordType extends DefaultRecordType> {
4141
fixEnd?: number | false;
4242
fixedStartShadow?: boolean;
4343
fixedEndShadow?: boolean;
44+
offsetFixedStartShadow?: number;
45+
offsetFixedEndShadow?: number;
4446
zIndex?: number;
4547
allColsFixedLeft?: boolean;
4648

@@ -107,6 +109,8 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
107109
fixEnd,
108110
fixedStartShadow,
109111
fixedEndShadow,
112+
offsetFixedStartShadow,
113+
offsetFixedEndShadow,
110114
zIndex,
111115

112116
// Private
@@ -146,12 +150,12 @@ function Cell<RecordType>(props: CellProps<RecordType>) {
146150
const showStartShadow =
147151
(isFixStart && fixedStartShadow && absScroll) -
148152
// For precision, we not show shadow by default which has better user experience.
149-
(fixStart as number) >=
153+
(offsetFixedStartShadow as number) >=
150154
1;
151155
const showEndShadow =
152156
(isFixEnd && fixedEndShadow && scrollWidth - absScroll) -
153157
// Same as above
154-
(fixEnd as number) >=
158+
(offsetFixedEndShadow as number) >=
155159
1;
156160

157161
return [showStartShadow, showEndShadow];

src/hooks/useStickyOffsets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function useStickyOffsets<RecordType>(
3232
return {
3333
start: startOffsets,
3434
end: endOffsets,
35+
widths: colWidths,
3536
};
3637
}, [colWidths, flattenColumns]);
3738

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export type GetRowKey<RecordType> = (record: RecordType, index?: number) => Key;
133133
export interface StickyOffsets {
134134
start: readonly number[];
135135
end: readonly number[];
136+
widths: readonly number[];
136137
isSticky?: boolean;
137138
}
138139

src/utils/fixUtil.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export interface FixedInfo {
1212
/** `fixed: end` with shadow */
1313
fixedEndShadow?: boolean;
1414

15+
/** Show the shadow when `scrollLeft` arrive for `fixed: start` */
16+
offsetFixedStartShadow?: number;
17+
/** Show the shadow when `scrollLeft` arrive for `fixed: end` */
18+
offsetFixedEndShadow?: number;
19+
1520
zIndex?: number;
1621
}
1722

@@ -41,8 +46,8 @@ export function getCellFixedInfo(
4146
}
4247

4348
// check if need to add shadow
44-
let fixedStartShadow: boolean;
45-
let fixedEndShadow: boolean;
49+
let fixedStartShadow = false;
50+
let fixedEndShadow = false;
4651

4752
// Calc `zIndex`.
4853
// first fixed start (start -> end) column `zIndex` should be greater than next column.
@@ -58,11 +63,32 @@ export function getCellFixedInfo(
5863
zIndex = colEnd;
5964
}
6065

66+
// Check if scrollLeft will show the shadow
67+
let offsetFixedStartShadow = 0;
68+
let offsetFixedEndShadow = 0;
69+
70+
if (fixedStartShadow) {
71+
for (let i = 0; i < colStart; i += 1) {
72+
if (!isFixedStart(columns[i])) {
73+
offsetFixedStartShadow += stickyOffsets.widths[i] || 0;
74+
}
75+
}
76+
}
77+
if (fixedEndShadow) {
78+
for (let i = columns.length - 1; i > colEnd; i -= 1) {
79+
if (!isFixedEnd(columns[i])) {
80+
offsetFixedEndShadow += stickyOffsets.widths[i] || 0;
81+
}
82+
}
83+
}
84+
6185
return {
6286
fixStart,
6387
fixEnd,
6488
fixedStartShadow,
6589
fixedEndShadow,
90+
offsetFixedStartShadow,
91+
offsetFixedEndShadow,
6692
isSticky: stickyOffsets.isSticky,
6793
zIndex,
6894
};

0 commit comments

Comments
 (0)