-
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
onClick firing for disabled buttons in v15.4.0 #8308
Comments
Is the target element the
So if the target is the The result would be an event dispatch on both the button and the span. Again, purely speculative, but maybe it can help out @spicyj until I can look at it in a few hours. |
The target is the
The same but without the
|
@RoccoC 👍 React manipulates the |
I see the function Adding this to the end of /* SimpleEventPlugin.js */
// extractEvents function snip
if (shouldPreventMouseEvent(event._dispatchInstances)) {
return null;
}
return event; |
At no point does any step check to see if the instance for the listener is disabled. Maybe we can do that early on in var listener = listenerAtPhase(inst, event, phase);
if (listener && shouldDispatchListener(inst, event, phase)) {
// only redefine `_dispatchInstances` and _dispatchListener` if it should actually execute
} |
@RoccoC one issue there is I think it would be better if we could prevent the listener from being registered with the event in the first place. |
@aweary aye. Happy to dig into this unless someone has already taken it. Here's a test case: |
Following @aweary's thoughts, I first looked into avoiding the subscription all together. However, it turns out, there are some additional things to figure out there. When React updates a component, it adds/removes event listeners based on whether or not they have changed. This is problematic for disabling events. Changing the The simplest solution does appear to be just making function shouldPreventMouseEvent(inst) {
if (inst) {
var focus = inst;
while (focus) {
if (focus._currentElement && focus._currentElement.props.disabled) {
return isInteractive(focus._tag);
}
focus = focus._hostParent;
}
}
return false;
} Basically bubble up the tree and see if the child is within a disabled parent. If so, return true/false if that element is interactive or not. Side note: it looks like there is a substantial difference in the event implementation between master and |
I sent out this PR for discussion: |
Fix for facebook#8308. This is a bad hack -- EventPluginHub.getListener isn't even DOM-specific -- but this works for now and lets us release 15.4.1.
Fix for #8308. This is a bad hack -- EventPluginHub.getListener isn't even DOM-specific -- but this works for now and lets us release 15.4.1.
Not sure if this was closed or not but I'm still experiencing the issue: (will check different versions): {
"presets": ["es2015", "react", "stage-1"],
} causes my |
Yes but in my ES6 code I do not have an
but when rendered it turns into: <a disabled>
<span className='fa fa-plus-circle'></span>Add Story to Top
</a> Which did not work |
Sorry, I can not follow you. I saw your ES6 code in the Codepen <a disabled={this.state.shouldDisable} onClick={(e) => funcCheck(e)}>
<span>Stuff in button</span>
</a> it's obviously have the A tag in the React render function. Did you put the wrong code in the Codepen ? |
Ok thanks You were correct monkindey. This was actually an issue my babel... and after reinstalling babel and switching from |
Fix for facebook#8308. This is a bad hack -- EventPluginHub.getListener isn't even DOM-specific -- but this works for now and lets us release 15.4.1.
This has since been fixed. |
@gaearon It looks like the bug is back since [email protected] |
If you have a case where this doesn't work properly, please open a new issue. |
not sure if this is related. In react when we set button props I'm just still not certain that this is correct. |
With the latest 15.4.0 ReactJS release,
onClick
is now firing for disabledbutton
elements which have child HTML elements:https://jsfiddle.net/rcataldo/69z2wepo/62589/
In the previous ReactJS version, the onClick handler would not be called.
Note that onClick is not called if I remove the
<span>
from the button.The text was updated successfully, but these errors were encountered: