I'm trying to inspect the host.children[~].assignedSlot. (Preferably, from within shadow root).
But in Polyfilled browsers it's null. I noticed that, if I call assignedSlot on any element from host.shadowRoot.querySelector('*').assignedSlot, shadow tree get synchronously "rendered", and host.children[~].assignedSlot starts to return correct value.
It feels like assignedSlot getter renders incorrect tree. It renders a tree that contains the given element instead of the tree that may contain a slot in question - parent element's shadow tree.
Attach shadow to shadow-host, which contains <slot name="given">
Read div.assignedSlot
<template id="shadowRoot">
<slot name="given"></slot>
</template>
<div id="shadowHost">
<div slot="given" id="slottable">I'm distributed</div>
</div>
<script>
shadowHost.attachShadow({mode: 'open'})
.appendChild(document.importNode(shadowRoot.content, true));
const slottable = shadowHost.querySelector('[slot]');
console.log(slottable.assignedSlot); // null
// trick Polymer to render this shadow tree to make `assignedSlot` of element accessible
shadowHost.firstChild.assignedSlot; // does not have to be a slot
console.log(slottable.assignedSlot); // [HTMLSlotElement]
</script>
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Description
I'm trying to inspect the
host.children[~].assignedSlot
. (Preferably, from within shadow root).But in Polyfilled browsers it's
null
. I noticed that, if I callassignedSlot
on any element fromhost.shadowRoot.querySelector('*').assignedSlot
, shadow tree get synchronously "rendered", andhost.children[~].assignedSlot
starts to return correct value.It feels like
assignedSlot
getter renders incorrect tree. It renders a tree that contains the given element instead of the tree that may contain aslot
in question - parent element's shadow tree.Live Demo
https://jsbin.com/tapaqoy/3/edit?html,console,output
Steps to Reproduce
shadow-host
<div slot="given">
to shadow hostshadow-host
, which contains<slot name="given">
div.assignedSlot
Expected Results
A reference to the slot should be given
Actual Results
It returns
null
Browsers Affected
Versions