[BUG] Layout animations do not animate completely when container is scrolled
See original GitHub issue1. Describe the bug
I have a scrollable div, within which I have a list of motion.div
s. These use AnimatePresence
to animate themselves away, and each has layout
set so the remaining items will animate to fill the hole left by that item.
When the div is scrolled, removing an item results in incomplete transitions and overlapping items, or other items above the removed items will move down, e.g.:
3. IMPORTANT: Provide a CodeSandbox reproduction of the bug
4. Steps to reproduce
- Scroll the items in the inner div
- Then click an item to remove it.
Sometimes, they will overlap or leave a gap. This minimal repro renders lighter-weight components than my real app, so it can be a bit harder to see it mess up - try scrolling with a trackpad and clicking before the scroll fully settles (though in my full application, this happens reliably even when scrolling has settled).
5. Expected behavior
I expect the item that’s clicked to animate out, and the remaining items to animate into their place in the list.
6. Video or screenshots
https://user-images.githubusercontent.com/313208/156072905-5884d634-02aa-40e2-b1a3-2c7cc49e9712.mov
7. Environment details
Chrome 98 on an M1Max MacBook Pro.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (1 by maintainers)
Top GitHub Comments
layoutScroll
doesn’t fix the issue for me.i think you should use
usePresence
hook, and callsafeToRemove
function which is returned withisPresent
which indicated the presence of element as boolean (doc: https://www.framer.com/docs/animate-presence/#usepresence) i am not sure will this work in your case or no, i wish it help you.