mui / material-ui

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.
https://mui.com/material-ui/
MIT License
93.91k stars 32.26k forks source link

Style transition not working with mui/system #33979

Open georgewfsantos opened 2 years ago

georgewfsantos commented 2 years ago

We've recently changed from styled-components to styled() coming from mui/system. We noticed that transitions do not take place as expected. Below is the code for a font-size transition when we were using styled-components:

const StyledHeader = styled(Grid)<{ $scrolled: boolean }>`
  background: linear-gradient(127.84deg, #bbf7f7 0%, #f3e1fc 100%);
  box-shadow: ${props =>
    props.$scrolled
      ? '0px 2px 4px -1px rgba(0, 0, 0, 0.05), 0px 4px 5px 0px rgba(0, 0, 0, 0.03), 0px 1px 10px 0px rgba(0, 0, 0, 0.03)'
      : 'none'};
  ${({ $scrolled }) =>
    $scrolled &&
    `
    ${StyledTitle} {
      font-size: 1.4rem;
    }
  `}
  padding: 8px;
  padding-top: 16px;
  transition: padding 0.5s;
  position: sticky;
  top: ${TOPBAR_HEIGHT}px;
  z-index: 996;
`

const StyledTitle = styled(Typography)<{ $mobileBreakpoint: string }>`
  transition: font-size 0.5s;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: block;
  overflow: hidden;
  margin-y: 1rem;
` 

When using styled() from mui/system this transition does not take place. The code is as follows:

const StyledHeader = styled(Grid)(() => ({
    background: 'linear-gradient(127.84deg, #bbf7f7 0%, #f3e1fc 100%)',
    boxShadow: scrolled
      ? '0px 2px 4px -1px rgba(0, 0, 0, 0.05), 0px 4px 5px 0px rgba(0, 0, 0, 0.03), 0px 1px 10px 0px rgba(0, 0, 0, 0.03)'
      : 'none',
    padding: '8px',
    paddingTop: '16px',
    transition: 'padding 0.5s',
    position: 'sticky',
    top: `${TOPBAR_HEIGHT}px`,
    zIndex: 996,
  }))

  const StyledTitle = styled(Typography)(() => ({
    fontSize: scrolled ? '1.4rem !important' : 'inherit',
    transition: 'font-size 0.5s',
    whiteSpace: 'nowrap',
    textOverflow: 'ellipsis',
    display: 'block',
    overflow: 'hidden',
    marginY: '1rem',
  }))

Ps.: If I define the font-size to be changed in a hover event, using the class '&:hover',the transition will work.

I'm attaching some screen recordings below of the transitions as they worked before, and how they're not working properly now, in that order.

Thanks in advance.

https://user-images.githubusercontent.com/33661312/185409004-e52f128c-d16f-46f7-b991-04ec6005f986.mp4 https://user-images.githubusercontent.com/33661312/185409022-64d9a56a-79f1-4b94-9a4c-650f33bcbf84.mp4

mnajdova commented 2 years ago

Can you please share a codesandbox with the whole code so that it's easier to debug? You can start by using this template https://material-ui.com/r/issue-template-latest

georgewfsantos commented 2 years ago

@mnajdova , here it is. You just to need to uncomment the respective block of code and comment the other one to alternate between the styled-component and muy/system's styled version. Thank you in advance. https://codesandbox.io/s/quirky-torvalds-ewysk7?file=/src/App.tsx