<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>66547</bug_id>
          
          <creation_ts>2011-08-19 04:59:19 -0700</creation_ts>
          <short_desc>dragenter &amp; dragleave events do not include relatedTarget in the event object</short_desc>
          <delta_ts>2026-03-19 15:42:47 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>UI Events</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=242627</see_also>
    
    <see_also>https://github.com/web-platform-tests/wpt/pull/58567</see_also>
          <bug_file_loc>http://jsfiddle.net/pimvdb/HU6Mk/8/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>pimvdb</reporter>
          <assigned_to name="Brent Fulgham">bfulgham</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>alexreardon</cc>
    
    <cc>andreas</cc>
    
    <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>broofa</cc>
    
    <cc>caqittepp-549</cc>
    
    <cc>cdumez</cc>
    
    <cc>charged2886</cc>
    
    <cc>dglazkov</cc>
    
    <cc>dipish</cc>
    
    <cc>dominicc</cc>
    
    <cc>fguillen.mail</cc>
    
    <cc>graouts</cc>
    
    <cc>guillaume.brunerie</cc>
    
    <cc>jakob.stahl91</cc>
    
    <cc>karlcow</cc>
    
    <cc>megan_gardner</cc>
    
    <cc>michaelcpuckett</cc>
    
    <cc>mtraceur</cc>
    
    <cc>nate.whittaker</cc>
    
    <cc>piotr.nalepa</cc>
    
    <cc>robertc</cc>
    
    <cc>thorton</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>453746</commentid>
    <comment_count>0</comment_count>
      <attachid>104491</attachid>
    <who name="">pimvdb</who>
    <bug_when>2011-08-19 04:59:19 -0700</bug_when>
    <thetext>Created attachment 104491
Test case

Scenario:

 - a drag element
 - a drop target element, which has a child element
 - drop target element has a &apos;dragleave&apos; event bound which uses e.relatedTarget


Problem:

In the event handler for &apos;dragleave&apos;, &apos;e.relatedTarget&apos; is null. This is unfortunate, because when dragging inside the drop target element from the parent into the child, &apos;e.relatedTarget&apos; is not the parent element. As a result, it is impossible to determine whether the dragging is still happening inside the parent element or that the mouse dragged outside the parent element.

This property is available on Firefox and should be available as said in the specification:

http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mouseevents</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>454337</commentid>
    <comment_count>1</comment_count>
    <who name="">pimvdb</who>
    <bug_when>2011-08-20 04:26:07 -0700</bug_when>
    <thetext>I did a quick research and it looks like that &apos;relatedTarget&apos; is indeed not passed.

http://www.google.com/codesearch#OAMlx_jo-ck/src/third_party/WebKit/Source/WebCore/page/EventHandler.cpp&amp;l=1725

The penultimate argument which is passed to MouseEvent::create (which corresponds to the &apos;relatedTarget&apos; parameter) is &apos;0&apos; and is probably therefore &apos;null&apos; in JavaScript.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>504694</commentid>
    <comment_count>2</comment_count>
    <who name="Dipish">dipish</who>
    <bug_when>2011-11-17 02:57:33 -0800</bug_when>
    <thetext>I confirm the behaviour (tested in Chrome 15.0.874.121).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>528545</commentid>
    <comment_count>3</comment_count>
    <who name="Andreas Blixt">andreas</who>
    <bug_when>2012-01-02 09:35:25 -0800</bug_when>
    <thetext>I can reproduce this on &quot;AppleWebKit/535.8 Chrome/17.0.944.0&quot; and &quot;AppleWebKit/535.7 Chrome/16.0.912.63&quot;.

Due to the lack of relatedTarget, I have not found a feasible workaround for doing consistent effects based on dragenter/dragleave, beyond keeping extra state outside of the events that keeps track of whether any dragenter events have been triggered on child element.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>630831</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Holmquist">mtraceur</who>
    <bug_when>2012-05-22 15:37:38 -0700</bug_when>
    <thetext>I can confirm this happening with Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/12.04 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19

It would be awesome if someone could implement this, instead of leaving drag events broken, because it really makes things difficult.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>701102</commentid>
    <comment_count>5</comment_count>
    <who name="Fernando Guillen">fguillen.mail</who>
    <bug_when>2012-08-21 14:01:55 -0700</bug_when>
    <thetext>Same issue here:

Having this nested DOM elements:

&lt;div id=&quot;drop&quot;&gt;
  &lt;div&gt;drop here&lt;/div&gt;
&lt;/div&gt;​

I want to capture dragenter and dragleave in the whole #drop element so I can play with its CSS:

$(&quot;#drop&quot;).on( &quot;dragenter&quot;, function() {
  $(&quot;#drop&quot;).addClass( &quot;dragOver&quot; );
});

$(&quot;#drop&quot;).on( &quot;dragleave&quot;, function() {
  $(&quot;#drop&quot;).removeClass( &quot;dragOver&quot; );
});

The problem is that when I&apos;m dragging over this element and my mouse arrives to the nested element the dragleave event is triggered so I lost my CSS behavior.

This behavior is completely non-consistent with other events like mouesenter and mouseleave which work properly with nested elements.

Another non-consistent behavior is that if I move out of the nested element again the dragenter event is not triggered, and I have to leave completely the outer element and go again into it so the dragenter event is triggered.

Check the jsFiddle example:  http://jsfiddle.net/fguillen/473kH/ in this example you can play with the normal mouse events and check their behavior in comparison with the drag events.

StackOverflow thread:  http://stackoverflow.com/questions/10867506/dragleave-of-parent-element-fires-when-dragging-over-children-elements

Failing in:

Chrome OSX
Firefox OSX
Safari OSX</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>701104</commentid>
    <comment_count>6</comment_count>
    <who name="Fernando Guillen">fguillen.mail</who>
    <bug_when>2012-08-21 14:02:28 -0700</bug_when>
    <thetext>Another StackOverflow thread:  http://stackoverflow.com/questions/7110353/html5-dragleave-fired-when-hovering-a-child-element</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>745631</commentid>
    <comment_count>7</comment_count>
    <who name="">caqittepp-549</who>
    <bug_when>2012-10-18 15:22:55 -0700</bug_when>
    <thetext>This is fixed in Firefox with either relatedTarget or dragexit.
Either would be welcome since it&apos;s now a year later and still not possible to do drag and drop without hacks in the world&apos;s most advanced and most used browser.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>937891</commentid>
    <comment_count>8</comment_count>
    <who name="Robert Kieffer">broofa</who>
    <bug_when>2013-10-09 05:59:52 -0700</bug_when>
    <thetext>Chrome version of this bug: https://code.google.com/p/chromium/issues/detail?id=159534
Mozilla bug where this issue was fixed in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=458613

Mozilla&apos;s support for the relatedTarget attribute solves this problem, and makes sense given how the mechanics of mouseover/mouseout events are identical to dragenter/dragleave events.  It&apos;d be awesome if we could have consistent support for this across browsers.  This is definitely a thorn in the side of developers want to implement dropzone effects on all but the simplest DOM structures.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1478886</commentid>
    <comment_count>9</comment_count>
    <who name="sunpietro">piotr.nalepa</who>
    <bug_when>2018-11-15 07:18:57 -0800</bug_when>
    <thetext>I have found this issue in Safari 12.0.1 (13606.2.104.1.2). Seems like it&apos;s still not fixed.

Here&apos;s the updated fiddle (I&apos;ve forked the one mentioned earlier and updated it a bit) http://jsfiddle.net/7tfm5eL1/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1510467</commentid>
    <comment_count>10</comment_count>
    <who name="Michael Puckett">michaelcpuckett</who>
    <bug_when>2019-02-27 09:54:00 -0800</bug_when>
    <thetext>This has been fixed in Chrome

https://bugs.chromium.org/p/chromium/issues/detail?id=159534

I believe this means the bug now exists only Safari.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1732774</commentid>
    <comment_count>11</comment_count>
    <who name="Feross Aboukhadijeh">feross</who>
    <bug_when>2021-02-23 20:43:18 -0800</bug_when>
    <thetext>This issue still exists in Safari. It does not exist in Chrome or Firefox. Please fix it. It&apos;s causing me to need hacky setTimeout() code to work around this issue in my drag-drop library with 150k downloads per month: https://github.com/feross/drag-drop</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1830560</commentid>
    <comment_count>12</comment_count>
    <who name="Guillaume">guillaume.brunerie</who>
    <bug_when>2022-01-13 08:42:50 -0800</bug_when>
    <thetext>It has now been more than 10 years since the original bug report, and it is still impossible to reliably determine whether a dragleave event actually left the element.
Is there any plan to fix it?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1879703</commentid>
    <comment_count>13</comment_count>
    <who name="">alexreardon</who>
    <bug_when>2022-07-01 03:47:31 -0700</bug_when>
    <thetext>I can confirm that `event.relatedTarget` appears to always be `null` on `dragleave` events in Safari 15.5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1882318</commentid>
    <comment_count>14</comment_count>
    <who name="">alexreardon</who>
    <bug_when>2022-07-11 18:59:55 -0700</bug_when>
    <thetext>Here is a reproducible test case: https://codesandbox.io/s/event-relatedtarget-for-dragenter-and-dragleave-safari-bug-gpph01

