Skip to content

Commit

Permalink
Allow custom elements extending native ones (#6570)
Browse files Browse the repository at this point in the history
...by passing the `is` attribute as the second param to `createElement`.
See http://webcomponents.org/polyfills/custom-elements/
  • Loading branch information
jscissr authored and zpao committed Apr 29, 2016
1 parent c1e3f7e commit 3d31361
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ ReactDOMComponent.Mixin = {
div.innerHTML = `<${type}></${type}>`;
el = div.removeChild(div.firstChild);
} else {
el = ownerDocument.createElement(this._currentElement.type);
el = ownerDocument.createElement(this._currentElement.type, props.is || null);
}
} else {
el = ownerDocument.createElementNS(
Expand Down
13 changes: 13 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
describe('ReactDOMComponent', function() {
var React;
var ReactDOM;
var ReactDOMFeatureFlags;
var ReactDOMServer;
var inputValueTracking;

beforeEach(function() {
jest.resetModuleRegistry();
React = require('React');
ReactDOM = require('ReactDOM');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
ReactDOMServer = require('ReactDOMServer');
inputValueTracking = require('inputValueTracking');
});
Expand Down Expand Up @@ -906,6 +908,17 @@ describe('ReactDOMComponent', function() {
'or use `props.dangerouslySetInnerHTML`. Check the render method of X.'
);
});

it('should support custom elements which extend native elements', function() {
if (ReactDOMFeatureFlags.useCreateElement) {
var container = document.createElement('div');
spyOn(document, 'createElement').andCallThrough();
ReactDOM.render(<div is="custom-div" />, container);
expect(document.createElement).toHaveBeenCalledWith('div', 'custom-div');
} else {
expect(ReactDOMServer.renderToString(<div is="custom-div" />)).toContain('is="custom-div"');
}
});
});

describe('updateComponent', function() {
Expand Down

0 comments on commit 3d31361

Please sign in to comment.