-
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
Disabled inputs should not respond to clicks in IE #6215
Conversation
03b4c59
to
0e63de5
Compare
@@ -81,7 +82,7 @@ var ReactDOMInput = { | |||
onChange: inst._wrapperState.onChange, | |||
}); | |||
|
|||
return nativeProps; | |||
return DisabledInputUtils.getNativeProps(inst, nativeProps); |
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.
Why is DisabledInputUtils.getNativeProps
called last here unlike ReactDOMSelect
and all other components where it is called inline in the assign
call?
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.
Good point. Looking at this again, I've got a new thought regarding assign
. I'll post that in a second.
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.
I'm playing around with an idea to try to save that object allocation, but to directly reply to your comment. It should be consistent with the other components. I'll do that now.
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.
Yeah I think we should really try hard to save allocations here.
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.
Okay. I believe I've addressed the original desire with 2eeebf9. I've also rebased from upstream.
0e63de5
to
2eeebf9
Compare
@@ -81,7 +82,7 @@ var ReactDOMInput = { | |||
onChange: inst._wrapperState.onChange, | |||
}); | |||
|
|||
return nativeProps; | |||
return nativeProps |
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.
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.
@nhunzaker updated the pull request. |
@gaearon This is where I am at to reduce allocations: What do you think? |
I missed that you are reusing the |
Cool. In the mean time I'll fix that semicolon! |
// Copy the props, except the mouse listeners | ||
var nativeProps = {}; | ||
for (var key in props) { | ||
if (props.hasOwnProperty(key) && !disableableMouseListenerNames[key]) { |
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.
There's a small optimization here. No need to check hasOwnProperty
if the key is a disabled event handler.
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.
@gaearon I know you just tested this everywhere, but do you mind if I change this to:
for (var key in props) {
if (!disableableMouseListenerNames[key] && props.hasOwnProperty(key)) {
nativeProps[key] = props[key];
}
}
It'll cut hasOwnProperty
checks.
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.
Sure if you feel this makes a difference. I wouldn’t worry too much about optimizing this code path because usually you only have a handful of disabled inputs on the page.
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.
Oh it might save a few microseconds. I'll go ahead and do it, since I've got everything open still.
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.
Done it 6a1b3cc
I don't feel strongly either way. This could theoretically be breaking so probably shouldn't go out in a patch release. |
Is it likely somebody relies on Maybe we could include it in a minor. We still think it’s a bugfix but minor would be a bit lower risk. Is that what you were saying? |
@nhunzaker updated the pull request. |
From #1790 it wasn't clear to me which browsers are affected. If it is inconsistent across browsers then I'm less worried, but still probably a little better to put it in a minor rather than a patch. |
@spicyj I did some work on that here:#1820 (comment) |
So no browsers fire mouse events on disabled inputs normally? If so, this seems smart. |
@spicyj That has been my observation. |
@nhunzaker Thanks for the investigation and for confirming. |
@spicyj You're welcome! As a final note. I forgot I had some work handling this by hacking the SimpleEventPlugin: nhunzaker/react@nh-fix-disabled-inputs...nhunzaker:nh-disabled-event-plugin Originally, I couldn't get this to work, but with more knowledge about how the synthetic event system works, I was able to get the test suite to pass. It also eliminates the wrapper around Button and saves some extra memory allocations. This isn't fully thought through, but does it jump out as a promising lead? |
That would seem to also work. I don't have a strong feeling on which is better. |
@spicyj I want to keep exploring an event plugin, but I think the safest route is to move forward with what is in this PR. |
6a1b3cc
to
387a36a
Compare
Just updated this with master. |
We’ll cut 15 and get back to this asap. |
Sounds good! |
This commit migrates over the disabled property behavior from ReactDOMButton into a general purpose disabled event filter. It also applies that behavior to inputs, selects, and textareas.
387a36a
to
ec2c542
Compare
@nhunzaker updated the pull request. |
Don’t see any reason not to get this in. Thanks! |
Thanks @nhunzaker and @gaearon! |
Hizzah! |
@gaearon Is this safe in 15.0.x? Seems like could be potentially behavior changing. Or does it just fix a bug in some browsers? |
As far as I tested, it just makes the behavior in older versions of IE (<= 11) consistent with all other browsers that ignore mouse events on disabled inputs. We already had an identical fix for buttons—it just wasn’t wide enough. |
Cool, thanks! I just wanted to double since I didn't look closely. |
Disabled inputs should not respond to clicks in IE (cherry picked from commit 36e4fe5)
This PR reimplements the fix I provided in #3349 using the latest version of React.
Basically, it creates a general purpose utility for filtering events that should not fire when an input is disabled, then it applies that behavior to the
input
,select
andtextarea
wrappers.Third times a charm! I promise I won't let this hang for another year (though I still have one day 😄).
Fixes #1790