-
Notifications
You must be signed in to change notification settings - Fork 56
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
Constructable Stylesheets #308
Comments
Why doesn't the explainer have any info on how this relates to CSS Shadow Parts? https://drafts.csswg.org/css-shadow-parts/ They seem somewhat related |
I already raised an issue about using real constructors WICG/construct-stylesheets#57 |
Talking to @plinss, I now see the reason for this, but it is something we need web component authors to use and adopt when creating their custom elements, so I think it would be great if you could show a full example on how this would work in the explainer - basically showing the developer experience for using this feature |
They're not particularly related, as far as I can tell. Shadow Parts exposes chunks of shadow DOM to the outside world for styling purposes; Constructable Stylesheets helps shadow-DOM-using elements style themselves efficiently (plus some other use-cases unrelated to shadow DOM). They're pretty distinct and have no real interaction with each other. |
By full example, do you mean adding something like const style = new CSSStyleSheet();
style.replace(":host { color: red; }");
class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.adoptedStyleSheets = [style];
}
}; vs the old way? class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.innerHTML = '<style>:host { color: red; }</style>';
}
}; |
@rakina yes, exactly. Like what is the proper way to construct this and the developer ergonomics - how are we going to recommend developers use this?
|
I see that there is a PR (WICG/construct-stylesheets#61) that changes the API and which has not been merged |
@kenchris I see, I'll update the explainer to have some examples like that then (once my PR is merged) |
The new methods PR had been merged and the explainer has been updated. The explainer isn't currently addressing your points though. I think for your first point something like this might make sense: const myElementSheet = new CSSStyleSheet();
class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: "open"});
shadowRoot.adoptedStyleSheets = [myElementSheet];
}
connectedCallback() {
// Only actually parse the stylesheet when the first instance is connected.
if (myElementSheet.cssRules.length == 0) {
myElementSheet.replaceSync(styleText);
}
}
} Looks reasonable to me but I might be wrong. |
Yes the example looks fine, please add it to the spec so that it is clear how it is supposed to be used. Filed WICG/construct-stylesheets#66 |
Thanks for submitting this for TAG review. We've looked at this and this generally seems pretty good -- while we're still poking at a few of the details, we're happy with closing the issue at this point. |
Bonjour TAG,
I'm requesting a TAG review of:
You should also know that...
There might be small API changes due to current open issues but the basic idea should stay the same, that is to allow creating
CSSStyleSheet
objects and use them inDocumentOrShadowRoot.adoptedStyleSheets
.Open issues that might need further attention:
We'd prefer the TAG provide feedback as (please select one):
The text was updated successfully, but these errors were encountered: