In my app, the expansion arrow has to be in the left side of the panel. But, by default it's displaying in the right side.
This :
<ExpansionPanelSummary
className={classes.panelSummary}
expandIcon={<ExpandMoreIcon />}
IconButtonProps={{edge: 'start'}}
aria-controls='panel1a-content'
id='panel1a-header'
>
Doesn't made it.
Granted, you can't (easily) change the order in which the components appear in the HTML. However, there is a way using only CSS. ExpansionPanelSummary
uses display: flex
; you can therefore set the order
property on the icon to make it appear to the left of the content.
This can be achieved with either useStyles
or withStyles
(Or possibly using plain CSS, but I haven't tried it); here's how you'd go about using the latter:
import withStyles from "@material-ui/core/styles/withStyles";
const IconLeftExpansionPanelSummary = withStyles({
expandIcon: {
order: -1
}
})(ExpansionPanelSummary);
You can then write the rest of your code using IconLeftExpansionPanelSummary
instead of ExpansionPanelSummary
when you want the icon to appear to the left. Don't forget to set IconButtonProps={{edge: 'start'}}
on the component for proper spacing.
<AccordionSummary
className={classes.accordionSummary}
classes={{
expandIcon: classes.expandIcon,
expanded: classes.expanded
}}
IconButtonProps={{
disableRipple: true
}}
></AccordionSummary>
You can add class and use flex-direction
accordionSummary: {
flexDirection: 'row-reverse'
}
It's simple
<ExpansionPanelSummary>
like this<ExpansionPanelSummary className={classes.panelSummary}>
panelSummary:{flexDirection: "row-reverse"},
In case using css
<ExpansionPanelSummary>
like this<ExpansionPanelSummary className="panelSummary">
.panelSummary{flex-direction: row-reverse;}
you can get the expansion panel icon on left by removing it from expandIcon and add it as a children in Summary something like this
<ExpansionPanel defaultExpanded={true}>
<ExpansionPanelSummary aria-controls="panel1a-content">
{this.state.expanded ? <RemoveIcon/> : <ExpandIcon />}
<Typography component='h4' variant='h4'>My Expansion Panel</Typography>
</ExpansionPanelSummary>
<ExpansionPanelsDetails />
</ExpansionPanel>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With