`event.relatedTarget` is always `null` for `dragenter` and `dragleave` events</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1882330</commentid>
    <comment_count>15</comment_count>
    <who name="">alexreardon</who>
    <bug_when>2022-07-11 21:28:13 -0700</bug_when>
    <thetext>New bug to track that both dragenter and dragleave don&apos;t have event.relatedTarget set -&gt; https://bugs.webkit.org/show_bug.cgi?id=242627</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1882567</commentid>
    <comment_count>16</comment_count>
    <who name="Sam Sneddon [:gsnedders]">gsnedders</who>
    <bug_when>2022-07-12 14:21:24 -0700</bug_when>
    <thetext>(In reply to alexreardon from comment #15)
&gt; New bug to track that both dragenter and dragleave don&apos;t have
&gt; event.relatedTarget set -&gt; https://bugs.webkit.org/show_bug.cgi?id=242627

Let&apos;s just generalise this bug and close the other.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1882570</commentid>
    <comment_count>17</comment_count>
    <who name="Sam Sneddon [:gsnedders]">gsnedders</who>
    <bug_when>2022-07-12 14:21:55 -0700</bug_when>
    <thetext>*** Bug 242627 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1882874</commentid>
    <comment_count>18</comment_count>
    <who name="">alexreardon</who>
    <bug_when>2022-07-12 18:19:06 -0700</bug_when>
    <thetext>Here is a workaround for this bug. It is a decent amount of code 😢

https://gist.github.com/alexreardon/10c595cbb840608a2828db56df99fa79</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910618</commentid>
    <comment_count>19</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-11-06 04:53:47 -0800</bug_when>
    <thetext>I tried to merge Blink patch in below PR request but I think it is beyond expertise to do so, it compiles on few platforms but not on all:

Link - https://github.com/WebKit/WebKit/pull/5929

Few build errors are easy to fix but in general, I think I might not be able to do it.

Appreciate if someone else look into it. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2011974</commentid>
    <comment_count>20</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-02-08 15:43:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/122588344&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187182</commentid>
    <comment_count>21</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2026-03-04 17:31:06 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/59939</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187476</commentid>
    <comment_count>22</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2026-03-05 12:53:49 -0800</bug_when>
    <thetext>(In reply to alexreardon from comment #18)
&gt; Here is a workaround for this bug. It is a decent amount of code 😢
&gt; 
&gt; https://gist.github.com/alexreardon/10c595cbb840608a2828db56df99fa79

The current PR produces the same behavior in Safari and Chrome on alexreardon@gmail.com&apos;s test case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2188036</commentid>
    <comment_count>23</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-03-06 23:56:19 -0800</bug_when>
    <thetext>Committed 308850@main (e0f194b565c5): &lt;https://commits.webkit.org/308850@main&gt;

Reviewed commits have been landed. Closing PR #59939 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191141</commentid>
    <comment_count>24</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2026-03-17 14:53:12 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/58567</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2191860</commentid>
    <comment_count>25</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-03-19 15:42:47 -0700</bug_when>
    <thetext>Committed 305413.526@safari-7624-branch (d7d2dbf9ce7e): &lt;https://commits.webkit.org/305413.526@safari-7624-branch&gt;

Reviewed commits have been landed. Closing PR #4629 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>104491</attachid>
            <date>2011-08-19 04:59:19 -0700</date>
            <delta_ts>2011-08-19 04:59:19 -0700</delta_ts>
            <desc>Test case</desc>
            <filename>dragleave.html</filename>
            <type>text/html</type>
            <size>768</size>
            <attacher>pimvdb</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxoZWFkPg0KICA8dGl0bGU+ZHJhZ2xlYXZlIGlzc3Vl
PC90aXRsZT4NCg0KICA8c2NyaXB0IHR5cGU9J3RleHQvamF2YXNjcmlwdCc+DQogICAgd2luZG93
Lm9ubG9hZD1mdW5jdGlvbigpew0KICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2Ryb3An
KS5hZGRFdmVudExpc3RlbmVyKCdkcmFnbGVhdmUnLA0KICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uKGUpIHsNCiAgICAgICAgICBj
b25zb2xlLmxvZyhlLnJlbGF0ZWRUYXJnZXQpOw0KICAgICAgfSk7DQoNCiAgICAgIGRvY3VtZW50
LmdldEVsZW1lbnRCeUlkKCdkcmFnJykuYWRkRXZlbnRMaXN0ZW5lcignZHJhZ3N0YXJ0JywNCiAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmdW5j
dGlvbihlKSB7DQogICAgICAgICAgZS5hbGxvd2VkRWZmZWN0ID0gImNvcHkiOw0KICAgICAgICAg
IGUuZGF0YVRyYW5zZmVyLnNldERhdGEoInRleHQvcGxhaW4iLCAidGVzdCIpOw0KICAgICAgfSk7
DQogICAgfQ0KICA8L3NjcmlwdD4NCg0KPC9oZWFkPg0KPGJvZHk+DQoNCiAgPGRpdiBpZD0iZHJh
ZyIgZHJhZ2dhYmxlPSJ0cnVlIj5kcmFnIG1lPC9kaXY+DQoNCiAgPGhyPg0KDQogIDxkaXYgaWQ9
ImRyb3AiPg0KICAgIGRyb3AgaGVyZQ0KICAgIDxwPmNoaWxkPC9wPg0KICAgIHBhcmVudA0KICA8
L2Rpdj4NCg0KPC9ib2R5Pg0KPC9odG1sPg0K
</data>

          </attachment>
      

    </bug>

</bugzilla>