Skip to content

feat(TreeView): allow selection without expansion#7714

Merged
tlabaj merged 12 commits intopatternfly:mainfrom
kmcfaul:treeview-toggle-update
Jul 29, 2022
Merged

feat(TreeView): allow selection without expansion#7714
tlabaj merged 12 commits intopatternfly:mainfrom
kmcfaul:treeview-toggle-update

Conversation

@kmcfaul
Copy link
Copy Markdown
Contributor

@kmcfaul kmcfaul commented Jul 19, 2022

What: Closes #7378

Adds hasSelectableNodes prop 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.

@kmcfaul
Copy link
Copy Markdown
Contributor Author

kmcfaul commented Jul 19, 2022

@mcoker One thing I noticed on the core PR was that the pf-c-tree-view__node was still a button (and the toggle was in a span) in the With selectable, expandable nodes example, which I think was the example showcasing this behavioral change, but in your PR description you mentioned that the node should now be a div with the toggle changing to a button. I went with the div > button structure right now but let me know if I misunderstood and should change something.

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Jul 19, 2022

@mcoker
Copy link
Copy Markdown
Contributor

mcoker commented Jul 19, 2022

@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?

Copy link
Copy Markdown
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread packages/react-core/src/components/TreeView/TreeViewListItem.tsx Outdated
Copy link
Copy Markdown
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr - Looking at this PR, looks like we need to:

  • Make .pf-c-tree-v-ew__node-container a span
  • Make .pf-c-tree-view__node-toggle a span in 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 a span
  • Add .pf-m-selectable to 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-selectable when 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-toggle when it isn't a button
  • Checkbox .pf-c-tree-view__node is now a <label>
    • .pf-c-tree-view__node-text is 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 a span. 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 a button. 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 button and the toggle is a span (since you can't nest a button in a button). Clicking the toggle toggles the node expansion, clicking anywhere else selects the node.

@mmenestr
Copy link
Copy Markdown
Collaborator

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?

@kmcfaul
Copy link
Copy Markdown
Contributor Author

kmcfaul commented Jul 27, 2022

@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

@thatblindgeye
Copy link
Copy Markdown
Contributor

I opened #7759 as a followup for the keyboard nav issues

@mmenestr
Copy link
Copy Markdown
Collaborator

Ok, no no if we're allowing a parent node to be selected then it should have that styling! Looks good!

Copy link
Copy Markdown
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread packages/react-core/src/components/TreeView/TreeViewListItem.tsx Outdated
Copy link
Copy Markdown
Contributor

@mcoker mcoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments below, let me know what you think, but otherwise this looks good!

Comment thread packages/react-core/src/components/TreeView/TreeViewListItem.tsx Outdated
Comment thread packages/react-core/src/components/TreeView/TreeViewListItem.tsx Outdated
Comment on lines +48 to +49
/** Flag indicating that tree nodes should be independently selectable, even when having children */
hasSelectableNodes?: boolean;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that, will update

@mcoker
Copy link
Copy Markdown
Contributor

mcoker commented Jul 29, 2022

@kmcfaul patternfly/patternfly#4991 has been merged and is in core v4.206.1

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tree view - ability to select parent nodes without changing expand state

7 participants