Skip to content

Commit

Permalink
fix: selection bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Sep 25, 2023
1 parent 9b984ce commit f6d716c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/table-core/src/features/RowSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const RowSelection: TableFeature = {
const rowSelection: RowSelectionState = { ...old }

table.getRowModel().rows.forEach(row => {
mutateRowIsSelected(rowSelection, row.id, resolvedValue, table)
mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)
})

return rowSelection
Expand Down Expand Up @@ -487,9 +487,13 @@ export const RowSelection: TableFeature = {

const selectedRowIds = { ...old }

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

return selectedRowIds
})
Expand Down Expand Up @@ -549,6 +553,7 @@ const mutateRowIsSelected = <TData extends RowData>(
selectedRowIds: Record<string, boolean>,
id: string,
value: boolean,
includeChildren: boolean,
table: Table<TData>
) => {
const row = table.getRow(id)
Expand All @@ -571,9 +576,9 @@ const mutateRowIsSelected = <TData extends RowData>(
}
// }

if (row.subRows?.length && row.getCanSelectSubRows()) {
if (includeChildren && row.subRows?.length && row.getCanSelectSubRows()) {
row.subRows.forEach(row =>
mutateRowIsSelected(selectedRowIds, row.id, value, table)
mutateRowIsSelected(selectedRowIds, row.id, value, includeChildren, table)
)
}
}
Expand Down

0 comments on commit f6d716c

Please sign in to comment.