最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far