Skip to content

Allow slotting indirect children #10273

Open
@jakearchibald

Description

What problem are you trying to solve?

Imagine a custom element for a custom <select>:

<ui-select>
  <ui-select-group>
    <ui-group-summary>England</ui-group-summary>
    <ui-select-option>London <small>(capital)</small></ui-select-option>
    <ui-select-option>Brighton</ui-select-option></ui-select-group>
  <ui-select-group>
    <ui-group-summary>Scotland</ui-group-summary>
    <ui-select-option>Edinburgh <small>(capital)</small></ui-select-option>
    <ui-select-option>Glasgow</ui-select-option>
  </ui-select-group>
</ui-select>

Sometimes the options will be rendered in their groups in an overlay. Sometimes the selected option will be rendered inline.

Implementation-wise, this would be two slots:

  • One for the overlay content
  • One for the selected item content

When the select is in the closed state, I want to be able to assign the childNodes of the selected <ui-select-option> to the "selected item content" slot.

When the select is in the open state, I want to unassign the nodes in the "selected item content" slot, and assign the <ui-select>'s childNodes to the "overlay content" slot (I may use something like element() to make the selected item appear to be in both places at once).

What solutions exist today?

slot.assign(...nodes)

However, the nodes have to be direct children of the shadow host, so it doesn't work for the use-case above.

How would you solve it?

Allow slottables to be descendants of the shadow root host.

This could be allowed for slot.assign only, or it could be allowed for slottables in general.

I don't know if this would need to be an opt-in behaviour. Right now, surprisingly, calling slot.assign on a node that isn't a direct child of the shadow host, fails silently. Well, technically it succeeds, but the set nodes are ignored in step 5.2 of find slottables.

Anything else?

There are other cases where this would be useful. Eg, cases where the light-dom content of a custom element is a mix of data and content.

For example, the light-dom content could describe a list of books. The shadow DOM may render this as a table, or a list, potentially sorted, depending on the environment and interactions. Again, in this case, the component would want to manually slot the content.

Previous discussions:

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: shadowRelates to shadow trees (as defined in DOM)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions