问题
I am trying to create an "enhanced" select element by slotting contents using Shadow dom into it.
This is the file (the full code is in in Glitch:
import { LitElement, html } from 'lit-element'
export class Select extends LitElement {
render () {
return html`
<select id="_native">
<slot></slot>
</select>
`
}
}
customElements.define('nn-select', Select)
However, nothing seems to get slotted.
Renaming select into select2 "solves" the problem.
Is there a limitation so that we cannot <slot> into native elements?
回答1:
Yes, there a limitation: a <select> element accepts only <option> elements as children. As a consequence, you cannot use <slot>.
Same limitation with <tr> and <td>...
See this other SO post on the same subject.
来源:https://stackoverflow.com/questions/57878970/using-slot-in-native-select-element