shadycss icon indicating copy to clipboard operation
shadycss copied to clipboard

No output in shadow dom host

Open schalkneethling opened this issue 8 years ago • 1 comments

I have the following HTML(some details removed for brevity)

<div id="output" class="output">
    <shadow-output></shadow-output>
    <template id="shadow_contents"></template>
</div>

I am loading the following JS:

webcomponents-hi-sd-ce.js

I then have the following JS

var output = getOutput();
var tmpl = document.getElementById('shadow_contents');

var styleContainer = document.createElement('style');
styleContainer.textContent = output.cssContent;

var htmlContainer = document.createElement('div');
htmlContainer.innerHTML = output.htmlContent;

tmpl.append(styleContainer);
tmpl.append(htmlContainer);

ShadyCSS.prepareTemplate(tmpl, 'shadow-output');

class ShadyOutput extends HTMLElement {
    connectedCallback() {
        ShadyCSS.styleElement(this);
        if (!this.shadowRoot) {
            this.attachShadow({ mode: 'open' });
            this.shadowRoot.appendChild(
                document.importNode(tmpl.content, true)
            );
        }
    }
}

customElements.define('shadow-output', ShadyOutput);

I can see that the elements appended to the template element are present but, nothing is being written to the host i.e. shadow-output

screen shot 2018-05-07 at 16 47 08

I am sure I am overlooking something but, not sure where things are going wrong.

schalkneethling avatar May 07 '18 14:05 schalkneethling

I think I figured out how this all works :) So, closing this out. There might still be an issue here, that I managed to work around or, not.

schalkneethling avatar May 16 '18 13:05 schalkneethling