Material-UI ExpansionPanelSummary expanded class

佐手、 提交于 2020-06-01 06:42:28

问题


In the documentation for Material-UI ExpansionPanelSummary there are several class override names where expanded is one of them. Could someone explain why it is not possible to use the following code to set the size of the root as well as expanded state?

<ExpansionPanelSummary classes={{ root: { midWidth: 30}, expanded: { minWidth: 30} }}>
  foo bar
</ExpansionPanelSummary>

回答1:


you need to follow the styles overriding methods as the material-ui suggested.

please find methods from here: https://material-ui.com/customization/overrides/

here I used classes overriding using withStyles from material ui

const styles = theme => ({
  root: {
    minWidth: 300
  },
  heading: {
    fontSize: theme.typography.pxToRem(15),
    fontWeight: theme.typography.fontWeightRegular
  },
  expanded: { minWidth: 30, backgroundColor: "red" }
});

function SimpleExpansionPanel(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <ExpansionPanel>
        <ExpansionPanelSummary
          expandIcon={<ExpandMoreIcon />}
          classes={{ root: classes.root, expanded: classes.expanded }}
        >
          <Typography className={classes.heading}>Expansion Panel 1</Typography>
        </ExpansionPanelSummary>
        <ExpansionPanelDetails>
          <Typography>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
            malesuada lacus ex, sit amet blandit leo lobortis eget.
          </Typography>
        </ExpansionPanelDetails>
      </ExpansionPanel>
    </div>
  );
}

export default withStyles(styles)(SimpleExpansionPanel);

find the working example from here: https://codesandbox.io/s/zl4141wm44

I have added expanded and root as you suggested but you can use the other properties as well.(changed the background color in expanded to understand it correctly)



来源:https://stackoverflow.com/questions/51122546/material-ui-expansionpanelsummary-expanded-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!