question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mouseenter fires on disabled inputs whereas mouseleave does not

See original GitHub issue

There is an asymmetry to EnterLeave event plugin. Since mouseenter is created from the relativeTarget of the mouseout event it fires even though the target is disabled. Since the mouseleave is the inverse, i.e requires that the disabled element fire a mouseout, it doesn’t fire a mouseleave for the disabled element.

I am pretty sure the correct behavior here is that neither event should fire if its target is disabled, since this mirrors mouseout. No idea if none-chrome browsers have the same behavior for which mouse events fire on disabled elements.

Additional caveat I just realized, React is probably also not firing mousenter events in the case where the mouse leaves a disabled element into a non disabled element

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:26
  • Comments:39 (14 by maintainers)

github_iconTop GitHub Comments

40reactions
andykogcommented, Dec 14, 2016

There is also a css workaroud:

button[disabled] { pointer-events: none; }

Updated @CoryDanielson’s fiddle: https://jsfiddle.net/Sl1v3r/sLsut3cy/

30reactions
andykogcommented, Dec 29, 2015

There is also a problem for elements, containing disabled element. onMouseEnter works, onMouseLeave doesn’t.

<div onMouseEnter={e => console.log("ok")}
     onMouseLeave={e => alert("doesn't work")}
>
    <button disabled={true} style={{ width: "100%" }}>Test</button>
</div>

Native mouseleave event works as expected in the same situation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

html - Mouseenter is never triggered when entering through ...
Mouseenter is never triggered when entering through disabled child element · Move mouse over blue box · Move mouse over checkbox · No...
Read more >
React does not fire onMouseLeave events on a disabled button
React does not fire onMouseLeave events on a disabled button. December 22, 2018 ... Consider removing mouseenter/mouseleave polyfill.
Read more >
11382 (Mouseenter doesn't fire on a disabled input element)
I am thinking we may want to ban only click events with the idea that those are the most common events that should...
Read more >
Moving the mouse: mouseover/out, mouseenter/leave
relatedTarget – is the element from which the mouse came ... Events mouseenter/mouseleave do not bubble. ... Fire Orange Fame, Southeast
Read more >
Element: mouseleave event - Web APIs | MDN
This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found