Skip to content

fix: let parent rows unselect child rows when not itself selected#6364

Merged
KevinVandy merged 1 commit into
betafrom
fix-parent-row-unselect
Jul 1, 2026
Merged

fix: let parent rows unselect child rows when not itself selected#6364
KevinVandy merged 1 commit into
betafrom
fix-parent-row-unselect

Conversation

@KevinVandy

@KevinVandy KevinVandy commented Jul 1, 2026

Copy link
Copy Markdown
Member
  • 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 getIsAllSubRowsSelected and getCanSelectSubRows functions.
  • 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.

- 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 `getIsAllSubRowsSelected` and `getCanSelectSubRows` functions.
- Improved performance by optimizing selection checks in utility functions.
@nx-cloud

nx-cloud Bot commented Jul 1, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 461622f

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 6m 6s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 24s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-01 05:59:04 UTC

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 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.ts
Adds memoDeps to row_getIsSomeSelected and row_getIsAllSubRowsSelected; removes early-return in row_toggleSelected; refactors isSubRowSelected's forEach to an indexed for loop with break.
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 checked logic to also be true when sub-row selection is supported and all sub-rows are selected; React example additionally adds debugRows: true and adds rest.checked to an effect's dependency list.

Perf notes formatting

Layer / File(s) Summary
Perf snippet reformatting
perf-done.md, perf-skipped.md
Condenses 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) in rowSelectionFeature.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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown
More templates

@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@6364

commit: 461622f

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

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 win

Handle the zero-selectable-descendant case. isSubRowSelected() returns 'all' when every descendant is non-selectable, so checked={row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()} can mark a parent as checked even though nothing below it can be selected. Return false for 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 b1a80cc and 461622f.

📒 Files selected for processing (12)
  • examples/alpine/expanding/index.html
  • examples/angular/expanding/src/app/expandable-cell/expandable-cell.ts
  • examples/lit/expanding/src/main.ts
  • examples/preact/expanding/src/main.tsx
  • examples/react/expanding/src/main.tsx
  • examples/solid/expanding/src/App.tsx
  • examples/svelte/expanding/src/App.svelte
  • examples/vue/expanding/src/App.tsx
  • packages/table-core/src/features/row-selection/rowSelectionFeature.ts
  • packages/table-core/src/features/row-selection/rowSelectionFeature.utils.ts
  • perf-done.md
  • perf-skipped.md

@KevinVandy KevinVandy merged commit c276ccd into beta Jul 1, 2026
8 checks passed
@KevinVandy KevinVandy deleted the fix-parent-row-unselect branch July 1, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant