You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Drag and Drop not working inside MatDialog (wrong previous and current index) #15880
Reorder items in a list inside Mat-dialog using Angular Material Drag and Drop.
What is the current behavior?
Drag and drop does not work properly on the last items of the list. Previous and current index are the same in the moveItemInArray function
What are the steps to reproduce?
I have an array, where each item contains a list of colors. Clicking the edit button opens an Angular Material Dialog with the list of colors (for that item). The colors can be reordered using drag and drop. The list of colors from the first items of the list work fine, but when trying to reorder the list of colors in the last items of the list, drag and drop does not work. I did some debugging and found out that for the items not working, the event passed to the moveItemInArray, has the same number for the current and the previous index.
As previously mentioned, click on the edit button for one of the first items in the list and try reordering the colors, it works fine, choose the last item in the list and you will see the colors cannot be reordered, take a look at the console to get the previous and current indexes.
Not sure whether this is a CDK or a Mat-Dialog dialog.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 7, Angular Material 7.3.7
Chrome, Firefox
Is there anything else we should know?
When reducing the list of items to just a couple of them, then all list of colors for all items work fine. Problem starts when the list of items starts to grow in number.
Reacted by Ingo Bürk, Christian Kliche, Yuta Moriyama, AndyMart1n, Ricardo Barata, Niclas Kaufmann, Hariharan Devaraj, Renjith P N, Tourist2010 and Zdeněk Haták
I'm having the suspicion that this somehow has to do with MatDialog. I've also observed that sometimes the indices are different, but still not correct. It also seems to only happen in combination with cdkDropList, a standalone cdkDrag works fine.
For the record, the data passed to the dialog doesn't matter – you can even pass a static array and observe the same effect.
changed the title [-]Bug: Drag and Drop not working (wrong previous and current index)[/-][+]Bug: Drag and Drop not working inside MatDialog (wrong previous and current index)[/+]on Apr 25, 2019
I wasn't sure either where the problem was, but as you mentioned it might be on the MatDialog side and not the CDK. Any ideas on how to get this working? I don't see any errors on the console, so don't really know where to start looking to get a fix for this.
It seems to correlate of the combination of opening a dialog when you have scrolled the page.
Try this: make the window as big as possible, load the app and open the dialog for the most bottom item without scrolling; it works fine. Now make the window smaller, reload the app, scroll to the same item and edit it again; it will now break.
As you can also see, when a dialog opens, somehow the body scroll disappears, which I assume is intended behavior for dialogs. I think this somehow interferes with the calculations done for the drag/drop translate styles.
@betancourtc I think a workaround would be to inject a MAT_DIALOG_SCROLL_STRATEGY that does not use the block scroll strategy. This is of course suboptimal since you probably do not want to allow scrolling while a modal is open – it should make the drag and drop work for now, though.
This is about as far as I was able to get. I think it would be good if the people working on drag and drop could weigh in now, at least we identified that the issue is the scrollblock.
I'm unable to reproduce the issue, the drag and drop seems to be working correctly. Can you confirm it is breaking and let me know what browser and version you are using?
@andrewseguin I was able to reproduce the issue trying to drag and drop the colors on the last theme (number 50) from my example in StackBlitz on Chrome Version 73.0.3683.103 (64-bit) and on Firefox Version 66.0.3 (64-bit). Both on Windows 10.
@andrewseguin The problem only occurs when you click "Edit" on one of the items on the bottom if you had to scroll (significantly). If you have a big monitor, make sure to resize the window to something small so you need to scroll down first.
I am absolutely able to reproduce with the provided StackBlitz (as can be seen by my previous research efforts). The issue gets gradually worse as you have scrolled more, and at some point it just breaks entirely.
BTW, I somewhat disagree with the P4 label. Drag and drop in a modal is no edge-case, and this is part of the CDK flat-out breaking in its core functionality.
Reacted by anton-white, Maksim, Vlad Vidac, Renjith P N, userradu and Tourist2010
Reacted by Joel Duckworth, betancourtc, Yuta Moriyama, cdrapes17, Anton von Borries, Renjith P N and Gustavo G. Kozoroski
Angular CLI: 8.0.3
Node: 10.16.0
OS: darwin x64
Angular: 8.0.1
If I was scrolled down on site and then I opened dialog with Drag&Drop two lists, order in them or move item from list to another list is not working. Event of drop function returns same container for previous or current container property, with same indexes.
Same problem here but derives from different actions. (It has nothing to do with scrolling in my case)
The drag and drop lists are inside matDialog. The first time I open the dialog works fine in Chrome and IE. No matter how many times I open the same matDialog everything works fine.
However if I open another matDialog and then try to open the MatDialog with the drag and drop list, it does not work. The event.container is the same as the event.previousContainer and it does not drop the item neither in the left nor in the right list and vise versa.
The funny thing is that works fine with IE but not with Chrome.
I have the same problem, but just with a single dialog, that contains a drag'n'drop directive, the directive works fine within my parent component, but doesn't react to drag inside a dialog
I have no scroll into my parent nor my dialog
I have the same problem, but just with a single dialog, that contains a drag'n'drop directive, the directive works fine within my parent component, but doesn't react to drag inside a dialog
I have no scroll into my parent nor my dialog
Activity
Airblader commentedon Apr 24, 2019
I'm having the suspicion that this somehow has to do with MatDialog. I've also observed that sometimes the indices are different, but still not correct. It also seems to only happen in combination with cdkDropList, a standalone cdkDrag works fine.
For the record, the data passed to the dialog doesn't matter – you can even pass a static array and observe the same effect.
[-]Bug: Drag and Drop not working (wrong previous and current index)[/-][+]Bug: Drag and Drop not working inside MatDialog (wrong previous and current index)[/+]betancourtc commentedon Apr 26, 2019
I wasn't sure either where the problem was, but as you mentioned it might be on the MatDialog side and not the CDK. Any ideas on how to get this working? I don't see any errors on the console, so don't really know where to start looking to get a fix for this.
Airblader commentedon Apr 26, 2019
It seems to correlate of the combination of opening a dialog when you have scrolled the page.
Try this: make the window as big as possible, load the app and open the dialog for the most bottom item without scrolling; it works fine. Now make the window smaller, reload the app, scroll to the same item and edit it again; it will now break.
As you can also see, when a dialog opens, somehow the body scroll disappears, which I assume is intended behavior for dialogs. I think this somehow interferes with the calculations done for the drag/drop translate styles.
Airblader commentedon Apr 26, 2019
Disabling the
cdk-global-scrollblockclass applied to the<html>tag when modals open makes the issue disappear.Edit: If
cdk-global-scrollbackis applied to body rather than html it also seems to work. I'm sure this would break something else, of course. ;-)Airblader commentedon Apr 26, 2019
@betancourtc I think a workaround would be to inject a
MAT_DIALOG_SCROLL_STRATEGYthat does not use the block scroll strategy. This is of course suboptimal since you probably do not want to allow scrolling while a modal is open – it should make the drag and drop work for now, though.Airblader commentedon Apr 26, 2019
This is about as far as I was able to get. I think it would be good if the people working on drag and drop could weigh in now, at least we identified that the issue is the scrollblock.
betancourtc commentedon May 3, 2019
@Airblader Thanks a lot for your help. I hope too the people working on the drag and drop module take a look at this. Cheers
andrewseguin commentedon May 7, 2019
I'm unable to reproduce the issue, the drag and drop seems to be working correctly. Can you confirm it is breaking and let me know what browser and version you are using?
betancourtc commentedon May 8, 2019
@andrewseguin I was able to reproduce the issue trying to drag and drop the colors on the last theme (number 50) from my example in StackBlitz on Chrome Version 73.0.3683.103 (64-bit) and on Firefox Version 66.0.3 (64-bit). Both on Windows 10.
Airblader commentedon May 8, 2019
@andrewseguin The problem only occurs when you click "Edit" on one of the items on the bottom if you had to scroll (significantly). If you have a big monitor, make sure to resize the window to something small so you need to scroll down first.
I am absolutely able to reproduce with the provided StackBlitz (as can be seen by my previous research efforts). The issue gets gradually worse as you have scrolled more, and at some point it just breaks entirely.
Airblader commentedon May 8, 2019
BTW, I somewhat disagree with the P4 label. Drag and drop in a modal is no edge-case, and this is part of the CDK flat-out breaking in its core functionality.
striky1 commentedon Jul 2, 2019
Hi here,
I can confirm that it is not working also on:
If I was scrolled down on site and then I opened dialog with Drag&Drop two lists, order in them or move item from list to another list is not working. Event of drop function returns same container for previous or current container property, with same indexes.
Can u take a look on that, pls? :)
6 remaining items
ENM1989 commentedon Nov 26, 2019
Same problem here with mat-dialog and drag and drop.
uvcreation commentedon Dec 9, 2019
Same problem here, is someone got the solution for this issue?
larqitos commentedon Dec 11, 2019
@uvcreation you can take a look at my quick fix here: #15880 (comment)
uvcreation commentedon Dec 11, 2019
@larqitos It works for me after using ::ng-deep. Thanks mate!
kotsopoulosd commentedon Dec 20, 2019
Same problem here but derives from different actions. (It has nothing to do with scrolling in my case)
The drag and drop lists are inside matDialog. The first time I open the dialog works fine in Chrome and IE. No matter how many times I open the same matDialog everything works fine.
However if I open another matDialog and then try to open the MatDialog with the drag and drop list, it does not work. The event.container is the same as the event.previousContainer and it does not drop the item neither in the left nor in the right list and vise versa.
The funny thing is that works fine with IE but not with Chrome.
Angular CLI: 8.3.8
Node: 10.16.3
OS: win32 x64
Angular: 8.2.9
Hydhen commentedon May 12, 2020
I have the same problem, but just with a single dialog, that contains a drag'n'drop directive, the directive works fine within my parent component, but doesn't react to drag inside a dialog
I have no scroll into my parent nor my dialog
uvcreation commentedon Jun 10, 2020
try to add this to your component css file
::ng-deep html.cdk-global-scrollblock {
top: 0px !important;
}
crisbeto commentedon Aug 16, 2020
Duplicate of #14280.
angular-automatic-lock-bot commentedon Sep 16, 2020
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.