-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(cdk/drag-drop): don't stop event propagation unless nested #21227
Conversation
Some time ago we added logic to stop event propagation so that nested drag items don't trigger multiple sequences. Stopping propagation for all events seems to interfere multiple other use cases so these changes add some logic so that we only stop propagation when items are nested. There was something similar in angular#19334, but I decided not to move forward with it, because it required consumers to know the internals of the `drag-drop` module, whereas this approach can do it automatically. Fixes angular#19333.
Also, On top of walking up the drag ref chain, even if a parent drag ref is enabled, its handles need to be checked to be enabled and to actually be encapsulating the click/touch, otherwise there is no need to stop propagation. If |
I think the parent leaking is unlikely, because usually the child components will be removed together with the parent. It technically can happen if the Regarding checking whether the parent is disabled/the handles are disabled, I'm not sure it's worth the extra effort at the moment, because even if we were to stop propagation, the parent is disabled so you can't start dragging it anyway. As for the HTML5 dragging, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Some time ago we added logic to stop event propagation so that nested drag items don't trigger multiple sequences. Stopping propagation for all events seems to interfere multiple other use cases so these changes add some logic so that we only stop propagation when items are nested. There was something similar in #19334, but I decided not to move forward with it, because it required consumers to know the internals of the `drag-drop` module, whereas this approach can do it automatically. Fixes #19333. (cherry picked from commit e42d502)
VERY NICE. This is a great solution! Thank you @annieyw. |
…ar#21227) Some time ago we added logic to stop event propagation so that nested drag items don't trigger multiple sequences. Stopping propagation for all events seems to interfere multiple other use cases so these changes add some logic so that we only stop propagation when items are nested. There was something similar in angular#19334, but I decided not to move forward with it, because it required consumers to know the internals of the `drag-drop` module, whereas this approach can do it automatically. Fixes angular#19333.
How do I reverse the effects of this merge request? This completely breaks nested / multi-level drag-drop. |
The idea with this PR was that it would still stop propagation when it's nested. Can you post an example where it breaks? |
The rough outlines are:
Here is a temporary fix:
|
I'm also confused as to how and why this got merged. It can clearly leak memory. CdkDrag input property > CdkDropList input property > DragRefConfig property |
As I mentioned above, the configuration option is sub-optimal because it's coupled to the current implementation and people would have to know about the internals of the CDK. The option can become useless if we changed the internals. As for the memory leak, it's unlikely to have a child which outlives the parent. I'll look into a solution for handling the case from @luastoned |
A configurable property would be ideal -- that was my original feature request & PR, but the angular team decided that was "too much control" for users to have about internals of the library. Encapsulating technical issues is great, but lack of fine-grained control in low level features of CDK will continue to cause challenges and ongoing issues like this, IMO. I can see situations where you'd even want nested containers to propagate events to an intermediate element. So... it's just a matter of what the library maintainers want to support or not. That's just my perspective. |
This could maybe be an acceptable answer if the code was for a specific application, but I don't understand how this is acceptable for a general purpose library of a framework that supports dynamic components. If the decision is made to not cleanup this implementation, then can you at least make |
…ateOutlet Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
…ateOutlet Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
…ateOutlet (#21668) Some logic was added in #21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
…ateOutlet (#21668) Some logic was added in #21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM. (cherry picked from commit 92cb67e)
…ateOutlet (angular#21668) Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
…ateOutlet (angular#21668) Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
This change has broken dragging on mobile devices. On mobile dragging will also trigger scroll. To reproduce go here on a mobile device or use chrome's toggle device tool bar: https://material.angular.io/cdk/drag-drop/examples then scroll down a bit and then try to drag one of the boxes. You can see that screen also scrolls. Same issue is not present in: https://v10.material.angular.io/cdk/drag-drop/examples |
…ateOutlet (angular#21668) Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
…ateOutlet (angular#21668) Some logic was added in angular#21227 which would only `stopPropagation` when dragging if a parent drag item is detected. The problem is that we resolve the parent using DI which won't work if the item is projected through something like `ngTemplateOutlet`. These changes resolve the issue by falling back to resolving the parent through the DOM.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Some time ago we added logic to stop event propagation so that nested drag items don't trigger multiple sequences. Stopping propagation for all events seems to interfere multiple other use cases so these changes add some logic so that we only stop propagation when items are nested.
There was something similar in #19334, but I decided not to move forward with it, because it required consumers to know the internals of the
drag-drop
module, whereas this approach can do it automatically.Fixes #19333.