Skip to content

Commit b754e60

Browse files
vicbmatsko
authored andcommitted
feat(compiler): add support ::ng-deep
- /deep/ is deprecated and being removed from Chrome - >>> is semantically invalid in a stylesheet - sass will no longer support either in any version of sass -> use ::ng-deep in emulated shadow DOM mode Because the deep combinator is deprecated in the CSS spec, `/deep/`, `>>>` and `::ng-deep` are also deprecated in emulated shadow DOM mode and will be removed in the future. see https://www.chromestatus.com/features/6750456638341120
1 parent 81734cf commit b754e60

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

‎aio/content/guide/component-styles.md‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ if some ancestor element has the CSS class `theme-light`.
119119

120120

121121

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

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

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

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

135136
</code-example>
136137

137-
The `/deep/` selector also has the alias `>>>`. You can use either interchangeably.
138-
138+
The `/deep/` combinator also has the aliases `>>>`, and `::ng-deep`.
139139

140140
<div class="alert is-important">
141141

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

146146
</div>
147147

148+
<div class="alert is-important">
149+
150+
The shadow-piercing descendant combinator is deprecated and [support is being removed from major browsers](https://www.chromestatus.com/features/6750456638341120) and tools.
151+
As such we plan to drop support in Angular (for all 3 of `/deep/`, `>>>` and `::ng-deep`).
152+
Until then `::ng-deep` should be preferred for a broader compatibility with the tools.
153+
154+
</div>
155+
148156
{@a loading-styles}
149157

150158
## Loading component styles

‎packages/compiler/src/shadow_css.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,11 @@ const _shadowDOMSelectorsRe = [
513513
/\/shadow-deep\//g,
514514
/\/shadow\//g,
515515
];
516-
const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)/g;
516+
517+
// The deep combinator is deprecated in the CSS spec
518+
// Support for `>>>`, `deep`, `::ng-deep` is then also deprecated and will be removed in the future.
519+
// see https://github.com/angular/angular/pull/17677
520+
const _shadowDeepSelectors = /(?:>>>)|(?:\/deep\/)|(?:::ng-deep)/g;
517521
const _selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$';
518522
const _polyfillHostRe = /-shadowcsshost/gim;
519523
const _colonHostRe = /:host/gim;

‎packages/compiler/test/shadow_css_spec.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ export function main() {
231231
expect(css).toEqual('x[a] y {}');
232232
});
233233

234+
it('should handle ::ng-deep', () => {
235+
let css = '::ng-deep y {}';
236+
expect(s(css, 'a')).toEqual('y {}');
237+
css = 'x ::ng-deep y {}';
238+
expect(s(css, 'a')).toEqual('x[a] y {}');
239+
css = ':host > ::ng-deep .x {}';
240+
expect(s(css, 'a', 'h')).toEqual('[h] > .x {}');
241+
css = ':host ::ng-deep > .x {}';
242+
expect(s(css, 'a', 'h')).toEqual('[h] > .x {}');
243+
css = ':host > ::ng-deep > .x {}';
244+
expect(s(css, 'a', 'h')).toEqual('[h] > > .x {}');
245+
});
246+
234247
it('should pass through @import directives', () => {
235248
const styleStr = '@import url("https://fonts.googleapis.com/css?family=Roboto");';
236249
const css = s(styleStr, 'a');

0 commit comments

Comments
 (0)