Skip to content

cdk-high-contrast mixin not working anymore without :host selector #18147

Closed
@biolauri

Description

@biolauri

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:

  1. Use cdk-high-contrast mixin outside of :host selector in Angular 9 Release Candidate
  2. See that its coding is not applied in high contrast mode
  3. Use mixin within :host selector
  4. See that its is applied in high contrast mode
StackBlitz
  1. Open StackBlitz to reproduce
  2. Click button to emulate high contrast mode
  3. 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

Metadata

Metadata

Assignees

Labels

AccessibilityThis issue is related to accessibility (a11y)P2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions