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

Function updateNamedCousins

code/composition/public/app.js:4734–4774  ·  view source on GitHub ↗
(rootNode, props)

Source from the content-addressed store, hash-verified

4732}
4733
4734function updateNamedCousins(rootNode, props) {
4735 var name = props.name;
4736 if (props.type === 'radio' && name != null) {
4737 var queryRoot = rootNode;
4738
4739 while (queryRoot.parentNode) {
4740 queryRoot = queryRoot.parentNode;
4741 }
4742
4743 // If `rootNode.form` was non-null, then we could try `form.elements`,
4744 // but that sometimes behaves strangely in IE8. We could also try using
4745 // `form.getElementsByName`, but that will only return direct children
4746 // and won't include inputs that use the HTML5 `form=` attribute. Since
4747 // the input might not even be in a form. It might not even be in the
4748 // document. Let's just use the local `querySelectorAll` to ensure we don't
4749 // miss anything.
4750 var group = queryRoot.querySelectorAll('input[name=' + JSON.stringify('' + name) + '][type="radio"]');
4751
4752 for (var i = 0; i < group.length; i++) {
4753 var otherNode = group[i];
4754 if (otherNode === rootNode || otherNode.form !== rootNode.form) {
4755 continue;
4756 }
4757 // This will throw if radio buttons rendered by different copies of React
4758 // and the same name are rendered into the same form (same as #1939).
4759 // That's probably okay; we don't support it just as we don't support
4760 // mixing React radio buttons with non-React ones.
4761 var otherProps = getFiberCurrentPropsFromNode$1(otherNode);
4762 !otherProps ? invariant(false, 'ReactDOMInput: Mixing React and non-React radio inputs with the same `name` is not supported.') : void 0;
4763
4764 // We need update the tracked value on the named cousin since the value
4765 // was changed but the input saw no event or value set
4766 updateValueIfChanged(otherNode);
4767
4768 // If this is a controlled radio button group, forcing the input that
4769 // was previously checked to update will cause it to be come re-checked
4770 // as appropriate.
4771 updateWrapper(otherNode, otherProps);
4772 }
4773 }
4774}
4775
4776// In Chrome, assigning defaultValue to certain input types triggers input validation.
4777// 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