MCPcopy
hub / github.com/facebook/react / updateInput

Function updateInput

packages/react-dom-bindings/src/client/ReactDOMInput.js:89–204  ·  view source on GitHub ↗
(
  element: Element,
  value: ?string,
  defaultValue: ?string,
  lastDefaultValue: ?string,
  checked: ?boolean,
  defaultChecked: ?boolean,
  type: ?string,
  name: ?string,
)

Source from the content-addressed store, hash-verified

87}
88
89export function updateInput(
90 element: Element,
91 value: ?string,
92 defaultValue: ?string,
93 lastDefaultValue: ?string,
94 checked: ?boolean,
95 defaultChecked: ?boolean,
96 type: ?string,
97 name: ?string,
98) {
99 const node: HTMLInputElement = (element: any);
100
101 // Temporarily disconnect the input from any radio buttons.
102 // Changing the type or name as the same time as changing the checked value
103 // needs to be atomically applied. We can only ensure that by disconnecting
104 // the name while do the mutations and then reapply the name after that's done.
105 node.name = '';
106
107 if (
108 type != null &&
109 typeof type !== 'function' &&
110 typeof type !== 'symbol' &&
111 typeof type !== 'boolean'
112 ) {
113 if (__DEV__) {
114 checkAttributeStringCoercion(type, 'type');
115 }
116 node.type = type;
117 } else {
118 node.removeAttribute('type');
119 }
120
121 if (value != null) {
122 if (type === 'number') {
123 if (
124 // $FlowFixMe[incompatible-type]
125 (value === 0 && node.value === '') ||
126 // We explicitly want to coerce to number here if possible.
127 // eslint-disable-next-line
128 node.value != (value: any)
129 ) {
130 node.value = toString(getToStringValue(value));
131 }
132 } else if (node.value !== toString(getToStringValue(value))) {
133 node.value = toString(getToStringValue(value));
134 }
135 } else if (type === 'submit' || type === 'reset') {
136 // Submit/reset inputs need the attribute removed completely to avoid
137 // blank-text buttons.
138 node.removeAttribute('value');
139 }
140
141 if (disableInputAttributeSyncing) {
142 // When not syncing the value attribute, React only assigns a new value
143 // whenever the defaultValue React prop has changed. When not present,
144 // React does nothing
145 if (defaultValue != null) {
146 setDefaultValue(node, type, getToStringValue(defaultValue));

Callers 2

updatePropertiesFunction · 0.90

Calls 4

toStringFunction · 0.90
getToStringValueFunction · 0.90
setDefaultValueFunction · 0.85

Tested by

no test coverage detected