Issue
I want to change the icon based on whether the accordion is expanded or not.
I see that on the material ui page that the CSS have .Mui-expanded which can see whether expanded={true} or false, but how can I use this to set a different icon when expanded is true or false.
So I want to set IconA if expand is true and IconB if expand is false.
expandIcon={<IconA/>}
Solution
You can use expandIcon
prop available for AccordionSummary
component. Set condition like this: expandIcon={expanded === 'panel1'?<ExpandMoreIcon />:<Minimize/>}
<Accordion expanded={expanded === 'panel1'} onChange={handleChange('panel1')}>
<AccordionSummary
expandIcon={expanded === 'panel1'?<ExpandMoreIcon />:<Minimize/>}
aria-controls="panel1bh-content"
id="panel1bh-header"
>
<Typography className={classes.heading}>General settings</Typography>
<Typography className={classes.secondaryHeading}>I am an accordion</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Nulla facilisi. Phasellus sollicitudin nulla et quam mattis feugiat. Aliquam eget
maximus est, id dignissim quam.
</Typography>
</AccordionDetails>
</Accordion>
This sample code is taken from docs:https://material-ui.com/components/accordion/#controlled-accordion
Answered By - Murli Prajapati
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.