@@ -137,6 +137,53 @@ test('should use the fallback value for columns without explicit width', () => {
137137 ] ) ;
138138} ) ;
139139
140+ test ( 'should respect minWidth when dynamically adding columns via visibleColumns' , ( ) => {
141+ const columns : TableProps . ColumnDefinition < Item > [ ] = [
142+ { id : 'id' , header : '' , cell : item => item . id , width : 100 } ,
143+ { id : 'small-width' , header : '' , cell : ( ) => '-' , width : 80 , minWidth : 150 } ,
144+ { id : 'width-only' , header : '' , cell : ( ) => '-' , width : 180 } ,
145+ { id : 'minWidth-larger' , header : '' , cell : ( ) => '-' , width : 180 , minWidth : 200 } ,
146+ { id : 'no-width-no-minWidth' , header : '' , cell : ( ) => '-' } ,
147+ { id : 'no-width-minWidth-large' , header : '' , cell : ( ) => '-' , minWidth : 200 } ,
148+ { id : 'no-width-minWidth-small' , header : '' , cell : ( ) => '-' , minWidth : 80 } ,
149+ { id : 'width-larger-than-minWidth' , header : '' , cell : ( ) => '-' , width : 200 , minWidth : 100 } ,
150+ ] ;
151+ const { wrapper, rerender } = renderTable (
152+ < Table columnDefinitions = { columns } visibleColumns = { [ 'id' ] } items = { defaultItems } resizableColumns = { true } />
153+ ) ;
154+ expect ( wrapper . findColumnHeaders ( ) . map ( column => column . getElement ( ) . style . width ) ) . toEqual ( [ '100px' ] ) ;
155+
156+ // Dynamically add columns with various width/minWidth configurations
157+ rerender (
158+ < Table
159+ columnDefinitions = { columns }
160+ visibleColumns = { [
161+ 'id' ,
162+ 'small-width' ,
163+ 'width-only' ,
164+ 'minWidth-larger' ,
165+ 'no-width-no-minWidth' ,
166+ 'no-width-minWidth-large' ,
167+ 'no-width-minWidth-small' ,
168+ 'width-larger-than-minWidth' ,
169+ ] }
170+ items = { defaultItems }
171+ resizableColumns = { true }
172+ />
173+ ) ;
174+
175+ expect ( wrapper . findColumnHeaders ( ) . map ( column => column . getElement ( ) . style . width ) ) . toEqual ( [
176+ '100px' , // original column unchanged
177+ '150px' , // width=80, minWidth=150 -> use minWidth because 150 > 80
178+ '180px' , // width=180, no minWidth -> minWidth defaults to width, use 180
179+ '200px' , // width=180, minWidth=200 -> use minWidth because 200 > 180
180+ '120px' , // no width, no minWidth -> width defaults to DEFAULT (120), minWidth defaults to width
181+ '200px' , // no width, minWidth=200 -> width defaults to DEFAULT (120), minWidth=200 -> use 200
182+ '120px' , // no width, minWidth=80 -> width defaults to DEFAULT (120), minWidth=80 -> use 120
183+ '200px' , // width=200, minWidth=100 -> use width because 200 > 100
184+ ] ) ;
185+ } ) ;
186+
140187describe ( 'reading widths from the DOM' , ( ) => {
141188 const originalBoundingClientRect = HTMLElement . prototype . getBoundingClientRect ;
142189 beforeEach ( ( ) => {
0 commit comments