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

Already on GitHub? Sign in to your account

DropList created with DragDrop.createDropList is broken #16961

Closed
tornaia opened this issue Sep 3, 2019 · 5 comments · Fixed by #16963
Closed

DropList created with DragDrop.createDropList is broken #16961

tornaia opened this issue Sep 3, 2019 · 5 comments · Fixed by #16963
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@tornaia
Copy link

tornaia commented Sep 3, 2019

Reproduction

https://stackblitz.com/edit/angular-8-drag-and-drop-dynamic-components

Steps to reproduce:

  1. Click on the add item a few times
  2. Try to drag-and-drop these items

Expected Behavior

The order of the items can be changed

Actual Behavior

The order of the items remains always the same and the "dropped" event previousIndex and currentIndex properties have always the same value.

Environment

  • Angular: 8.2.3
  • CDK/Material: 8.1.4
  • Browser(s): Chrome 76 (but its not a browser specific issue)
  • Operating System: Windows
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 3, 2019
It looks like something I overlooked when I first implemented the `sortingDisabled` flag. Currently it's set to `false` by default which means that sorting won't work unless users opt into it.

Fixes angular#16961.
@crisbeto crisbeto self-assigned this Sep 3, 2019
@crisbeto crisbeto added has pr P2 The issue is important to a large percentage of users, with a workaround labels Sep 3, 2019
@crisbeto
Copy link
Member

crisbeto commented Sep 3, 2019

It looks like the issue is because we accidentally left the sortingDisabled flag on which means that sorting is disabled by default. It's not a problem for the drag&drop directives, because they override the setting. It'll be fixed by #16963, but until then you can work around it for your case by adding this.dropListRef.sortingDisabled = false.

@tornaia
Copy link
Author

tornaia commented Sep 3, 2019

Hi @crisbeto,

Thank you for the prompt reply!

I've applied the suggested workaround and it looks a bit better now: the dropped event has now the correct previousIndex and currentIndex value - unfortunately the order of the items are still always the same - despite the use of moveItemInArray.

Please find here the updated repro case:
https://stackblitz.com/edit/angular-8-drag-and-drop-dynamic-components-with-workaround

@crisbeto
Copy link
Member

crisbeto commented Sep 3, 2019

The moveItemInArray only moves the items inside of your internal array, it won't move the elements in the DOM for you. Usually you'd have an ngFor that renders out the items so that when you change the data, Angular will move the items for you.

@tornaia
Copy link
Author

tornaia commented Sep 3, 2019

I see now - thanks!

jelbourn pushed a commit that referenced this issue Sep 6, 2019
It looks like something I overlooked when I first implemented the `sortingDisabled` flag. Currently it's set to `false` by default which means that sorting won't work unless users opt into it.

Fixes #16961.
crisbeto added a commit to crisbeto/material2 that referenced this issue Sep 7, 2019
It looks like something I overlooked when I first implemented the `sortingDisabled` flag. Currently it's set to `false` by default which means that sorting won't work unless users opt into it.

Fixes angular#16961.
jelbourn pushed a commit that referenced this issue Sep 9, 2019
It looks like something I overlooked when I first implemented the `sortingDisabled` flag. Currently it's set to `false` by default which means that sorting won't work unless users opt into it.

Fixes #16961.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants