Style transition not working with mui/system
@mnajdova is already working on this.
Since Aug 22, 2022.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.