@@ -237,19 +237,25 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
237
237
return valign ;
238
238
}
239
239
240
+ // returns the grid-template-column CSS attribute for the grid
240
241
get gridTemplateColumns ( ) : string {
242
+ // if there is no select checkbox or custom column widths, each column is the same width and they take up the available space
241
243
if ( ! this . args . isSelectable && ! this . columnWidths ) {
242
244
return `repeat(${ this . args . columns . length } , 1fr)` ;
243
- }
245
+ }
244
246
247
+ // if there is a select checkbox, the first column is 'auto' width to hug the checkbox content
245
248
let style = this . args . isSelectable ? 'auto' : '' ;
246
249
247
250
if ( this . columnWidths ) {
251
+ // check the custom column widths, if the current column has a custom width use the custom width. otherwise take the available space.
248
252
for ( let i = 0 ; i < this . columnWidths . length ; i ++ ) {
249
253
style = `${ style } ${ this . columnWidths [ i ] ? this . columnWidths [ i ] : '1fr' } ` ;
250
254
}
251
255
} else {
256
+ // if there are no custom column widths, remaining columns are the same width and take up the available space
252
257
for ( let i = 0 ; i < this . args . columns . length ; i ++ ) {
258
+ // Note: can't use `repeat()` syntax because the first column is not the same as the rest.
253
259
style = `${ style } 1fr` ;
254
260
}
255
261
}
@@ -330,31 +336,32 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
330
336
selectionKey ?: string
331
337
) : void {
332
338
const { onSelectionChange } = this . args ;
333
- if ( typeof onSelectionChange === 'function' ) {
334
- onSelectionChange ( {
335
- selectionKey : selectionKey ,
336
- selectionCheckboxElement : checkbox ,
337
- selectedRowsKeys : this . _selectableRows . reduce < string [ ] > ( ( acc , row ) => {
338
- if ( row . checkbox . checked ) {
339
- acc . push ( row . selectionKey ) ;
340
- }
339
+
340
+ if ( typeof onSelectionChange !== 'function' ) return ;
341
+
342
+ onSelectionChange ( {
343
+ selectionKey : selectionKey ,
344
+ selectionCheckboxElement : checkbox ,
345
+ selectedRowsKeys : this . _selectableRows . reduce < string [ ] > ( ( acc , row ) => {
346
+ if ( row . checkbox . checked ) {
347
+ acc . push ( row . selectionKey ) ;
348
+ }
349
+ return acc ;
350
+ } , [ ] ) ,
351
+ selectableRowsStates : this . _selectableRows . reduce (
352
+ (
353
+ acc : { selectionKey : string ; isSelected : boolean | undefined } [ ] ,
354
+ row
355
+ ) => {
356
+ acc . push ( {
357
+ selectionKey : row . selectionKey ,
358
+ isSelected : row . checkbox . checked ,
359
+ } ) ;
341
360
return acc ;
342
- } , [ ] ) ,
343
- selectableRowsStates : this . _selectableRows . reduce (
344
- (
345
- acc : { selectionKey : string ; isSelected : boolean | undefined } [ ] ,
346
- row
347
- ) => {
348
- acc . push ( {
349
- selectionKey : row . selectionKey ,
350
- isSelected : row . checkbox . checked ,
351
- } ) ;
352
- return acc ;
353
- } ,
354
- [ ]
355
- ) ,
356
- } ) ;
357
- }
361
+ } ,
362
+ [ ]
363
+ ) ,
364
+ } ) ;
358
365
}
359
366
360
367
@action
0 commit comments