Skip to content
Source
Sign inSign up
TanStack/table

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

MergedKevinVandymerged 1 commit intobeta fromrefs/pull/6364/headmerged by KevinVandy

KevinVandycommented
  • 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.
    1. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 461622f68370d623a2cbd15143f35246e41ab0fa

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:sherif,t...✅ Succeeded6m 6sView ↗
      nx run-many --targets=build --exclude=examples/**✅ Succeeded24sView ↗

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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
      Title check✅ PassedThe title clearly describes the main row-selection behavior fix and matches the changeset.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck 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.
    3. 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

    4. 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 b1a80cc8014afecc5364e8be15b3aa7df167419b and 461622f68370d623a2cbd15143f35246e41ab0fa.

      📒 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
    5. KevinVandy merged thisc276ccd

    6. KevinVandy closed this

Sign in to join this conversation.