Skip to content

Commit

Permalink
Ensure isSubRowSelected returns false if no subRows are selctable
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel 'Aaron' Cohen committed Nov 4, 2024
1 parent 453dc71 commit 6af6819
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/table-core/src/features/RowSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ export const RowSelection: TableFeature = {
return table.getIsAllPageRowsSelected()
? false
: paginationFlatRows
.filter(row => row.getCanSelect())
.some(d => d.getIsSelected() || d.getIsSomeSelected())
.filter(row => row.getCanSelect())
.some(d => d.getIsSelected() || d.getIsSomeSelected())
}

table.getToggleAllRowsSelectedHandler = () => {
Expand Down Expand Up @@ -635,6 +635,7 @@ export function isSubRowSelected<TData extends RowData>(

let allChildrenSelected = true
let someSelected = false
let someSelectable = false

row.subRows.forEach(subRow => {
// Bail out early if we know both of these
Expand All @@ -643,6 +644,7 @@ export function isSubRowSelected<TData extends RowData>(
}

if (subRow.getCanSelect()) {
someSelectable = true
if (isRowSelected(subRow, selection)) {
someSelected = true
} else {
Expand All @@ -664,5 +666,7 @@ export function isSubRowSelected<TData extends RowData>(
}
})

if (!someSelectable) return false

return allChildrenSelected ? 'all' : someSelected ? 'some' : false
}

0 comments on commit 6af6819

Please sign in to comment.