react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

[TreeView] parent/child selectionBehavior

Open nathanforce opened this issue 1 year ago โ€ข 1 comments

Provide a general summary of the feature here

I'm having a hard time implementing parent/child selection behavior in a TreeView. Specifically I'd like to be able to:

  1. select a parent and all of its children by selecting the parent checkbox.
  2. Unselecting a child while siblings are still selected switches the parent to indeterminate
  3. Unselecting the last child unselects the parent
  4. Should onSelectionChange include parent keys? In my case parents are basically just meant for grouping and in my external state I'm only interested in knowing which child items are selected.

๐Ÿค” Expected Behavior?

Support intuitive parent/child selection.

๐Ÿ˜ฏ Current Behavior

Parents and children feel unrelated

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

I'm building this sort of CheckboxTree, which I suspect is a pretty common usage of Tree.

image

๐Ÿ’ป Examples

No response

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

nathanforce avatar Jun 20 '24 20:06 nathanforce

We'll be most likely looking to add this behavior to our implementation of RSP TreeView (and by extension RAC Tree) since it is supported by Spectrum Design, but I'm unsure when that work will be slated to be picked up. As for the implementation, I imagine SelectionManager would need to be updated to have a mode where toggling the selection of a node that has children would also select the children. As for onSelectionChange including the parent keys I imagine we would still want to include them for use cases do care about parent key selection as well but maybe that could be changed via a option as well.

LFDanLu avatar Jun 21 '24 23:06 LFDanLu

@nathanforce were you able to find an implementation to this? I am trying to do something similar as well.

imjhonny avatar Apr 16 '25 08:04 imjhonny

Yes, but for now we've had to patch the package and manipulate the collection directly.

nathanforce avatar Apr 16 '25 10:04 nathanforce