Skip to content

Commit afe2716

Browse files
author
shleewhite
committed
chore: incorporate feedback for advanced-table/index.hbs
1 parent 49259ef commit afe2716

File tree

1 file changed

+32
-25
lines changed
  • packages/components/src/components/hds/advanced-table

1 file changed

+32
-25
lines changed

packages/components/src/components/hds/advanced-table/index.ts

+32-25
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,25 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
237237
return valign;
238238
}
239239

240+
// returns the grid-template-column CSS attribute for the grid
240241
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
241243
if (!this.args.isSelectable && !this.columnWidths) {
242244
return `repeat(${this.args.columns.length}, 1fr)`;
243-
}
245+
}
244246

247+
// if there is a select checkbox, the first column is 'auto' width to hug the checkbox content
245248
let style = this.args.isSelectable ? 'auto' : '';
246249

247250
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.
248252
for (let i = 0; i < this.columnWidths.length; i++) {
249253
style = `${style} ${this.columnWidths[i] ? this.columnWidths[i] : '1fr'}`;
250254
}
251255
} else {
256+
// if there are no custom column widths, remaining columns are the same width and take up the available space
252257
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.
253259
style = `${style} 1fr`;
254260
}
255261
}
@@ -330,31 +336,32 @@ export default class HdsAdvancedTable extends Component<HdsAdvancedTableSignatur
330336
selectionKey?: string
331337
): void {
332338
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+
});
341360
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+
});
358365
}
359366

360367
@action

0 commit comments

Comments
 (0)