You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
slot element's fallback contents is never used #317
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.
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.
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:
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>.
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.
+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).
+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.
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".
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.
Activity
hayatoito commentedon Sep 14, 2015
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.
rniwa commentedon Sep 14, 2015
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
slotelement should not refer to it:@travisleithead, @annevk: do you have any opinions about this feature?
JanMiksovsky commentedon Sep 14, 2015
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>.rniwa commentedon Sep 14, 2015
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.
annevk commentedon Sep 14, 2015
I'm good either way. It does seem somewhat useful to have parts of your shadow tree be overrideable in this manner.
hayatoito commentedon Sep 15, 2015
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.
travisleithead commentedon Sep 16, 2015
+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
slotthat has nothing distributed should likewise just render as a transparent content model (e.g,, it's fallback content).amiller-gh commentedon Sep 24, 2015
+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.
Slot elements should support fallback contents
hayatoito commentedon Oct 5, 2015
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:
<div>Hello <slot name="d"></slot></div>is fallback contents of slot c.[Fix #317] Support fallback content in *get distributed nodes algorit…
hayatoito commentedon Oct 7, 2015
I've revised the algorithms at 609a11e.
The change of 96403c3 broke the assumption of:
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.
rniwa commentedon Oct 7, 2015
Makes sense. We don't want
getAssignedNodesto include the fallback contents.Slot elements should support fallback contents
[Fix WICG#317] Support fallback contents for slots