( element: Element, value: ?string, defaultValue: ?string, children: ?string, )
| 91 | } |
| 92 | |
| 93 | export 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 | |
| 150 | export function hydrateTextarea( |
no test coverage detected