Tree selection don't respect original tree value when filter is applied
Describe the bug
When using the Tree component with the properties filter=true and selectionMode="checkbox", the selection does not respect the original value of the tree. This scenario causes the tree to propagate the selection to parents even when not all parent's children are selected.
Pull Request Link
No response
Reason for not contributing a PR
- [ ] Lack of time
- [x] Unsure how to implement the fix/feature
- [x] Difficulty understanding the codebase
- [ ] Other
Other Reason
The tree component is a difficult one. I will try to create the solution on a PR, but maybe it is better to leave this to the official team.
Reproducer
https://stackblitz.com/~/github.com/jmussigotardelo-incomm/bug-in-p-tree-selection-with-filter
Environment
The environment was created from the PrimeNG Issue Template and the implementation was copied from the Tree official documentation, the only implementation I did was setting the filter="true" property.
Angular version
^20
PrimeNG version
v20
Node version
^20.3.0
Browser(s)
Microsoft Edge for Business Version 142.0.3595.94 (Official build) (64-bit)
Steps to reproduce the behavior
- Click on the search input
- Search for "expenses"
- Click on the "Expenses.doc"
- Reset or delete applied filter value
- Open node "Documents" and node "Work"
- You will see that only the node "Expenses.doc" is selected, but the node's parents are fully selected,
Expected behavior
If the original tree have a parent node with unselected children, they should be marked as partially selected.
Investigating the tree component code, the filtered nodes becomes the source of truth when the filter is applied, but considering the filter is only a tool to search nodes on the original tree, the original should always be the rule to check whether a node should be partially selected or not.
I understand this can be opinionated, so I think we should have, at least, an additional property to set whether the selection should consider the original tree or the current filtered nodes.
I opened an issue but didn't get a response from them, but I'm bumping your post :) Thanks for bringing it up again. https://github.com/primefaces/primeng/issues/18936