primeng
primeng copied to clipboard
TreeSelect: Programmatic selection does not propagate
Describe the bug
When selecting nodes in a checkbox-based treselect using mouse clicks, the default behavior is to propagate selection up the tree so that ancestors will be either selected or partially selected, as required.
When setting the selection for a tree programmatically the expected behavior is that this propagation would also take place, but it currently does not.
This bug is pretty onerous to work around. Correctly propagating this state manually requires a considerable amount of code, especially if you want to handle all the possible cases, like choosing non-leaf nodes, propagating both up and down, and distinguishing partial- and full-selection (since one is managed by modifying the contents of the node tree itself, and the other is managed by manipulating the actual selection value). The existing implementation of propagation does not seem to be packaged in a way that allows users of the library to easily trigger the existing logic directly, so a manual workaround produces significant code duplication.
Environment
This stackblitz uses Angular v11 and primeng v13, but I experienced the issue originally using v14 of each, and later also using v15 of each. https://stackblitz.com/edit/primeng-treeselect-demo-rddvht?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts,package.json
Reproducer
No response
Angular version
14
PrimeNG version
14
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
18
Browser(s)
No response
Steps to reproduce the behavior
See here: https://stackblitz.com/edit/primeng-treeselect-demo-rddvht?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts,package.json
Expected behavior
Whenver a tree, treeselect, or other related component has its selection modified, even it is being modified programmatically, the configured propagation behavior should be allowed to take place.