-
Notifications
You must be signed in to change notification settings - Fork 47.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simulate.mouseEnter and Simulate.mouseLeave not working #1297
Comments
Yeah, unfortunately mouseEnter/mouseLeave don't get simulated properly at the moment due to their unique bubbling situation. The biggest blocker here is picking a good API, I think. Maybe just |
Why should the user care about where the mouse moves from/to? Perhaps this can be handled internally? Is the problem due to bubbling here? I may need to dive into the code a little more to get a better understanding and stop saying nonsense :P |
Yes, it's due to bubbling. If you have the DOM structure
and your mouse moves from C to D, then C and B receive mouseleave events, D receives a mouseenter event, and A receives nothing. All other events bubble up to the root. Perhaps it's good enough to just make simulated mouseEnter and mouseLeave events not bubble at all. |
That would work at least where I was trying to test. While testing I generally don't need anything too complex, just making sure the right behavior triggers when the event happens. Hopefully that's the way others do as well |
(As a workaround for now, you can use SimulateNative.mouseOver and SimulateNative.mouseOut (making sure to specify relatedTarget appropriately on each) and together they will cause React to fire onMouseEnter and onMouseLeave events.) |
Do we have a good solution for such case now? I'm trying my solution but feeling so tricky. componentDidMount: ->
root = @refs.root.getDOMNode()
root.onmouseenter = @onMouseEnter
root.onmouseleave = @onMouseLeave
onMouseEnter: (event) ->
console.log 'enter\t', event.target.className
onMouseLeave: (event) ->
console.log 'leave\t', event.target.className And I got still quite strange results:
|
@spicyj can you give an example. I can't find any documentation on SimulateNative or how to set relatedTarget appropriately? |
@ryanzec You want to do something like this: function simulateMouseOver(from, to) {
simulateNative.mouseOut(from, { relatedTarget: to });
simulateNative.mouseOver(to, { relatedTarget: from });
} The simulates the mouse moving |
Do we have a good solution for such case now? or It can not be solved? |
I am manually applying this patch until it is pulled into the core: |
Fixes facebook#1297. onMouseEnter and onMouseLeave shouldn't *actually* use direct dispatch, but doing so is more useful than doing nothing (and I don't think it precludes adding proper enter/leave dispatching later, either). Test Plan: grunt test
Any update on this? |
I was able to get my tests to pass using SimulateNative. Here's my codez: // and_or_component.jsx
render: function () {
var props = {
className: 'chain and-or',
onMouseLeave: this._handleMouseLeave,
onClick: this._toggleEditing
};
return (
<span {...props}>
Some content here
</span>
);
},
_handleMouseLeave: function () {
this.setState({editing: false});
},
// and_or_component.jsx.test
it('sets state to editing:false when the mouse leaves', function () {
var and_or = React.TestUtils.renderIntoDocument(<AndOr />);
var node = and_or.getDOMNode();
React.TestUtils.Simulate.click(node);
React.TestUtils.SimulateNative.mouseOut(node);
expect(and_or.state.editing).to.equal(false);
}); Test results:
|
@brianblocker I tried that using both |
@ryanzec Passed
Failed
Update:This seems to also work: |
No update so far? Maybe some workarounds? |
Sorry, really missed it. Thanks for it! |
While testing I wanted to simulate
mouseEnter
andmouseLeave
events, but for some reason they are not firing the handlers in the component.Here's a fiddle to show you: http://jsfiddle.net/leoasis/RH2vm/
You'll see that with the Simulate functions, only the click is actually triggered, while the other ones not. With the real events everything works perfectly.
I tried to debug a little bit what's going on, but didn't get much information, especially since it's the first time I'm diving into the events mechanism internals in React.
If you want more info, then I can try and dig a bit deeper, but I think the fiddle is clear enough.
The text was updated successfully, but these errors were encountered: