MCPcopy Create free account
hub / github.com/reactjs/react-rails / updateWrapper

Function updateWrapper

lib/assets/react-source/development/react.js:5558–5618  ·  view source on GitHub ↗
(element, props)

Source from the content-addressed store, hash-verified

5556 }
5557 }
5558 function updateWrapper(element, props) {
5559 var node = element;
5560
5561 {
5562 var controlled = isControlled(props);
5563
5564 if (!node._wrapperState.controlled && controlled && !didWarnUncontrolledToControlled) {
5565 error('A component is changing an uncontrolled input of type %s to be controlled. ' + 'Input elements should not switch from uncontrolled to controlled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type);
5566
5567 didWarnUncontrolledToControlled = true;
5568 }
5569
5570 if (node._wrapperState.controlled && !controlled && !didWarnControlledToUncontrolled) {
5571 error('A component is changing a controlled input of type %s to be uncontrolled. ' + 'Input elements should not switch from controlled to uncontrolled (or vice versa). ' + 'Decide between using a controlled or uncontrolled input ' + 'element for the lifetime of the component. More info: https://fb.me/react-controlled-components', props.type);
5572
5573 didWarnControlledToUncontrolled = true;
5574 }
5575 }
5576
5577 updateChecked(element, props);
5578 var value = getToStringValue(props.value);
5579 var type = props.type;
5580
5581 if (value != null) {
5582 if (type === 'number') {
5583 if (value === 0 && node.value === '' || // We explicitly want to coerce to number here if possible.
5584 // eslint-disable-next-line
5585 node.value != value) {
5586 node.value = toString(value);
5587 }
5588 } else if (node.value !== toString(value)) {
5589 node.value = toString(value);
5590 }
5591 } else if (type === 'submit' || type === 'reset') {
5592 // Submit/reset inputs need the attribute removed completely to avoid
5593 // blank-text buttons.
5594 node.removeAttribute('value');
5595 return;
5596 }
5597
5598 {
5599 // When syncing the value attribute, the value comes from a cascade of
5600 // properties:
5601 // 1. The value React property
5602 // 2. The defaultValue React property
5603 // 3. Otherwise there should be no change
5604 if (props.hasOwnProperty('value')) {
5605 setDefaultValue(node, props.type, value);
5606 } else if (props.hasOwnProperty('defaultValue')) {
5607 setDefaultValue(node, props.type, getToStringValue(props.defaultValue));
5608 }
5609 }
5610
5611 {
5612 // When syncing the checked attribute, it only changes when it needs
5613 // to be removed, such as transitioning from a checkbox into a text input
5614 if (props.checked == null && props.defaultChecked != null) {
5615 node.defaultChecked = !!props.defaultChecked;

Callers 3

restoreControlledStateFunction · 0.85
updateNamedCousinsFunction · 0.85
updatePropertiesFunction · 0.85

Calls 6

isControlledFunction · 0.85
updateCheckedFunction · 0.85
getToStringValueFunction · 0.85
toStringFunction · 0.85
setDefaultValueFunction · 0.85
errorFunction · 0.70

Tested by

no test coverage detected