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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 TreeView selection state fixes/enhancements #555

Closed
klondikedragon opened this issue Oct 2, 2022 · 2 comments 路 Fixed by #556
Closed

馃悰 TreeView selection state fixes/enhancements #555

klondikedragon opened this issue Oct 2, 2022 · 2 comments 路 Fixed by #556
Labels
enhancement New feature or request

Comments

@klondikedragon
Copy link
Contributor

All the recent enhancements to TreeView are very much appreciated, especially the narrowSpacing behavior and the keyboard navigation!

My application is using both single-selection and multi-selection TreeView widgets, and I've noticed some bugs and useful enhancements:

  • 馃悰 A single-selection TreeView that is given an initial list of items that has a single item selected may improperly clear out the selection state of this item if the single selected item has any children (initState calls buildItems and that improperly calls updateSelected).
  • 馃悰 In single-selection mode, if a child item is selected, and then the parent is collapsed so that the child is hidden, and then the parent item is selected, the child item's selected state is not properly set to false. If you expand the parent, then the child item will still be selected and it will have multiple items selected even though it's a single-selection tree view.
  • onItemInvoked is called for 3 different reasons: when the item's selection state is toggled, when the item is expanded or collapsed, or when the item is otherwise pressed (or space/enter is pressed). Without knowing the item invoke reason, it's not easy to implement logic that toggles the selection state of an item only when it's pressed (and not for the other two reasons).
  • Along the same lines, an application may want to toggle the selection state of a given item in a multi-selection mode tree, and some helper methods should be exposed so that the same logic can be used to set the new selection state of an item and all of its children, as well as to appropriately update the selection state of the parent(s) of an item.
  • You may want to allow a parent item to remain selected even if the user deselects all of the children (it would show the "indeterminate" checkbox state in this case). This can be useful if the parent
  • For this reason, you may also want to have included in the list of selectedItems passed to the onSelectionChanged callback any parent items that are partially selected.

I'll submit a PR that fixes these bugs and implements these enhancements. With these enhancements, my application can now easily programmatically change the selection state when an item is clicked/pressed (storing selection state in riverpod and propagating changed item list back to treeview widget through provider rebuild), and also parent items can remain selected even if children are all deselected. Note that it still defaults to the old behavior.

@bdlukaa
Copy link
Owner

bdlukaa commented Oct 2, 2022

You may want to allow a parent item to remain selected even if the user deselects all of the children (it would show the "indeterminate" checkbox state in this case).

I don't think this behavior exists in the native implementation. Can you tell an use-case for this?

@bdlukaa bdlukaa added the enhancement New feature or request label Oct 2, 2022
@klondikedragon
Copy link
Contributor Author

I don't think this behavior exists in the native implementation. Can you tell an use-case for this?

Let's say that the tree view is showing a list of folders defining which folders you want to search for files within. It's possible that the user wants to search for files in a given parent directory but not any of that parent directory's children directories. That would require the ability for the children to be deselected but the parent to remain selected. For example:

Root
  |--> Parent
        |-->Child1
        |-->Child2
        |-->Child3

The user might want to search for files in the Root and Parent directories, but not for files in the Child[123] subdirectories`, etc.

Another common use case are backup applications where the user is choosing what they want to restore (and the UX typically shows a folder tree on the left, and a flat listview on the right showing files just within the currently highlighted directory), and they want to restore the files in the parent directory, but they don't want to restore content in the child subdirectories.

It definitely shouldn't be the default behavior, but is a nice optional behavior needed for cases where each treeview item might logically contain things besides just the child items shown in the tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants