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

[#13171] Needless checkbox warning when using onClick instead of onChange #13175

Closed
wants to merge 1 commit into from
Closed

[#13171] Needless checkbox warning when using onClick instead of onChange #13175

wants to merge 1 commit into from

Conversation

y-gagar1n
Copy link

Fixes #13171

Adds additional check for onClick presence before showing the warning.

@gaearon
Copy link
Collaborator

gaearon commented Jul 17, 2018

Are there any cases where React's onChange fires but onClick doesn't?

@philipp-spiess
Copy link
Contributor

Nope, we internally use onClick as well:

function shouldUseClickEvent(elem) {
// Use the `click` event to detect changes to checkbox and radio inputs.
// This approach works across all browsers, whereas `change` does not fire
// until `blur` in IE8.
const nodeName = elem.nodeName;
return (
nodeName &&
nodeName.toLowerCase() === 'input' &&
(elem.type === 'checkbox' || elem.type === 'radio')
);
}
function getTargetInstForClickEvent(topLevelType, targetInst) {
if (topLevelType === TOP_CLICK) {
return getInstIfValueChanged(targetInst);
}
}

@gaearon
Copy link
Collaborator

gaearon commented Jul 17, 2018

Hmm. Then what's the use of allowing both events in this case? Seems like nudging towards just one makes it easier for e.g. third party component developers who need to decide on their event naming.

@philipp-spiess
Copy link
Contributor

I also think that makes more sense. It's also more consistent as we currently require an onChange handler for all controlled inputs IIRC.

@gaearon
Copy link
Collaborator

gaearon commented Jul 17, 2018

Okay, I'll close it then. There are no benefits to using onClick in React — so let's keep the warning to encourage consistency.

@gaearon gaearon closed this Jul 17, 2018
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.

4 participants