[bug]: Translating values starting from 0 requires unit symbol
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 29.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Which react-spring target are you using?
-
@react-spring/web -
@react-spring/three -
@react-spring/native -
@react-spring/konva -
@react-spring/zdog
What version of react-spring are you using?
9.7.3
What's Wrong?
I have a really simple toggled animation of a menu that initially is set to transform: translateY(-100%), when the state is change it slides into view at transform: translateY(0), when the state is then changed again the animation is skipped and the menu just disappears. I found this was due to not having a % unit symbol on the end, others have also found this same issue
To Reproduce
import React from "react";
import { useSpring, animated } from '@react-spring/web';
export default function Menu({ isMenuActive, data }) {
const springs = useSpring({
transform: isMenuActive ? `translateY(0%)` : `translateY(-100%)`,
});
return (
<>
<animated.div style={springs} className="menu-container">
<p>Menu Items</p>
<p>Menu Items</p>
<p>Menu Items</p>
</animated.div>
</>
);
}
Use this basic react hook to animate in the menu component.
Expected Behaviour
When the animation value start at 0 it should infer either the pixel or percentage value so it translates smoothly as it does in normal CSS.
Link to repo
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.
Research direction
Start with the @react-spring/web reproduction in the linked CodeSandbox and trace how the transform value is interpreted when one endpoint is translateY(0) and the other includes a percentage. Verify the behavior for both @react-spring/web and @react-spring/three, then add a regression test showing that toggling the menu animates smoothly without requiring a unit on zero.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100