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] Scroll jump bug #24096

Closed
bumTomica opened this issue Dec 21, 2020 · 4 comments · Fixed by #24105
Closed

[TreeView] Scroll jump bug #24096

bumTomica opened this issue Dec 21, 2020 · 4 comments · Fixed by #24105
Labels
bug 🐛 Something doesn't work 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.

Comments

@bumTomica
Copy link

bumTomica commented Dec 21, 2020

When Tree View has a larger height than the window height, clicking Tree Items first jumps the position of the item to the top and then on the second click toggles. See the video, please.

A similar thing happens in the last items too - it just positions the element to the bottom and it is really hard to click it then.

Items in the middle seem fine.

Official doc examples have the same problem.

treeview-scroll-bug.mov

Versions

v5.0.0-alpha.20

@bumTomica bumTomica added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 21, 2020
@oliviertassinari oliviertassinari added 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 and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 21, 2020
@oliviertassinari

This comment was marked as resolved.

@bumTomica
Copy link
Author

bumTomica commented Dec 21, 2020

@oliviertassinari here you go: https://codesandbox.io/s/scroll-jump-bug-24096-forked-o2q9h

Just add some content before the tree, and page needs to have scroll.

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work and removed status: waiting for author Issue with insufficient information labels Dec 21, 2020
@oliviertassinari
Copy link
Member

@bumTomica Thanks for reporting the issue. @joshwooding What do you think about this fix?

diff --git a/packages/material-ui-lab/src/TreeItem/TreeItem.js b/packages/material-ui-lab/src/TreeItem/TreeItem.js
index 742f6663e5..54b960cebf 100644
--- a/packages/material-ui-lab/src/TreeItem/TreeItem.js
+++ b/packages/material-ui-lab/src/TreeItem/TreeItem.js
@@ -223,7 +223,7 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
   function handleFocus(event) {
     // DOM focus stays on the tree which manages focus with aria-activedescendant
     if (event.target === event.currentTarget) {
-      ownerDocument(event.target).getElementById(treeId).focus();
+      ownerDocument(event.target).getElementById(treeId).focus({ preventScroll: true });
     }

     const unfocusable = !disabledItemsFocusable && disabled;

@joshwooding
Copy link
Member

@bumTomica Thanks for reporting the issue. @joshwooding What do you think about this fix?

diff --git a/packages/material-ui-lab/src/TreeItem/TreeItem.js b/packages/material-ui-lab/src/TreeItem/TreeItem.js
index 742f6663e5..54b960cebf 100644
--- a/packages/material-ui-lab/src/TreeItem/TreeItem.js
+++ b/packages/material-ui-lab/src/TreeItem/TreeItem.js
@@ -223,7 +223,7 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
   function handleFocus(event) {
     // DOM focus stays on the tree which manages focus with aria-activedescendant
     if (event.target === event.currentTarget) {
-      ownerDocument(event.target).getElementById(treeId).focus();
+      ownerDocument(event.target).getElementById(treeId).focus({ preventScroll: true });
     }

     const unfocusable = !disabledItemsFocusable && disabled;

Looks good

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! good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants