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

Customized tree view - Material UI issue #24369

Closed
ayupur opened this issue Jan 11, 2021 · 10 comments
Closed

Customized tree view - Material UI issue #24369

ayupur opened this issue Jan 11, 2021 · 10 comments
Labels
component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow

Comments

@ayupur
Copy link

ayupur commented Jan 11, 2021

I have created a tree using "Customized tree view - material UI". However, I'm facing a challenge:
defaultEndIcon state is getting lost on accordion collapse and then expand:

Selected defaultEndIcon:

unnamed

Accordion collapsed and then expanded again:
unnamed (1)

defaultEndIcon sate is lost

PFB codesandbox url:
https://codesandbox.io/s/material-demo-forked-9ovph?file=/demo.tsx

PFA codesandbox screen recording for reproducing the issue.

Screen.Recording.2021-01-11.at.4.17.07.PM.mov
@ayupur ayupur added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 11, 2021
@povilass
Copy link
Contributor

It re-renders the endIcon component again and you lose your state if you open it again it set to the initial value. You need to save that state to your treeNode with checked attribute yourself it's not a bug.

@ayupur
Copy link
Author

ayupur commented Jan 11, 2021

Re-rendering entire tree on expand and collapse is not a optimised approach.
If entire tree is getting re-rendered then how it is able to remember which tree item was expanded? I'm not maintaining any state for tree item expansion.

@povilass
Copy link
Contributor

Your Icon is re-rendering all the time, not the tree. The tree has its own state which branch is open from the beginning even it is not rendered. Take a look at what happens when you collapse a tree item, the result is no DOM element found in HTML so where did the state go? It's stored in the root of the tree which is persisting on the top level.

Going back to your problem why you think it should store your Icon state if it renders all the time on open and close?

@ayupur
Copy link
Author

ayupur commented Jan 11, 2021

expand and defaultEndIcon both are the properties of TreeView. I've already maintained the state of icon in TreeEndIcon file. So, that state should be preserved during expanding and collapsing. Why is the icon re-rendering on expand/collapse? This is a bug.
Screenshot 2021-01-11 at 9 46 28 PM

@ayupur
Copy link
Author

ayupur commented Jan 11, 2021

I think collapsing accordion should only hide its inner content and show during expansion. But any of its inner content should not re-render. There is a fault in the accordion implementation.

According to me, ul.MuiCollapse-container.MuiTreeItem-group.MuiCollapse-entered { display: none } -> during collapse &
ul.MuiCollapse-container.MuiTreeItem-group.MuiCollapse-entered { display: block } -> when we expand and doing so, my icon state is not lost. I've checked this.

@oliviertassinari oliviertassinari added component: tree view TreeView, TreeItem. This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 11, 2021
@support
Copy link

support bot commented Jan 11, 2021

👋 Thanks for using Material-UI!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://material-ui.com/getting-started/support/. Thanks!

If you have a question on StackOverflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@support support bot closed this as completed Jan 11, 2021
@ayupur
Copy link
Author

ayupur commented Jan 12, 2021

@oliviertassinari, there's a bug in tree view accordion which is implemented by material ui team and not by me. You will understand if you read my comments carefully.

@ayupur
Copy link
Author

ayupur commented Jan 12, 2021

Kindly reopen it.

@povilass
Copy link
Contributor

povilass commented Jan 12, 2021

Take a look at code I added TransitionProps={{ unmountOnExit: false }} and it works as you want it. Take a look at Item docs and also why Accordion doing that docs because default TransitionProps={{ unmountOnExit: true }} for tree.

@ayupur
Copy link
Author

ayupur commented Jan 12, 2021

@povilass, thanks a lot!!!

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! support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants