Skip to content

Commit f6d716c

Browse files
committed
fix: selection bug
1 parent 9b984ce commit f6d716c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export const RowSelection: TableFeature = {
255255
const rowSelection: RowSelectionState = { ...old }
256256

257257
table.getRowModel().rows.forEach(row => {
258-
mutateRowIsSelected(rowSelection, row.id, resolvedValue, table)
258+
mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)
259259
})
260260

261261
return rowSelection
@@ -487,9 +487,13 @@ export const RowSelection: TableFeature = {
487487

488488
const selectedRowIds = { ...old }
489489

490-
if (opts?.selectChildren ?? true) {
491-
mutateRowIsSelected(selectedRowIds, row.id, value, table)
492-
}
490+
mutateRowIsSelected(
491+
selectedRowIds,
492+
row.id,
493+
value,
494+
opts?.selectChildren ?? true,
495+
table
496+
)
493497

494498
return selectedRowIds
495499
})
@@ -549,6 +553,7 @@ const mutateRowIsSelected = <TData extends RowData>(
549553
selectedRowIds: Record<string, boolean>,
550554
id: string,
551555
value: boolean,
556+
includeChildren: boolean,
552557
table: Table<TData>
553558
) => {
554559
const row = table.getRow(id)
@@ -571,9 +576,9 @@ const mutateRowIsSelected = <TData extends RowData>(
571576
}
572577
// }
573578

574-
if (row.subRows?.length && row.getCanSelectSubRows()) {
579+
if (includeChildren && row.subRows?.length && row.getCanSelectSubRows()) {
575580
row.subRows.forEach(row =>
576-
mutateRowIsSelected(selectedRowIds, row.id, value, table)
581+
mutateRowIsSelected(selectedRowIds, row.id, value, includeChildren, table)
577582
)
578583
}
579584
}

0 commit comments

Comments
 (0)