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

when use css guards plus mixins seems not to be working #2566

Closed
maxidr opened this issue Apr 22, 2015 · 3 comments
Closed

when use css guards plus mixins seems not to be working #2566

maxidr opened this issue Apr 22, 2015 · 3 comments

Comments

@maxidr
Copy link

maxidr commented Apr 22, 2015

My case:

app.less

@import "../../vendor/nifty-v2.2/less/nifty.less";


.project-selector .project-name { 
    .label;
    .label-mint;      // line 203
    font-size: 100%;
}

nifty.less

@enable-mint                : true;

& when (@enable-mint = true) {
    .label-mint{background-color: @mint-bg}
}

When try to use the .label-mint as a mixin fails with the error:

[20:38:34] Error with LESS: .label-mint is undefined in file /Users/maxidr/Projects/customer_insight/dashboard-frontend/src/less/app.less line no. 203

I'm really lost, I'm using the mixin in a wrong way?

Thanks

@seven-phases-max
Copy link
Member

Mixins defined in a ruleset are visible in that ruleset (and its children) only. And & {} is also just a ruleset (it's not really an euphemism for anif statement).

For your example the solution is as simple as:

@enable-mint: true;

.label-mint when (@enable-mint = true) {
    background-color: @mint-bg;
}

If you can't modify "nifty.less" use extend instead:

.project-selector .project-name { 
    &:extend(.label, .label-mint);
    font-size: 100%;
}

For more details on why & {} is not if clone see #2072.

@maxidr
Copy link
Author

maxidr commented Apr 23, 2015

Thank you very much Max!, I understand now.

@seven-phases-max
Copy link
Member

Closing as "expected behaviour".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants