Skip to content

ViewEncapsulation.Emulated breaks if certain attribute selectors (*= and ~=) are used. #6249

Description

@Honn

Update: The first two issues, *= and ~=, are no longer a problem (last tested in RC.4) but the problem with spaces in values still exists. See the third comment.


Emulated view encapsulation can fail if there are any attribute selectors using contains or contains word, so *= or ~=.

Example:
Let's say we have a component with the selector my-component. It also has a custom attriute called custom-attribute. First a working case, using attribute equals.

my-component[custom-attribute="value"] {
    background-color: red;
}

# View encapsulation converts this to
my-component[custom-attribute="value"][_ngcontent-eod-X] {
    background-color: red;
}

In this case both the view encaptulation and the custom attribute selector will work as expected. However, lets use a contains selector instead (note the *= in the selector).

my-component[custom-attribute*="value"] {
    background-color: red;
}

This time the view encapsulation gets confused and adds the new attribute in the middle of the selector!

my-component[custom-attribute[_ngcontent-eod-X]*="value"] {
    background-color: red;
}

Needless to say this cases both the encaptulation and the attribute selector to fail.

Final note: It appears that the ^= doesn't have this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions