-
-
Notifications
You must be signed in to change notification settings - Fork 855
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SVG elements (like motion.text) now update when given a MotionValue a…
…s children, matching HTML element behavior (#2841) * Update the motion value of a child via its firstChild text node instead of innerText * Added changelog entry * Improved changelog entry * Added a test for motion.text inside an svg * Still use textContent where possible * An example of providing a MotionValue to a component directly. Testing both a SVG text and HTML h1 element * SVG also supports updating through textContent * Since the implementation in HTMLVisualElement and SVGVisualElement is now identical, move logic to DOMVisualElement * Updated tests and changelog entry to reflect latest changes --------- Co-authored-by: Matt Perry <[email protected]>
- Loading branch information
1 parent
7c6b174
commit 7c66534
Showing
5 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { animate, motion, useMotionValue, useTransform } from "framer-motion" | ||
import { useEffect } from "react" | ||
|
||
/** | ||
* An example of providing a MotionValue to a component directly. Testing both | ||
* a SVG text and HTML h1 element. | ||
*/ | ||
export const App = () => { | ||
const count = useMotionValue(0); | ||
const rounded = useTransform(count, Math.round); | ||
useEffect(() => { | ||
const animation = animate(count, 100, { duration: 10 }); | ||
return animation.stop; | ||
}, []) | ||
|
||
return (<> | ||
<p>SVG</p> | ||
<svg | ||
width="250" | ||
height="250" | ||
viewBox="0 0 250 250" | ||
xmlns="http://www.w3.org/2000/svg" | ||
style={{ border: '1px solid white' }} | ||
> | ||
<motion.text | ||
x={125} | ||
y={125} | ||
fontSize={40} | ||
dominantBaseline="middle" | ||
textAnchor="middle" | ||
fill="currentColor" | ||
> | ||
{rounded} | ||
</motion.text> | ||
</svg> | ||
<p>HTML</p> | ||
<motion.h1>{rounded}</motion.h1> | ||
<motion.p>{rounded}</motion.p> | ||
</>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters