question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Background color not animating via className change

See original GitHub issue

2. Describe the bug

I was inspecting this switch/toggle example where the position of the handle animates as well as the background color of the component.

This is done by switching classNames based on state (.on and .off) This example no longer works with recent versions of this package (using 2.9.4).

I understand this might be an API change instead of a bug, but is there a way to achieve what’s being showcased with newer versions of this package?

I’m using tailwindcss, so i was hoping to just add a bg-green-400 when the toggle is on.

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

https://codesandbox.io/s/0d68e?file=/package.json

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Open codesandbox link
  2. Switch to a recent version of framer-motion
  3. try the toggle

5. Expected behavior

Was expecting the toggle to animate position and color.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
KirdesMFcommented, Dec 14, 2020

no idea sorry

2reactions
KirdesMFcommented, Dec 14, 2020

you need to add a transition to your class if you want to animate via classname. I guess the layout prop let you animate only the layout position not the color or background color.

Here a codesandbox with both solution.

https://codesandbox.io/s/framer-motion-automatic-animation-switch-demo-forked-dk1bj?file=/src/App.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

background-color property on changed class not working
The list item with className "differentClass" shall have its background-color changed to orange. But that's not working.
Read more >
className Not Changing back ground image? - SitePoint
Ok. I have an onclick that does things and changes the className of my 'logo' div. All of the background images for div...
Read more >
CSS Animations tips and tricks - MDN Web Docs
The animation details are included in the "changing" class, which says that the @keyframes named "colorchange" should be used over the course ...
Read more >
Using React Transition Group to improve UI - LogRocket Blog
The library does not define styles itself but manipulates the DOM in useful ways, making the implementation of transitions and animations ...
Read more >
Background Color - Tailwind CSS
Control the background color of an element using the bg-{color} utilities. Save changes. <button class ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found