Bug 242627 - event.relatedTarget is always null for dragenter and dragleave events
Summary: event.relatedTarget is always null for dragenter and dragleave events
Status: RESOLVED DUPLICATE of bug 66547
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 15
Hardware: Mac (Apple Silicon) macOS 12
: P2 Normal
Assignee: Nobody
URL: https://codesandbox.io/s/event-relate...
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-11 19:12 PDT by alexreardon
Modified: 2022-07-12 14:21 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description alexreardon 2022-07-11 19:12:19 PDT
According to my reading of the [drag and drop spec](https://html.spec.whatwg.org/multipage/dnd.html#dnd), as well as the behaviour of Chrome and Firefox, `dragenter` and `dragleave` events are supposed to set the related target event property (`event.relatedTarget`).

- `dragenter`: `event.relatedTarget` is the previous _current target element_ (where the drag is coming from)
- `dragleave`: `event.relatedTarget` is the new _current target element_ (where the drag has gone too)


When dragging into a window: `event.relatedTarget` should be `null` on `dragenter`

When dragging out of a window: `event.relatedTarget` should be `null` on `dragleave`

In Safari, for `dragenter` and `dragleave` events, the `event.relatedTarget` property is _always_ `null`. This is unhelpful. Doing this makes it painful to detect when a drag is entering / exiting the window. 


Reproduction case: 

- sandbox: https://codesandbox.io/s/event-relatedtarget-for-dragenter-and-dragleave-safari-bug-gpph01
- independent example: https://gpph01.csb.app/


As a work around you need to count `dragenter` and `dragleave` events to determine whether a drag is entering / leaving a window
Comment 1 alexreardon 2022-07-11 19:13:30 PDT
This bug is related to: https://bugs.webkit.org/show_bug.cgi?id=66547

But that bug was only for the `dragleave` event
Comment 2 Sam Sneddon [:gsnedders] 2022-07-12 14:21:55 PDT
As mentioned, generalising the other bug to cover both events.

*** This bug has been marked as a duplicate of bug 66547 ***