Web Components Named Slots

In my previous post I described how to send data in form of attributes to a web component. Since this mechanism is only applicable for simple values, there also is a separate mechanism for inserting complex values.

Let me explain the goal first.If I have a web component which consists of the following internal structure.

To use this component, you have to insert it into the DOM and it will render a visual representation.If I now want to fill those empty placeholders with content I have to use HTML elements within the component.

Font-face-name; missing-glyph; The list of names above is the summary of all hyphen-containing element names from the applicable specifications, namely SVG and MathML. If you want to check if a given string is a valid custom element name, check Mathias Bynens's app. Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps. Custom components and widgets build on the Web Component standards, will work across modern browsers, and can be used with any JavaScript library or framework that works with HTML.

With this definition, the browser no longer knows where to place the header line or the content line within my control.

To tackle that issue, the spec proposes the use of “slot” elements, which will represent placeholders which can later be filled by content.

Slot elements can be placed anywhere within the component. It is preferred that those slots are named (if only one slot exists, the name can be omitted).

This is what a web component with slots would look like.

To use those predefined slots, the attached element has to name the slot it wants to be placed in.

Web Components Named Slots No Deposit

Components

Now the control gets rendered with the header and content part at the right places.

Named

In my previous post I described how to send data in form of attributes to a web component. Since this mechanism is only applicable for simple values, there also is a separate mechanism for inserting complex values.

Let me explain the goal first.If I have a web component which consists of the following internal structure.

To use this component, you have to insert it into the DOM and it will render a visual representation.If I now want to fill those empty placeholders with content I have to use HTML elements within the component.

With this definition, the browser no longer knows where to place the header line or the content line within my control.

To tackle that issue, the spec proposes the use of “slot” elements, which will represent placeholders which can later be filled by content.

Web Components Named Slots

Slot elements can be placed anywhere within the component. It is preferred that those slots are named (if only one slot exists, the name can be omitted).

This is what a web component with slots would look like.

Slots

To use those predefined slots, the attached element has to name the slot it wants to be placed in.

Web Components Named Slots Real Money

Now the control gets rendered with the header and content part at the right places.