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] Label text is not selectable #9958

Closed
cryzer12 opened this issue Jan 18, 2021 · 14 comments · Fixed by #12226
Closed

[TreeView] Label text is not selectable #9958

cryzer12 opened this issue Jan 18, 2021 · 14 comments · Fixed by #12226
Assignees
Labels
bug 🐛 Something doesn't work component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer

Comments

@cryzer12
Copy link

cryzer12 commented Jan 18, 2021

Summary

(Text label doesn't user select in v5)

Hi, I had a case in which it was necessary to copy the contents of the TreeItem, now this is not possible and it is blocked using JavaScript, I tried to change the behavior by disabling preventSelection to the onDownMouse event inside the custom ContentComponent in the TreeItem, but it did not help, is there a solution?

@cryzer12 cryzer12 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 18, 2021
@oliviertassinari oliviertassinari added component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 18, 2021
@oliviertassinari oliviertassinari changed the title TreeItem text label doesn't user select in MUI v.5 [TreeView] text label doesn't user select in v5 Jan 18, 2021
@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Jan 18, 2021
@oliviertassinari
Copy link
Member

@cryzer12 The prevent text selection was made a default behavior in mui/material-ui#22846 by @joshwooding. You can disable it following this composition example: https://next.material-ui.com/components/tree-view/#contentcomponent-prop, removing the call to preventSelection().

@cryzer12
Copy link
Author

@oliviertassinari,
I removed the call to preventSelection() in handle MouseDown using the example data on codesandbox. And still user-select doesn't work for the TreeItem, as if the preventDefault(event) on the onMouseDown was also set on the TreeItem
example

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work and removed support: question Community support but can be turned into an improvement labels Jan 18, 2021
@oliviertassinari
Copy link
Member

@oliviertassinari
Copy link
Member

@cryzer12 What's your use case for allowing text selection?

@joshwooding
Copy link
Member

I could find the origin of the issue, it's the same one as mui/material-ui#24096:

https://github.com/mui-org/material-ui/blob/b2ee9521fe3b745b697ab1dd625320cdf675e0ab/packages/material-ui-lab/src/TreeItem/TreeItem.js#L226

The behavior has changed in mui/material-ui#21695. cc @joshwooding

Interesting, looks like we need to revisit that logic.

@cryzer12
Copy link
Author

@oliviertassinari,
at the moment I just use css property user-select ;D

@oliviertassinari
Copy link
Member

@cryzer12 What do you mean?

@alexgonch
Copy link
Contributor

@oliviertassinari I have the exact same problem as the OP: we need to allow users to select text within the Tree List label. I cannot override the onFocus prop because it is "unsupported". The docs recommend using onNodeFocus, but it cannot stop the event propagation. Overriding methods exposed in useTreeItem doesn't help either.

Is there a workaround?

@andreterron
Copy link

I'm having the same issue.

@oliviertassinari, my scenario is that I'm building a JSON-like object viewer, and I'd like to be able to select the text from either the keys or values.

If I disable JavaScript using the Chrome Dev Tools, I can select the text.

Do you have any pointers or tips on where to start if I want to take a look at this?

@hvahan
Copy link

hvahan commented Mar 29, 2022

@oliviertassinari is there any update regarding this issue?

@fareed-cellino
Copy link

@oliviertassinari is there any update regarding this issue? We need to enable use select on Tree label.

@hermhe
Copy link

hermhe commented May 5, 2023

Hi @oliviertassinari , we also need the text selection. It seems that the reason is due to the focus management is changed in v5, the focus is always on the ul in the outermost and you manage the child focus by aria-activedescendant, so we can't select the text without any focus in li. My workaround is to temporarily change this part of the logic to the v4 version. But I don't think this is a good way to solve this issue, do you have any plan to fix it in v5?

@joserodolfofreitas joserodolfofreitas changed the title [TreeView] text label doesn't user select in v5 [TreeView] text label is not selectable Aug 7, 2023
@joserodolfofreitas joserodolfofreitas transferred this issue from mui/material-ui Aug 7, 2023
@joserodolfofreitas joserodolfofreitas changed the title [TreeView] text label is not selectable [TreeView] Label text is not selectable Aug 7, 2023
@oliviertassinari oliviertassinari added design This is about UI or UX design, please involve a designer and removed design: ux labels Aug 18, 2023
@elilevit
Copy link

Also need this...any updates?

Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @cryzer12?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

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! design This is about UI or UX design, please involve a designer
Projects
None yet
Development

Successfully merging a pull request may close this issue.