Skip to content

React Beautiful DnD example doesn't behave as expected #112

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jwld opened this issue Sep 5, 2019 · 6 comments
Open

React Beautiful DnD example doesn't behave as expected #112

jwld opened this issue Sep 5, 2019 · 6 comments

Comments

@jwld
Copy link

jwld commented Sep 5, 2019

Are you submitting a bug report or a feature request?

Bug

What is the current behavior?

  1. Add 3 items to the array in this sandbox: https://codesandbox.io/s/8k0ykyr7z9
  2. Swap the 1st and 3rd item, and the list ends up reading 3-2-1 (because of the use of .swap() rather than .move())

What is the expected behavior?

The list should read 3-1-2.

Sandbox Link

https://codesandbox.io/s/8k0ykyr7z9

@NateRadebaugh
Copy link

Could this be because of the way the examples for react-final-form-arrays set the key to be name, which is based on index, which the react docs explicitly caution against:

We don’t recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny’s article for an in-depth explanation on the negative impacts of using an index as a key. If you choose not to assign an explicit key to list items then React will default to using indexes as keys.

However, what other options do we have since the data in the form is not available to us?

@jwld
Copy link
Author

jwld commented Oct 3, 2019

It works as expected if .move() is used instead. It's just confusing if you copy the code from that example because at some point you'll realise it's swapping the source and destination cards, rather than just moving the source, which is probably the intended behaviour in most situations.

I probably should've just made a PR because it's a simple change, will do that later!

@gadiGuesty
Copy link

@jwld in the docs example it's with .move()and it still does not work.
any updates on this?

@gadiGuesty
Copy link

gadiGuesty commented Sep 15, 2020

@NateRadebaugh it works only in newer versions of react-final-form-arrays when fields allows to extract other properties like id in the example.Example should be fixed as:

{fields.map((name, index) => {
                const {id} = fields.value[index];
                return(
                  <Draggable
                    key={id}
                    draggableId={id}
                    index={index}>
                    ...

@gadiGuesty
Copy link

gadiGuesty commented Sep 15, 2020

Duplicate of #94
Duplicate of #150

@noveogroup-amorgunov
Copy link

@gadiGuesty you saved my day, thank you a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants