Skip to content

Commit 673bdc3

Browse files
jquenseEthan-Arrowood
authored andcommitted
Update value tracking on cousin radios (facebook#11028)
* fix radio updates * Format fixtures and ReactDOMFiberInput
1 parent bc5d9f1 commit 673bdc3

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

fixtures/dom/src/components/fixtures/input-change-events/RadioGroupFixture.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class RadioGroupFixture extends React.Component {
2626

2727
render() {
2828
const {changeCount} = this.state;
29-
const color = changeCount === 2 ? 'green' : 'red';
29+
const color = changeCount >= 3 ? 'green' : 'red';
3030

3131
return (
3232
<Fixture>

fixtures/dom/src/components/fixtures/input-change-events/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ class InputChangeEvents extends React.Component {
5757
<TestCase.Steps>
5858
<li>Click on the "Radio 2"</li>
5959
<li>Click back to "Radio 1"</li>
60+
<li>Click back to "Radio 2"</li>
6061
</TestCase.Steps>
6162

6263
<TestCase.ExpectedResult>
63-
The <code>onChange</code> call count should equal 2
64+
The <code>onChange</code> call count increment on each value change
65+
(at least 3+)
6466
</TestCase.ExpectedResult>
6567

6668
<RadioGroupFixture />

packages/react-dom/src/client/ReactDOMFiberComponent.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,6 @@ export function updateProperties(
782782
// happen after `updateDOMProperties`. Otherwise HTML5 input validations
783783
// raise warnings and prevent the new value from being assigned.
784784
ReactDOMFiberInput.updateWrapper(domElement, nextRawProps);
785-
786-
// We also check that we haven't missed a value update, such as a
787-
// Radio group shifting the checked value to another named radio input.
788-
inputValueTracking.updateValueIfChanged((domElement: any));
789785
break;
790786
case 'textarea':
791787
ReactDOMFiberTextarea.updateWrapper(domElement, nextRawProps);

packages/react-dom/src/client/ReactDOMFiberInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import warning from 'fbjs/lib/warning';
1515
import * as DOMPropertyOperations from './DOMPropertyOperations';
1616
import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';
1717
import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
18+
import * as inputValueTracking from './inputValueTracking';
1819

1920
type InputWithWrapperState = HTMLInputElement & {
2021
_wrapperState: {
@@ -320,6 +321,11 @@ function updateNamedCousins(rootNode, props) {
320321
'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
321322
'same `name` is not supported.',
322323
);
324+
325+
// We need update the tracked value on the named cousin since the value
326+
// was changed but the input saw no event or value set
327+
inputValueTracking.updateValueIfChanged(otherNode);
328+
323329
// If this is a controlled radio button group, forcing the input that
324330
// was previously checked to update will cause it to be come re-checked
325331
// as appropriate.

packages/react-dom/src/client/inputValueTracking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type ValueTracker = {
1212
setValue(value: string): void,
1313
stopTracking(): void,
1414
};
15-
type WrapperState = {_valueTracker: ?ValueTracker};
15+
type WrapperState = {_valueTracker?: ?ValueTracker};
1616
type ElementWithValueTracker = HTMLInputElement & WrapperState;
1717

1818
function isCheckable(elem: HTMLInputElement) {

0 commit comments

Comments
 (0)