Skip to content
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

Update value tracking on cousin radios #11028

Merged
merged 3 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RadioGroupFixture extends React.Component {

render() {
const {changeCount} = this.state;
const color = changeCount === 2 ? 'green' : 'red';
const color = changeCount >= 3 ? 'green' : 'red';

return (
<Fixture>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ class InputChangeEvents extends React.Component {
<TestCase.Steps>
<li>Click on the "Radio 2"</li>
<li>Click back to "Radio 1"</li>
<li>Click back to "Radio 2"</li>
</TestCase.Steps>

<TestCase.ExpectedResult>
The <code>onChange</code> call count should equal 2
The <code>onChange</code> call count increment on each value change
(at least 3+)
</TestCase.ExpectedResult>

<RadioGroupFixture />
Expand Down
4 changes: 0 additions & 4 deletions packages/react-dom/src/client/ReactDOMFiberComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,10 +782,6 @@ export function updateProperties(
// happen after `updateDOMProperties`. Otherwise HTML5 input validations
// raise warnings and prevent the new value from being assigned.
ReactDOMFiberInput.updateWrapper(domElement, nextRawProps);

// 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((domElement: any));
break;
case 'textarea':
ReactDOMFiberTextarea.updateWrapper(domElement, nextRawProps);
Expand Down
6 changes: 6 additions & 0 deletions packages/react-dom/src/client/ReactDOMFiberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import warning from 'fbjs/lib/warning';
import * as DOMPropertyOperations from './DOMPropertyOperations';
import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';
import ReactControlledValuePropTypes from '../shared/ReactControlledValuePropTypes';
import * as inputValueTracking from './inputValueTracking';

type InputWithWrapperState = HTMLInputElement & {
_wrapperState: {
Expand Down Expand Up @@ -320,6 +321,11 @@ function updateNamedCousins(rootNode, props) {
'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
'same `name` is not supported.',
);

// We need update the tracked value on the named cousin since the value
// was changed but the input saw no event or value set
inputValueTracking.updateValueIfChanged(otherNode);

// If this is a controlled radio button group, forcing the input that
// was previously checked to update will cause it to be come re-checked
// as appropriate.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/client/inputValueTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ValueTracker = {
setValue(value: string): void,
stopTracking(): void,
};
type WrapperState = {_valueTracker: ?ValueTracker};
type WrapperState = {_valueTracker?: ?ValueTracker};
type ElementWithValueTracker = HTMLInputElement & WrapperState;

function isCheckable(elem: HTMLInputElement) {
Expand Down