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.

onMouseEnter does not fire on an underlaying element if an element above is removed

See original GitHub issue

Do you want to request a feature or report a bug?

Bug - I did do some searching around the issues to see if there was a similar/dupe, but I could not find one.

What is the current behavior?

With 2 elements overlaying on top of each other, if the upper element gets removed while the cursor is over both elements, mouse enter never fires on the element below. I compared this to native browser events and the issue does not appear to persist there (native browser events appear to fire mouse enter for the underlying div when the overlaying div gets removed).

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

CodeSandbox Example

I provided a top level boolean constant to switch between using react’s synthetic events and the native browser events. In the console I keep track of state updates as console logs. The simple way to test - open the console, mouse over the upper div in a position that is also on top of the lower div, click to remove the upper div, the lower div SHOULD fire mouse enter. It does not with synthetic events, but it does with browser events.

What is the expected behavior?

Expected behavior for me would be if react would fire mouse enter on the underlaying div when the upper div is removed.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

"dependencies": {
    "react": "16.5.2",
    "react-dom": "16.5.2",
  },

I have not had a chance to test previous versions.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
elertancommented, Jan 17, 2020

I’m facing a similar problem. I have a list with elements that represent entities, on hover I want to show actions for these entities, such as a delete action. When I delete an entity, the list moves up to fill the ‘gap’ that it would have created, placing the cursor on top of the next element, however this does not trigger the onMouseEnter event on that element, thus not showing the actions.

As far as I’m aware React does not provide other API’s that would allow me to capture an event that the cursor has entered this element when the DOM’s element change position instead of the user moving the mouse. I have also tried onMouseOver, but that also only triggers after the user having to move the mouse.

0reactions
tianzhichcommented, Dec 27, 2022

same problem here

Read more comments on GitHub >

github_iconTop Results From Across the Web

React onMouseEnter not firing in Chrome when element ...
React will currently not fire the onMouseEnter event when an element blocking the event element disappears. This is not the case with ...
Read more >
onmouseleave does not fire if you have mutiple elements react
It is firing when I hover over another element such as the navbar or console but doesn't fire when the mouse leaves the...
Read more >
Element: click event - Web APIs | MDN
Any click events will be fired at the underlying element(s) instead. See this live example for a demonstration. Known workarounds for this bug:....
Read more >
.hover() | jQuery API Documentation
A function to execute when the mouse pointer leaves the element. The .hover() method binds handlers for both mouseenter and mouseleave events. You...
Read more >
Understanding JavaScript Mouse Events By Examples
The mouseleave fires when the mouse cursor is over an element and then moves to the outside of the element's boundaries. Both mouseenter...
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