Using <slot> in native <select> element

邮差的信 提交于 2020-07-21 04:58:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!