-
Notifications
You must be signed in to change notification settings - Fork 26.3k
docs(core): improve viewEncapsulation documentation #44151
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
docs(core): improve viewEncapsulation documentation #44151
Conversation
|
@dario-piotrowicz thanks for creating this PR 👍 |
|
|
||
| <code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example> |
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've removed the example as it didn't seem beneficial to me as:
- after my changes the introductory text above already makes clear how to apply the strategy so I don't really think actually showing it adds much here
- in the same docs page (below) there are various examples showing the application of the encapsulation strategy, so this example again didn't seem to add much to me
|
|
||
| <code-example path="view-encapsulation/src/app/no-encapsulation.component.ts" header="src/app/no-encapsulation.component.ts"></code-example>> | ||
|
|
||
| Angular adds the styles for this component as global styles to the `<head>` of the document. | ||
|
|
||
| **Angular also adds the styles to all shadow DOM hosts.** Therefore, the styles are available throughout the application. |
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.
this was already mentioned above so I don't think there is a need to emphasise it
|
|
||
| `ViewEncapsulation.ShadowDom` only works on browsers that have built-in support | ||
| for the shadow DOM (see [Can I use - Shadow DOM v1](https://caniuse.com/shadowdomv1)). | ||
| Not all browsers support it, which is why the `ViewEncapsulation.Emulated` is the recommended and default mode. |
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 changed "The support is still limited" to "Not all browsers support it" because as you can see in the caniuse link the support is actually pretty good I think
c902a56 to
00e3081
Compare
| /* | ||
| // #docregion encapsulation.shadow | ||
| // warning: not all browsers support shadow DOM encapsulation at this time | ||
| encapsulation: ViewEncapsulation.ShadowDom | ||
| // #enddocregion encapsulation.shadow | ||
| */ |
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've removed this because as mentioned in this comment I feel like it is an unnecessary example
|
|
||
| <code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example> | ||
| <div class="alert is-important"> |
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.
maybe it should be is-helpful? 🤷♂️
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.
Don't all browsers that we officially support have ShadowDOM support now?
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 think the real reason we are still defaulting to emulated is that is makes it hard to pierce theming into the components because there is not a well lit path for how to do this with ShadowDOM. I think @jelbourn has more context here.
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.
yes I wrote something similar in my comment below, happy to change this to whatever is preferred 🙂
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 think this is fine unless @jelbourn (or anyone else has a view).
496cbbe to
fdc735e
Compare
|
@dario-piotrowicz - while I review this PR can you fix up the commit message slightly? Add some sentence casing and fix a typo: |
|
You can preview c902a56 at https://pr44151-c902a56.ngbuilds.io/. |
Slighlty improve the `viewEncapsulation` documentation (both in code comments and content files) to make it more clear and understandable. See angular#44099 (comment)
fdc735e to
f5c611c
Compare
|
You can preview f5c611c at https://pr44151-f5c611c.ngbuilds.io/. |
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.
Thanks for working on this @dario-piotrowicz - definitely an improvement. I made a bunch of suggestions - mostly just stylistic.
| [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM)) | ||
| to attach a shadow DOM to the component's host element, and then puts the component | ||
| view inside that shadow DOM. The component's styles are included within the shadow DOM. | ||
| The available options are: |
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 think the docs team prefer to keep an imperative feel to the docs. So probably it would be best to revert this change:
| The available options are: | |
| Choose from the following modes: |
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.
ok 🙂 👍
but my issue here was especially that before mode made more sense as we had ShadowDom, Emulated and None, to which "mode" was more appropriate, but now we have ViewEncapsulation.ShadowDom, ViewEncapsulation.Emulated and ViewEncapsulation.None, which are actual specific value of the ViewEncapsulation enum, so I just wanted to rephrase it to indicate such.
What do you think? should I revert also the names to the old version?
|
@petebacondarwin thanks a lot for the awesome reviewing 🙂 , sorry I made you comment that much 😓 I replied to most of you comments, I've asked follow up questions to a few, please have another look when you have the chance 🙂 |
|
You can preview 8308abe at https://pr44151-8308abe.ngbuilds.io/. |
8308abe to
7599409
Compare
|
You can preview 7599409 at https://pr44151-7599409.ngbuilds.io/. |
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.
Thanks for the updates @dario-piotrowicz - LGTM!!
|
|
||
| <code-example path="component-styles/src/app/quest-summary.component.ts" region="encapsulation.shadow" header="src/app/quest-summary.component.ts"></code-example> | ||
| <div class="alert is-important"> |
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 think this is fine unless @jelbourn (or anyone else has a view).
|
You can preview 94a6c10 at https://pr44151-94a6c10.ngbuilds.io/. |
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.
LGTM though my knowledge in this area is limited.
|
FYI, marking this PR as ready for merge, since we have all the necessary approvals. Note to the Caretaker: the CI job failure is unrelated, so we can proceed with the merge. |
|
This PR was merged into the repository by commit 6ae3858. |
Slighlty improve the `viewEncapsulation` documentation (both in code comments and content files) to make it more clear and understandable. See #44099 (comment) PR Close #44151
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |




Slighlty improve the
viewEncapsulationdocumentation (both in codecomments and content files) to make it more clear and understandable.
See #44099 (comment)
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
@AndrewKushnir as promised 🙂