-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Do not extract mouse events for children of disabled parents #8329
Conversation
7fd6845
to
1ffbdab
Compare
Thanks for sending this in. I think this makes sense though we will need to change it for fiber soon. If this cherry-picks cleanly from master, can you send the PR to master instead and then we'll pick it over? Travis is also failing but I'm not sure why. I restarted it. cc @sebmarkbage who might want it written a different way |
@spicyj I just added one more test to be sure we also cover the case when a child is the element with the mouse handler prop. Master's event listening is definitely different, but I think we may be able to use the same technique. I'll give it a shot. |
I don't think it's valid to nest interactive elements so we should be able to bail out and stop climbing once we encounter an element where isInteractive returns true. |
Ideally we should do this during We could make |
If an element is nested within an interactive element that is disabled, and has its own event handler, it looks like it still triggers the event handler. https://jsfiddle.net/outdxpb9/ <button disabled>
<span onclick="window.alert('clicked')">
Click me
</span>
</button> Correct me if I'm wrong, but won't this change prevent the click handler on the
@sebmarkbage I think that's close to what I suggested doing here, right? |
@aweary ah got it. Very interesting. I'll update the second test to match that. |
There's an extra wrench thrown in here: http://codepen.io/nhunzaker/pen/XNpVJv
In the example above, the label will tricker a click event, but the button and fieldset will not. I think the rules here are:
|
59e7d36
to
2ccd14e
Compare
Okay. I've added this logic to
I think I'm on the right track, and all tests pass, but I don't think this is a valid solution yet. I have a couple of outstanding questions:
|
dd4850e
to
8c6e9be
Compare
Neat! I was able to fix the Fiber test errors (though I don't understand Fiber very well, and it probably needs 3 shrewed 👀). I noticed that SimulateNative was double-dispatching events, so I fixed that too (which I could PR against master if you want). Basically getting the parent instance was fixed in So cool! Even closer to Fiber being ready! |
|
||
function shouldIgnoreElement(inst) { | ||
if (inst && isInteractive(inst)) { | ||
if (ReactDOMFeatureFlags.useFiber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not sufficient because we can use ReactDOM and ReactDOMFiber at the same time when the flag is not on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. ReactTreeTraversal
uses this check:
if (typeof inst.tag === 'number') {
Is that the preferred route? Would it be worth making that a more established convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry... tunnel vision. There's also the condition above it:
if (inst._hostParent !== undefined) {
return inst._hostParent;
}
Which could be subbed out for inst._currentElement
in this case.
👍 for @nhunzaker |
Has anyone noticed behaviour differs per browser, e.g. Chrome triggers browser events on children of disabled elements, Firefox does not. Is this pull request more of a cross-browser fix? |
@mattfysh Yes, browsers behave differently.Not sure about the expected behavior in React.Here are my test results without React. Cases:
Behaviors:
Note that the event target in IE is always the disabled element. |
Closing as stale. |
Potential fix for #8308. React (my fault) only sifts out mouse events for disabled elements that are the direct target of dispatch. If an element is the child of a disabled parent, the event incorrectly dispatches because
SimpleEventPlugin
doesn't see adisabled
prop. For example:Incorrectly fires the onClick handler
Original test case (From that issue) here:
https://jsfiddle.net/rcataldo/69z2wepo/62589/