Animated text swap
When Copy turns into Copied, the button snaps to its new width and everything next to it shifts. Morphing the text lets the box follow the letters instead.
12345{ "rules": { "systomic/animated-text-swap": "warn" }}See the difference
{copied ? "Copied" : "Copy"}<TextMorph>{copied ? "Copied" : "Copy"}</TextMorph>What doesn't work
2 findings123456789101112export function CopyButton({ copied }: { copied: boolean }) { return ( <button> {copied ? "Copied" : "Copy"} </button> );}
export function copied(span: HTMLElement) { span.textContent = "Copied"; setTimeout(() => (span.textContent = "Copy"), 1500);}systomic/animated-text-swap The label swaps from Copy to Copied without animation, so the button jumps to the new width. Consider morphing it with Torph (<TextMorph> from torph/react).
systomic/animated-text-swap span.textContent swaps text without animation, so its box jumps to the new width. Consider morphing it with Torph: new TextMorph({ element }).update(text) from torph.
What works
No findings12345678910111213141516import { TextMorph } from "torph/react";import { TextMorph as Morph } from "torph";
export function CopyButton({ copied }: { copied: boolean }) { return ( <button> <TextMorph>{copied ? "Copied" : "Copy"}</TextMorph> </button> );}
export function copied(span: HTMLElement) { const morph = new Morph({ element: span }); morph.update("Copied"); setTimeout(() => morph.update("Copy"), 1500);}Details
A label that changes in place (Copy → Copied, Save → Saving…) snaps to its new width: the button grows or shrinks in one frame and everything next to it shifts. Morphing the text animates the letters and the box together, so the change reads as a response instead of a layout jump.
Torph does this without dependencies, for React, Vue, Svelte and plain DOM. The rule suggests it but doesn’t require it: any wrapper listed in animatedWrappers counts.
12<button>{copied ? "Copied" : "Copy"}</button> // reported<button><TextMorph>{copied ? "Copied" : "Copy"}</TextMorph></button> // import { TextMorph } from "torph/react"The label swaps from
CopytoCopiedwithout animation, so the button jumps to the new width. Consider morphing it with Torph (<TextMorph>fromtorph/react).
In DOM scripts (vanilla, Astro <script>):
123456span.textContent = "Copied"; // reportedsetTimeout(() => (span.textContent = "Copy"), 1500);
const morph = new TextMorph({ element: span }); // import { TextMorph } from "torph"morph.update("Copied");setTimeout(() => morph.update("Copy"), 1500);What is checked
- JSX: a ternary between two different, non-empty string literals rendered as children (
{a ? "Copied" : "Copy"}), unless it is inside ananimatedWrapperscomponent. - DOM:
x.textContent = …orx.innerText = …assigned a string ternary inside a function (handler, callback), or assigned twice where one assignment is inside the other’s function (set, then reset in a callback). Reported once per target.
Not reported: dynamic text ({a ? name : "Anonymous"}), show/hide ({a ? "Copy" : ""}), attributes (aria-label={…}), single DOM writes (also a ternary at the top level, which runs once on load) and writes in unrelated functions.
Torph respects prefers-reduced-motion by default.
| Option | Default |
|---|---|
animatedWrappers |
["TextMorph"] |
checkDom |
true |