[menu] Motion with Menu
Bug report
Current behavior
Bug when using Motion with Menu: when using the render component in Menu.Popup, the initial side value is always “bottom” and only switches to “top” after requestAnimationFrame. As a result, if you set the initial animation with side === “top”, it won’t run; in practice it only recognizes side === “bottom”.
<Menu.Popup
render={(props, state) => {
console.log("state", state); // allway bottom
return (
<motion.div
{...props}
animate={{
opacity: 1,
y: 0,
x: 0,
scale: 1,
}}
exit={{
opacity: 0,
y:
state.side === "bottom"
? -8
: state.side === "top"
? 8
: 0,
scale: 0.95,
}}
initial={{
opacity: 0,
y:
state.side === "bottom"
? -8
: state.side === "top"
? 8
: 0,
scale: 0.95,
}}
onAnimationComplete={() => {
if (!open) {
actionsRef?.current.unmount();
}
}}
transition={{
duration: 0.2,
ease: "easeOut",
}}
/>
);
}}
>
{children}
</Menu.Popup>
Base UI version
1.0.0
Which browser are you using?
Chrome
Which OS are you using?
Mac OS.
@daonham Would you mind providing a repro?
https://codesandbox.io/p/devbox/suspicious-sky-wlw93h
https://github.com/user-attachments/assets/8e27d8bd-e542-4d81-ab63-8f1137a781bc
As far as I know, this is a missing feature in Motion: https://github.com/motiondivision/motion/issues/1878 (the maintainer closed the issue without understanding what I was demonstrating 😅)
It has a hacky workaround, but you might be better off using plain CSS and linear(...) if you want a spring animation
Closing here as an upstream Motion limitation: the initial animation values are read before positioning has resolved, as discussed in motiondivision/motion#1878. CSS transitions with linear() easing are an alternative for spring-like motion.