The solution mentioned above https://stackoverflow.com/a/63691313/11603006 is absolutely right but has the disadvantage that you must use a useState
hook to show a different icon when the accordion is collapsed/expanded. This makes it however difficult (impossible?) to specify a custom expandIcon globally in the Theme. Therefore Mui should in my opinion pass the expand state to the expandIcon
prop. There is a feature request for this https://github.com/mui/material-ui/issues/18326 but it has not been implemented yet. As a workaround and an alternative to the above solution, which has the benefit that it can be used in the theme globaly, it is possible to provide a custom icon in that way:
const CustomExpandIcon = () => {
return (
<Box
sx={{
'.Mui-expanded & > .collapsIconWrapper': {
display: 'none',
},
'.expandIconWrapper': {
display: 'none',
},
'.Mui-expanded & > .expandIconWrapper': {
display: 'block',
},
}}
>
<div className="expandIconWrapper">
<MinusIcon />
</div>
<div className="collapsIconWrapper">
<PlusIcon />
</div>
</Box>
)
}
See: https://codesandbox.io/s/basicaccordion-material-demo-forked-2916o