Skip to content

Commit

Permalink
Fix uncontrolled radios
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jul 19, 2017
1 parent 6d40e0c commit 1a320eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/renderers/dom/client/__tests__/inputValueTracking-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,11 @@ describe('inputValueTracking', function() {
it('should stop tracking', function() {
inputValueTracking.track(mockComponent);

expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe(
true,
);
expect(mockComponent._wrapperState.valueTracker).not.toEqual(null);

inputValueTracking.stopTracking(mockComponent);

expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe(
false,
);
expect(mockComponent._wrapperState.valueTracker).toEqual(null);

expect(input.hasOwnProperty('value')).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/dom/client/inputValueTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function attachTracker(inst, tracker) {
}

function detachTracker(inst) {
delete inst._wrapperState.valueTracker;
inst._wrapperState.valueTracker = null;
}

function getValueFromNode(node) {
Expand Down
4 changes: 4 additions & 0 deletions src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ ReactDOMComponent.Mixin = {
// happen after `_updateDOMProperties`. Otherwise HTML5 input validations
// raise warnings and prevent the new value from being assigned.
ReactDOMInput.updateWrapper(this);

// We also check that we haven't missed a value update, such as a
// Radio group shifting the checked value to another named radio input.
inputValueTracking.updateValueIfChanged(this);
break;
case 'textarea':
ReactDOMTextarea.updateWrapper(this);
Expand Down

0 comments on commit 1a320eb

Please sign in to comment.