Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeSelect: Programmatic selection does not propagate #12714

Closed
xanderflood opened this issue Mar 6, 2023 · 11 comments
Closed

TreeSelect: Programmatic selection does not propagate #12714

xanderflood opened this issue Mar 6, 2023 · 11 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@xanderflood
Copy link

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.

@xanderflood xanderflood added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 6, 2023
@StephanBis
Copy link

Is there any update on this? We have 4 levels in our tree and programmatic selection is not propagating.

@StephanBis
Copy link

StephanBis commented Jun 21, 2024

Setting propogateSelectionUp property helped in my case

I don't see how this would fix the issue, the defaults for both propogateSelectionUp and propogateSelectionDown are true. When clicking manually, propagation works fine up and down, but not programmatically.

@xanderflood
Copy link
Author

FWIW, my workaround was to disable propagation in both directions so that we could take control and implement the propagation logic ourselves.

In our specific use case, reimplementing the logic from scratch produced a much simpler implementation than the stock one provided by primeng. That one attempts to cope with dozens of configuration scenarios that weren't valuable for us, and as a result is obscenely complex. While it's frustrating to do, you might find that you are also able to produce something far simpler and more bug-free than PrimeNg's approach. I will note that the choice to have "selection" and "partialSelection" represented in fundamentally different ways (one via a separate selection array and the other via a piece of state recorded on individual nodes) is very strange and made it more frustrating to work with.

@abelokon0711
Copy link

abelokon0711 commented Jul 30, 2024

@xanderflood We are facing the same issue. Would you mind sharing your solution through a Gist or creating a PR to resolve this issue?

@AbhishekKatariya9
Copy link

@xanderflood, it would be really helpful if you could share your custom code through a Gist. Thanks!

@subrothosamantha
Copy link

I faced the same issue, and here is my workaround code to make it work. Thanks.
https://gist.github.com/subrothosamantha/6afd6e39de96c28ec1b016ff9e15af13

@autonomobil
Copy link

+1

@populater
Copy link

populater commented Dec 2, 2024

+1
And also on PrimeNG v17, still doesn't work...

I faced the same issue, and here is my workaround code to make it work. Thanks. https://gist.github.com/subrothosamantha/6afd6e39de96c28ec1b016ff9e15af13

This doesn't even compile btw (v17)..

@mertsincan
Copy link
Member

Hi,

So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation and try the latest PrimeNG version(v19). If there is no improvement on this, can you open a new issue so we can include it in our roadmap?

Thanks a lot for your understanding!
Best Regards,

@autonomobil
Copy link

Incredible, just close ALL open issues (this is just one of many) to be "maybe" fixed 🤯

What instead of just closing this issue, you check the issue? This is still a open, valid bug

@mertsincan
Copy link
Member

mertsincan commented Dec 25, 2024

If you still feel the issue hasn’t been resolved, you’re welcome to open a new one and back it up with a pull request. This helps us stay organized and build a clear roadmap. With 1,000–2,000 tickets, it’s tough to track everything, so community contributions through PRs can make a big difference. I think it is better to put some issues on a roadmap rather than letting them get lost.

#17069

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

8 participants