After integrating material UI into my existing application, I encountered a peculiar issue. When adding material UI components to modals, the entering animation fails to trigger. Interestingly, downgrading material UI or removing all MUI components resolves the problem, and using any other UI library does not reproduce the issue.
https://codesandbox.io/s/mui-animation-issue-mgph3
import React, { useState, useEffect } from "react";
import styled from "styled-components";
import Test from "./Test";
const Overlay = styled.div`
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 10000;
`;
const Modal = styled.div`
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
width: 100px;
height: 100px;
align-items: center;
background: white;
`;
const modalsComponentLookupTable = {
Test
};
const ModalContainer = ({ setModals, children }) => {
const [modalStyle, setModalStyle] = useState({
opacity: 0,
transition: "opacity 2000ms",
willChange: "opacity",
transitionTimingFunction: "cubic-bezier(0.165, 0.840, 0.440, 1.000)"
});
const [bgStyle, setBgStyle] = useState({
background: "rgba(0, 0, 0, 1)",
willChange: "opacity",
transition: "opacity 2000ms cubic-bezier(0.165, 0.840, 0.440, 1.000)",
opacity: 0
});
const unMountStyle = () => {
// css for unmount animation
setModalStyle({
opacity: 0,
transition: "opacity 2200ms",
willChange: "opacity",
transitionTimingFunction: "cubic-bezier(0.165, 0.840, 0.440, 1.000)"
});
setBgStyle({
background: "rgba(0, 0, 0, 1)",
willChange: "opacity",
transition: "opacity 2200ms cubic-bezier(0.165, 0.840, 0.440, 1.000)",
opacity: 0
});
};
const mountStyle = () => {
// css for mount animation
setModalStyle({
opacity: 1,
transition: "opacity: 2000ms",
willChange: "opacity",
transitionTimingFunction: "cubic-bezier(0.165, 0.840, 0.440, 1.000)"
});
setBgStyle({
willChange: "opacity",
opacity: 1,
background: "rgba(0, 0, 0, 1)",
transition: "opacity 2000ms cubic-bezier(0.165, 0.840, 0.440, 1.000)"
});
};
useEffect(() => {
mountStyle();
}, []);
const back = e => {
e.stopPropagation();
unMountStyle();
setTimeout(() => setModals([]), 2200);
};
return (
<Overlay onClick={back} style={bgStyle}>
<Modal style={modalStyle}>{children}</Modal>
</Overlay>
);
};
const ModalsManager = ({ modals, setModals }) => {
const renderedModals = modals.map(modalDescription => {
const ModalComponent = modalsComponentLookupTable[modalDescription];
return (
<ModalContainer setModals={setModals}>
<ModalComponent />
</ModalContainer>
);
});
return <span>{renderedModals}</span>;
};
export default ModalsManager;
When utilizing MUI components within the Test
component, the entering animation does not activate. No error messages appear in the console.
It seems that there might be an issue within my code causing this behavior, as the Material-UI team mentioned it's not related to their library according to their response on GitHub: https://github.com/mui-org/material-ui/issues/17888