Skip to content

Commit bcdc52b

Browse files
sorvellSteve Orvelljustinfagnani
authored
[scoped-custom-element-registry] Adds shadowRoot.createElementNS (#582)
* Adds shadowRoot.createElementNS --------- Co-authored-by: Steve Orvell <[email protected]> Co-authored-by: Justin Fagnani <[email protected]>
1 parent aeb2038 commit bcdc52b

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

packages/scoped-custom-element-registry/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14-
- registry in ShadowRootInit; matches current proposal but customElements
14+
- Added support for ShadowRoot.prototype.createElementNS()
15+
16+
- Added the `registry` property to ShadowRootInit to match current proposal. `customElements`
1517
remains supported for compatibility
1618

1719
### Changed

packages/scoped-custom-element-registry/src/scoped-custom-element-registry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ const installScopedCreationMethod = (
656656
};
657657
};
658658
installScopedCreationMethod(ShadowRoot, 'createElement', document);
659+
installScopedCreationMethod(ShadowRoot, 'createElementNS', document);
659660
installScopedCreationMethod(ShadowRoot, 'importNode', document);
660661
installScopedCreationMethod(Element, 'insertAdjacentHTML');
661662

packages/scoped-custom-element-registry/test/ShadowRoot.test.html.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,51 @@ describe('ShadowRoot', () => {
163163
});
164164
});
165165

166+
describe('createElementNS', () => {
167+
it('should create a regular element', () => {
168+
const registry = new CustomElementRegistry();
169+
const shadowRoot = getShadowRoot(registry);
170+
171+
const $el = shadowRoot.createElementNS(
172+
'http://www.w3.org/1999/xhtml',
173+
'div'
174+
);
175+
176+
expect($el).to.not.be.undefined;
177+
expect($el).to.be.instanceof(HTMLDivElement);
178+
});
179+
180+
it(`shouldn't upgrade an element defined in the global registry`, () => {
181+
const {tagName, CustomElementClass} = getTestElement();
182+
customElements.define(tagName, CustomElementClass);
183+
const registry = new CustomElementRegistry();
184+
const shadowRoot = getShadowRoot(registry);
185+
186+
const $el = shadowRoot.createElementNS(
187+
'http://www.w3.org/1999/xhtml',
188+
tagName
189+
);
190+
191+
expect($el).to.not.be.undefined;
192+
expect($el).to.not.be.instanceof(CustomElementClass);
193+
});
194+
195+
it(`should upgrade an element defined in the custom registry`, () => {
196+
const {tagName, CustomElementClass} = getTestElement();
197+
const registry = new CustomElementRegistry();
198+
registry.define(tagName, CustomElementClass);
199+
const shadowRoot = getShadowRoot(registry);
200+
201+
const $el = shadowRoot.createElementNS(
202+
'http://www.w3.org/1999/xhtml',
203+
tagName
204+
);
205+
206+
expect($el).to.not.be.undefined;
207+
expect($el).to.be.instanceof(CustomElementClass);
208+
});
209+
});
210+
166211
describe('innerHTML', () => {
167212
it(`shouldn't upgrade a defined custom element in the global registry`, () => {
168213
const {tagName, CustomElementClass} = getTestElement();
@@ -292,6 +337,34 @@ describe('ShadowRoot', () => {
292337
});
293338
});
294339

340+
describe('createElementNS', () => {
341+
it('should create a regular element', () => {
342+
const shadowRoot = getShadowRoot();
343+
344+
const $el = shadowRoot.createElementNS(
345+
'http://www.w3.org/1999/xhtml',
346+
'div'
347+
);
348+
349+
expect($el).to.not.be.undefined;
350+
expect($el).to.be.instanceof(HTMLDivElement);
351+
});
352+
353+
it(`should upgrade an element defined in the global registry`, () => {
354+
const {tagName, CustomElementClass} = getTestElement();
355+
customElements.define(tagName, CustomElementClass);
356+
const shadowRoot = getShadowRoot();
357+
358+
const $el = shadowRoot.createElementNS(
359+
'http://www.w3.org/1999/xhtml',
360+
tagName
361+
);
362+
363+
expect($el).to.not.be.undefined;
364+
expect($el).to.be.instanceof(CustomElementClass);
365+
});
366+
});
367+
295368
describe('innerHTML', () => {
296369
it(`shouldn't upgrade a defined custom element in a custom registry`, () => {
297370
const {tagName, CustomElementClass} = getTestElement();

0 commit comments

Comments
 (0)