I'm new to Material-UI for React. I have a really simple question about the MUI accordions. I have the following piece of code:
import React from "react";
import { makeStyles, withStyles } from "@material-ui/core/styles";
import Accordion from "@material-ui/core/Accordion";
import MuiAccordionSummary from "@material-ui/core/AccordionSummary";
import AccordionDetails from "@material-ui/core/AccordionDetails";
import Typography from "@material-ui/core/Typography";
import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
const useStyles = makeStyles((theme) => ({
root: {
width: "100%"
},
heading: {
fontSize: theme.typography.pxToRem(15),
fontWeight: theme.typography.fontWeightRegular
}
}));
const AccordionSummary = withStyles({
})(MuiAccordionSummary);
export default function SimpleAccordion() {
const classes = useStyles();
return (
<div className={classes.root}>
<Accordion
defaultExpanded={true}
>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel1a-content"
id="panel1a-header"
>
<Typography className={classes.heading}>Accordion 1</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
malesuada lacus ex, sit amet blandit leo lobortis eget.
</Typography>
</AccordionDetails>
</Accordion>
<Accordion
defaultExpanded={true}
>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls="panel2a-content"
id="panel2a-header"
>
<Typography className={classes.heading}>Accordion 2</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse
malesuada lacus ex, sit amet blandit leo lobortis eget.
</Typography>
</AccordionDetails>
</Accordion>
</div>
);
}
Which looks like:
I'm trying to change the color of the header to grey. How can it be achieved?
CodePudding user response:
Unless I'm missing something, just change the background-color of AccordionSummary
:
V5
<AccordionSummary
sx={{
backgroundColor: "gray"
}}
>
V4
const useStyles = makeStyles({
summary: {
backgroundColor: 'gray',
}
);
<AccordionSummary
className={classes.summary}
>