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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] strange behavior when mixing controlled states and "Shift" multiselection #15340

Open
1 task done
stephzero1 opened this issue Nov 8, 2024 · 4 comments
Open
1 task done
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information

Comments

@stephzero1
Copy link

stephzero1 commented Nov 8, 2024

Search keywords

treeview multiselection controlled shfit selection

Latest version

  • I have tested the latest version

Affected products

Tree View

Steps to reproduce

Link to live example: https://codesandbox.io/p/sandbox/broken-tree-view-v6pc5w?file=%2Fsrc%2FDemo.js

Steps:

  1. SimpleTreeView (but i think is the same with RichTreeView)
  2. First select with mouse or other input one item
  3. Then imperatively command a selection of one and only one specific item
  4. Press "Shift" for multi selection and select one other entry (so command a selection from the previously controlled selected items to the new selected one)
  5. Weird

Current behavior

Screencast.From.2024-11-08.12-47-17.webm

Expected behavior

Screencast.From.2024-11-08.12-49-10.webm

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Order ID or Support key 💳 (optional)

No response

@stephzero1 stephzero1 added bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 8, 2024
@github-actions github-actions bot added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Nov 8, 2024
@stephzero1 stephzero1 changed the title TreeView strange behavior when mixing Controlled states and "Shift" multiselection [TreeView] strange behavior when mixing controlled states and "Shift" multiselection Nov 8, 2024
@michelengelen
Copy link
Member

Seems like the focus is saved where the mouseclick was last registered.
I'll have a look on monday! 👍🏼

@stephzero1
Copy link
Author

Seems like the focus is saved where the mouseclick was last registered. I'll have a look on monday! 👍🏼

yea i noticed now, thank you!

@michelengelen
Copy link
Member

Haven't found a good enough solution to this.
There is basically a discrepancy between selection via mouse and programmatic selection ... I have asked @noraleonte to check as well.

@noraleonte
Copy link
Contributor

Hey @stephzero1 👋
In your example, the handleselectClick does not trigger the methods that internally handle selection, it just changes the state that you created. That's why multi selection doesn't work correctly. In order to imperatively select an item, you can use the Tree View's imperative API. Here's an updated demo for how to do that and you can read more about this API in this section from the docs. Let me know if this helps 💪

@LukasTy LukasTy added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

4 participants