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 to programmatically selected tree item #10113

Closed
bharatkashyap opened this issue Aug 22, 2023 · 7 comments · Fixed by #13485
Closed

[TreeView] Scroll to programmatically selected tree item #10113

bharatkashyap opened this issue Aug 22, 2023 · 7 comments · Fixed by #13485
Assignees
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@bharatkashyap
Copy link
Member

bharatkashyap commented Aug 22, 2023

Summary 💡

When selection is brought to a tree item programmatically, that page should scroll to that item in the tree view component.

Examples 🌈

Screen.Recording.2023-09-16.at.16.53.32.mov

Motivation 🔦

The TreeView component acts as a page hierarchy explorer for Toolpad with content often overflowing beyond its container. With this feature, the tree view component would scroll to the item currently selected in the page (and the tree itself as well)

Order ID 💳 (optional)

No response

@bharatkashyap bharatkashyap added new feature New feature or request status: waiting for maintainer These issues haven't been looked at yet by a maintainer component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! labels Aug 22, 2023
@flaviendelangle flaviendelangle added waiting for 👍 Waiting for upvotes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 1, 2023
@oliviertassinari
Copy link
Member

I have added an illustration.

@flaviendelangle
Copy link
Member

@bharatkashyap we discussed this issue this morning

Right now, I guess that you are controlling the selected items using the defaultSelected prop (renamed defaultSelectedItems in v7 btw).
If we added two imperative methods apiRef.current.selectItem and apiRef.current.scrollToItem (exact DX may vary), would it allow you to stop controlling the item and to fix the scroll problem you have?

@bharatkashyap
Copy link
Member Author

@bharatkashyap we discussed this issue this morning

Right now, I guess that you are controlling the selected items using the defaultSelected prop (renamed defaultSelectedItems in v7 btw). If we added two imperative methods apiRef.current.selectItem and apiRef.current.scrollToItem (exact DX may vary), would it allow you to stop controlling the item and to fix the scroll problem you have?

Yes, this would serve the purpose

@matteotrapani
Copy link

Hey!
I have the same exact issue. I have a tree view that the user can navigate programmatically (by clicking on a button "go to details" of a different page), but I can't find a simple way to allow the autofocus on the tree view.

Is the solution proposed by @flaviendelangle going to fix it?

Thanks

@flaviendelangle
Copy link
Member

It should yes
We should implement this feature in the coming weeks since we have several users asking for it 👍

@tamnguyenvt
Copy link

You can set and use document.getElementById(yourIdHere).scrollIntoView()

Copy link

github-actions bot commented Jul 2, 2024

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@bharatkashyap: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! new feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants