11import * as React from 'react' ;
22import type { ColumnType } from './interface' ;
33import { INTERNAL_COL_DEFINE } from './utils/legacyUtil' ;
4+ import { useContext } from '@rc-component/context' ;
5+ import TableContext from './context/TableContext' ;
46
57export interface ColGroupProps < RecordType > {
68 colWidths : readonly ( number | string ) [ ] ;
@@ -9,6 +11,8 @@ export interface ColGroupProps<RecordType> {
911}
1012
1113function ColGroup < RecordType > ( { colWidths, columns, columCount } : ColGroupProps < RecordType > ) {
14+ const { tableLayout } = useContext ( TableContext , [ 'tableLayout' ] ) ;
15+
1216 const cols : React . ReactElement [ ] = [ ] ;
1317 const len = columCount || columns . length ;
1418
@@ -18,11 +22,20 @@ function ColGroup<RecordType>({ colWidths, columns, columCount }: ColGroupProps<
1822 for ( let i = len - 1 ; i >= 0 ; i -= 1 ) {
1923 const width = colWidths [ i ] ;
2024 const column = columns && columns [ i ] ;
21- const additionalProps = column && column [ INTERNAL_COL_DEFINE ] ;
25+ let additionalProps ;
26+ let minWidth : number ;
27+ if ( column ) {
28+ additionalProps = column [ INTERNAL_COL_DEFINE ] ;
29+
30+ // fixed will cause layout problems
31+ if ( tableLayout === 'auto' ) {
32+ minWidth = column . minWidth ;
33+ }
34+ }
2235
23- if ( width || additionalProps || mustInsert ) {
36+ if ( width || minWidth || additionalProps || mustInsert ) {
2437 const { columnType, ...restAdditionalProps } = additionalProps || { } ;
25- cols . unshift ( < col key = { i } style = { { width } } { ...restAdditionalProps } /> ) ;
38+ cols . unshift ( < col key = { i } style = { { width, minWidth } } { ...restAdditionalProps } /> ) ;
2639 mustInsert = true ;
2740 }
2841 }
0 commit comments