adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.12k stars 1.06k forks source link

[TreeView] parent/child selectionBehavior #6589

Open nathanforce opened 1 week ago

nathanforce commented 1 week ago

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

LFDanLu commented 1 week ago

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.