Skip to content

Commit 4fb5627

Browse files
committed
fix: allow opt-out for selecting child rows
1 parent f1be41d commit 4fb5627

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/table-core/src/features/RowSelection.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface RowSelectionRow {
9797
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-selection#toggleselected)
9898
* @link [Guide](https://tanstack.com/table/v8/docs/guide/row-selection)
9999
*/
100-
toggleSelected: (value?: boolean) => void
100+
toggleSelected: (value?: boolean, opts?: { selectChildren?: boolean }) => void
101101
}
102102

103103
export interface RowSelectionInstance<TData extends RowData> {
@@ -475,7 +475,7 @@ export const RowSelection: TableFeature = {
475475
row: Row<TData>,
476476
table: Table<TData>
477477
): void => {
478-
row.toggleSelected = value => {
478+
row.toggleSelected = (value, opts) => {
479479
const isSelected = row.getIsSelected()
480480

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

488488
const selectedRowIds = { ...old }
489489

490-
mutateRowIsSelected(selectedRowIds, row.id, value, table)
490+
if (opts?.selectChildren ?? true) {
491+
mutateRowIsSelected(selectedRowIds, row.id, value, table)
492+
}
491493

492494
return selectedRowIds
493495
})

0 commit comments

Comments
 (0)