feat(TreeView): allow selection without expansion#7714
feat(TreeView): allow selection without expansion#7714tlabaj merged 12 commits intopatternfly:mainfrom
Conversation
|
@mcoker One thing I noticed on the core PR was that the |
|
Preview: https://patternfly-react-pr-7714.surge.sh A11y report: https://patternfly-react-pr-7714-a11y.surge.sh |
|
@kmcfaul sorry for the confusion, we made another update after I opened the PR and I didn't update the description. What's in the PR URL, or maybe more accurately the core workspace. Can you go from that? Or would you prefer I go through the changes and update the PR description? |
thatblindgeye
left a comment
There was a problem hiding this comment.
I'm noticing issues when trying to navigate/interact with the example via VO or keyboard. Essentially I can select a tree item fine, but I can't find a way to toggle the expand state in anyway. See the following video (using VO):
Tree.view.selection.and.expandable.VO.issue.mov
The "with checkboxes" example works a bit better in terms of VO/keyboard being able to expand/collapse a tree item or check/uncheck the checkbox without one affecting the other. I made some comments below about what I tried doing locally to try and resolve this.
| @@ -94,14 +97,23 @@ const TreeViewListItemBase: React.FunctionComponent<TreeViewListItemProps> = ({ | |||
| }, [isExpanded, defaultExpanded]); | |||
|
|
|||
| const Component = hasCheck ? 'div' : 'button'; | |||
There was a problem hiding this comment.
I was able to replicate the behavior from the "with checkboxes" example by updating this to hasCheck || hasSelectableNodes ? 'div' : 'button' (more info in another comment below)
mcoker
left a comment
There was a problem hiding this comment.
tl;dr - Looking at this PR, looks like we need to:
- Make
.pf-c-tree-v-ew__node-containeraspan - Make
.pf-c-tree-view__node-toggleaspanin expandable, non-checkbox nodes - Looks like all nodes of a selectable tree view are getting
.pf-m-selectable- only the expandable node needs it. - Make checkbox nodes a
label, and change the node-text element inside to aspan - Add
.pf-m-selectableto the expandable checkbox nodes
I also found a few bugs and put up a core PR - patternfly/patternfly#4990
Reviewing the core PR, the changes are:
- A tree view node has
.pf-m-selectablewhen it's expandabale/selectable (including checkbox nodes) - These elements changed to a
<span>for HTML validity reasons, not a big deal:.pf-c-tree-view__node-container.pf-c-tree-view__node-content.pf-c-tree-view__node-togglewhen it isn't a button
- Checkbox
.pf-c-tree-view__nodeis now a<label>.pf-c-tree-view__node-textis a<span>since it was a<label>- HTML label attrs moved from node-text to node
- Updated hover states on the toggle icon so that it changes color when you're hovering the thing that will toggle expansion. ie, the node if non-selectable, the toggle if selectable.
With the intention that basically
- A default tree view node is a
button, the toggle is aspan. The whole node toggles expansion, the toggle icon is just for show and changes colors when you hover/focus on the node. - A checkbox node is a
label, and the toggle inside is abutton. Clicking on the toggle will toggle expansion, clicking anywhere else will trigger the checkbox to be checked/selected. - A non-checkbox selectable node is a
buttonand the toggle is aspan(since you can't nest a button in a button). Clicking the toggle toggles the node expansion, clicking anywhere else selects the node.
|
This looks good overall, my only question is whether we should allow someone to select a full expandable node in a tree view - or whether they should only be allowed to select a child node with no expansion? |
|
@mmenestr That is the default behavior if you are referring to the blue bold styling that is applied to the selected node. I adjusted it to apply to a parent node because the new flag allows a parent node to be selected directly now, but I can change it back if we don't want that visually. LMK |
|
I opened #7759 as a followup for the keyboard nav issues |
|
Ok, no no if we're allowing a parent node to be selected then it should have that styling! Looks good! |
mcoker
left a comment
There was a problem hiding this comment.
LGTM other than the keyboard issue @thatblindgeye noted and one small nit on the for and id attrs on nodes.
I did rework the aria-labels on the nodes and toggles in this PR if we want to consider that - patternfly/patternfly#4991
mcoker
left a comment
There was a problem hiding this comment.
LGTM! I'd like to get patternfly/patternfly#4991 merged and pulled in so we can make sure it fixes the toggle button's icon color when that node is selected.
thatblindgeye
left a comment
There was a problem hiding this comment.
Just a few comments below, let me know what you think, but otherwise this looks good!
| /** Flag indicating that tree nodes should be independently selectable, even when having children */ | ||
| hasSelectableNodes?: boolean; |
There was a problem hiding this comment.
Nitpick that I wouldn't block over: isSelectable could be an alternative prop name, as it would also align with our Card and Table selectable variants that have a similar prop.
There was a problem hiding this comment.
Yeah the prop name is something I wasn't too sure on. I thought about isSelectable but wasn't sure if it would be clear that it would make the nodes selectable opposed to the whole tree. I'm open to either prop name if anyone feels strongly one way or the other.
There was a problem hiding this comment.
Ah that's a fair point. I might think that having selectable items would make the tree view selectable in nature, but I do see how it isn't exactly clear. How do you feel about the idea of TreeView with prop hasSelectableNodes, and the TreeViewListItem with prop isSelectable?
There was a problem hiding this comment.
I like that, will update
|
@kmcfaul patternfly/patternfly#4991 has been merged and is in core v4.206.1 |
What: Closes #7378
Adds
hasSelectableNodesprop that separates expansion & selection behaviors - clicking the row will select it while clicking the toggle button will trigger the expansion. This flag will also allow parent nodes to be selected (in addition to leaf nodes) and apply the current style modifier to them.