Reputation: 514
I'm building out an accordion with Material UI, and I noticed that when I have the Accordion directly in my file's return, it works fine. But if I make a sub-component and return it, the animation does not work. Note that opening the accordion is fine, but it suddenly pops open instead of having that smooth transition. Any idea what's causing this?
Dependencies in sandbox reflect the version in my package.json.
Upvotes: 0
Views: 1036
Reputation: 13357
You're [re]defining your QuestionAccordion
component inside of your App
component, so the re-render is happening before the accordion animation can compete. Define your QuestionAccordion
component outside of the App
component and it should behave normally. For example:
const QuestionAccordion = ({
dueAccordionOpen,
handleAccordionChange,
questionsMap
}: {
dueAccordionOpen: boolean;
handleAccordionChange: (val: QuestionTypes) => void;
questionsMap: any;
}) => { ... }
export const App = () => { ... }
Working CodeSandbox: https://codesandbox.io/s/material-ui-animation-problem-forked-msohg6?file=/src/App.tsx:995-1021
Upvotes: 1