[Data Grid] Fix tree data unable to deselect row for exclude model #19846
+31
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #19046
Before: https://stackblitz.com/edit/axg8fqmk?file=src%2FDemo.tsx
After: https://stackblitz.com/edit/54tkqjct?file=src%2FDemo.tsx
The Bug
When using a controlled exclude model with tree data and row selection propagation, the grid corrupts the model by treating excluded row IDs as selected row IDs.
Step-by-Step Bug Flow
1. User provides controlled exclude model
Meaning: "All rows selected EXCEPT row 1 (Thomas)"
2. Grid calls
getPropagatedRowSelectionModel
When the controlled prop is provided,
syncControlledState
(line 849) calls:3. Bug: Function treats excluded IDs as selected IDs
Before Fix (lines 436-466):
4. What happens inside the propagation
Tree structure:
Propagation flow:
findRowsToSelect
is called withid = 1
(Thomas - an EXCLUDED row)[2, 3, 4]
selectionManager.select(childId)
What
select()
does for exclude models:5. The corruption
Starting model:
After propagation:
What happened:
select()
was called on its children (2, 3, 4)findRowsToSelect
on them!The Root Cause
Semantic mismatch:
findRowsToSelect
is designed for SELECTION propagationfindRowsToSelect
on unselected rows and usingselect()
to "propagate" them corrupts the modelWhy exclude models don't need propagation:
When a user actually deselects a row via UI interaction, propagation ALREADY happens correctly:
Result after UI deselection:
The model is semantically complete - no "propagation reapplication" needed.
The Solution
Skip propagation for exclude models in
getPropagatedRowSelectionModel
Location:
useGridRowSelection.ts:440
Change:
Test
Added a test to ensure that the exclude model is unchanged when getting from
getPropagatedRowSelectionModel