MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / updateNamedCousins

Function updateNamedCousins

code/styling/public/app.js:4596–4636  ·  view source on GitHub ↗
(rootNode, props)

Source from the content-addressed store, hash-verified

4594}
4595
4596function updateNamedCousins(rootNode, props) {
4597 var name = props.name;
4598 if (props.type === 'radio' && name != null) {
4599 var queryRoot = rootNode;
4600
4601 while (queryRoot.parentNode) {
4602 queryRoot = queryRoot.parentNode;
4603 }
4604
4605 // If `rootNode.form` was non-null, then we could try `form.elements`,
4606 // but that sometimes behaves strangely in IE8. We could also try using
4607 // `form.getElementsByName`, but that will only return direct children
4608 // and won't include inputs that use the HTML5 `form=` attribute. Since
4609 // the input might not even be in a form. It might not even be in the
4610 // document. Let's just use the local `querySelectorAll` to ensure we don't
4611 // miss anything.
4612 var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
4613
4614 for (var i = 0; i < group.length; i++) {
4615 var otherNode = group[i];
4616 if (otherNode === rootNode || otherNode.form !== rootNode.form) {
4617 continue;
4618 }
4619 // This will throw if radio buttons rendered by different copies of React
4620 // and the same name are rendered into the same form (same as #1939).
4621 // That's probably okay; we don't support it just as we don't support
4622 // mixing React radio buttons with non-React ones.
4623 var otherProps = getFiberCurrentPropsFromNode$1(otherNode);
4624 !otherProps ? invariant(false, 'ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported.') : void 0;
4625
4626 // We need update the tracked value on the named cousin since the value
4627 // was changed but the input saw no event or value set
4628 updateValueIfChanged(otherNode);
4629
4630 // If this is a controlled radio button group, forcing the input that
4631 // was previously checked to update will cause it to be come re-checked
4632 // as appropriate.
4633 updateWrapper(otherNode, otherProps);
4634 }
4635 }
4636}
4637
4638// In Chrome, assigning defaultValue to certain input types triggers input validation.
4639// For number inputs, the display value loses trailing decimal points. For email inputs,

Callers 1

restoreControlledStateFunction · 0.70

Calls 4

invariantFunction · 0.70
updateValueIfChangedFunction · 0.70
updateWrapperFunction · 0.70

Tested by

no test coverage detected