-
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
Pushing Styles into Shadow DOM (@shadow
rules)
#1053
Comments
I think it would be most useful to be the former: it should at least allow a compound selector. Especially since non-custom elements can have shadow roots too. |
I like this idea, but I do think that something using |
Could this be done using a "magic" selector, like, say I personally like the idea of using Maybe something like |
This is a case that I strongly believe we should not support. Allowing page authors to override private state of components would be akin to asking TC39 to allow outside code to read private fields of classes or internal state of closures. It violates the contract set up by the library author and leads to fragile coupling that can put a undue burden on them. It's fine for a component author to choose to relax encapsulation. It's not fine for someone else to easily break it. |
Strongly agree with @justinfagnani on this point. There are situations where owners of design systems and components want to strongly enforce that certain things cannot be changed, and sometimes this has legal implications. |
Correct me if I'm wrong, but in this regard, nothing would change here. Elements with an open shadow-DOM can already have their internal state messed with by the outside world and Allowing users who can already, technically speaking, insert entire style sheets into a shadow-DOM from the outside, or even make more significant changes to its internal structure, wouldn't really change anything in that regard. |
i also agree with justin and rob. we should let existing encapsulated components stay that way. another point about this is that in a future world where open stylable components exist, there will be much less of a need to force push styles to an encapsulated component, because the ability to relax encapsulation will also exist. if open stylable components come first, imo there will be almost no need for pushing styles into a non-open-stylable component because devs can just make open stylable components in the first place, or choose to only use third party components if they are open-stylable. |
This isn't correct because currently CSS cannot select into open shadow roots. Allowing that is breaking the contract currently provided to shadow roots. This is exactly why I proposed #909, because it is a change to allow CSS to select into shadow roots and the web component author, not the page author, should opt into that. |
I'm not quite seeing how this is worse than allowing the outside to reach into the shadow DOM and just insert a style tag there; or worse yet, delete random nodes. |
In the discussion around #909, one requirement that has been brought up repeatedly is for a mechanism whereby the website can define Styles that would apply inside a web component's shadow DOM.
Generally speaking, the requirement comes down to something like this:
As a starting point for discussion, I'd like to propose something like this:
It seems reasonable to restrict this only to
mode="open"
shadow DOMs, and that this should be applied to nested shadow DOMs out of the box. The selector for the actual element could be a complete selector including combinators, or could be restricted to element names with at least one-
In the discussion around #909 several other mechanisms have been proposed to achieve this.
@knowler suggested using a
:shadowroot
pseudo-class inside@scope
rules to scope styles to the root of the shadow DOM, effectively pushing these styles into the shadow DOM in the process.@jaredcwhite proposed using
:shadowdom
inside a@scope
block to select elements inside the shadow-dom attached to the scope's root node.There's probably more that I'm missing.
The text was updated successfully, but these errors were encountered: