Skip to content

Commit

Permalink
Fixing test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Dec 5, 2022
1 parent 9953226 commit 94cc0cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/framer-motion/package.json
Expand Up @@ -72,15 +72,15 @@
"bundlesize": [
{
"path": "./dist/size-rollup-motion.js",
"maxSize": "28.9 kB"
"maxSize": "29 kB"
},
{
"path": "./dist/size-rollup-m.js",
"maxSize": "4.7 kB"
"maxSize": "4.75 kB"
},
{
"path": "./dist/size-rollup-dom-animation.js",
"maxSize": "14.13 kB"
"maxSize": "14.2kB"
},
{
"path": "./dist/size-rollup-dom-max.js",
Expand Down
17 changes: 17 additions & 0 deletions packages/framer-motion/src/motion/__tests__/component-svg.test.tsx
Expand Up @@ -88,6 +88,23 @@ describe("SVG", () => {
render(<Component />)
})

test("doesn't read viewBox as '0 0 0 0'", () => {
const Component = () => {
return (
<motion.svg
viewBox="0 0 100 100"
transition={{ delay: 1 }}
animate={{ viewBox: "100 100 200 200" }}
/>
)
}
const { container } = render(<Component />)
expect(container.firstChild as Element).toHaveAttribute(
"viewBox",
"0 0 100 100"
)
})

test("animates viewBox", () => {
const Component = () => {
return (
Expand Down
6 changes: 4 additions & 2 deletions packages/framer-motion/src/render/svg/utils/build-attrs.ts
Expand Up @@ -27,13 +27,15 @@ export function buildSVGAttrs(
transformTemplate?: MotionProps["transformTemplate"]
) {
buildHTMLStyles(state, latest, options, transformTemplate)

console.log(state.attrs, state.style)
/**
* For svg tags we just want to make sure viewBox is animatable and treat all the styles
* as normal HTML tags.
*/
if (isSVGTag) {
state.attrs.viewBox = state.style.viewBox
if (state.style.viewBox) {
state.attrs.viewBox = state.style.viewBox
}
return
}

Expand Down
1 change: 1 addition & 0 deletions packages/framer-motion/src/render/svg/utils/render.ts
Expand Up @@ -14,6 +14,7 @@ export function renderSVG(
renderHTML(element as any, renderState, undefined, projection)

for (const key in renderState.attrs) {
console.log(key, renderState.attrs)
element.setAttribute(
!camelCaseAttributes.has(key) ? camelToDash(key) : key,
renderState.attrs[key] as string
Expand Down

0 comments on commit 94cc0cf

Please sign in to comment.