Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Reorder component doesn't work as expected when list contains objects #2287

Closed
Tunzeki opened this issue Aug 10, 2023 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@Tunzeki
Copy link

Tunzeki commented Aug 10, 2023

1. Read the FAQs 馃憞

2. Describe the bug

The items on the screen disappear when an attempt to reorder is made

3. IMPORTANT: Provide a CodeSandbox reproduction of the bug

A CodeSandbox minimal reproduction will allow us to quickly follow the reproduction steps. Without one, this bug report won't be accepted.

4. Steps to reproduce

Steps to reproduce the behavior:

  1. Go to 'https://codesandbox.io/s/framer-motion-5-drag-to-reorder-lists-forked-s84qwh?file=/src/App.tsx:343-464'
  2. Try to reorder any item on the list
  3. Notice how the items disappear from the screen

5. Expected behavior

Items should remain on the screen and I should be able to reorder them.

6. Video or screenshots

If applicable, add a video or screenshots to help explain the bug.

7. Environment details

If applicable, let us know which OS, browser, browser version etc you're using.

FAQs

Framer Motion won't install

Framer Motion 7+ uses React 18 as a minimum. If you can't upgrade React, install the latest version of Framer Motion 6.

height: "auto" is jumping

Animating to/from auto requires measuring the DOM. There's no perfect way to do this and if you have also applied padding to the same element, these measurements might be wrong.

The recommended solution is to move padding to a child element. See this issue for the full discussion.

Type error with AnimateSharedLayout

AnimateSharedLayout was deprecated in 5.0. Refer to the upgrade guide for instructions on how to remove.

Preact isn't working

Framer Motion isn't compatible with Preact.

AnimatePresence isn't working

Have all of its immediate children got a unique key prop that remains the same for that component every render?

// Bad: The index could be given to a different component if the order of items changes
<AnimatePresence>
  {items.map((item, index) => <Component key={index} />)}
</AnimatePresence>
// Good: The item ID is unique to each component
<AnimatePresence>
  {items.map((item, index) => <Component key={item.id} />)}
</AnimatePresence>

Is the AnimatePresence correctly outside of the controlling conditional? AnimatePresence must be rendered whenever you expect an exit animation to run - it can't do so if it's unmounted!

// Bad: AnimatePresence is unmounted - exit animations won't run
{isVisible && (
  <AnimatePresence>
    <Component />
  </AnimatePresence>
)}
// Good: Only the children are unmounted - exit animations will run
<AnimatePresence>
  {isVisible && <Component />}
</AnimatePresence>
@Tunzeki Tunzeki added the bug Something isn't working label Aug 10, 2023
@ali-idrizi
Copy link

I think the value of Reorder.Item should match an item in the array, so you should pass the entire item to value, instead of just the letter. Like:

{items.map((item) => (
  <Item key={item.id} item={item} />
))}

And in Item.tsx:

<Reorder.Item value={item} style={{ boxShadow, y }}>
  <span>{item.letter}</span>
</Reorder.Item>

@Tunzeki
Copy link
Author

Tunzeki commented Aug 14, 2023

OMG! That fixed it!! Thank you so much.

@Tunzeki Tunzeki closed this as completed Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants