* Sets the value for a property on a node. * * @param {DOMElement} node * @param {string} name * @param {*} value
(node, name, value, isCustomComponentTag)
| 4372 | * @param {*} value |
| 4373 | */ |
| 4374 | function setValueForProperty(node, name, value, isCustomComponentTag) { |
| 4375 | var propertyInfo = getPropertyInfo(name); |
| 4376 | if (shouldIgnoreAttribute(name, propertyInfo, isCustomComponentTag)) { |
| 4377 | return; |
| 4378 | } |
| 4379 | if (shouldRemoveAttribute(name, value, propertyInfo, isCustomComponentTag)) { |
| 4380 | value = null; |
| 4381 | } |
| 4382 | // If the prop isn't in the special list, treat it as a simple attribute. |
| 4383 | if (isCustomComponentTag || propertyInfo === null) { |
| 4384 | if (isAttributeNameSafe(name)) { |
| 4385 | var _attributeName = name; |
| 4386 | if (value === null) { |
| 4387 | node.removeAttribute(_attributeName); |
| 4388 | } else { |
| 4389 | node.setAttribute(_attributeName, '' + value); |
| 4390 | } |
| 4391 | } |
| 4392 | return; |
| 4393 | } |
| 4394 | var mustUseProperty = propertyInfo.mustUseProperty; |
| 4395 | |
| 4396 | if (mustUseProperty) { |
| 4397 | var propertyName = propertyInfo.propertyName; |
| 4398 | |
| 4399 | if (value === null) { |
| 4400 | var type = propertyInfo.type; |
| 4401 | |
| 4402 | node[propertyName] = type === BOOLEAN ? false : ''; |
| 4403 | } else { |
| 4404 | // Contrary to `setAttribute`, object properties are properly |
| 4405 | // `toString`ed by IE8/9. |
| 4406 | node[propertyName] = value; |
| 4407 | } |
| 4408 | return; |
| 4409 | } |
| 4410 | // The rest are treated as attributes with special cases. |
| 4411 | var attributeName = propertyInfo.attributeName, |
| 4412 | attributeNamespace = propertyInfo.attributeNamespace; |
| 4413 | |
| 4414 | if (value === null) { |
| 4415 | node.removeAttribute(attributeName); |
| 4416 | } else { |
| 4417 | var _type = propertyInfo.type; |
| 4418 | |
| 4419 | var attributeValue = void 0; |
| 4420 | if (_type === BOOLEAN || _type === OVERLOADED_BOOLEAN && value === true) { |
| 4421 | attributeValue = ''; |
| 4422 | } else { |
| 4423 | // `setAttribute` with objects becomes only `[object]` in IE8/9, |
| 4424 | // ('' + value) makes it output the correct toString()-value. |
| 4425 | attributeValue = '' + value; |
| 4426 | } |
| 4427 | if (attributeNamespace) { |
| 4428 | node.setAttributeNS(attributeNamespace, attributeName, attributeValue); |
| 4429 | } else { |
| 4430 | node.setAttribute(attributeName, attributeValue); |
| 4431 | } |
no test coverage detected