Skip to content

MouseEvent doesn't recognize react's Synthetic onMouseLeave #12978

Closed
@DannyvanHolten

Description

@DannyvanHolten

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

What is the current behavior?
The Javascript MouseEvent doesn't recognize react's synthetic event.

Code example:

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:

This doesn't work: https://jsfiddle.net/Luktwrdm/456/
Whereas this does: https://jsfiddle.net/7xyyyjc5/1/

class App extends React.Component {
  handleMouseLeave = () => {
    console.log('left');
  };

  handleClose = () => {
    const evt = new MouseEvent('onmouseleave', {
      view: window,
      bubbles: true,
      cancelable: true,
    });

    const ele = document.getElementById('element');
    ele.dispatchEvent(evt);
  };

  render() {
    return (
      <div
        id="element"
        onMouseLeave={this.handleMouseLeave}
      >
        <button onClick={this.handleClose}>
          Close
        </button>
      </div>
    );
  }
}

ReactDOM.render(<App name="world" />, document.getElementById('container'));

Click the button and it doesn't trigger the onMouseLeave event.

What is the expected behavior?

That the MouseEvent sees the synthetic event and handles the onMouseLeave correctly.

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

React version 16.2 - all browsers.
Not that I know of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions