( domElement: Element, tag: string, key: string, value: mixed, props: any, prevValue: mixed, )
| 339 | const xmlNamespace = 'http://www.w3.org/XML/1998/namespace'; |
| 340 | |
| 341 | function setProp( |
| 342 | domElement: Element, |
| 343 | tag: string, |
| 344 | key: string, |
| 345 | value: mixed, |
| 346 | props: any, |
| 347 | prevValue: mixed, |
| 348 | ): void { |
| 349 | switch (key) { |
| 350 | case 'children': { |
| 351 | if (typeof value === 'string') { |
| 352 | if (__DEV__) { |
| 353 | validateTextNesting(value, tag, false); |
| 354 | } |
| 355 | // Avoid setting initial textContent when the text is empty. In IE11 setting |
| 356 | // textContent on a <textarea> will cause the placeholder to not |
| 357 | // show within the <textarea> until it has been focused and blurred again. |
| 358 | // https://github.com/facebook/react/issues/6731#issuecomment-254874553 |
| 359 | const canSetTextContent = |
| 360 | tag !== 'body' && (tag !== 'textarea' || value !== ''); |
| 361 | if (canSetTextContent) { |
| 362 | setTextContent(domElement, value); |
| 363 | } |
| 364 | } else if (typeof value === 'number' || typeof value === 'bigint') { |
| 365 | if (__DEV__) { |
| 366 | // $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint |
| 367 | validateTextNesting('' + value, tag, false); |
| 368 | } |
| 369 | const canSetTextContent = tag !== 'body'; |
| 370 | if (canSetTextContent) { |
| 371 | // $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint |
| 372 | setTextContent(domElement, '' + value); |
| 373 | } |
| 374 | } else { |
| 375 | return; |
| 376 | } |
| 377 | break; |
| 378 | } |
| 379 | // These are very common props and therefore are in the beginning of the switch. |
| 380 | // TODO: aria-label is a very common prop but allows booleans so is not like the others |
| 381 | // but should ideally go in this list too. |
| 382 | case 'className': |
| 383 | setValueForKnownAttribute(domElement, 'class', value); |
| 384 | break; |
| 385 | case 'tabIndex': |
| 386 | // This has to be case sensitive in SVG. |
| 387 | setValueForKnownAttribute(domElement, 'tabindex', value); |
| 388 | break; |
| 389 | case 'dir': |
| 390 | case 'role': |
| 391 | case 'viewBox': |
| 392 | case 'width': |
| 393 | case 'height': { |
| 394 | setValueForKnownAttribute(domElement, key, value); |
| 395 | break; |
| 396 | } |
| 397 | case 'style': { |
| 398 | setValueForStyles(domElement, value, prevValue); |
no test coverage detected