[bug]: Translating values starting from 0 requires unit symbol

Open
#2,303 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
react, typescript
Domain
frontend

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.

Description

area: core kind: bug
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

https://codesandbox.io/s/kind-black-sgr767?file=/src/App.js

Dominant language
TypeScript
Stars
29.3k
Forks
1.2k
Avg merge
3d 15h
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pmndrs/react-spring

All issues in pmndrs/react-spring

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.