Skip to content

Commit f30eb5f

Browse files
committed
fix(Table): min-width no works and skip fixed layout
1 parent 936eb92 commit f30eb5f

5 files changed

Lines changed: 173 additions & 164 deletions

File tree

packages/components/table/BaseTable.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { forwardRef, RefAttributes, useEffect, useImperativeHandle, useMe
22
import classNames from 'classnames';
33
import { pick } from 'lodash-es';
44
import log from '@tdesign/common-js/log/index';
5-
import { getIEVersion } from '@tdesign/common-js/utils/helper';
5+
import { getIEVersion, isChromium } from '@tdesign/common-js/utils/helper';
66
import Affix, { type AffixRef } from '../affix';
77
import useDefaultProps from '../hooks/useDefaultProps';
88
import useElementLazyRender from '../hooks/useElementLazyRender';
@@ -308,11 +308,20 @@ const BaseTable = forwardRef<BaseTableRef, BaseTableProps>((originalProps, ref)
308308
width: formatCSSUnit((isFixedHeader || resizable ? thWidthList.current[col.colKey] : undefined) || col.width),
309309
};
310310
if (col.minWidth) {
311-
style.minWidth = formatCSSUnit(col.minWidth);
311+
if (isChromium()) {
312+
style.minWidth = formatCSSUnit(col.minWidth);
313+
} else {
314+
style.width = formatCSSUnit(col.minWidth);
315+
}
312316
}
313317
// 没有设置任何宽度的场景下,需要保留表格正常显示的最小宽度,否则会出现因宽度过小的抖动问题
314318
if (!style.width && !col.minWidth && props.tableLayout === 'fixed') {
315-
style.minWidth = '80px';
319+
if (isChromium()) {
320+
style.minWidth = '80px';
321+
} else {
322+
// 非 Chromium 内核浏览器中,min-width 兼容性差
323+
style.width = '80px';
324+
}
316325
}
317326
return <col key={col.colKey || index} style={style} />;
318327
})}

packages/components/table/__tests__/__snapshots__/pagination.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ exports[`BaseTable Pagination > locale data pagination controlled > pagination.c
149149
>
150150
<colgroup>
151151
<col
152-
style="min-width: 80px;"
152+
style="width: 80px;"
153153
/>
154154
<col
155-
style="min-width: 80px;"
155+
style="width: 80px;"
156156
/>
157157
<col
158-
style="min-width: 80px;"
158+
style="width: 80px;"
159159
/>
160160
</colgroup>
161161
<thead

packages/components/table/__tests__/__snapshots__/vitest-table.test.jsx.snap

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ exports[`BaseTable Component > props.showHeader: BaseTable contains element \`th
1414
>
1515
<colgroup>
1616
<col
17-
style="min-width: 80px;"
17+
style="width: 80px;"
1818
/>
1919
<col
20-
style="min-width: 80px;"
20+
style="width: 80px;"
2121
/>
2222
<col
23-
style="min-width: 80px;"
23+
style="width: 80px;"
2424
/>
2525
</colgroup>
2626
<thead
@@ -169,13 +169,13 @@ exports[`BaseTable Component > props.size is equal to large 1`] = `
169169
>
170170
<colgroup>
171171
<col
172-
style="min-width: 80px;"
172+
style="width: 80px;"
173173
/>
174174
<col
175-
style="min-width: 80px;"
175+
style="width: 80px;"
176176
/>
177177
<col
178-
style="min-width: 80px;"
178+
style="width: 80px;"
179179
/>
180180
</colgroup>
181181
<thead
@@ -324,13 +324,13 @@ exports[`BaseTable Component > props.size is equal to medium 1`] = `
324324
>
325325
<colgroup>
326326
<col
327-
style="min-width: 80px;"
327+
style="width: 80px;"
328328
/>
329329
<col
330-
style="min-width: 80px;"
330+
style="width: 80px;"
331331
/>
332332
<col
333-
style="min-width: 80px;"
333+
style="width: 80px;"
334334
/>
335335
</colgroup>
336336
<thead
@@ -479,13 +479,13 @@ exports[`BaseTable Component > props.size is equal to small 1`] = `
479479
>
480480
<colgroup>
481481
<col
482-
style="min-width: 80px;"
482+
style="width: 80px;"
483483
/>
484484
<col
485-
style="min-width: 80px;"
485+
style="width: 80px;"
486486
/>
487487
<col
488-
style="min-width: 80px;"
488+
style="width: 80px;"
489489
/>
490490
</colgroup>
491491
<thead
@@ -783,13 +783,13 @@ exports[`BaseTable Component > props.tableLayout is equal to fixed 1`] = `
783783
>
784784
<colgroup>
785785
<col
786-
style="min-width: 80px;"
786+
style="width: 80px;"
787787
/>
788788
<col
789-
style="min-width: 80px;"
789+
style="width: 80px;"
790790
/>
791791
<col
792-
style="min-width: 80px;"
792+
style="width: 80px;"
793793
/>
794794
</colgroup>
795795
<thead

0 commit comments

Comments
 (0)