mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[TreeView] Keyboard navigation gets broken when focused back with `Shift + Tab` keypress

Open AlexisLeite opened this issue 3 years ago • 7 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Steps to reproduce 🕹

Link to live example: https://mui.com/material-ui/react-tree-view/

Steps:

  1. Focus with keyboard on the file system tree view
  2. Expand the first item, put focus on first child of first item and press spacebar to select it
  3. Press left arrow twice in order to collapse the father.
  4. Press tab to get focus out of the tree
  5. Press Shift+Tab to get focus in the tree again
  6. Try to navigate it with arrow keys, it will throw error on the console, and the tree wont work

Current behavior 😯

The keyboard navigation gets broken

Expected behavior 🤔

The keyboard navigation to work ok

Context 🔦

No response

Your environment 🌎

The error is in the material UI documentation website

AlexisLeite avatar Mar 14 '23 20:03 AlexisLeite

I am not able to shift the focus back to the tree again with Shift + Tab in Windows. @AlexisLeite Can you help me to reproduce?

ZeeshanTamboli avatar Mar 16 '23 10:03 ZeeshanTamboli

Well, that is exactly the problem. But in fact, the focus is in the hidden node of the tree. And as the step mui/material-ui#6 says, if you open the browser console you will see some errors thrown by the tree

AlexisLeite avatar Mar 16 '23 12:03 AlexisLeite

@AlexisLeite But since I am not able to focus back to the Tree view with Shift + Tab key, I am not able to reproduce the error in console mentioned in point 6 by navigating with the arrow keys.

Edit: Okay, so it focuses back to a hidden node. I got the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'parentId')

ZeeshanTamboli avatar Mar 16 '23 13:03 ZeeshanTamboli

You cannot see the focus but the element is focused anyway. And if you open the console and then go through the mentioned steps, you should come to the following situation: https://vimeo.com/808688486

EDIT: Exactly as you mentioned in your edit

AlexisLeite avatar Mar 16 '23 13:03 AlexisLeite

I investigated a bit locally, but I am not aware of the internals of the Tree View component, so I don't know where it focuses back to after the Shift + Tab key operation. And it definitely should not throw a console error. So I am marking it as a bug.

ZeeshanTamboli avatar Mar 16 '23 13:03 ZeeshanTamboli

It looks like child nodes are removed when the parent is collapsed. I think the issue is that tabindex=0 is only ever applied to the root UL element and never changes. The tree items never change from tabindex=-1. That root UL doesn't seem to register any key presses, so it can technically be focused but then can't do anything. (And it's an issue in both directions; you can put focus before the tree and tab to it, or shift-tab back to it and still have this issue.)

I'd expect a roving tabindex where the last-focused item (not the last-selected) gets tabindex=0. Then that item is what's in the tab order when you navigate away and back.

scardamalias avatar Jul 09 '23 15:07 scardamalias

@scardamalias Would you like to give it a try to fix it?

ZeeshanTamboli avatar Jul 14 '23 13:07 ZeeshanTamboli