Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/framer-motion/src/render/svg/__tests__/use-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,50 @@ describe("SVG useProps", () => {
style: {},
})
})

test("should keep offsetDistance as CSS style, not SVG attribute", () => {
const { result } = renderHook(() =>
useSVGProps(
{ style: {} } as any,
{
offsetDistance: "50%",
offsetPath: "path('M 0 0 L 100 100')",
},
false,
"circle"
)
)

expect(result.current).toStrictEqual({
style: {
offsetDistance: "50%",
offsetPath: "path('M 0 0 L 100 100')",
},
})
})

test("should keep all CSS motion path properties as styles", () => {
const { result } = renderHook(() =>
useSVGProps(
{ style: {} } as any,
{
offsetDistance: "25%",
offsetPath: "path('M 0 0 L 100 100')",
offsetRotate: "auto",
offsetAnchor: "center",
},
false,
"rect"
)
)

expect(result.current).toStrictEqual({
style: {
offsetDistance: "25%",
offsetPath: "path('M 0 0 L 100 100')",
offsetRotate: "auto",
offsetAnchor: "center",
},
})
})
})
17 changes: 17 additions & 0 deletions packages/framer-motion/src/render/svg/utils/build-attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { ResolvedValues } from "../../types"
import { SVGRenderState } from "../types"
import { buildSVGPath } from "./path"

/**
* CSS Motion Path properties that should remain as CSS styles on SVG elements.
*/
const cssMotionPathProperties = [
"offsetDistance",
"offsetPath",
"offsetRotate",
"offsetAnchor",
]

/**
* Build SVG visual attributes, like cx and style.transform
*/
Expand Down Expand Up @@ -62,6 +72,13 @@ export function buildSVGAttrs(
delete attrs.transformBox
}

for (const key of cssMotionPathProperties) {
if (attrs[key] !== undefined) {
style[key] = attrs[key]
delete attrs[key]
}
}

// Render attrX/attrY/attrScale as attributes
if (attrX !== undefined) attrs.x = attrX
if (attrY !== undefined) attrs.y = attrY
Expand Down