import { LitElement, html,customElements } from 'lit-element';
class MyElement extends LitElement {
render(){
const {slotted} = this; //how to get this slotted variable
return html`
<p>
<slot></slot>
${slotted ? 'has slot' : 'no slot'}
</p>
`;
}
}
customElements.define('my-element', MyElement);
```html
<my-elemen></my-elemen>
<my-elemen>test</my-elemen>
By "slotted" do you mean that element children have been assigned to the slot? I'm going to assume that's the case.
To see what elements are assigned to a <slot>, call assignedNodes() on the slot (docs).
To be informed of of changes to the assignedNodes() of a slot, you can listen to the slotchange event on the <slot> (docs).
Most helpful comment
By "slotted" do you mean that element children have been assigned to the slot? I'm going to assume that's the case.
To see what elements are assigned to a
<slot>, callassignedNodes()on the slot (docs).To be informed of of changes to the
assignedNodes()of a slot, you can listen to theslotchangeevent on the<slot>(docs).