Skip to content

Commit 7e56c63

Browse files
committed
fix Table style when scroll={{ x: true }} and fixed columns
close ant-design/ant-design#22160
1 parent 5baa5b1 commit 7e56c63

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/BaseTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ class BaseTable<ValueType> extends React.Component<BaseTableProps<ValueType>> {
144144
const { table } = this.context;
145145
const { components } = table;
146146
const { prefixCls, scroll, data, getBodyWrapper } = table.props;
147-
const { expander, tableClassName, hasHead, hasBody, fixed } = this.props;
147+
const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.props;
148148
const tableStyle: React.CSSProperties = {};
149149

150150
if (!fixed && scroll.x) {
151+
// 当有固定列时,width auto 会导致 body table 的宽度撑不开,从而固定列无法对齐
152+
// 详情见:https://github.com/ant-design/ant-design/issues/22160
153+
const tableWidthScrollX = isAnyColumnsFixed ? 'max-content' : 'auto';
151154
// not set width, then use content fixed width
152-
tableStyle.width = scroll.x === true ? 'auto' : scroll.x;
155+
tableStyle.width = scroll.x === true ? tableWidthScrollX : scroll.x;
153156
}
154157

155158
const Table = hasBody ? components.table : 'table';

tests/__snapshots__/Table.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ exports[`Table scroll renders scroll.x is true 1`] = `
18881888
>
18891889
<table
18901890
class="rc-table-fixed"
1891-
style="width:max-content"
1891+
style="width:auto"
18921892
>
18931893
<colgroup>
18941894
<col />

0 commit comments

Comments
 (0)