(type, props, rootContainerElement, parentNamespace)
| 9751 | } |
| 9752 | |
| 9753 | function createElement(type, props, rootContainerElement, parentNamespace) { |
| 9754 | var isCustomComponentTag; // We create tags in the namespace of their parent container, except HTML |
| 9755 | // tags get no namespace. |
| 9756 | |
| 9757 | var ownerDocument = getOwnerDocumentFromRootContainer(rootContainerElement); |
| 9758 | var domElement; |
| 9759 | var namespaceURI = parentNamespace; |
| 9760 | |
| 9761 | if (namespaceURI === HTML_NAMESPACE) { |
| 9762 | namespaceURI = getIntrinsicNamespace(type); |
| 9763 | } |
| 9764 | |
| 9765 | if (namespaceURI === HTML_NAMESPACE) { |
| 9766 | { |
| 9767 | isCustomComponentTag = isCustomComponent(type, props); // Should this check be gated by parent namespace? Not sure we want to |
| 9768 | // allow <SVG> or <mATH>. |
| 9769 | |
| 9770 | if (!isCustomComponentTag && type !== type.toLowerCase()) { |
| 9771 | error('<%s /> is using incorrect casing. ' + 'Use PascalCase for React components, ' + 'or lowercase for HTML elements.', type); |
| 9772 | } |
| 9773 | } |
| 9774 | |
| 9775 | if (type === 'script') { |
| 9776 | // Create the script via .innerHTML so its "parser-inserted" flag is |
| 9777 | // set to true and it does not execute |
| 9778 | var div = ownerDocument.createElement('div'); |
| 9779 | |
| 9780 | div.innerHTML = '<script><' + '/script>'; // eslint-disable-line |
| 9781 | // This is guaranteed to yield a script element. |
| 9782 | |
| 9783 | var firstChild = div.firstChild; |
| 9784 | domElement = div.removeChild(firstChild); |
| 9785 | } else if (typeof props.is === 'string') { |
| 9786 | // $FlowIssue `createElement` should be updated for Web Components |
| 9787 | domElement = ownerDocument.createElement(type, { |
| 9788 | is: props.is |
| 9789 | }); |
| 9790 | } else { |
| 9791 | // Separate else branch instead of using `props.is || undefined` above because of a Firefox bug. |
| 9792 | // See discussion in https://github.com/facebook/react/pull/6896 |
| 9793 | // and discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1276240 |
| 9794 | domElement = ownerDocument.createElement(type); // Normally attributes are assigned in `setInitialDOMProperties`, however the `multiple` and `size` |
| 9795 | // attributes on `select`s needs to be added before `option`s are inserted. |
| 9796 | // This prevents: |
| 9797 | // - a bug where the `select` does not scroll to the correct option because singular |
| 9798 | // `select` elements automatically pick the first item #13222 |
| 9799 | // - a bug where the `select` set the first item as selected despite the `size` attribute #14239 |
| 9800 | // See https://github.com/facebook/react/issues/13222 |
| 9801 | // and https://github.com/facebook/react/issues/14239 |
| 9802 | |
| 9803 | if (type === 'select') { |
| 9804 | var node = domElement; |
| 9805 | |
| 9806 | if (props.multiple) { |
| 9807 | node.multiple = true; |
| 9808 | } else if (props.size) { |
| 9809 | // Setting a size greater than 1 causes a select to behave like `multiple=true`, where |
| 9810 | // it is possible that no option is selected. |
no test coverage detected
searching dependent graphs…