Skip to content

TheGoat395/Codex-Skills / skills/motion-react-layout-transitions

motion-react-layout-transitions

Verified

Animate state-driven layout/layoutId changes.

references/motion-react-layout-transitions-guide.md

View on GitHub
# Motion React Layout Transitions Guide

## Purpose

Animate layout changes in a way that clarifies continuity instead of causing jumpy UI.

## Use When

- A component changes size, position, order, selected state, or layout in response to React state.
- Shared element continuity would make a product UI, portfolio, gallery, nav underline, or tab set feel polished.
- The project uses Motion and layout changes currently snap awkwardly.

## Do Not Use When

- The animation is only a route-level page transition.
- The layout change is better expressed with instant state for speed or accessibility.
- A browser View Transition or GSAP timeline is the established local pattern.

## Discovery Questions

- Which element should visually persist between states?
- Does the transition need `layout`, `layoutId`, or a `LayoutGroup`?
- What should happen to focus and scroll during the layout change?
- Does the layout animation distort children, images, borders, or shadows?

## Decision Tree

- Use `layout` for a single element's size/position changes.
- Use `layoutId` for shared element transitions between components.
- Use `LayoutGroup` when related elements need coordinated measurement.
- Prefer transform-based layout animation and avoid animating raw width/height manually.
- Disable or simplify layout motion when reduced motion is requested.

## Implementation Rules

- Animate continuity only where users benefit from understanding what moved.
- Avoid shared element transitions between visually unrelated objects.
- Preserve semantic DOM order and keyboard flow.
- Keep stable keys for animated lists.
- Watch for clipping, z-index, border-radius distortion, and image stretching.

## Useful Patterns

- Active nav underline with `layoutId`.
- Portfolio grid card expands into a preview panel.
- Filter chips reorder with subtle layout motion.
- Product UI pane shifts between summary and detail while preserving context.

## Anti-Patterns

- Layout animations on every list item in a dense dashboard.
- Missing keys causing components to animate as the wrong object.
- Huge springy movement on serious or luxury UI.
- Animating layout without testing mobile wraps.

## QA Checklist

- Test repeated open/close, filter, reorder, and resize.
- Check mobile, reduced motion, and keyboard focus.
- Inspect z-index and clipping during transition.
- Run build/lint to catch React key and import issues.

## Acceptance Criteria

- Layout motion improves orientation and feels physically plausible.
- No content jumps, overlaps, or distorts during transitions.
- The implementation remains accessible and maintainable.

## Shared scope

For applicable substantial web work, reuse the [shared scoped web contract](../../website-operating-rules/references/scoped-web-contract.md) when available. Preserve current authorization, stack and requested scope; this optional reference does not require another planning or approval cycle.

## Official Source Anchors

- Motion layout animations: https://motion.dev/docs/react-layout-animations
- Motion for React: https://motion.dev/docs/react
- MDN prefers-reduced-motion: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion

## Measurement-specific failures

For the installed Motion version, check `layoutScroll` on a scroll container and `layoutRoot` on a fixed layout root when coordinates drift during scroll. Non-replaced inline elements cannot be transformed; choose an appropriate display type. For scale distortion, inspect child layout participation and set supported radius/shadow values through Motion-readable styles. Scope repeated shared IDs with `LayoutGroup` when unrelated instances collide. Verify the original scroll/open/reorder path after changing measurement ownership. [Official layout guidance](https://motion.dev/docs/react-layout-animations).
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall