From d65ce402bc1ddb5f7656506e26a1406daf0c530e Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Fri, 14 Jul 2017 10:05:50 -0400 Subject: [PATCH] Fix uncontrolled radios --- .../dom/client/__tests__/inputValueTracking-test.js | 8 ++------ src/renderers/dom/client/inputValueTracking.js | 2 +- src/renderers/dom/shared/ReactDOMComponent.js | 4 ++++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/renderers/dom/client/__tests__/inputValueTracking-test.js b/src/renderers/dom/client/__tests__/inputValueTracking-test.js index 103964cc1d745..e96a233ba80ed 100644 --- a/src/renderers/dom/client/__tests__/inputValueTracking-test.js +++ b/src/renderers/dom/client/__tests__/inputValueTracking-test.js @@ -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); }); diff --git a/src/renderers/dom/client/inputValueTracking.js b/src/renderers/dom/client/inputValueTracking.js index f0086f03a1530..5b300d5d05f1b 100644 --- a/src/renderers/dom/client/inputValueTracking.js +++ b/src/renderers/dom/client/inputValueTracking.js @@ -31,7 +31,7 @@ function attachTracker(inst, tracker) { } function detachTracker(inst) { - delete inst._wrapperState.valueTracker; + inst._wrapperState.valueTracker = null; } function getValueFromNode(node) { diff --git a/src/renderers/dom/shared/ReactDOMComponent.js b/src/renderers/dom/shared/ReactDOMComponent.js index 6c7a1ca8bd012..77d1df67aa5e4 100644 --- a/src/renderers/dom/shared/ReactDOMComponent.js +++ b/src/renderers/dom/shared/ReactDOMComponent.js @@ -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);