-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named slots and the slot attribute requirement #726
Comments
You basically want the selectors that the Shadow DOM V0 element supported. I'm not sure why that feature was dropped. |
@PaulHMason I would be OK with that but for extension purposes I prefer the interface concept @rniwa
Being able to define the slot via interface would be very powerful indeed and reduce redundancy in more complex elements. |
Like we previously stated, Apple's preference here is to add imperative slotting API as well as providing a mechanism to slot elements on their interfaces so that the inheritance would work. We need to be careful as to in which realm and when JS states are read (since the timing of |
Also see the issue #719. |
Thanks for the update! So if I am reading you correctly, a more declarative approach may be in the works depending on some selector work? |
@cary-smith no, @rniwa states that only an imperative solution would be acceptable to Apple. Thus far we haven't been able to figure out such an API. |
@annevk Thanks for the clarification! I may have misunderstood the
I thought that might mean we may be able to slot children according to child element's interface instead of the |
That's not true. We're against using the CSS selector as a mechanism to match an element but not against providing a declarative mechanism to select an element based on its type such as the interface object. Our only requirement is that the slotting mechanism be performant; i.e. not as slow as evaluating a CSS selector whenever a node gets modified. |
My bad. So |
Sure. In fact, we suggested that but Google veto'ed it saying we should keep it simple. |
An episode: at moving Blink's all UA shadow implementations from V0 to V1, Maybe using CSS Selector is too powerful to be performant, but we need to find options to explore for extending the current capability. So we need use cases that can't be represented with V1 APIs. |
So here are two concrete use cases I'd like to solve:
I am curious about the internal mechanisms Blink and WebKit use for their UA shadow roots, and whether we could clean those up into a proposal for something to expose to the web platform. |
Blink's internal mechanism can't be a starter of a proposal. |
Sure, but I was curious what the hard-coded handling looked like in C++, and whether it would make sense to expose hooks that would allow similar JS code to be inserted in the appropriate places? |
In WebKit, we added the ability to override what the slot name for a given element is, and the slot assignment for Exposing this API would involve exposing the timing at which slotting would happen so it's kind of non-starter. |
Here is hard coding. This can be considered as a kind of imperative APIs, if we would expose. Web developers have to provide a function hook for a shadow root (or for the definition of a custom element), as such: function canBeAssigned(host_child, internal_slot) {
// ...
return true | false;
} |
Yup, I don't want to expose the timing of slot assigning. That should be kept as an engine's internal matter. |
I think a better approach for JS is to provide an imperative API to set the list of nodes assigned to a slot. e.g. |
I think For example suppose you had some component that was a slideshow or something, you would probably want to write something like this: class SlideShow extends HTMLElement {
...
_changeToNextSlide() {
const hiddenSlides = this._shadowRoot.querySelector("#hiddenSlides")
const visibleSlide = this._shadowRoot.querySelector("#visibleSlide")
hiddenSlides.assign(this.children[this.currentSlide])
this.currentSlide += 1
visibleSlide.assign(this.children[this.currentSlide])
}
} |
The problem with |
Rough consensus that we'd prefer an imperative API in Tokyo. |
So after building quite a few components and reading through #343, I was wondering if you could clarify something for me:
Given a complex shadowDOM template with multiple named-slot locations I am curious why an element selector cannot be used if it is only focused on the children of the element involved. In-house we are trying to develop multiple elements that have specific styling inherent to them. Some of these elements have specified child elements that can be used which are not dissimilar to a
<tr>
in a<table>
element (the<tr>
does not really have a use outside a<table>
).For the developers that use our elements, there is now required boilerplate to place that child element in the named slot due to the required
slot="someSlotName"
. This can be overcome by the child element generating its ownslot="someSlotName"
attribute but it cannot do so during its own construction, only during the connectedCallback. This creates quite a bit of unnecessary churn during the initial connection of an element because it starts unslotted then gets moved/projected into place (the most noticeable slowdown happens when using polyfills like Polymer).Staying within the context of only selecting from the element children and without pretending to know the complexity involved, I am curious if the v0
selector="someElementType"
or the more preferred method @rniwa had mentioned about interface selection are possible . Maybe something likeThis would allow certain element types to be slotted according to the design of the shadow template instead of the boilderplate attribute.....kinda like
<table>
knows where to place a<thead>
element without<thead slot="head">
.If I am foolishly missing some pattern, please let me know.
Thoughts?
The text was updated successfully, but these errors were encountered: