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

Function initTextarea

packages/react-dom-bindings/src/client/ReactDOMTextarea.js:93–148  ·  view source on GitHub ↗
(
  element: Element,
  value: ?string,
  defaultValue: ?string,
  children: ?string,
)

Source from the content-addressed store, hash-verified

91}
92
93export function initTextarea(
94 element: Element,
95 value: ?string,
96 defaultValue: ?string,
97 children: ?string,
98) {
99 const node: HTMLTextAreaElement = (element: any);
100
101 let initialValue = value;
102
103 // Only bother fetching default value if we're going to use it
104 if (initialValue == null) {
105 if (children != null) {
106 if (!disableTextareaChildren) {
107 if (defaultValue != null) {
108 throw new Error(
109 'If you supply `defaultValue` on a <textarea>, do not pass children.',
110 );
111 }
112
113 if (isArray(children)) {
114 if (children.length > 1) {
115 throw new Error('<textarea> can only have at most one child.');
116 }
117
118 children = children[0];
119 }
120
121 defaultValue = children;
122 }
123 }
124 if (defaultValue == null) {
125 defaultValue = '';
126 }
127 initialValue = defaultValue;
128 }
129
130 const stringValue = getToStringValue(initialValue);
131 node.defaultValue = (stringValue: any); // This will be toString:ed.
132
133 // This is in postMount because we need access to the DOM node, which is not
134 // available until after the component has mounted.
135 const textContent = node.textContent;
136
137 // Only set node.value if textContent is equal to the expected
138 // initial value. In IE10/IE11 there is a bug where the placeholder attribute
139 // will populate textContent as well.
140 // https://developer.microsoft.com/microsoft-edge/platform/issues/101525/
141 if (textContent === stringValue) {
142 if (textContent !== '' && textContent !== null) {
143 node.value = textContent;
144 }
145 }
146
147 track((element: any));
148}
149
150export function hydrateTextarea(

Callers 2

setInitialPropertiesFunction · 0.90
hydratePropertiesFunction · 0.90

Calls 3

getToStringValueFunction · 0.90
trackFunction · 0.90
isArrayFunction · 0.85

Tested by

no test coverage detected