JairajJangle / react-native-tree-multi-select

Super-fast tree view with multi-selection capabilities, using checkboxes and search filtering.
MIT License
42 stars 5 forks source link

[FEAT-REQ] Single node selection like radio button #68

Open sowka1995 opened 1 month ago

sowka1995 commented 1 month ago

Hi,

well done! Your control looks great, but is it possible to adapt your solution to single node selection? I need something exactly like this, but instead of checkboxes, for example, a radiobutton, where you can select only one node.

Thanks in advance for your answer!

JairajJangle commented 1 month ago

Hey there!

Thank you for your kind words! 😊

The functionality that you described can be implemented using the current version itself with a combination of these customizations and props: onCheck callback, CheckboxComponent / CustomNodeRowComponent, and the ref-exposed function: unSelectNodes.

Although there is no built-in support to implement single node selection directly, thanks to the high customizability of the TreeView component, the implementation is totally possible, specifically like this:

  1. Use CheckboxComponent / CustomNodeRowComponent to create your own custom tree node component that uses a radio button instead of the checkbox.
  2. Implement the onCheck callback to determine/store which tree node has been checked by the user.
  3. On each onCheck callback call the unSelectNodes ref function to unselect the previously checked node. This way you can ensure only one node is checked at a time.

I hope this helps! If you have any more questions or need further assistance, feel free to ask. 🙏

sowka1995 commented 1 month ago

Thanks for the answer!. Unfortunately, the program then falls into an infinite update loop after calling unselectNodes in the onCheck handler. Additionally, is it possible to disable auto selection of all direct children when we click on the parent? eg. when I click on the root then only this one node is selected not all childs