jakezatecky / react-checkbox-tree

A simple and elegant checkbox tree for React.
https://jakezatecky.github.io/react-checkbox-tree/
MIT License
709 stars 211 forks source link

For a node having children node as empty array the node is being treated as parent node and selection does not work for this node #189

Open AggarwalShipra opened 4 years ago

AggarwalShipra commented 4 years ago

When we create a node and define children array as an empty array the node is treated as parent node but does not have any child now when we try to toggle selection for this node it does not work.

According to code: The node is not getting toggled because in the code we have a toggledChecked function and if a node is parent node and does not have any child node it is not getting toggled at all as it is returning false for all the conditions in this function. As per the code, it is working fine but the node should get toggle. So I think it is a bug in code if children array is [] the node should not be treated as a parent or if it is to be treated as a parent the code for toggling should be fixed.

And maybe It is due to this issue only that we get the issue in the selection of nodes after filtering result because due to recursion the children is set as [] for nodes and their selection don't work

Reproduction steps when defining the nodes for checkbox tree just pass children : [] for one of the nodes, and you will notice that you won't be able to toggle the selection.

Code Fix To fix this code for my use case I tried changing the code to treat node as leaf node if children: [] image

Could you please confirm if this is an issue because I don't think it is expected behavior. As we are not able to toggle the checkbox if the child array is empty.

jakezatecky commented 4 years ago

Yes, it is a unfortunately a current issue.

mehrdad-masoumi commented 4 years ago

کص ننت با این پکیجت دیوث فارسی نوشتم حالیت نشه

arvind0364 commented 3 years ago

We are still facing the same issue.Is there any temporary fix for this.The parent node is considered as child and able to toggle the checkbox,but the css of the child nodes are applied(for which having children:[]).