-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Accordion] renders components even when it's closed. #10569
Comments
@jbsmith969 This issue shares some root cause with #10183. You are free to change the behavior. The following option disables the rendering of the component in the DOM. <ExpansionPanel CollapseProps={{ unmountOnExit: true }}> https://codesandbox.io/s/p9z3jk639x
This is an interesting point to discuss. It's a tradeoff. By not mounting the hidden content you will make the content unreachable for SEO and increase the responsiveness as more work is going to be needed by the browser to display the content at the click interaction. On the other hand, mounting everything makes to initial reconciliation of the page slower. |
I would like to chip in here, i have a usecase where it is benefitial to have to content rendered all the time to make form submits easier (even if they are not visible). It's a settings page where the expansionPanel is used to seperate the form into sections (where some details are most of the time not really important). |
@oliviertassinari I had the same issue, and the CollapseProps works for me, thanks. Personally, I think not rendering children unless the panel is open is more intuitive. |
Hey @oliviertassinari! Thanks for the response. Sorry, I must have missed that |
@Loktor I agree, it's a problem we have already been facing and solved on the
Yes, I do think that the unmounting should be the default behavior. You will most likely render many items with the
@jbsmith969 You won't find this key in our documentation. It's a property implemented by
Oh great! I think that we should implement the same approach than with the |
If no one has picked it up yet , I'd like to give this one a go |
@oliviertassinari Don't we need to set
|
If you use the unmount option, is the content still on the page for Readers? If the content is not on the page, then this is not an accessible option. I solved this yesterday but looping through the links and toggling the tabIndex between -1 and 0, which seems to have the proper functioning, but it would be nice if this behavior was not only baked in but default. |
Just an update, on version 4.2.1 uses
|
We've added a section to our docs describing different tradeoffs:
-- https://material-ui.com/components/expansion-panels/#performance |
Thanks everyone for your amazing contribution! An idea to get the best of both worlds in this case: This way we don't render complicated DOM that is hidden, but do publish all the content we want for the crawlers WDYT? |
@odedbendov This sounds like cloaking, not great, but it can be implemented by unmounting the accordion when hidden, and rendering something else in place, visually hidden. |
Any plans of having the same feature available for Joy-ui? |
The child components still render even when the Accordion is not expanded on [email protected]. |
@CalvinJamesHeath |
@mib00038 because if I add some simple logic inside the accordion like
But that unfortunately breaks the smooth expanding transition. |
@CalvinJamesHeath If you render the Accordion Details with a big component tree nested inside, or if you have many Accordions, you may want to change this behavior by setting unmountOnExit to true inside the slotProps.transition prop to improve performance:
Also try moving your expaned logic into the Accordion expanded prop: Does that help ? |
Yeah I already had all that set. The AccordionDetails childs also get mounted even though the accordion is not expanded. I wanted to see if there was a way not to mount them to increase performance. |
I agree with @CalvinJamesHeath , I think it might be related to this error message:
Chrome suggests to use instead slotprops, which of course doesn't work. I was working with MUI v.5.11.2 and using
works fine, but on v.5.11.15, this is deprecated and slotProps is not doing its job when using the suggested
A similar issue was reported here: |
Setting |
Does this library render components even when they are hidden? For example, ExpansionPanel. It appears that this component renders everything inside even when it's closed by default. What if you have components inside of there that have extensive functionality going on and you had 20 expansion panels doing the same thing and the user only opened one of them? Doesn't this seem inefficient running through functionality of several components that may never even be seen by the user?
I am aware that I could potentially look at the onClick function and find out if the panel is expanded or not then render the component, but it seems like this should be a default behavior of the ExpandedPanel or any component that show/hides components.
Expected Behavior
Only render components inside the ExpansionPanel when it's open. Unmount components inside the ExapansionPanel when it is closed.
Current Behavior
Renders component regardless if the ExpansionPanel is open or closed.
Steps to Reproduce (for bugs)
Check out the console.logs for the sandbox below. They kick off regardless of the ExpansionPanel being closed.
https://codesandbox.io/s/lyo2m9ky0q
The text was updated successfully, but these errors were encountered: