-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Treeview] Node selection support #16795
Comments
This comment has been minimized.
This comment has been minimized.
@oliviertassinari onFocus does the trick for me, thanks so much : ) |
Some further feedback, I found that using onFocus as a way to manage selected state less than ideal. Some downsides are:
Overall, the user would have to think unnecessarily on the implementation of TreeView to use it. |
There's some other bugs I encountered for TreeView, maybe I should start a new issue, but I decided to post here.
|
@oliviertassinari How could the onFocus work if you want to select parent without closing the node? |
Would a checkbox TreeView solve this? |
@joshwooding Not always sometimes a radio would be better if there is select only 1. Think of files and folders with details panel. |
The TreeView needs to have a state to manage selected nodes ideally controllable from a prop. For example, in VSCode, if you select a file to open the editor and go edit the file, the file item in the treeview lost focus, however it's still selected. Sometimes the selection in the treeview needs to sync to external events, for example, VSCode's treeview sync to current active file. Ideally when receiving the selected node prop, the treeview needs to perform a minimum change to reflect the new selected state, leaving previous expansion state by the user untouched. To sum it up, I think a prop to control selected nodes and an event to notice nodes being selected are what's missing. |
I would only listen to the focus event at the root of the tree view. The focus event bubbles.
The use case seems valid to me 👍. |
Is somebody already working on this? I can work on this issue. |
@baig I'm not aware of anyone working on the issue. I think that it's clear to go 💃. What solution do you envision? Here is a proposal API: selected?: string[]; // an array, e.g. in the file system, we can select multiple items.
onSelect?: (event, nodeId: string) cc @joshwooding But I have a couple of questions:
|
@oliviertassinari The proposed API makes sense to me. My answer to your questions:
Ideally both the click and the keyboard event should trigger the select event. We can also complete it in steps and add the support for the keyboard event later.
I think it should be identical by default. If valid use cases pop up, then we can add support for customizing focus/select styles.
I'll second you by saying that we should support both modes. Again, we can add support for the uncontrolled mode later. |
There is a section in the aria practices that discusses selection keyboard interaction on a multi select tree but nothing mentioning click specifically or even single select |
@joshwooding Thanks for linking the wai-aria 📚! It's a gold mine ⛏. They seem to encourage the "selection follows focus" approach, unless it slows down the UX. When the approach is not used, the selection and focus state should have different styles. (also related to the tabs cc @mbrookes) @baig I think that this new information confirms that we are on the right direction. |
@oliviertassinari I'll start working on the implementation. You can assign this task to me. |
While working on the implementation, few questions have popped up:
|
|
If the use case is a typical file manager...
|
So what about?: selected?: string | string[]; // an array, when multiselect is true
defaultSelected?: string | string[];
onSelect?: (event, nodeId: string | string[]) => void;
multiselect?: boolean; // false by default |
Yes - as you say, in the case of tabs, it is recommended in the aria practices that the active tab follows focus, unless this would introduce latency when switching tabs (such as downloading the tab content), in which case changing the active tab should be in response to a key-press. Where a tree view is controlling the displayed content (most cases?), it is essentially equivalent to nested vertical tabs, so the same approach would apply. |
Checking in on this to see if any progress has made, if so, maybe I'll run with it, feel free to share a branch. |
I'll share my work over the weekend. Ideally I'd like to wrap it up myself but I've been busy lately and couldn't work on it. |
@switz I'm resuming work on this issue this weekend. I'll share the branch too. Sorry, couldn't do it last week. |
|
I opened a related feature request here: #17702 After playing around with the problem, I managed to control selection state without focus by overriding the label component's onClick and TreeItem's onKeyDown: You could achieve multi-select in a similar way. I still think a more powerful API would be great though. |
is there any way to keep the tree-view always expanded even the node is clicked? |
Hi! I need to programmatically update selected leaf nodes when scrolling through a document. Thanks :) |
@oliviertassinari @joshwooding I have a working version of the TreeView with a div in the TreeItem label. This div has a Radio button that needs to be selected. I can tell what is selected by a using react's useState with an object where the filename/path is the key. My issue is that the radio button when pressed also fires the directories to expand/close. When all I want is the radio button's event to be handles and not the whole TreeItem to execute the Collapse. I tried to change the value of the "in" parameter on the "TransitionProps" but there doesn't seem to be a way from the "TreeItem" TransitionComponent. I am used the customized tree view as an example. If need be I can create a new issue with this. However I cannot post any code examples because of the privacy of the companies code. TLDR -> radio button needs to be pressed and not also fired off the events of the TreeItem for expansion. |
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 you select anywhere outside the tree, the white selection gets deselected. Right now i'm leveraging off the
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, |
@darewreck54 I'm trying to figure out the same thing. As a developer, I'd like to be able to change my icon from Anyone know the simplest way to do this? |
onClick and onKeyDown should be replaced once material-ui TreeItem has node selection support: mui/material-ui#16795
onClick and onKeyDown should be replaced once material-ui TreeItem has node selection support: mui/material-ui#16795
onClick and onKeyDown should be replaced once material-ui TreeItem has node selection support: mui/material-ui#16795
onClick and onKeyDown should be replaced once material-ui TreeItem has node selection support: mui/material-ui#16795
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.
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.
The text was updated successfully, but these errors were encountered: