Skip to content

Commit

Permalink
capricorn86#451@patch: Continue fixes missing innerHTML in html-templ…
Browse files Browse the repository at this point in the history
…ate.
  • Loading branch information
Mas0nShi committed Jun 15, 2022
1 parent 63a4800 commit 157dbcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -4,6 +4,7 @@ import IDocumentFragment from '../document-fragment/IDocumentFragment';
import INode from '../node/INode';
import IHTMLTemplateElement from './IHTMLTemplateElement';
import XMLSerializer from '../../xml-serializer/XMLSerializer';
import XMLParser from '../../xml-parser/XMLParser';

/**
* HTML Template Element.
Expand All @@ -20,7 +21,13 @@ export default class HTMLTemplateElement extends HTMLElement implements IHTMLTem
* @param html HTML.
*/
public set innerHTML(html: string) {
super.innerHTML = html;
for (const child of this.content.childNodes.slice()) {
this.content.removeChild(child);
}

for (const node of XMLParser.parse(this.ownerDocument, html).childNodes.slice()) {
this.content.appendChild(node);
}
}

/**
Expand Down
Expand Up @@ -19,7 +19,11 @@ describe('HTMLTemplateElement', () => {

it('InnerHTML', () => {
const div = '<div>happy-dom is cool!</div>';
expect(element.content.childNodes.length).toBe(0);
element.innerHTML = div;
expect(element.innerHTML).toBe(div);
expect(element.content.childNodes.length).toBe(1);
element.innerHTML = '';
expect(element.content.childNodes.length).toBe(0);
});
});

0 comments on commit 157dbcf

Please sign in to comment.