Slotted polyfill does not work if slot is not a direct child
Description
If you use ::slotted(foo) where foo is not a direct child of the element, the polyfill will not style foo properly.
The polyfill rewrites the ::slotted(foo) to my-elem > foo, which is incorrect if there is an element in-between. Given the JSBin, I think the correct rewrite is .style-scope.my-elem section > foo. For example the polyfill could add a class slot-X to the parent of <slot>, such that it rewrites to .style-scope.my-elem .slot-default > foo.
JSBin
http://jsbin.com/pumogujefe/edit?html,output
Expected results
In Firefox, the background should be red just as it is in Chrome
Actual results
In Firefox the background is white, while in Chrome it is red
This is cause by the fact that the parent Shadow DOM elements show up as normal DOM elements in the polyfilled markup
Related to:
Polymer v2: this.parentElement points to the wrong DOM element when using polyfills Polymer/polymer#4506
Is there any news on this, running into the same issue. 😢
Hey @azakus is there any chance this can be solved? Does https://github.com/webcomponents/shadydom/issues/119 fix this? Thanks for looking into this.
The shortest workaround is to modify style generated by ShadyCSS. It is working for IE11,FireFox etc. It is worked like a charm
connectedCallback(){
super.connectedCallback();
let tagName = this.constructor.is;
let style = Array.from(document.styleSheets).find((item) => item.ownerNode && item.ownerNode.getAttribute("scope") === tagName);
if(style){
Array.from(style.cssRules || style.rules || []).forEach((rule)=>{
if(rule.selectorText.indexOf("slot") > -1){
rule.selectorText = rule.selectorText.replace(/>/ig," ");
}
})
}
}
Example of my style
:host ::slotted([slot=au-drawer-toggle]) {
display: none;
}
Example of mockup
<div class$="drawer-container [[location]]" id="container">
<div class="drawer-main">
<slot name="main"></slot>
</div>
<div class="drawer-drawer" id='drawerDrawer'>
<div class="content-wrapper" id="contentWrapper">
<slot name="drawer"></slot>
</div>
<slot name="au-drawer-toggle"></slot>
</div>
</div>
This is an issue in ShadyDOM: http://jsbin.com/doxawoliyi/edit?html,console,output
This issue was moved to webcomponents/shadydom#258