Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions aio/content/guide/component-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ if some ancestor element has the CSS class `theme-light`.



### /deep/
### (deprecated) `/deep/`, `>>>`, and `::ng-deep`

Component styles normally apply only to the HTML in the component's own template.

Use the `/deep/` selector to force a style down through the child component tree into all the child component views.
The `/deep/` selector works to any depth of nested components, and it applies to both the view
Use the `/deep/` shadow-piercing descendant combinator to force a style down through the child
component tree into all the child component views.
The `/deep/` combinator works to any depth of nested components, and it applies to both the view
children and content children of the component.

The following example targets all `<h3>` elements, from the host element down
Expand All @@ -134,17 +135,24 @@ through this component to all of its child elements in the DOM.

</code-example>

The `/deep/` selector also has the alias `>>>`. You can use either interchangeably.

The `/deep/` combinator also has the aliases `>>>`, and `::ng-deep`.

<div class="alert is-important">

Use the `/deep/` and `>>>` selectors only with *emulated* view encapsulation.
Use `/deep/`, `>>>` and `::ng-deep` only with *emulated* view encapsulation.
Emulated is the default and most commonly used view encapsulation. For more information, see the
[Controlling view encapsulation](guide/component-styles#view-encapsulation) section.

</div>

<div class="alert is-important">

The shadow-piercing descendant combinator is deprecated and [support is being removed from major browsers](https://www.chromestatus.com/features/6750456638341120) and tools.
As such we plan to drop support in Angular (for all 3 of `/deep/`, `>>>` and `::ng-deep`).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will styles be projected downward when support for all of these are removed?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what version of node-sass (or the Angular-CLI I guess) supports ::ng-deep?

@mlc-mlapis mlc-mlapis Jun 26, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use CSS Custom Properties (the previous name was CSS Variables) but I am still not sure that this is and will be the only way.

BTW: CSS Custom Properties are not supported by IE at all ... it is too old.

Until then `::ng-deep` should be preferred for a broader compatibility with the tools.

</div>

{@a loading-styles}

## Loading component styles
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler/src/shadow_css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,11 @@ const _shadowDOMSelectorsRe = [
/\/shadow-deep\//g,
/\/shadow\//g,
];
const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)/g;

// The deep combinator is deprecated in the CSS spec
// Support for `>>>`, `deep`, `::ng-deep` is then also deprecated and will be removed in the future.
// see https://github.com/angular/angular/pull/17677
const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)|(?:::ng-deep)/g;
const _selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$';
const _polyfillHostRe = /-shadowcsshost/gim;
const _colonHostRe = /:host/gim;
Expand Down
13 changes: 13 additions & 0 deletions packages/compiler/test/shadow_css_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ export function main() {
expect(css).toEqual('x[a] y {}');
});

it('should handle ::ng-deep', () => {
let css = '::ng-deep y {}';
expect(s(css, 'a')).toEqual('y {}');
css = 'x ::ng-deep y {}';
expect(s(css, 'a')).toEqual('x[a] y {}');
css = ':host > ::ng-deep .x {}';
expect(s(css, 'a', 'h')).toEqual('[h] > .x {}');
css = ':host ::ng-deep > .x {}';
expect(s(css, 'a', 'h')).toEqual('[h] > .x {}');
css = ':host > ::ng-deep > .x {}';
expect(s(css, 'a', 'h')).toEqual('[h] > > .x {}');
});

it('should pass through @import directives', () => {
const styleStr = '@import url("https://fonts.googleapis.com/css?family=Roboto");';
const css = s(styleStr, 'a');
Expand Down