最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using <slot> in native <select> element - Stack Overflow

programmeradmin5浏览0评论

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?

Share Improve this question asked Sep 10, 2019 at 22:34 MercMerc 17.2k18 gold badges86 silver badges132 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

发布评论

评论列表(0)

  1. 暂无评论