admin管理员组文章数量:1023187
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?
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 Answer
Reset to default 7Yes, 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.
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?
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 Answer
Reset to default 7Yes, 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.
本文标签: javascriptUsing ltslotgt in native ltselectgt elementStack Overflow
版权声明:本文标题:javascript - Using <slot> in native <select> element - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745597767a2158271.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论