Skip to content
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

Combination of multiple :host-context and :host selectors don't work #41237

Closed
kreuzerk opened this issue Mar 17, 2021 · 2 comments
Closed

Combination of multiple :host-context and :host selectors don't work #41237

kreuzerk opened this issue Mar 17, 2021 · 2 comments
Assignees
Labels
area: core Issues related to the framework runtime core: CSS encapsulation P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Milestone

Comments

@kreuzerk
Copy link
Contributor

🐞 bug report

Affected Package

12.0.0-next.4

Is this a regression?

No

Description

Version 12.0.0-next.4 of Angular brings improved support for host-context selectors. (See PR)

We are currently implementing a UI library and this fix will be very helpful for our project. However, we think that there's still an enhancement for this feature.

I installed 12.0.0-next.4 and tested the following scenario.

@Component({
    selector: 'foo-component,bar-component',
    template: `<h1>Some text</h1>`,
    styles: [`
        :host-context(.mobi-b2c-theme-light) :host(bar-component) {
            color: blue;
        }
        :host-context(.mobi-b2c-theme-light) :host(foo-component) {
            color: red;
        }
    `]
})
export class SomeComponent {
}

I tried this with inline styles and with a separate stylesheet referenced by styleUrls. Both didn't work. However, @petebacondarwin found a workaround.


styles: [
  `:host-context(.mobi-b2c-theme-light) :host(bar-component) {
    color: blue;
  }`,
  `:host-context(.mobi-b2c-theme-light) :host(foo-component) {
    color: red;
  }`
]

foo-component should be red and bar-component should be blue. Currently, only the first selector gets applied. Means bar is blue and foo is not affected by any styles. The generated CSS looks like this:


.mobi-b2c-theme-light   bar-component[_nghost-%COMP%] {
    color: blue;
}
.mobi-b2c-theme-light[_nghost-%COMP%]   foo-component[_nghost-%COMP%], .mobi-b2c-theme-light   [_nghost-%COMP%]   foo-component[_nghost-%COMP%] {
    color: red;
}"

🔬 Minimal Reproduction

https://github.com/kreuzerk/host-selector-example

I needed to create a Stackblitz because I was unable to pull the next version of Angular into Stackblitz ;)

🌍 Your Environment

Angular Version:
12.0.0-next.4

@petebacondarwin petebacondarwin added area: core Issues related to the framework runtime core: CSS encapsulation P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Mar 17, 2021
@ngbot ngbot bot added this to the Backlog milestone Mar 17, 2021
@petebacondarwin petebacondarwin self-assigned this Mar 17, 2021
@petebacondarwin
Copy link
Member

Working on this now...

petebacondarwin added a commit to petebacondarwin/angular that referenced this issue Mar 18, 2021
…lectors

When there was more than one rule in a single style string, only the first
rule was having its `:host` selector processed correctly. Now subsequent
rules will also be processed accurately.

Fixes angular#41237
mhevery pushed a commit that referenced this issue Mar 19, 2021
…lectors (#41261)

When there was more than one rule in a single style string, only the first
rule was having its `:host` selector processed correctly. Now subsequent
rules will also be processed accurately.

Fixes #41237

PR Close #41261
TeriGlover pushed a commit to TeriGlover/angular that referenced this issue Apr 5, 2021
…lectors (angular#41261)

When there was more than one rule in a single style string, only the first
rule was having its `:host` selector processed correctly. Now subsequent
rules will also be processed accurately.

Fixes angular#41237

PR Close angular#41261
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: CSS encapsulation P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants