React-spring: Animating linear-gradient background-color

Created on 5 Oct 2019  路  6Comments  路  Source: pmndrs/react-spring

馃悰 Bug Report

It is not possible to animate background-color with linear gradient value with either renderprops nor the hooks

To Reproduce

Does not work

<Spring
  from={{ backgroundColor: 'linear-gradient(135deg, rgb(185, 198, 109) 0%, rgb(34, 48, 17) 100%)' }}
  to={{ backgroundColor: 'linear-gradient(135deg, rgb(192, 199, 165) 0%, rgb(31, 44, 31) 100%)' }}>
  {props => <div style={props}>hello</div>}
</Spring>

Works

<Spring
  from={{ background: 'linear-gradient(135deg, rgb(185, 198, 109) 0%, rgb(34, 48, 17) 100%)' }}
  to={{ background: 'linear-gradient(135deg, rgb(192, 199, 165) 0%, rgb(31, 44, 31) 100%)' }}>
  {props => <div style={props}>hello</div>}
</Spring>

Expected behavior

(A clear and concise description of what you expected to happen.)

Link to repro (highly encouraged)

(Please provide either a CodeSandbox demo or an example GitHub repo.)

Environment

  • react-spring v8.0.27
  • react v16.10.1
bug invalid

Most helpful comment

Oh, that's also expected. As this article says:

Because <gradient>s belong to the <image> data type, they can only be used where <image>s can be used. For this reason, linear-gradient() won't work on background-color and other properties that use the <color> data type.

All 6 comments

Please try with v9: npm install react-spring@next

If that doesn't work, create a sandbox for us to test with. Thanks 馃憤

It still didn't work with react-spring@next

heres is a codesandbox link

I also tried animating background property from linear gradient value to a normal rgba() and it also didnt work

@noushad-pp, could you elaborate more on what you expect to happen? I don't have any issues animating linear-gradient values for a background color.

@noushad-pp Your sandbox works for me.

I also tried animating background property from linear gradient value to a normal rgba() and it also didnt work

That's not expected to work

@aleclarson If you look at the codesandbox, the second div is completely white and thus its not animating

Oh, that's also expected. As this article says:

Because <gradient>s belong to the <image> data type, they can only be used where <image>s can be used. For this reason, linear-gradient() won't work on background-color and other properties that use the <color> data type.

Was this page helpful?
0 / 5 - 0 ratings