Re: [w3c/webcomponents] Provide a lightweight mechanism to add styles to a custom element (#468)

Thanks @WebReflection and @JanMiksovsky for the feedback! It's helpful to hear what web devs think of the API.

> As summary: why isn't this proposal working exactly like a <style> inside a
shadow root so that anything can be styled within the component and not
just the component itself which is super limited as it is?

So previously I think this thread had discussed a "fake shadow root" approach where you can style things in the custom element's shadow tree as well, but that wouldn't work for your purposes too since it still can't style non-shadow children. I think it was [discussed before](https://github.com/w3c/webcomponents/issues/468#issuecomment-400938104) that we're not going to solve styling children, but the reasoning isn't really clear. Maybe @sorvell @hayatoito can chime in?

If we want to allow styling the non-shadow children, I guess we will extend the scope of the default style to the custom element's subtree, so complex selector would work. We can style non-shadow children, but if there's a shadow root, we can't style shadow children. Maybe we have another option we can add, on whether the custom element default style should work in the scope of the custom element, or we should make it part of the custom element's shadow root's stylesheets. I don't know if that's a good pattern or not, maybe other people can give their thoughts on this. Implementation-wise, it shouldn't be that hard. I don't know whether spec-ing something like this is hard or now.

Side question: If you don't use Shadow DOM on the custom element, what are you doing currently to make sure your custom elements wouldn't accidentally get styled by some of your other rules?


> The "green" example in the explainer touches on this point. While that example is helpful in understanding ramifications of the feature, I don't think that situation represents a desirable outcome. Generally, I think it's going to be very unusual to attach a shadow root to an element you don't define.

I see, thanks for pointing this out. I think it's reasonable to move the position of the default styles to the end, or maybe make it possible for web authors to decide to put them on the front or the back (unless there's some edge cases for this that I'm not aware of).


> Can pseudo-elements be used in rules that match the element?
> Assuming the CSS Shadow Parts proposal were to proceed along its current lines, would a *::part selector in the default style sheet match a part in the element's shadow root?

Currently no, but if we can agree on extending the scope of the default style (like I mentioned above, or some other way) then this should work. I can see why this would be quite helpful.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/468#issuecomment-430483651

Received on Wednesday, 17 October 2018 04:15:07 UTC