6

I had this code in Material-UI v4 that worked perfectly:

<Button
  aria-expanded={optionsExpanded}
  onClick={() => dispatch(toggleOptionsExpanded())}
    endIcon={
      <ExpandMoreIcon
        className={clsx(classes.expand, {
          [classes.expandOpen]: optionsExpanded,
        })}
      />
  }
>
  Options
</Button>



const useStyles = makeStyles((theme) => ({
  expand: {
    transform: "rotate(0deg)",
      transition: theme.transitions.create("transform", {
      duration: theme.transitions.duration.shortest,
    }),
  },
  expandOpen: {
    transform: "rotate(180deg)",
  },
}));

The arrow will rotate like this:

enter image description here

However I can't seem to be able to replicate this using the v5 of Material-UI. I've tried using the sx prop, with conditional rendering and it turns but doesn't animate.

Neïl Rahmouni
  • 326
  • 2
  • 10

1 Answers1

6

This should be what you're looking for:

<Button
  aria-expanded={optionsExpanded}
  onClick={() => dispatch(toggleOptionsExpanded())}
  endIcon={
    <ExpandMoreIcon
      sx={[
        {
          transform: 'rotate(0deg)',
          transition: (theme) => theme.transitions.create('all', {
            duration: theme.transitions.duration.shortest,
          })
        },
        optionsExpanded && {
          transform: 'rotate(180deg)'
        }
      ]}
    />
  }
>
  Options
</Button>
Yannick
  • 446
  • 3
  • 6
  • 16