Skip to content

Commit

Permalink
fix: allow opt-out for selecting child rows
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Sep 25, 2023
1 parent f1be41d commit 4fb5627
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/table-core/src/features/RowSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface RowSelectionRow {
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleselected)
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
*/
toggleSelected: (value?: boolean) => void
toggleSelected: (value?: boolean, opts?: { selectChildren?: boolean }) => void
}

export interface RowSelectionInstance<TData extends RowData> {
Expand Down Expand Up @@ -475,7 +475,7 @@ export const RowSelection: TableFeature = {
row: Row<TData>,
table: Table<TData>
): void => {
row.toggleSelected = value => {
row.toggleSelected = (value, opts) => {
const isSelected = row.getIsSelected()

table.setRowSelection(old => {
Expand All @@ -487,7 +487,9 @@ export const RowSelection: TableFeature = {

const selectedRowIds = { ...old }

mutateRowIsSelected(selectedRowIds, row.id, value, table)
if (opts?.selectChildren ?? true) {
mutateRowIsSelected(selectedRowIds, row.id, value, table)
}

return selectedRowIds
})
Expand Down

0 comments on commit 4fb5627

Please sign in to comment.