question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Treeview] Node selection support

See original GitHub issue

Thanks very much for the release of the brand new TreeView component! ❤️ I’d like to request a basic feature for the Treeview component to emit an event when any node is selected.

You may have already planned this, but I couldn’t find any information for it, hence the request.

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

A node selected event fired when a node is selected or focused.

Current Behavior 😯

No event is fired at node selection, onNodeToggle event doesn’t fire for leaf nodes, onClick event can be attached to each TreeItem as a workaround, however it doesn’t support keyboard action.

Examples 🌈

Context 🔦

I’m implementing something where the rest of the UI needs to be updated according to the selection of the node. This is a much needed feature.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:32 (20 by maintainers)

github_iconTop GitHub Comments

7reactions
oliviertassinaricommented, Nov 13, 2019

I’m implementing something where the rest of the UI needs to be updated according to the selection of the node. This is a much needed feature.

What about using the existing onFocus prop?


On a similar topic, I would propose the introduction of a component prop to the TreeItem component. People should be able to render a link or a button, something that would handle the click, enter keyboard events natively.

Jul-29-2019 13-12-55

import React from 'react';
import Button from '@material-ui/core/Button';
import Link from '@material-ui/core/Link';
import TreeView from '@material-ui/lab/TreeView';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import TreeItem from '@material-ui/lab/TreeItem';

export default function FileSystemNavigator() {
  return (
    <TreeView defaultCollapseIcon={<ExpandMoreIcon />} defaultExpandIcon={<ChevronRightIcon />}>
      <TreeItem nodeId="1" label="Applications: ">
        <TreeItem component={Link} nodeId="2" label="Calendar : app" />
        <TreeItem component={Button} nodeId="4" label="Webstorm : app" />
      </TreeItem>
    </TreeView>
  );
}

cc @joshwooding

3reactions
darewreck54commented, Dec 28, 2019

Hi,

I was wondering what the status of this was? Right now when a user clicks, the color changes for the background of the selected. However, when you click anywhere outside the previous selected item gets deselected. Is there a way to prevent the deselect unless it another tree item gets selected.

When element is selected: image

When you select anywhere outside the tree, the white selection gets deselected.

Right now i’m leveraging off the

 style={{
        '--tree-view-color': color,
        '--tree-view-bg-color': bgColor,
      }}

As a workaround, I could probably create an internal state to manage what is selected, and then apply my own style. Wonder if there is any easier way to do. this thou?

Thanks, Derek

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Treeview] Node selection support #16795 - mui/material-ui
I'd like to request a basic feature for the Treeview component to emit an event when any node is selected. You may have...
Read more >
Treeview node selection in UI for WinForms | Telerik Forums
Hi, I have problems with with Q2 2011 : - every node of a treeview in my application is selectable not only by...
Read more >
How do I programmatically select a node in a TreeView control?
This FAQ explains the topic " How do I programmatically select a node in a TreeView control? ". You can submit your questions...
Read more >
TreeNode.Selected Property (System.Web.UI.WebControls)
The following code example demonstrates how to use the Selected property to select a node in the TreeView control. ASP.NET (C#) Copy.
Read more >
TreeView Node Selection - SAPIEN ... - SAPIEN Technologies
TreeView Node Selection. Ask your PowerShell-related questions, including questions on cmdlet development! Forum rules. Do not post any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found