-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Regression: onChange doesn't fire with defaultChecked and radio inputs #9988
Comments
cc @jquense |
I'm not sure..this is a weird kinda case, The problem seems to be that if you don't control the the group the onChange event doesn't fire (but the value is correct)...The case of mixing defaultChecked and |
Ah fairly certain I know what's happening. The |
addendum this only happens with uncontrolled groups because the I wish uncontrolled inputs didn't exist ;) |
Managed to reproduce this in a simpler test case, defaultChecked is not needed. var Hello = React.createClass({
render: function() {
return <div>
<input type="radio" name="foo" onChange={() => console.log(1)} />
<input type="radio" name="foo" onChange={() => console.log(2)} />
</div>;
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
); Changing between the radio buttons back and forth will only log 1 or 2 once. cc @Linkgoron This seems like an actual bug where the state of React's view of the DOM differs from the actual DOM See Fiddle for example: https://jsfiddle.net/aaqfzzjg/ |
Managed to reproduce the problem comparing 15.3.1 vs 15.6.1, also without defaultChecked |
To sum up the problem is uncontrolled radio/checkbox groups. should probably update the issue title |
Will this issue be fixed down the track? Because this problem is affecting my web app and now I am stuck with the v15.4.1 to make my radio buttons work. |
The easy workaround is to manage the radio buttons with component state, instead of relying on the underlying DOM. But yes, this is a bit annoying. |
This is especially annoying for Redux/MobX users where |
It sure what you mean by that... An app that doesn't use DOM state won't have this problem since it would be using only controlled componenta |
You're right, I meant to say component state. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
In React 15.6.1, this behaviour is changed; In 15.5.4, it fires the change event reliably.
15.6.1 - https://codesandbox.io/embed/VPA42ZnRo
15.5.4 - https://codesandbox.io/embed/JZ0mnE5oy
You'll need to have the console open to get the debugger statement.
In 15.6.1, the first change fires, but all subsequent changes do not fire. In 15.5.4, all changes fire.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 15.6.1 vs React 15.5.4; Chrome latest stable.
The text was updated successfully, but these errors were encountered: