Skip to content

Commit

Permalink
Ensures CSS variables are trimmed before animating (#2688)
Browse files Browse the repository at this point in the history
* Fixing animation of CSS vars

* Removing trims from parseCSSVariable

* Updating test
  • Loading branch information
mattgperry authored May 29, 2024
1 parent 016c3dd commit 4b5bb92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dev/tests/css-vars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const App = () => {
originX: 0,
originY: 0,
opacity: "var(--d)",
backgroundColor: "var(--a)",
backgroundColor: " var(--a)", // Should work even with space at start
scale: "var(--c)",
x: "var(--b)",
}}
Expand Down
21 changes: 13 additions & 8 deletions packages/framer-motion/src/render/dom/DOMKeyframesResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ export class DOMKeyframesResolver<
* If any keyframe is a CSS variable, we need to find its value by sampling the element
*/
for (let i = 0; i < unresolvedKeyframes.length; i++) {
const keyframe = unresolvedKeyframes[i]
if (typeof keyframe === "string" && isCSSVariableToken(keyframe)) {
const resolved = getVariableValue(keyframe, element.current)
let keyframe = unresolvedKeyframes[i]

if (resolved !== undefined) {
unresolvedKeyframes[i] = resolved as T
}
if (typeof keyframe === "string") {
keyframe = keyframe.trim()

if (isCSSVariableToken(keyframe)) {
const resolved = getVariableValue(keyframe, element.current)

if (resolved !== undefined) {
unresolvedKeyframes[i] = resolved as T
}

if (i === unresolvedKeyframes.length - 1) {
this.finalKeyframe = keyframe as T
if (i === unresolvedKeyframes.length - 1) {
this.finalKeyframe = keyframe as T
}
}
}
}
Expand Down

0 comments on commit 4b5bb92

Please sign in to comment.