Skip to content

feat(cdk/drag-drop): support configurable propagation of mousedown an… #19334

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

Closed
wants to merge 1 commit into from

Conversation

lincolnthree
Copy link

Fixes: #19333

@lincolnthree lincolnthree requested a review from crisbeto as a code owner May 12, 2020 18:59
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label May 12, 2020
@lincolnthree
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels May 12, 2020
…d touchstart events.

Allows exposing native mousedown and touchstart events to parent elements so that listeners farther up the chain can respond before a CdkDragEvent has started. Without these events, certain gestures (swiper, etc) cannot be achieved when events are started on a DragRef element.

Fixes: angular#19333
@lincolnthree
Copy link
Author

Fixed build error.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this make sense for your particular use case, but I'm not sure whether it fits as a public API, because people would have to be familiar with the internals of the drag-drop module to know what the implications would be.

Another issue is that this only disables the stopPropagation on mousedown/touchstart events. I think that people may assume that if propagateEvents is set to false, then we wouldn't propagate any events.

You should be able to resolve your issue by binding your events with event capturing turned on.

@lincolnthree
Copy link
Author

Hey, @crisbeto Thanks for reviewing.

In this case, we don't have control over the event listener bindings (and to be most configurable, I'd think the option would help people integrate with additional frameworks more easily.) To which other events are you referring?

Would it make sense if the property were named something more specific, like, "propagateNativeDomEvents"?

@pycraft114
Copy link

@crisbeto Hi :)
What is the recommended way you suggest to propagate an event?

@crisbeto
Copy link
Member

Sorry for the delayed response, I must've missed the notification. I'm still not sold on the idea of this being a public API since it assumes that people would know the internals of the drag-drop module. WDYT @jelbourn?

@lincolnthree
Copy link
Author

lincolnthree commented Jun 21, 2020

My 2 cents, summarized, and sorry if this sounds at all like a lecture or telling you what to do, I'm already working on a fork and this not being included will not really affect me -- just trying to be helpful and give a "real world" perspective that I think will help people:

Drag & Drop is part of the angular "component development kit", and people need control over how it behaves when building custom components. Without fine-grained control, ability to use features will be extremely limited to "general purpose" use-cases that you guys think up but that may not exactly fit real-world scenarios, forcing workarounds and hacks.

I don't feel like events being fired is really an "internal concern" as people rely on events being fired for all kinds of reasons. Events are a fact of life in JS I think that forcing an event model and consuming events without a way to override is taking control out of the users hands in a way that can be problematic.

This is the kind of fine-control needed to really build custom components for highly customized apps, which I assume is your goal :) Without it I'll just continue to fork. But it's here if you want it.

PS. I have other config features along these lines that I would submit if you folks are interested. Ability to disable the placeholder element, for instance. Support for centering the preview elements on the fired event coordinates. Etc.

@jelbourn
Copy link
Member

Looking at the code, it seems like calling stopPropagation isn't a feature or an intended observable behavior, but is instead just an implementation details to prevent nested dragging interactions from breaking. As such, adding a config option to control this implementation detail seems problematic.

My take it that it would be better to solve the nested dragging issue another way, such that the component doesn't have to call stopPropagation at all. Then the events work as expected and no public API is necessary.

@lincolnthree
Copy link
Author

Fine by me. I don't actually believe this call to stopPropagation() is necessary in the first place, but I don't know the internal details ;) and I figured a configuration option was safer.

@lschuft
Copy link

lschuft commented Dec 2, 2020

Hello @crisbeto @jelbourn! What's the status on this issue? Is it waiting for corrections, or it will not be merged altogether? I currently have a use case that manifests this issue where this public API would be useful.

I agree that this would assume people know the internals of the drag-drop module, but stopping event propagation is actually quite dangerous because it breaks the event listening flow of apps and even third-party libraries. And worse, we can't actually fix it without removing whatever code is calling stopPropagation(). In the StackBlitz I explain how I'm not able to capture the click made inside a drag item in any way.

While dangerous, the stopPropagation() in this case is useful to avoid breaking nested scenarios. But if the drag-drop consumer does not use nesting, then he should be able to deactivate its usage. So this option would be useful if a refactoring is not planned in the near-future.

crisbeto added a commit to crisbeto/material2 that referenced this pull request Dec 6, 2020
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.
annieyw pushed a commit that referenced this pull request Jan 6, 2021
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.
annieyw pushed a commit that referenced this pull request Jan 6, 2021
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)
@crisbeto
Copy link
Member

crisbeto commented Jan 6, 2021

The underlying issue should've been resolved in #21227 so I'll close this PR.

@crisbeto crisbeto closed this Jan 6, 2021
@lincolnthree
Copy link
Author

Very good. Thanks for finding a solution. Getting closer to a usable basis for custom D&D needs.

wagnermaciel pushed a commit to wagnermaciel/components that referenced this pull request Jan 14, 2021
…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.
@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 Feb 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fr(cdk/drag-drop): support configurable propagation of mousedown and touchstart events
6 participants