Description
Since reworking the cdk-high-contrast
mixin in #17378 for Angular 9, this mixin doesn't work anymore when not being used within :host
in ViewEncapsulation.Emulated
(which is currently default).
As the new High Contrast Service adds its classes to the root of the document, the compound selector generated by the mixin relies on the class cdk-high-contrast-active
(or any other derived target class) being outside of the ViewEncapsulation for the current component. But without using the :host
selector around, every selector gets their component attribute for View Encapsulation.
Inside :host
, it does work as Angular's preparing ViewEncapsulation is ignoring everything before :host
.
This should at least be documented, but I would prefer a way of handling in all cases. I'd say, it's bad practice to wrap everything in :host
, which is a workaround currently.
By the way, the example in the current documentation doesn't work either (and the documentation is quite outdated, for which I'll add another issue).
Reproduction
Steps to reproduce:
- Use
cdk-high-contrast
mixin outside of:host
selector in Angular 9 Release Candidate - See that its coding is not applied in high contrast mode
- Use mixin within
:host
selector - See that its is applied in high contrast mode
StackBlitz
- Open StackBlitz to reproduce
- Click button to emulate high contrast mode
- Inspect applied SCSS coding (the red border should be seen instead of the green one)
Expected Behavior
The mixin should generate output, so that the attribute (component) selector doesn't get added to the .cdk-high-contrast-active
selector:
.cdk-high-contrast-active [_nghost-umf-c0] .border-in-high-contrast[_ngcontent-umf-c0]{border:2px solid green}
In StackBlitz, the green border.
Actual Behavior
Attribute (component) selector ([_ngcontent-umf-c0]
) does get added to the .cdk-high-contrast-active
selector:
.cdk-high-contrast-active[_ngcontent-umf-c0] .border-in-high-contrast[_ngcontent-umf-c0]{border:2px solid red}
In StackBlitz, the red border.
Environment
- Angular: 9.0.0-rc.7
- CDK/Material: 9.0.0-rc.7
- Browser(s): Internet Explorer; Chrome with adding
cdk-high-contrast-active
class manually - Operating System (e.g. Windows, macOS, Ubuntu): Windows