Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material ui - change the height of the Accordion

I am working on the migration of a JavaFx HMI to a web application working with React.js. For the display of graphical widgets, I'm also working with Material.ui.

To match with the layout of the HMI I have to update the layout of some predefined components by Material ui.

In my case, I need to reduce the height of the Accordion. I did something like this :

const IconLeftAccordionSummary = withStyles({
  root: {
    minHeight: 15,
    maxHeight: 15,
    backgroundColor: '#a5a5a5',
})(AccordionSummary);

and then I basically use it like this

<IconLeftAccordionSummary>
</IconLeftAccordionSummary>

Here is the result, it's what I'm expected when it's collapsed. enter image description here

However, when I expand it, it comes back to its original height, with some margins between blocks. Like this: enter image description here

I tried different things like adding

'&$expanded': {
  minHeight: 15,
  maxHeight: 15,
},

or

expanded: {
  minHeight: 15,
  maxHeight: 15
},

in the definition of IconLeftAccordionSummary, but nothing changes.

Does anyone can help me on how to do this ? Am I at least trying to do it in the right way?

Thank you :)

like image 669
Ptiseb Avatar asked Sep 20 '25 05:09

Ptiseb


1 Answers

After some tries I found an answer:

const StyledAccordionSummary = withStyles({
root: {
    minHeight: 15,
    maxHeight: 15,
    backgroundColor: '#a5a5a5',
    '&.Mui-expanded': {
      minHeight: 15,
      maxHeight: 15,
      backgroundColor: '#a5a5a5',
    }
},
expandIcon: {
    order: -1
}
})(AccordionSummary);

And I apply this style to the AccordionSummary component.

"root" applies on the accordion when it's closed, and the '&.Mui-expanded' applies on the accordion when it's opened.

like image 130
Ptiseb Avatar answered Sep 21 '25 21:09

Ptiseb