systomic

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.

  • SuggestionIn suggestions.json: good practice. It only ever warns.
  • WarningShows in the editor and in CI output, but doesn't fail the run (unless you pass --deny-warnings).

See the difference

Before
{copied ? "Copied" : "Copy"}
After
<TextMorph>{copied ? "Copied" : "Copy"}</TextMorph>

What doesn't work

2 findings

What works

No findings

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.

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).

In DOM scripts (vanilla, Astro <script>):

What is checked

  • JSX: a ternary between two different, non-empty string literals rendered as children ({a ? "Copied" : "Copy"}), unless it is inside an animatedWrappers component.
  • DOM: x.textContent = … or x.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
Esc