-
Notifications
You must be signed in to change notification settings - Fork 672
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
[css-scoping] Proposal: Allow <slot> with LightDOM Web Components #10420
Comments
I'd love to see your thoughts on how something like this could be resilient to DOM changes overtime, both from without the element AND within, rather than supporting what initially appears to be a one time stamp render merge of the initial content of the element and the "template" of the element. Specifically, you use |
Thanks for your questions @Westbrook
The
In either way the page would have access to the LightDOM children of the custom element. |
This doesn't describe how slots work, particularly what host elements slots are associated with and what elements are slottable. |
@justinfagnani I know I am lacking a detailed description regarding slots in LightDOM, I just want to express the sentiment that a lot of authors I met during conferences and in my project work (main design system and large component libraries) suffer from the hard encapsulation that ShadowDOM poses onto. This is the main reason. Seeing #10808 empowers this albeit from the CSS side. Either way would be fine for authors I think. |
CSS evolved extensively in the last four years and gained a lot of features such as
:has()
,@container
,@layer
,@scope
,CSS Anchor Positioning
and@property()
, to name a few.These new CSS features change the concept of how we can write composable and high-distributable HTML with Web Components without always resolving to the highest power by utilizing ShadowDOM.
In the rise of design systems, there is currently no way to combine the powers of both ModernCSS and
<slot>
. This proposal aims to solve this problem.Shadow Boundaries vs ModernCSS
Using ShadowDOM leads to a lot of new CSS features being rendered useless; to provide an incomplete list of problems identified so far:
@container
) across shadow boundaries of nested ShadowDOM Web components (was resolved via [css-contain] CQ vs shadow boundaries #5984 in spec but needs to be implemented across vendors).CSS Anchor Positioning
does not work cross shadow boundaries.:has()
to style a parent depending on his slotted children (there is a proposal for a:has-slotted
selector)@layer()
. Each shadow-root recreates the semantics of the layers.::part
that are limited in styling ShadowDOM content from the outside.@import()
Solutions in the wild
There are articles in the web community that express the same sentiment about slots being the only-missing ShadowDOM feature.
Proposed solution
Since
<slot>
s are native to the ShadowDOM and cannot be polyfilled in the regular DOM (and style encapsulation can be achieved natively via modern CSS) the proposed solution is to let users use<slot>
with LightDOM Web Components.A simplified example with slots inside a
<template>
without attaching ashadowRoot
open-stylable
via [css-cascade-5] Add an adoptStyles capability in ShadowRoots (WICG 909: open-stylable Shadow Roots) #10176).@layer
and@scope
to provide a finer-grained CSS encapsulation.:host(parent-component) ::slotted(child-component) {…}
to establish connections between nested ShadowDOM Web Components.slotchange
event (optional).Open questions
How can we signal that a LightDOM Web Component is using
<slot>
s without attaching another root node and appending the template to it?A path forward
Addendum
This is my first proposal that formed up after great talks with @bramus, @una, @fantasai, @andruud and @mirisuzanne at the CSSDay 2024.
Happy for any comments/corrections/recommendations, cheers!
The text was updated successfully, but these errors were encountered: