Skip to content

slot element's fallback contents is never used #317

Closed

Description

@rniwa

It seems like the latest spec doesn't define when the fallback contents of a slot element is used.

Since the CSS Scoping Module Level 1 refers to the concepts of distribution list and insertion point (this should be renamed to slot), we should probably define that either a slot element without any distributed nodes doesn't constitute a insertion point (a.k.a. slot).

We could alternatively define that an insertion point can have an empty distribution list, and then make the CSS Scoping Module define the fallback behavior but that seems cumbersome.

Activity

  1. hayatoito commented on Sep 14, 2015

    @hayatoito
    Contributor

    I don't understand the point. Could you clarify that?

    Are you proposing the we should recover the concept of fallback contents because it's convenient?

    e.g. <slot name="xxx"><div>fallback contents here if there is no xxx</div></slot>

    I intentionally removed the concept of fallback contents from v1 because the proposal doesn't include it.
    Please correct me if I misunderstand the issue here.

  2. rniwa commented on Sep 14, 2015

    @rniwa
    CollaboratorAuthor

    I'm indifferent with regards to wether we support fallback or not but the spec should be consistent. If we're getting rid of the concept of fallback then, the definition of slot element should not refer to it:

    Children
    Anything as fallback content

    @travisleithead, @annevk: do you have any opinions about this feature?

  3. JanMiksovsky commented on Sep 14, 2015

    @JanMiksovsky

    Just to share my own experience here: I have occasionally found uses for fallback content.

    As a practical example, I'm currently working on a general-purpose dropdown combo box component. This component includes a button that can be used to invoke the dropdown. (You can view a simple work-in-progress demo that shows the dropdown button.)

    By default, this dropdown button displays a downward-pointing arrow, but it's important for the component to allow developers to override this. E.g., in a dropdown calendar subclass, the button could show a calendar icon.

    This result is achieved by supplying fallback content to the <content> element. (Here's the relevant line in the component source code using Polymer's syntax.) The same component source file actually has one other instance of supplying fallback content.

    Again, in my experience, this sort of situation is relatively rare, but from time to time I need a component to supply default content. In those cases, it's been nice to have this supported directly by the <content> element. Given that experience, it may be nice to have fallback content directly supported by <slot>.

  4. rniwa commented on Sep 14, 2015

    @rniwa
    CollaboratorAuthor

    That does sound like a compelling use case for fallback. Since the cost of supporting fallback is so low, we might as well as support it unless we find some problems with it.

  5. annevk commented on Sep 14, 2015

    @annevk
    Collaborator

    I'm good either way. It does seem somewhat useful to have parts of your shadow tree be overrideable in this manner.

  6. hayatoito commented on Sep 15, 2015

    @hayatoito
    Contributor

    Okay. Let me wait for another +1 to this feature.
    We know that this feature is useful, but the cost of supporting is non-zero.

  7. travisleithead commented on Sep 16, 2015

    @travisleithead
    Member

    +1 This behavior, to some extent, follows the pattern of Host Elements. Their children are their "fallback content" until a Shadow DOM is attached. Similarly, a slot that has nothing distributed should likewise just render as a transparent content model (e.g,, it's fallback content).

  8. amiller-gh commented on Sep 24, 2015

    @amiller-gh

    +1 from me as well. I've had multiple use cases where fallback content for slots has been tremendously convenient.

    Ex: Passing a list of items to a custom drop down component – if a list of items is passed, the element should display the list. If nothing is included in the component, the developer may want it to contain a default "no options available" empty state.

    Ex: (real life example here) A custom element that automagically inlines SVG from an SVG sprite as its shadow content. In an effort to make things accessible by default, it would be appropriate to include default screen reader text in a named slot. Perhaps a slot called "sr-label" with the default content "beautiful icon" for example. However, if a user wants to provide their own screen reader label copy that may be more descriptive of the actual use case, they are more than able to.

    I also agree with @travisleitheid and enjoy the parallels it has to host element fallback content, it's a good mental model.

  9. hayatoito commented on Oct 5, 2015

    @hayatoito
    Contributor

    Thank you for the interests. I've supported "fallback contents" features at 96403c3.

    Although the change for the spec might look simple, that implies the important thing: "Slots can be nested many times as fallback contents of a parent slot".

    e.g. We can write the following markup:

     <slot name="a">
       <slot name="b">
          <slot name="c">
            <div>hello <slot name="d"></slot></div>
          </slot>
       </slot>
    </slot>
    
    • <div>Hello <slot name="d"></slot></div> is fallback contents of slot c.
    • slot c is fallback contents of slot b
    • slot b is fallback contents of slot a
    • etc.
  10. added a commit that references this issue on Oct 7, 2015
    609a11e
  11. hayatoito commented on Oct 7, 2015

    @hayatoito
    Contributor

    I've revised the algorithms at 609a11e.

    The change of 96403c3 broke the assumption of:

    • S == N.assignedSlot <===> N is in the member of S.getAssignedNodes().

    because it changed the behavior of getAssignedNodes.

    Now 609a11e supports the fallback content at the layer of get distributed nodes algorithm, instead of at the layer of get assigned nodes algorithm. The assumption no longer breaks.

  12. rniwa commented on Oct 7, 2015

    @rniwa
    CollaboratorAuthor

    Makes sense. We don't want getAssignedNodes to include the fallback contents.

  13. added a commit that references this issue on Jul 30, 2025
    96403c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions