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

Ability to turn off dash case for CSSClass directive #3001

Closed
pflannery opened this issue Jul 12, 2015 · 20 comments
Closed

Ability to turn off dash case for CSSClass directive #3001

pflannery opened this issue Jul 12, 2015 · 20 comments
Labels
effort1: hours feature Issue that requests a new feature

Comments

@pflannery
Copy link

I'm finding problems with css that uses camel case when using CSSClass because this line automatically converts each class to dashed case.

Can we have a choice between camel case and raw input when using the CSSClass directive?
Would be nice if we could provide a means to configure CSSClass directive per component.

@pkozlowski-opensource
Copy link
Member

@pflannery why it is causing issues for you in practice? AFAIK css class names are not case-sensitive (https://developer.mozilla.org/en/docs/Case_Sensitivity_in_class_and_id_Names) and you can't have mixed cases in your HTML markup.

I'm finding problems with css that uses camel case

Could you be more precise? What is the exact use-case?

Can we have a choice between camel case and raw input when using the CSSClass directive?
Would be nice if we could provide a means to configure CSSClass directive per component.

This wouldn't work as 3rd party components would be dependent on app's settings and thus could break without warning.

Once again, I would be keen on knowing more about your exact use-case. It sounds like you might have mixed-case in your CSS classes (which is not great) and then trying to replicate this markup in your HTML.

@pflannery
Copy link
Author

@pkozlowski-opensource The problem comes with using and writing libraries that follow camel case guidelines like OOCSS or using libraries like animate.css

Camel case is my preference over dashed case. For me I would have to convert all my previous libraries over to dashed case or would be forced to write them all as lower case (for angular) to get around the dash case transformer. I personally want to keep readability using camel case classes both in code and html.

This wouldn't work as 3rd party components would be dependent on app's settings and thus could break without warning.

Then perhaps a separate directive is a better approach?

@pkozlowski-opensource
Copy link
Member

OK, I see, this is only for readability then, right?

Then perhaps a separate directive is a better approach?

As it is coded today, this conversion affects all the places where a CSS class is set on an element, so a separate directive wouldn't work / isn't enough.

@tbosch maybe we are too aggressive about this conversion and should do it only when a CSS class name comes from HTML attribute value (that is, when using [class.foo]=expr syntax?

@mhevery
Copy link
Contributor

mhevery commented Jul 22, 2015

I don't see how a choice of CSS class names causes an issue. Could you provide a working example demonstrating the problem.

@tbragaf
Copy link

tbragaf commented Jul 22, 2015

Hi all!

I also came into this issue. Here s how it goes:

Html I provide:
image

Output Html:
image

As you can see, I used an expression to bind the class of the element.
But the output has hyphens instead of Capital Letters.

The expected output:
image

The actual output:
image


Result

As you can see in the actual output I don't have that darker blue color (from the expected output).
Also, those dashes appear on the output HTML.

Best regards,
Tiago Braga

@pkozlowski-opensource
Copy link
Member

@TiagoBraga39 as quick work-around make sure that your CSS class names are lower-cased (which makes sense anyway, since browsers are not dealing with case-sensitive CSS)

@tbragaf
Copy link

tbragaf commented Jul 22, 2015

@pkozlowski-opensource The thing is I actually have a ton of css classes with capital letters, which worked on NG1, and now I can't use them in NG2?

@pkozlowski-opensource
Copy link
Member

This is why I marked it as a work-around.

@pflannery
Copy link
Author

I've found a case where the work-around doesn't work.

It baffled me for a while because at first I was sure that classes are case sensitive but then I realised that it's because my angular project didn't have a doctype defined and when I added <!DOCTYPE html> at the top of the page this workaround stops working in firefox and chrome (didnt try any other browser). Something else I noticed is that the article posted above was last updated 05 Mar 2001.

I think the ability to output as WYSIWYG would resolve this.

@pflannery
Copy link
Author

@mhevery I've tried to post a working plunker example but cant get angular to work there. I always see "require is undefined"..if you have a template from plunker or fiddler etc.. I'd be happy to try demonstrate

@tbragaf
Copy link

tbragaf commented Jul 22, 2015

@pflannery
There you go: http://plnkr.co/edit/N5uD9ogaOghiKLRNP1JQ?p=preview

Note 1, It's just an Hello World Sample with 2 cdn:

  • Angular alpha 31
  • System 0.16
  • Note 2, About the traceur options

  • I can't exactly remember the options to put on config.js since I don't have the code with me.
  • It also goes with google traceur and couldn't find system 0.18 cdn, but for the sake of the plunker it should be fine.

    Best regards,
    Tiago Braga

    @pflannery
    Copy link
    Author

    @TiagoBraga39 thank you very much!

    Here is an example of the issue http://plnkr.co/edit/StVbjnVMWWnBZPtVQSsu?p=preview

    @tbragaf
    Copy link

    tbragaf commented Jul 23, 2015

    Yup, same behaviour.
    After changing to dash case as @pkozlowski-opensource said, it works. But only that way.

    @moizp
    Copy link

    moizp commented Jul 24, 2015

    +1 on maintaining original capitalization and dashes.

    We use css class names such as Tabs-tabLabel and dynamically bind Tabs-tabLabel--selected. Worked fine with ng1 (using ng-class) and we'd very much like to continue that in ng2.

    pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Jul 24, 2015
    pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Jul 24, 2015
    @tbosch
    Copy link
    Contributor

    tbosch commented Jul 24, 2015

    Just verified myself: querySelector does differentiate between the case in class names.

    pkozlowski-opensource added a commit to pkozlowski-opensource/angular that referenced this issue Jul 27, 2015
    Fixes angular#3001
    
    BREAKING CHANGE:
    
    View renderer used to take normalized CSS class names (ex. fooBar for foo-bar).
    With this change a rendered implementation gets a calss name as specified in a
    template, without any transformations / normalization. This change only affects
    custom view renderers that should be updated accordingly.
    pkozlowski-opensource added a commit that referenced this issue Jul 27, 2015
    Fixes #3001
    
    BREAKING CHANGE:
    
    View renderer used to take normalized CSS class names (ex. fooBar for foo-bar).
    With this change a rendered implementation gets a calss name as specified in a
    template, without any transformations / normalization. This change only affects
    custom view renderers that should be updated accordingly.
    
    Closes #3264
    @rixrix
    Copy link
    Contributor

    rixrix commented Jul 29, 2015

    Hi, tnx for not de-normalizing the CSS class name

    @moizp
    Copy link

    moizp commented Aug 3, 2015

    Thanks for the change. It's better than before but still not working as expected. Tried the following with alpha 33.

    While using [class.Tabs-tabLabel--selected] = "tab.isActive()" the css class is only selected if it is in lower-case i.e. .tabs-tablabel--selected. It should work with .Tabs-tabLabel--selected

    @pkozlowski-opensource
    Copy link
    Member

    @amoizp you are talking about a different issue here. You need to keep in mind that HTML is not case-sensitive nor case-preserving, so if you type [class.Tabs-tabLabel-selected] = "tab.isActive()" in HTML a browser will "auto-correct" it to be [class.tabs-tablabel-selected] = "tab.isActive()" (lower-casing all attribute names). This happens before angular's compiler run, so we can't do much about his one.

    @moizp
    Copy link

    moizp commented Aug 3, 2015

    @pkozlowski-opensource Got it, thanks.

    So far, our upgrade to angular 2 is working out very well. Keep it up guys!

    @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 6, 2019
    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
    Labels
    effort1: hours feature Issue that requests a new feature
    Projects
    None yet
    Development

    Successfully merging a pull request may close this issue.

    7 participants