motiondivision / motiondivision/motion
[FEATURE] Animate relative to the `layoutRoot` on shared layout animations with `layoutId`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 33.7k
- Forks
- 1.4k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 14
Description
Is your feature request related to a problem? Please describe.
When a new component is added that has a layoutId prop that matches an existing component, it will automatically animate out from the old component. However, when there is a content shift at the same time, it doesn't take the content shift into account and animates from the wrong position.
See this CodeSandbox for a demonstration (switch from 🍅 to 🥬 to see the tab underline incorrectly move to 🥬 from the right).
Describe the solution you'd like
Adding layout layoutRoot to a parent corrects this for layout animations and could do the same for shared layoutId animations (e.g. in the Sandbox example changing the unordered list element to <motion.ul layout layoutRoot>).
Describe alternatives you've considered
By delaying the shared layout animation until after the content shift has happened, this can be prevented but shouldn't be necessary.
const selectTab = (item: Ingredient) => {
setShowSidebar(item.label === "Lettuce"); // perform what causes content shift first
setTimeout(() => setSelectedTab(item), 0); // delay shared animation
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox and reproduce the incorrect underline movement by switching from 🍅 to 🥬. Compare the existing layout layoutRoot behavior with the shared layoutId case, then locate the relevant shared-layout implementation in the repository. Done means the content shift is incorporated without requiring the setTimeout workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100