fix: let parent rows unselect child rows when not itself selected #6364
beta fromrefs/pull/6364/head·merged by KevinVandy - Updated checkbox selection logic to account for sub-row selections in various examples (Alpine, Angular, React, Preact, Solid, Svelte, Vue).
- Refactored core row selection feature to include memoization for
getIsAllSubRowsSelectedandgetCanSelectSubRowsfunctions. - Improved performance by optimizing selection checks in utility functions.
🎯 Changes#
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested this code locally with
pnpm test:pr.
Summary by CodeRabbit#
New Features
- Expanded row-selection behavior in expandable table examples so parent checkboxes now appear selected when all nested rows are selected.
Bug Fixes
- Improved consistency of selection state across supported examples, including indeterminate checkbox behavior.
- Selection updates now refresh more reliably when row selection changes.
- 1
📝 Walkthrough
Walkthrough#
This PR updates table-core row selection selectors to include explicit memoDeps, removes an early-return short-circuit in row_toggleSelected, and refactors isSubRowSelected to use a for loop with break. Framework example apps update checkbox checked logic to reflect sub-row selection. Two perf markdown files get formatting-only edits.
Changes#
Row selection core logic and examples
Layer / File(s) Summary Core selector memoization and toggle/traversal logic
packages/table-core/src/features/row-selection/rowSelectionFeature.ts,rowSelectionFeature.utils.tsAdds memoDepstorow_getIsSomeSelectedandrow_getIsAllSubRowsSelected; removes early-return inrow_toggleSelected; refactorsisSubRowSelected'sforEachto an indexedforloop withbreak.Checkbox checked-state updates across framework examples
examples/alpine/...,examples/angular/...,examples/lit/...,examples/preact/...,examples/react/...,examples/solid/...,examples/svelte/...,examples/vue/...Updates the first-name column checkbox checkedlogic to also be true when sub-row selection is supported and all sub-rows are selected; React example additionally addsdebugRows: trueand addsrest.checkedto an effect's dependency list.Perf notes formatting
Layer / File(s) Summary Perf snippet reformatting
perf-done.md,perf-skipped.mdCondenses formatting of code snippets (conditional, assignment, return expression) without changing described logic. Estimated code review effort: 3 (Moderate) | ~25 minutes
Possibly related PRs
- TanStack/table#6344: Modifies the same row-selection core files (
row_toggleSelected, sub-row selection handling) inrowSelectionFeature.utils.ts.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title check ✅ Passed The title clearly describes the main row-selection behavior fix and matches the changeset. Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. ✨ Finishing Touches
📝 Generate docstrings
- Create stacked PR
- Commit on current branch
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch `fix-parent-row-unselect`
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.- TanStack/table#6344: Modifies the same row-selection core files (
More templates
- tanstack-alpine-table-example-basic-app-table
- tanstack-alpine-table-example-basic-create-table
- tanstack-alpine-table-example-basic-external-atoms
- tanstack-alpine-table-example-basic-external-state
- tanstack-alpine-table-example-column-groups
- tanstack-alpine-table-example-column-ordering
- tanstack-alpine-table-example-column-pinning
- tanstack-alpine-table-example-column-pinning-split
- tanstack-alpine-table-example-column-pinning-sticky
- tanstack-alpine-table-example-column-resizing
- tanstack-alpine-table-example-column-resizing-performant
- tanstack-alpine-table-example-column-sizing
- tanstack-alpine-table-example-column-visibility
- tanstack-alpine-table-example-custom-plugin
- tanstack-alpine-table-example-expanding
- tanstack-alpine-table-example-filters
- tanstack-alpine-table-example-filters-faceted
- tanstack-alpine-table-example-grouping
- tanstack-alpine-table-example-pagination
- tanstack-alpine-table-example-row-pinning
- tanstack-alpine-table-example-row-selection
- tanstack-alpine-table-example-sorting
- tanstack-alpine-table-example-sorting-dynamic-data
- tanstack-alpine-table-example-sub-components
- tanstack-lit-table-example-basic-app-table
- tanstack-lit-table-example-basic-external-atoms
- tanstack-lit-table-example-basic-external-state
- tanstack-lit-table-example-basic-subscribe
- tanstack-lit-table-example-basic-table-controller
- tanstack-lit-table-example-column-groups
- tanstack-lit-table-example-column-ordering
- tanstack-lit-table-example-column-pinning
- tanstack-lit-table-example-column-pinning-split
- tanstack-lit-table-example-column-pinning-sticky
- tanstack-lit-table-example-column-resizing
- tanstack-lit-table-example-column-resizing-performant
- tanstack-lit-table-example-column-sizing
- tanstack-lit-table-example-column-visibility
- tanstack-lit-table-example-composable-tables
- tanstack-lit-table-example-expanding
- tanstack-lit-table-example-filters
- tanstack-lit-table-example-filters-faceted
- tanstack-lit-table-example-filters-fuzzy
- tanstack-lit-table-example-grouping
- tanstack-lit-table-example-kitchen-sink
- tanstack-lit-table-example-pagination
- tanstack-lit-table-example-row-pinning
- tanstack-lit-table-example-row-selection
- tanstack-lit-table-example-sorting
- tanstack-lit-table-example-sorting-dynamic-data
- tanstack-lit-table-example-sub-components
- tanstack-lit-table-example-virtualized-columns
- tanstack-lit-table-example-virtualized-infinite-scrolling
- tanstack-lit-table-example-virtualized-rows
- tanstack-angular-table-example-basic-app-table
- tanstack-angular-table-example-basic-external-atoms
- tanstack-angular-table-example-basic-external-state
- tanstack-angular-table-example-basic-inject-table
- tanstack-angular-table-example-column-groups
- tanstack-angular-table-example-column-ordering
- tanstack-angular-table-example-column-pinning
- tanstack-angular-table-example-column-pinning-split
- tanstack-angular-table-example-column-pinning-sticky
- tanstack-angular-table-example-column-resizing
- tanstack-angular-table-example-column-resizing-performant
- tanstack-angular-table-example-column-sizing
- tanstack-angular-table-example-column-visibility
- tanstack-angular-table-example-composable-tables
- tanstack-angular-table-example-custom-plugin
- tanstack-angular-table-example-editable
- tanstack-angular-table-example-expanding
- tanstack-angular-table-example-filters
- tanstack-angular-table-example-filters-faceted
- tanstack-angular-table-example-filters-fuzzy
- tanstack-angular-table-example-grouping
- tanstack-angular-table-example-kitchen-sink
- tanstack-angular-table-example-pagination
- tanstack-angular-table-example-remote-data
- tanstack-angular-table-example-row-dnd
- tanstack-angular-table-example-row-pinning
- tanstack-angular-table-example-row-selection
- tanstack-angular-table-example-row-selection-signal
- tanstack-angular-table-example-signal-input
- tanstack-angular-table-example-sorting
- tanstack-angular-table-example-sub-components
- tanstack-angular-table-example-virtualized-columns
- tanstack-angular-table-example-virtualized-infinite-scrolling
- tanstack-angular-table-example-virtualized-rows
- tanstack-angular-table-example-with-tanstack-form
- tanstack-angular-table-example-with-tanstack-query
- tanstack-preact-table-example-basic-external-atoms
- tanstack-preact-table-example-basic-external-state
- tanstack-preact-table-example-basic-subscribe
- tanstack-preact-table-example-basic-use-app-table
- tanstack-preact-table-example-basic-use-table
- tanstack-preact-table-example-column-groups
- tanstack-preact-table-example-column-ordering
- tanstack-preact-table-example-column-pinning
- tanstack-preact-table-example-column-pinning-split
- tanstack-preact-table-example-column-pinning-sticky
- tanstack-preact-table-example-column-resizing
- tanstack-preact-table-example-column-resizing-performant
- tanstack-preact-table-example-column-sizing
- tanstack-preact-table-example-column-visibility
- tanstack-preact-table-example-composable-tables
- tanstack-preact-table-example-custom-plugin
- tanstack-preact-table-example-expanding
- tanstack-preact-table-example-filters
- tanstack-preact-table-example-filters-faceted
- tanstack-preact-table-example-filters-fuzzy
- tanstack-preact-table-example-grouping
- tanstack-preact-table-example-kitchen-sink
- tanstack-preact-table-example-pagination
- tanstack-preact-table-example-row-pinning
- tanstack-preact-table-example-row-selection
- tanstack-preact-table-example-sorting
- tanstack-preact-table-example-sub-components
- tanstack-preact-table-example-with-tanstack-form
- tanstack-preact-table-example-with-tanstack-query
- tanstack-solid-table-example-basic-app-table
- tanstack-solid-table-example-basic-external-atoms
- tanstack-solid-table-example-basic-external-state
- tanstack-solid-table-example-basic-use-table
- tanstack-solid-table-example-column-groups
- tanstack-solid-table-example-column-ordering
- tanstack-solid-table-example-column-pinning
- tanstack-solid-table-example-column-pinning-split
- tanstack-solid-table-example-column-pinning-sticky
- tanstack-solid-table-example-column-resizing
- tanstack-solid-table-example-column-resizing-performant
- tanstack-solid-table-example-column-sizing
- tanstack-solid-table-example-column-visibility
- tanstack-solid-table-example-composable-tables
- tanstack-solid-table-example-expanding
- tanstack-solid-table-example-filters
- tanstack-solid-table-example-filters-faceted
- tanstack-solid-table-example-filters-fuzzy
- tanstack-solid-table-example-grouping
- tanstack-solid-table-example-kitchen-sink
- tanstack-solid-table-example-pagination
- tanstack-solid-table-example-row-pinning
- tanstack-solid-table-example-row-selection
- tanstack-solid-table-example-sorting
- tanstack-solid-table-example-sub-components
- tanstack-solid-table-example-virtualized-columns
- tanstack-solid-table-example-virtualized-infinite-scrolling
- tanstack-solid-table-example-virtualized-rows
- tanstack-solid-table-example-with-tanstack-form
- tanstack-solid-table-example-with-tanstack-query
- tanstack-solid-table-example-with-tanstack-router
- tanstack-react-table-example-basic-external-atoms
- tanstack-react-table-example-basic-external-state
- tanstack-react-table-example-basic-subscribe
- tanstack-react-table-example-basic-use-app-table
- tanstack-react-table-example-basic-use-legacy-table
- tanstack-react-table-example-basic-use-table
- tanstack-react-table-example-column-dnd
- tanstack-react-table-example-column-groups
- tanstack-react-table-example-column-ordering
- tanstack-react-table-example-column-pinning
- tanstack-react-table-example-column-pinning-split
- tanstack-react-table-example-column-pinning-sticky
- tanstack-react-table-example-column-resizing
- tanstack-react-table-example-column-resizing-performant
- tanstack-react-table-example-column-sizing
- tanstack-react-table-example-column-visibility
- tanstack-react-table-example-composable-tables
- tanstack-react-table-example-custom-plugin
- tanstack-react-table-example-expanding
- tanstack-react-table-example-filters
- tanstack-react-table-example-filters-faceted
- tanstack-react-table-example-filters-fuzzy
- tanstack-react-table-example-grouping
- tanstack-react-table-example-kitchen-sink
- tanstack-react-table-example-kitchen-sink-hero-ui
- tanstack-react-table-example-kitchen-sink-mantine
- tanstack-react-table-example-kitchen-sink-material-ui
- tanstack-react-table-example-kitchen-sink-react-aria
- tanstack-react-table-example-kitchen-sink-shadcn-base
- tanstack-react-table-example-kitchen-sink-shadcn-radix
- tanstack-react-table-example-lib-hero-ui
- tanstack-react-table-example-lib-mantine
- tanstack-react-table-example-lib-material-ui
- tanstack-react-table-example-lib-react-aria
- tanstack-react-table-example-lib-shadcn-base
- tanstack-react-table-example-lib-shadcn-radix
- tanstack-react-table-example-mantine-react-table
- tanstack-react-table-example-material-react-table
- tanstack-react-table-example-pagination
- tanstack-react-table-example-row-dnd
- tanstack-react-table-example-row-pinning
- tanstack-react-table-example-row-selection
- tanstack-react-table-example-sorting
- tanstack-react-table-example-sub-components
- tanstack-react-table-example-virtualized-columns
- tanstack-react-table-example-virtualized-columns-experimental
- tanstack-react-table-example-virtualized-infinite-scrolling
- tanstack-react-table-example-virtualized-rows
- tanstack-react-table-example-virtualized-rows-experimental
- tanstack-react-table-example-with-tanstack-form
- tanstack-react-table-example-with-tanstack-query
- tanstack-react-table-example-with-tanstack-router
- tanstack-svelte-table-example-basic-app-table
- tanstack-svelte-table-example-basic-create-table
- tanstack-svelte-table-example-basic-external-atoms
- tanstack-svelte-table-example-basic-external-state
- tanstack-svelte-table-example-basic-snippets
- tanstack-svelte-table-example-column-groups
- tanstack-svelte-table-example-column-ordering
- tanstack-svelte-table-example-column-pinning
- tanstack-svelte-table-example-column-pinning-split
- tanstack-svelte-table-example-column-pinning-sticky
- tanstack-svelte-table-example-column-resizing
- tanstack-svelte-table-example-column-resizing-performant
- tanstack-svelte-table-example-column-sizing
- tanstack-svelte-table-example-column-visibility
- tanstack-svelte-table-example-composable-tables
- tanstack-svelte-table-example-expanding
- tanstack-svelte-table-example-filtering
- tanstack-svelte-table-example-filters-faceted
- tanstack-svelte-table-example-filters-fuzzy
- tanstack-svelte-table-example-grouping
- tanstack-svelte-table-example-kitchen-sink
- tanstack-svelte-table-example-pagination
- tanstack-svelte-table-example-row-pinning
- tanstack-svelte-table-example-row-selection
- tanstack-svelte-table-example-sorting
- tanstack-svelte-table-example-sub-components
- tanstack-svelte-table-example-virtualized-columns
- tanstack-svelte-table-example-virtualized-infinite-scrolling
- tanstack-svelte-table-example-virtualized-rows
- tanstack-svelte-table-example-with-tanstack-form
- tanstack-svelte-table-example-with-tanstack-query
- tanstack-vanilla-table-example-basic
- tanstack-vanilla-table-example-pagination
- tanstack-vanilla-table-example-sorting
- tanstack-vue-table-example-basic-external-atoms
- tanstack-vue-table-example-basic-external-state
- tanstack-vue-table-example-basic-use-app-table
- tanstack-vue-table-example-basic-use-table
- tanstack-vue-table-example-column-groups
- tanstack-vue-table-example-column-ordering
- tanstack-vue-table-example-column-pinning
- tanstack-vue-table-example-column-pinning-split
- tanstack-vue-table-example-column-pinning-sticky
- tanstack-vue-table-example-column-resizing
- tanstack-vue-table-example-column-resizing-performant
- tanstack-vue-table-example-column-sizing
- tanstack-vue-table-example-column-visibility
- tanstack-vue-table-example-composable-tables
- tanstack-vue-table-example-expanding
- tanstack-vue-table-example-filters
- tanstack-vue-table-example-filters-faceted
- tanstack-vue-table-example-filters-fuzzy
- tanstack-vue-table-example-grouping
- tanstack-vue-table-example-kitchen-sink
- tanstack-vue-table-example-pagination
- tanstack-vue-table-example-row-pinning
- tanstack-vue-table-example-row-selection
- tanstack-vue-table-example-sorting
- tanstack-vue-table-example-sub-components
- tanstack-vue-table-example-virtualized-columns
- tanstack-vue-table-example-virtualized-infinite-scrolling
- tanstack-vue-table-example-virtualized-rows
- tanstack-vue-table-example-with-tanstack-form
- tanstack-vue-table-example-with-tanstack-query
@tanstack/alpine-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/alpine-table@6364@tanstack/angular-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6364@tanstack/angular-table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table-devtools@6364@tanstack/lit-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6364@tanstack/match-sorter-utils
npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6364@tanstack/preact-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6364@tanstack/preact-table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table-devtools@6364@tanstack/react-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6364@tanstack/react-table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6364@tanstack/solid-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6364@tanstack/solid-table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6364@tanstack/svelte-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6364@tanstack/table-core
npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6364@tanstack/table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6364@tanstack/vue-table
npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6364@tanstack/vue-table-devtools
npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table-devtools@6364commit:
461622fCaution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts (1)
786-819: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winHandle the zero-selectable-descendant case.
isSubRowSelected()returns'all'when every descendant is non-selectable, sochecked={row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()}can mark a parent as checked even though nothing below it can be selected. Returnfalsefor that case, or track selectable descendants separately.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts` around lines 786 - 819, The `isSubRowSelected` logic in `rowSelectionFeature.utils.ts` currently treats a branch with only non-selectable descendants as `'all'`, which can make `getIsAllSubRowsSelected()` report true for a parent with nothing selectable below it. Update this helper to distinguish “all selectable descendants selected” from “no selectable descendants exist” by tracking whether any selectable descendant was found while walking `row.subRows`, and return `false` for the zero-selectable-descendant case. Keep the existing behavior for `someSelected`/`allChildrenSelected`, but ensure the final return only yields `'all'` when at least one selectable descendant exists and all of them are selected.🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Outside diff comments: In `@packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts`: - Around line 786-819: The `isSubRowSelected` logic in `rowSelectionFeature.utils.ts` currently treats a branch with only non-selectable descendants as `'all'`, which can make `getIsAllSubRowsSelected()` report true for a parent with nothing selectable below it. Update this helper to distinguish “all selectable descendants selected” from “no selectable descendants exist” by tracking whether any selectable descendant was found while walking `row.subRows`, and return `false` for the zero-selectable-descendant case. Keep the existing behavior for `someSelected`/`allChildrenSelected`, but ensure the final return only yields `'all'` when at least one selectable descendant exists and all of them are selected.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
fbe6b7a0-256a-42aa-a805-ffbb8d9d77b8📥 Commits
Reviewing files that changed from the base of the PR and between b1a80cc8014afecc5364e8be15b3aa7df167419b and 461622f68370d623a2cbd15143f35246e41ab0fa.
📒 Files selected for processing (12)
examples/alpine/expanding/index.htmlexamples/angular/expanding/src/app/expandable-cell/expandable-cell.tsexamples/lit/expanding/src/main.tsexamples/preact/expanding/src/main.tsxexamples/react/expanding/src/main.tsxexamples/solid/expanding/src/App.tsxexamples/svelte/expanding/src/App.svelteexamples/vue/expanding/src/App.tsxpackages/table-core/src/features/row-selection/rowSelectionFeature.tspackages/table-core/src/features/row-selection/rowSelectionFeature.utils.tsperf-done.mdperf-skipped.md
KevinVandy merged thisc276ccd
KevinVandy closed this
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit 461622f68370d623a2cbd15143f35246e41ab0fa
nx affected --targets=test:eslint,test:sherif,t...nx run-many --targets=build --exclude=examples/**☁️ Nx Cloud last updated this comment at
2026-07-01 05:59:04UTC