Issue with Animated Container Heights While Dragging Items Using Framer Motion and DnDKit

I’m working on a drag-and-drop feature using React, TailwindCSS, Framer Motion, and DnDKit. Everything works as intended except for one case, and I’m looking for help to resolve it.

TL;DR:
CodeSandbox link here. It works best if both containers have 3 items and you drag an item from container 1 to container 2 very slowly. You’ll notice the draggable item is “stuck” with the first item of container 2.

The Setup:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. I have multiple containers, each created using DnDKit’s useSortable.
2. Each container holds a list of items that can be dragged within the container or moved to another container.
3. I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size.
</code>
<code>1. I have multiple containers, each created using DnDKit’s useSortable. 2. Each container holds a list of items that can be dragged within the container or moved to another container. 3. I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size. </code>
1.  I have multiple containers, each created using DnDKit’s useSortable.
2.  Each container holds a list of items that can be dragged within the container or moved to another container.
3.  I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size.

The Problem:

When dragging an item from one container to another:

  • If I drag an item upward into a new container, everything works smoothly.
  • However, if I drag an item downward into a new container, I encounter a visual issue:
    • The height of the old container decreases.
    • The height of the new container increases.
    • This causes the new container to “move up,” shifting its items along, which causes the draggable item to behave incorrectly.

What I’ve Tried:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. Adding placeholders to maintain the container’s height during the drag.
2. Using Framer Motion’s layout and layoutId to control animations.
3. Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position.
</code>
<code>1. Adding placeholders to maintain the container’s height during the drag. 2. Using Framer Motion’s layout and layoutId to control animations. 3. Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position. </code>
1.  Adding placeholders to maintain the container’s height during the drag.
2.  Using Framer Motion’s layout and layoutId to control animations.
3.  Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position.

While these help to some extent, the issue persists when the layout of containers and items adjusts mid-drag.


What I Need Help With:

How can I:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. Prevent the items inside the new container from shifting while dragging?
2. Ensure smooth height animations without disrupting the drag-and-drop experience?
</code>
<code>1. Prevent the items inside the new container from shifting while dragging? 2. Ensure smooth height animations without disrupting the drag-and-drop experience? </code>
1.  Prevent the items inside the new container from shifting while dragging?
2.  Ensure smooth height animations without disrupting the drag-and-drop experience?

Any suggestions or ideas on how to resolve this? Thank you! 😊

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Issue with Animated Container Heights While Dragging Items Using Framer Motion and DnDKit

I’m working on a drag-and-drop feature using React, TailwindCSS, Framer Motion, and DnDKit. Everything works as intended except for one case, and I’m looking for help to resolve it.

TL;DR:
CodeSandbox link here. It works best if both containers have 3 items and you drag an item from container 1 to container 2 very slowly. You’ll notice the draggable item is “stuck” with the first item of container 2.

The Setup:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. I have multiple containers, each created using DnDKit’s useSortable.
2. Each container holds a list of items that can be dragged within the container or moved to another container.
3. I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size.
</code>
<code>1. I have multiple containers, each created using DnDKit’s useSortable. 2. Each container holds a list of items that can be dragged within the container or moved to another container. 3. I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size. </code>
1.  I have multiple containers, each created using DnDKit’s useSortable.
2.  Each container holds a list of items that can be dragged within the container or moved to another container.
3.  I use Framer Motion’s layoutId on the containers to animate the height when an item enters or leaves a container. This creates a smooth transition as the container adjusts its size.

The Problem:

When dragging an item from one container to another:

  • If I drag an item upward into a new container, everything works smoothly.
  • However, if I drag an item downward into a new container, I encounter a visual issue:
    • The height of the old container decreases.
    • The height of the new container increases.
    • This causes the new container to “move up,” shifting its items along, which causes the draggable item to behave incorrectly.

What I’ve Tried:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. Adding placeholders to maintain the container’s height during the drag.
2. Using Framer Motion’s layout and layoutId to control animations.
3. Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position.
</code>
<code>1. Adding placeholders to maintain the container’s height during the drag. 2. Using Framer Motion’s layout and layoutId to control animations. 3. Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position. </code>
1.  Adding placeholders to maintain the container’s height during the drag.
2.  Using Framer Motion’s layout and layoutId to control animations.
3.  Playing with the DragOverlay component in DnDKit to decouple the dragged item’s position.

While these help to some extent, the issue persists when the layout of containers and items adjusts mid-drag.


What I Need Help With:

How can I:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>1. Prevent the items inside the new container from shifting while dragging?
2. Ensure smooth height animations without disrupting the drag-and-drop experience?
</code>
<code>1. Prevent the items inside the new container from shifting while dragging? 2. Ensure smooth height animations without disrupting the drag-and-drop experience? </code>
1.  Prevent the items inside the new container from shifting while dragging?
2.  Ensure smooth height animations without disrupting the drag-and-drop experience?

Any suggestions or ideas on how to resolve this? Thank you! 😊

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật