Shopify / draggable

The JavaScript Drag & Drop library your grandparents warned you about.
https://shopify.github.io/draggable
MIT License
17.93k stars 1.09k forks source link

Why Sensors trigger events in source container? #539

Open hnrq opened 2 years ago

hnrq commented 2 years ago

I'm still playing around with this lib and I saw that SensorEvents are usually triggered in source container and the target itself is set inside the event's details. This causes some errors when trying to use Happy DOM for testing, because target should be set once the event is dispatched and should not be overriden.

However, everything breaks when triggering Sensor Events on the target itself instead of the container and I'd like to do this replacement here, because it feels like it's the right pattern imo. Any ideas for making this replacement?

zjffun commented 2 years ago

Which replacement not work? I try to replace one, it's work because we listen events on document.

hnrq commented 2 years ago

Hmmm. That's probably because you kept this line. I was thinking about also removing these targets that are being passed to the Event itself

zjffun commented 2 years ago

It seems we need to check all sensorEvent.target and related logic to achieve this replacement. Like https://github.com/zjffun/draggable/commit/6cf6e81266d8e8458c7fb4f8a641e136fa3e7813

zjffun commented 2 years ago

Mainly need to check the logic of source element and original element. See #242

image