-
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
Fixes chekedLink inconsistency (controlled inputs) #2220
Conversation
cc @petehunt I think this is right but I haven't looked at the valuelink stuff in a long time. Pete might have a better idea. |
it('should make text input controlled with valueLink', function() { | ||
var TextInput = React.createClass({ | ||
getInitialState: function () { | ||
return { text: 'initial' }; |
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.
nit: no spaces within braces
Looks good except a few style nits – mind fixing those up? |
Just bumped into this myself 👍 |
DOMPropertyOperations.setValueForProperty( | ||
rootNode, | ||
'checked', | ||
this.props.checked || false | ||
checked || false |
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.
!!checked
... but that shouldn't be needed either, I'm pretty sure checked
is enough.
fada69d
to
feb45cd
Compare
Sorry for taking so long on this, had a crazy week full of tests at the university. Just made those changes pointed and squashed |
@cirocosta The implementation looks great to me. For completeness, perhaps we should copy/reuse the |
@syranide , agree with you! I added a test for it. What do you think about the location of the test? I think where i put it (not right after the first test for radios) because in this we are relying on ReactLink, which is tested later, so i think it makes sense adding this test after it. This test is also a little bigger than the test for checkbox as radio inputs behave differently from checkboxes, as i stated on the commit description. What do you think? Thanks! |
expect(radioA.checked).toBe(true); | ||
expect(radioB.checked).toBe(false); | ||
|
||
radioA.checked = false; |
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.
While not technically wrong, setting only radioB.checked = true;
is enough.
@cirocosta Checking that ReactLink works before checking specific details of it seems sane yes. I'm not all that familiar with tests myself yet, but apart from my two minor nits it looks good to me at least. :) |
}, | ||
|
||
handleChange: function (value) { | ||
this.forceUpdate(); |
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.
This shouldn't actually be needed I think. It should be safe to just put null
instead of this.handleChange
for ReactLink (applies to all of them).
2579ed1
to
3ed44a9
Compare
Made those changes @syranide . Thinking again it was actually redundant to do those checks. And yeah, assigning |
@@ -281,6 +281,66 @@ describe('ReactDOMInput', function() { | |||
|
|||
}); | |||
|
|||
it('should make radio input controlled with checkedLink', function() { | |||
var RadioInput = React.createClass({ |
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.
var RadioInput = React.createClass({
render: function () {
return (
<input
type="radio"
checkedLink={new ReactLink(false, null)} />
);
}
});
Should be enough I think.
Technically this should even be enough:
var stub = ReactTestUtils.renderIntoDocument(
<input type="radio" checkedLink={new ReactLink(false, null)} />
);
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.
actually the second arg must be a function (emptyFunction
could be used) or it will throw as i remember. I'll take a look 👍
Thanks for the catch. Much more concise now @syranide :)
Getting the checked value directly from `this.props.checked` was causing an inconsistency between the expected behavior when using `checkedLink`. This commit addresses that inconsistent behavior and adds test to check if it is producing controlled inputs as we expect for checkbox, text and radio types.
3ed44a9
to
4e9dbb2
Compare
There's no doubt to me that the fix is correct 👍 In light of separate discussions about possibly dropping ReactLink support from core, having tests for non-ReactLink controlled inputs too would probably be a good idea. But I'll let @zpao weigh in on that (sorry for being annoying :)). |
This PR is over a year old, and doesn't merge cleanly. Plus, we're getting rid of value-linking in the core. So... I'm going to close this out. |
As stated on a thread in ReactJS mailing list, there is an inconsistency when using
checkedLink
andvalueLink
. With the second are totally able to create a controlled component, whilst with the first, we aren't.This PR fixes it by getting the value from the
LinkedValueUtils
just like how it is done forvalueLink
, making it consistent.