Using the docs/examples for overriding Material UI styling with styled-components, I've managed to style the root and "deeper elements" within an ExpansionPanel
and ExpansionPanelDetails
.
However, when I use the same technique to return an overridden ExpansionPanelSummary
from a function passed to styled()
, the ExpansionPanelSummary
moves in the DOM and the whole ExpansionPanel
no longer renders correctly.
The technique in question, as applied to ExpansionPanel
(this works as expected, on the container ExpansionPanel
):
import MUIExpansionPanel from '@material-ui/core/ExpansionPanel';
export const ExpansionPanel = styled(props => (
<MUIExpansionPanel
classes={{expanded: 'expanded'}}
{...props}
/>
))`
&& {
...root style overrides
}
&&.expanded {
...expanded style overrides
}
`;
The typical DOM (with class names abbreviated) for ExpansionPanel
and friends:
<div class="MuiExpansionPanel...">
<div class="MuiExpansionPanelSummary..." />
<div class="MuiCollapse-container...>
<div class="MuiCollapse-wrapper...>
<div class="MuiCollapse-wrapperInner...>
<div class="MuiExpansionPanelDetails..." />
</div>
</div>
</div>
</div>
The DOM when I apply the above technique to ExpansionPanelSummary
:
<div class="MuiExpansionPanel...">
<div class="MuiCollapse-container...>
<div class="MuiCollapse-wrapper...>
<div class="MuiCollapse-wrapperInner...>
<div class="MuiExpansionPanelSummary..." />
<div class="MuiExpansionPanelDetails..." />
</div>
</div>
</div>
</div>
For completeness, here's a minimal repro of what I'm doing to ExpansionPanelSummary
, that triggers the DOM switch:
export const ExpansionPanelSummary = styled(props => (
<MUIExpansionPanelSummary
{...props}
/>
))``;
And my JSX is standard ExpansionPanel
setup:
<ExpansionPanel>
<ExpansionPanelSummary>
Summary Label
</ExpansionPanelSummary>
<ExpansionPanelDetails>
<div>Some Content</div>
</ExpansionPanelDetails>
</ExpansionPanel>