Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change expansion panel icon position to the left?

Tags:

material-ui

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.

like image 857
Thomas Senechal Avatar asked Aug 12 '19 10:08

Thomas Senechal


4 Answers

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.

like image 101
Niss36 Avatar answered Sep 27 '22 16:09

Niss36


<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'
}
like image 45
Alexander Kudryavsky Avatar answered Sep 27 '22 18:09

Alexander Kudryavsky


It's simple

  1. add class on <ExpansionPanelSummary> like this

<ExpansionPanelSummary className={classes.panelSummary}>

  1. add css against this class in jss like this

panelSummary:{flexDirection: "row-reverse"},


In case using css

  1. add class on <ExpansionPanelSummary> like this

<ExpansionPanelSummary className="panelSummary">

  1. add css against this class in jss like this

.panelSummary{flex-direction: row-reverse;}

like image 37
Muhammad Muzamil Avatar answered Sep 27 '22 16:09

Muhammad Muzamil


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>
like image 43
Hamza Ahmed Avatar answered Sep 27 '22 16:09

Hamza Ahmed