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

css attribute selector [title~="flower"] doesn't work with view encapsulation #9644

Closed
esagawe opened this issue Jun 27, 2016 · 5 comments · Fixed by #11696
Closed

css attribute selector [title~="flower"] doesn't work with view encapsulation #9644

esagawe opened this issue Jun 27, 2016 · 5 comments · Fixed by #11696
Assignees
Labels
area: core Issues related to the framework runtime type: bug/fix

Comments

@esagawe
Copy link
Contributor

esagawe commented Jun 27, 2016

I'm submitting a ...

[x] bug report
[ ] feature request

Current behavior
I have the following code:

.foo[bar="baz"] {
    color: blue;
}

/* added a tilde an use another attribute value */
.foo[bar~="baz2"] {
    color: red;
}

<div class="foo" bar="baz">
    Test 1
</div>
<div class="foo" bar="baz baz2">
    Test 2
</div>

And Angular create this:

.foo[bar="baz"][_ngcontent-udm-1] {
    color: blue;
}

.foo[bar[_ngcontent-udm-1]~="baz2"][_ngcontent-udm-1] {
    color: red;
}

If I run the code the text color for "Test 1" turns blue and "Test 2" is still black. But if I change the code as followed within the Chrome debugger, "Test 2" will become red.

/* removed [_ngcontent-udm-1] */
.foo[bar~="baz2"][_ngcontent-udm-1] {
    color: red;
}

I don't see the reason for this behavior but for me it seems to be wrong.

The results were the same on Chrome and Firefox on a windows machine with angular rc1 and rc3. If encapsulation is set to ViewEncapsulation.None the css code works as expected, but I need the encapsulation.

@zoechi
Copy link
Contributor

zoechi commented Jun 27, 2016

A plunker to reproduce would be great

@esagawe
Copy link
Contributor Author

esagawe commented Jun 27, 2016

@esagawe
Copy link
Contributor Author

esagawe commented Aug 23, 2016

Do you need further information for this issue? I want to build a little widget and need a fix for it.

If you tell me where the css code is written to the html head, I could try to fix it on my own and create a pull request. I think it's somewhere within the ShadowCss class (shimCssText()), but I havn't debugged yet.

Btw. one[attr~="value"] is missing within the unit tests.

@mhevery mhevery added area: core Issues related to the framework runtime and removed comp: core/view/compiler labels Sep 7, 2016
@esagawe
Copy link
Contributor Author

esagawe commented Sep 17, 2016

The problem is the tilde within the seperators list within shadow_css.ts (line 429). My idea to remove the tilde from there doesn't work for the selector one ~ two {}.

Another solution could be to edit the final string with something like this:

var scopeSelectorExpression = new RegExp(/\[${scopeSelector}\] \~ \=, 'g');

scopeSelector = scoped + _scopeSelectorPart(selector.substring(startIndex));

return scopeSelector.replace(scopeSelectorExpression, '~=');

I don't really like this solution, but it should solve the problem. I can't be sure because the unit tests aren't running locally.

alexeagle pushed a commit that referenced this issue Sep 18, 2016
Change the seperator regular expression to ignore tildes which are followed by an equal sign.

Closes #9644
@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 Sep 9, 2019
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 type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants