-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting display:flex on accordion content creates double animation #2832
Comments
(I have an awkward sentence using the translator) The problem seems to be a conflict between automatically calculating heights in const rect = node.getBoundingClientRect();
heightRef.current = rect.height;
widthRef.current = rect.width; As you can see from the code above, we are dynamically calculating the height inside the radix However, the flex layout automatically calculates and places the height dynamically based on the size of the child elements. Therefore, the dynamically calculated height in Radix and the automatically calculated height in flex layout will conflict with each other, resulting in the height being calculated twice and animated twice as a result So, the solution is as follows const slideDown = keyframes({
from: { maxHeight: 0 },
to: { maxHeight: "var(--radix-accordion-content-height)" },
});
const slideUp = keyframes({
from: { maxHeight: "var(--radix-accordion-content-height)" },
to: { maxHeight: 0 },
});
max-height doesn't conflict with the automatic height calculation of flex layouts because the browser doesn't need to dynamically calculate the size during animation. Of course, I've only tested a very small part of this, so I'd love to hear back from the “radix” team |
I am struggling with the same bug @joseph0926! It also is affected with |
Bug report
Current Behavior
The default display for Accordion.Content is block. Setting it to flex causes a double animation when closing a section.
Expected behavior
The animation should not be affected by using display:flex
Reproducible example
Open / close the sections on this codesandbox: https://codesandbox.io/s/2r30e
Suggested solution
If this is technically not possible / too difficult to remove the double animation, a warning in the console would prevent a lot of debugging.
Your environment
The text was updated successfully, but these errors were encountered: