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

[Accordion] Unable to use component with AccordionSummary inside Accordion #15763

Closed
2 tasks done
WoodenPC opened this issue May 20, 2019 · 1 comment · Fixed by #18085
Closed
2 tasks done

[Accordion] Unable to use component with AccordionSummary inside Accordion #15763

WoodenPC opened this issue May 20, 2019 · 1 comment · Fixed by #18085
Assignees
Labels
component: accordion This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@WoodenPC
Copy link

WoodenPC commented May 20, 2019

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

Creating components like

const summary = React.memo(props => (
  <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
    <Typography>General settings</Typography>
    <Typography>I am an expansion panel</Typography>
  </ExpansionPanelSummary>
));

should work in

<ExpansionPanel>
  <Summary />
</ExpansionPanel>

Current Behavior 😯

If we have some controlled inputs inside expansion panel then every input change will trigger render function and ExpansionPanelSummary and content inside it will be rerendered. I trying to avoid that and created new stateless component with React.memo so there will be no unnecesary rerenders. But its not working :(

If I am doing something wrong please tell me how can i make this working :)

Steps to Reproduce 🕹

Link:

1.https://codesandbox.io/s/material-demo-po5mw

Context 🔦

Your Environment 🌎

Tech Version
Material-UI 4.0.0-beta
React 16.8.0
Browser Google Chrome 74.0.3729.157
TypeScript no
etc.
@eps1lon eps1lon self-assigned this May 21, 2019
@eps1lon eps1lon added component: accordion This is the name of the generic UI component, not the React module! new feature New feature or request labels May 21, 2019
@eps1lon
Copy link
Member

eps1lon commented May 21, 2019

Codesandbox not working is a combination of outdated customization API and current customization API not being used properly.

For 4.x you just have to forward the props of your summary component to ExpansionPanelSummary: https://codesandbox.io/s/custom-expansionpanelsummary-mospj. For 3.x you also have to hoist some statics: summary.muiName = ExpansionPanelSummary.muiName;.

Implementation notes: Another reason why context is better for state sharing. Avoids one pitfall when customizing.

@oliviertassinari oliviertassinari changed the title Unable to use component with ExpansionPanelSummary inside ExpansionPanel [Accordion] Unable to use component with AccordionSummary inside Accordion Jul 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: accordion 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.

2 participants