-
-
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
[TreeItem] TreeItem hijacks focus when typing on an input box that updates it. #19882
Comments
Please include your environment as was requested in the template. ## Your Environment 🌎
<!--
Include as many relevant details about the environment with which you experienced the bug.
If you encounter issues with typescript please include version and tsconfig.
-->
| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.?.? |
| React | |
| Browser | |
| TypeScript | |
| etc. | |
|
That is not reproducing what you describe though:
Could you describe the additional steps from your gif that are missing from the initial description? Also please include your browser. |
@eps1lon My apologies. Honestly it's not exactly the same each time. What I do to reproduce is to open and close the nodes multiple times, and then start typing items in the list and deleting the query again. Repeating the whole process until at some random point it freezes and I loose focus. Running |
I think I got it including the crash: The crash happens when I press |
Thank you @eps1lon. Happy to work this out if I can be given any pointers. Frustration made me just think of a "disableKeyEvents" setting on my project to get around it but we probably need something better. Let me know and happy to help. |
With a confirmed reproduction you can work on this. Would be greatly appreciated! |
@eps1lon I think I need a pointer on why this could happen if I want to fix this with a better solution other than "disableKeyEvents". If you're okay with that quick fix then happy to send a PR just now. |
I think starting with a test in https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/TreeView/TreeView.test.js that replays the reproduction would be a good start. Then it might be clearer how the fix should look like. |
Quick update: Fixed this on the weekend but was having trouble getting a test to pass. |
Do you have the branch pushed so that I can take a look? |
@eps1lon I’ll push it when I get home |
@eps1lon Sorry it took so long! |
@joshwooding @eps1lon The crash occurs because the TreeItem is not cleaned up properly by the TreeView. When the TreeItem is removed it informs the TreeView.
The TreeView cleans up the nodeMap
But when we then focus by first character - as did @eps1lon - the nodeMap has been cleaned up but the firstCharMap has not and the map variable is undefined
|
Could we just add a null check before
...but there's also the issue of focus stealing. I'm still trying to wrap my head around the details of the component, but I'd like to look at it more tonight when I have more time if no one's currently looking into it. |
@tonyhallett Thanks for the help. I've already fixed the crash in #19973 but having trouble with the asynchronous nature of the test. |
@joshwooding Your test 'works after conditional rendering' deals with ArrowDown. Is related to focusByFirstCharacter.
and the resolution
|
I was about to make a pull request for this. Proceed ? If desired could extract the firstCharMap clean up to a separate function. |
@tonyhallet Sounds good. It's probably better to make a separate function for the firstCharMap clean up part. |
@joshwooding Will do. Be tomorrow though |
@tonyhallett Cool. I would also add a null check for the map.parent in focusByFirstCharacter too. |
The sandbox provided https://codesandbox.io/s/bold-hill-rw9y5 illustrates two crashes. The first due to focusByFirstCharacter is still an issue. The second can be thrown with arrow down - this does not occur with the latest build. |
I am using a to change the contents of a TreeView and a matching TreeItem is being focused when I backspace.
CodeSandbox: https://codesandbox.io/s/bold-hill-rw9y5
Current Behavior 😯
The focus is lost from the text field and hijacked by the TreeItem
Expected Behavior 🤔
The focus should remain on the TextField since the user never selected or focused on the TreeItem.
Context 🔦
I want to be able to filter out items from a tree view.
The text was updated successfully, but these errors were encountered: