-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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
adoptedStyleSheet property docs #16773
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first half
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Never heard of this. Just a few questions.
Changing an adopted stylesheet will affect all the objects that adopt it. | ||
|
||
Stylesheets in the property are considered along with the document's other stylesheets. | ||
For the purpose of determining the final computed CSS of any element, they are considered to have been added _after_ the other stylesheets in the document ([`Document.styleSheets`](/en-US/docs/Web/API/Document/styleSheets)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as they are "later", they take precedence if selectors match, and are unlayered, so take precedence over all other styles. Is there a way to assign them to a layer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estelle Good question. This comes from the very last bullet point in the explainer
- Stylesheets added to
adoptedStyleSheets
are part of theDocumentOrShadowRoot
's style sheets, and they are ordered after theDocumentOrShadowRoot
'sstyleSheets
.
- This means when there are conflicting rules in the
adoptedStyleSheets
andstyleSheets
and the resolution will consider the order of stylesheets, they treat the sheets inadoptedStyleSheets
as ordered later.
I have more accurately captured this in suggestion: https://github.com/mdn/content/pull/16773/files#r888564793
Is there a way to assign them to a layer?
I don't know. Asked here: https://bugzilla.mozilla.org/show_bug.cgi?id=1644102#c13
AS an aside
If you search on "cascade" there are a few links other than your update topic. You might want to cross link to your updated doc (and making sure there are no glaring errors)? For example https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Cascade_and_inheritance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estelle Response from developer to questions:
Is there a way to assign constructed CSS stylesheet rules to a layer?
Using @layer
inside the stylesheet just like in a style element.
w3c/csswg-drafts#7002 tracks adding a per-stylesheet
layer.
For calculating the cascade, the explainer says that if there are rules in conflict that would be resolved by order or import, then the adopted stylesheets come last. The question is, can I assume that they are treated as author origin and that that even if imported in inline javascript, they will not be considered to be inline styles?
Hm? Not sure I follow. Yes, these are always author stylesheets. The order of the stylesheets is
- Stylesheets in the shadow tree (
<link>
and<style>
, in tree order) - Adopted stylesheets (in whatever order the array is).
So the only "special" thing about adopted stylesheets is that they're effective order of import into the user agent is after other stylesheets and in the order of the array. All other things like layers are as per the normal cascade rules. I think that is captured by the updated comment
Co-authored-by: Estelle Weyl <[email protected]>
Co-authored-by: Estelle Weyl <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few optional comments. Approved. Learned something FTW!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[deleted. left comment on wrong page]
Thanks for the review @estelle . I've incorporated the suggestions and will merge. |
This is a follow on from #16717 adding docs for the missing properties
Document.adoptedStyleSheets
andShadowRoot.adoptedStyleSheets
and updating the release note.In addition, this feature is part of "constructable stylesheets" for efficiently sharing CSS between shadow DOM sub trees. So I've updated the constructor for
CSSStyleSheet
to note this use and better cross link between all the related docs.Some of this is just necessary because there is no parent "Using constructable stylesheets" doc or link we can use.
Note that there is a missing guide doc still to be written at some point. I'll create a separate PR for that.
Other docs work can be tracked in #16624