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

[tree view] Unable to use input in TreeItem #12629

Closed
2 tasks done
kenianbei opened this issue Nov 24, 2019 · 7 comments · Fixed by mui/material-ui#18894
Closed
2 tasks done

[tree view] Unable to use input in TreeItem #12629

kenianbei opened this issue Nov 24, 2019 · 7 comments · Fixed by mui/material-ui#18894
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@kenianbei
Copy link

kenianbei commented Nov 24, 2019

When embedding an input or textfield in a TreeItem, user is unable to type anything other than space, backspace, delete, but no characters. However pasting does work. Also inputs do work within TreeView, but not TreeItem.

See: https://codesandbox.io/s/long-fire-csg6f?fontsize=14&hidenavigation=1&theme=dark

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

When embedding an input or textfield in a TreeItem, user is unable to type anything other than space, backspace, delete, but no characters. However pasting does work.

Expected Behavior 🤔

We should be able to have inputs or Textfield as children of TreeItem.

Steps to Reproduce 🕹

See: https://codesandbox.io/s/long-fire-csg6f?fontsize=14&hidenavigation=1&theme=dark

Context 🔦

Actually my context is that I have a Dialog within the TreeItem, and when it is opened it is still affected by this issue, since it is still nested within the TreeItem. If it isn't able to be fixed I will move the Dialog outside the TreeItem and use redux state to open the dialog.

Your Environment 🌎

Tech Version
Material-UI v4.6.1
Material-UI Lab v4.0.0-alpha.33
React 16.12.0
Browser Arch Linux Firefox and Chrome
TypeScript 3.7.2
etc.

Search keywords:

@kenianbei

This comment has been minimized.

@oliviertassinari oliviertassinari added the component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! label Nov 25, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 25, 2019

I don't think that it's a use case we really want to support. However, I guess we could play nicely with it. I see 3 options:

  1. We ignore the keyboard event if it comes from an editable field. We have similar logic in https://github.com/mui-org/material-ui/blob/f6a9ea17d64835f9a4180195ae043d02f97601f7/packages/material-ui/src/utils/focusVisible.js#L35-L45.
  2. We ignore the keyboard event if event.currentTarget !== event.target.
  3. We ignore the problem => won't fix.

@joshwooding Do you have a preference? I'm leaning toward 2.

@eps1lon
Copy link
Member

eps1lon commented Nov 25, 2019

I don't think that it's a use case we really want to support.

I had the same though initially but the problem is (as usual) portals. Having a dialog open from a tree is reasonable IMO.

For keyboard events I'm usually in favor of checking for target === currentTarget.

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 25, 2019

Yeah, +1 for not going with option 3 if we want to support:

Capture d’écran 2019-11-25 à 12 23 35
macOS

Capture d’écran 2019-11-25 à 12 25 57
Windows

It seems that our best option is number 2.

@oliviertassinari oliviertassinari added the new feature New feature or request label Nov 25, 2019
@eps1lon
Copy link
Member

eps1lon commented Nov 25, 2019

Yeah contentEditable is something that I always forget. Same applies to listitems (e.g. an editable TODO-list).

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Nov 26, 2019
@joshwooding
Copy link
Member

joshwooding commented Nov 27, 2019

I’m happy with 2. It was the first solution I thought of

@oliviertassinari oliviertassinari changed the title Unable to use input or Textfield in TreeItem [TreeView] Unable to use input in TreeItem Nov 30, 2019
@oliviertassinari
Copy link
Member

So I guess something like this would do it:

diff --git a/packages/material-ui-lab/src/TreeItem/TreeItem.js b/packages/material-ui-lab/src/TreeItem/TreeItem.js
index ae7be28ae..2066db063 100644
--- a/packages/material-ui-lab/src/TreeItem/TreeItem.js
+++ b/packages/material-ui-lab/src/TreeItem/TreeItem.js
@@ -150,7 +150,7 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
     let flag = false;
     const key = event.key;

-    if (event.altKey || event.ctrlKey || event.metaKey) {
+    if (event.altKey || event.ctrlKey || event.metaKey || event.currentTarget !== event.target) {
       return;
     }
     if (event.shift) {

@kenianbei Do you want to work on a pull request?

@oliviertassinari oliviertassinari transferred this issue from mui/material-ui Apr 1, 2024
@oliviertassinari oliviertassinari changed the title [TreeView] Unable to use input in TreeItem [tree view] Unable to use input in TreeItem Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants