Skip to content
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

Merged
merged 4 commits into from
Apr 14, 2016

Conversation

nhunzaker
Copy link
Contributor

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 and textarea wrappers.

Third times a charm! I promise I won't let this hang for another year (though I still have one day 😄).


Fixes #1790

@@ -81,7 +82,7 @@ var ReactDOMInput = {
onChange: inst._wrapperState.onChange,
});

return nativeProps;
return DisabledInputUtils.getNativeProps(inst, nativeProps);
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@@ -81,7 +82,7 @@ var ReactDOMInput = {
onChange: inst._wrapperState.onChange,
});

return nativeProps;
return nativeProps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noooooo

@gaearon gaearon added this to the 15.x milestone Mar 29, 2016
@facebook-github-bot
Copy link

@nhunzaker updated the pull request.

@nhunzaker
Copy link
Contributor Author

@gaearon This is where I am at to reduce allocations:

nhunzaker#1

What do you think?

@gaearon
Copy link
Collaborator

gaearon commented Mar 29, 2016

I missed that you are reusing the props when it’s not disabled. In this case I think it is fine as is.
2eeebf9 solved my concern but maybe somebody else has more.

@nhunzaker
Copy link
Contributor Author

Cool. In the mean time I'll fix that semicolon!

@gaearon
Copy link
Collaborator

gaearon commented Mar 29, 2016

I tested this on every major browser on OS X, and in IE9+ and Edge on Windows.
It looks good to me so I’m marking as accepted and setting 15.x milestone.
@zpao and @spicyj, if you have any objections please let me know.

// Copy the props, except the mouse listeners
var nativeProps = {};
for (var key in props) {
if (props.hasOwnProperty(key) && !disableableMouseListenerNames[key]) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done it 6a1b3cc

@sophiebits
Copy link
Collaborator

I don't feel strongly either way. This could theoretically be breaking so probably shouldn't go out in a patch release.

@gaearon
Copy link
Collaborator

gaearon commented Mar 29, 2016

Is it likely somebody relies on onChange firing on disabled elements in IE when it isn’t the case for other browsers? Not trolling, just not sure how often such situations happen in practice.

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?

@facebook-github-bot
Copy link

@nhunzaker updated the pull request.

@sophiebits
Copy link
Collaborator

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.

@nhunzaker
Copy link
Contributor Author

@spicyj I did some work on that here:#1820 (comment)

@sophiebits
Copy link
Collaborator

So no browsers fire mouse events on disabled inputs normally? If so, this seems smart.

@nhunzaker
Copy link
Contributor Author

@spicyj That has been my observation.

@sophiebits
Copy link
Collaborator

@nhunzaker Thanks for the investigation and for confirming.

@nhunzaker
Copy link
Contributor Author

@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?

@sophiebits
Copy link
Collaborator

That would seem to also work. I don't have a strong feeling on which is better.

@nhunzaker
Copy link
Contributor Author

@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.

@nhunzaker
Copy link
Contributor Author

Just updated this with master.

@gaearon
Copy link
Collaborator

gaearon commented Mar 31, 2016

We’ll cut 15 and get back to this asap.

@nhunzaker
Copy link
Contributor Author

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.
@facebook-github-bot
Copy link

@nhunzaker updated the pull request.

@gaearon gaearon modified the milestones: 15.x, 15.0.x Apr 9, 2016
@gaearon gaearon merged commit 36e4fe5 into facebook:master Apr 14, 2016
@gaearon
Copy link
Collaborator

gaearon commented Apr 14, 2016

Don’t see any reason not to get this in. Thanks!

@jimfb
Copy link
Contributor

jimfb commented Apr 14, 2016

Thanks @nhunzaker and @gaearon!

@nhunzaker
Copy link
Contributor Author

Hizzah!

@zpao
Copy link
Member

zpao commented Apr 22, 2016

@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?

@gaearon
Copy link
Collaborator

gaearon commented Apr 22, 2016

@zpao

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.

@zpao
Copy link
Member

zpao commented Apr 22, 2016

Cool, thanks! I just wanted to double since I didn't look closely.

@zpao zpao modified the milestones: 15.0.2, 15.0.x Apr 28, 2016
zpao pushed a commit that referenced this pull request Apr 28, 2016
Disabled inputs should not respond to clicks in IE
(cherry picked from commit 36e4fe5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disabled input still clickable in IE11
6 participants