Skip to content

Commit 41df3ad

Browse files
dashaowangweiwang
andauthored
fix: do not show shadow when all columns is fixed left (#847)
* 修复表格组件开启scrollX时全部列左固定时出现横向滚动条 * 修复表格在所有列全是左固定的时候,会出现横向滚动条的情况 * 提交测试用例 * fix:修改表格全部左固定时的样式名称 * fix:更新所有的表格列左固定的测试用例 Co-authored-by: weiwang <[email protected]>
1 parent 6061542 commit 41df3ad

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

assets/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
pointer-events: none;
9393
}
9494

95+
&-fix-left-all::after {
96+
display: none;
97+
}
98+
9599
&-fix-right-first,
96100
&-fix-right-last {
97101
box-shadow: -1px 0 0 @border-color;

src/Cell/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
import { getPathValue, validateValue } from '../utils/valueUtil';
1616
import StickyContext from '../context/StickyContext';
1717
import HoverContext from '../context/HoverContext';
18+
import BodyContext from '../context/BodyContext';
1819
import type { HoverContextProps } from '../context/HoverContext';
1920
import warning from 'rc-util/lib/warning';
2021
import PerfContext from '../context/PerfContext';
@@ -67,6 +68,7 @@ interface InternalCellProps<RecordType extends DefaultRecordType>
6768
lastFixLeft?: boolean;
6869
firstFixRight?: boolean;
6970
lastFixRight?: boolean;
71+
allColsFixedLeft?: boolean;
7072

7173
// ====================== Private Props ======================
7274
/** @private Used for `expandable` with nest tree */
@@ -141,6 +143,7 @@ function Cell<RecordType extends DefaultRecordType>(
141143

142144
const perfRecord = React.useContext(PerfContext);
143145
const supportSticky = React.useContext(StickyContext);
146+
const { allColumnsFixedLeft } = React.useContext(BodyContext);
144147

145148
// ==================== Child Node ====================
146149
const [childNode, legacyCellProps] = React.useMemo<
@@ -280,6 +283,7 @@ function Cell<RecordType extends DefaultRecordType>(
280283
[`${cellPrefixCls}-fix-left`]: isFixLeft && supportSticky,
281284
[`${cellPrefixCls}-fix-left-first`]: firstFixLeft && supportSticky,
282285
[`${cellPrefixCls}-fix-left-last`]: lastFixLeft && supportSticky,
286+
[`${cellPrefixCls}-fix-left-all`]: lastFixLeft && allColumnsFixedLeft && supportSticky,
283287
[`${cellPrefixCls}-fix-right`]: isFixRight && supportSticky,
284288
[`${cellPrefixCls}-fix-right-first`]: firstFixRight && supportSticky,
285289
[`${cellPrefixCls}-fix-right-last`]: lastFixRight && supportSticky,

src/Table.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
822822
onTriggerExpand,
823823
expandIconColumnIndex,
824824
indentSize,
825+
allColumnsFixedLeft: columnContext.flattenColumns.every(col => col.fixed === 'left'),
825826
}),
826827
[
827828
columnContext,

src/context/BodyContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface BodyContextProps<RecordType = DefaultRecordType> {
2727
expandIcon: RenderExpandIcon<RecordType>;
2828
onTriggerExpand: TriggerEventHandler<RecordType>;
2929
expandIconColumnIndex: number;
30+
allColumnsFixedLeft: boolean;
3031
}
3132

3233
const BodyContext = React.createContext<BodyContextProps>(null);

tests/FixedColumn.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,9 @@ describe('Table.FixedColumn', () => {
272272
wrapper.update();
273273
expect(wrapper.find('.rc-table-measure-row td')).toHaveLength(4);
274274
});
275+
276+
it('when all columns fixed left,cell should has classname rc-table-cell-fix-left-all', () => {
277+
const wrapper = mount(<Table columns={columns.slice(0, 2)} data={data} scroll={{ x: 1000 }} />);
278+
expect(wrapper.find('.rc-table-cell-fix-left-all')).toHaveLength(10);
279+
});
275280
});

0 commit comments

Comments
 (0)