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

New CSS filter functions conflict with built-in Sass functions #151

Closed
sorccu opened this issue Aug 16, 2013 · 27 comments · Fixed by #515
Closed

New CSS filter functions conflict with built-in Sass functions #151

sorccu opened this issue Aug 16, 2013 · 27 comments · Fixed by #515

Comments

@sorccu
Copy link

sorccu commented Aug 16, 2013

The following code:

foo {
  -webkit-filter: grayscale(100%);
}

Results in the following with sass 3.2.10:

foo {
  -webkit-filter: grayscale(100%); }

But the following with libsass master (at 4dd61de currently):

/private/tmp/test/grayscale.scss:2: error: argument `$color` of `grayscale($color)` must be a color
Backtrace:
    /private/tmp/test/grayscale.scss:2, in function `grayscale`
    /private/tmp/test/grayscale.scss:2

This seems to be a conflict with the built-in grayscale function.

@benfrain
Copy link

benfrain commented Sep 3, 2013

Yes, I just hit this too.

@terracatta
Copy link

Hitting this as well.

@calderas
Copy link

👍

@dimoreira
Copy link

Any news on this one?

@akhleung
Copy link

akhleung commented Dec 4, 2013

I'm currently working on @extend, but I'll try to get to this one before the holidays!

@lmartins
Copy link

lmartins commented Jan 9, 2014

Having this issue too.

@restlessdesign
Copy link

👍

Confirming that darken() and saturate() are also affected. Is there a workaround?

@kennethormandy
Copy link

Found a workaround, you can use this function in the meantime. It should be a drop-in solution:

@function grayscale($value) {
  @return #{ "grayscale(" + $value + ")" };
}

You can vendor prefix it, too, if you’d like:

@mixin filter($properties) {
  // Your vendor prefixing stuff here, I am using Bourbon:
  @include prefixer(filter, $properties, webkit moz spec);
}

Then, you can just write:

@include filter(grayscale(100%));

@akhleung
Copy link

Just putting this here for reference:
https://developer.mozilla.org/en-US/docs/Web/CSS/filter

@akhleung akhleung mentioned this issue Feb 10, 2014
@restlessdesign
Copy link

@kennethormandy Have you found a work around for the SASS functions which take two parameters?

@function darken($color, $amount) {
  @return #{ "darken(" + $color + "," + $amount ")" };
}

.selector {
    border: 1px solid darken(#f0f1f4, 3);
}

Outputs:

border: 1px solid darken(#f0f1f4,3"");

…but really it shouldn’t even be outputting darken—it should be a new color value entirely.

@kennethormandy
Copy link

Wow, I had no idea darken() didn’t work. @akhleung, is that a regression? Sorry, I was testing the problem and recreated the issue, ha. @restlessdesign, if you get rid of your custom function, darken() works already. So just write:

.selector {
    border: 1px solid darken(#f0f1f4, 3);
}

and you’ll get

.selector {
  border:1px solid #e7e9ee;
}

I think you might (understandably) be mixing up Sass’ functions with CSS Filters. The example I gave will only work because it’s a CSS Filter. If you’re looking to use Sass’ darken or saturate, that should work already, per the Sass docs. If you want to use the CSS Filter saturate, you’re on the right track basing it off of my greyscale() function. There is CSS darken() filter, so you’re actually just over-writing libsass’ built-in darken function right now.

@restlessdesign
Copy link

My mistake. I was nesting methods, and called adjust_hue instead of adjust-hue, which cascaded into darken(). Brutal, but I love that LibSass will actually report errors or give invalid output instead of silently ignoring calls! Sorry for the false alarm.

@mantismamita
Copy link

+1
Although the workaround works fine (thank you @kennethormandy) it would be nice if it were fixed.

@kleinfreund
Copy link

Is there any news on this one? Would be really nice to not obfuscate the code with the workaround provided above, although it works.

@arobbins
Copy link

arobbins commented Jul 5, 2014

Looking for a solution as-well =)

@Richard-Walton
Copy link

+1

2 similar comments
@igregson
Copy link

+1

@DougPuchalski
Copy link

+1

@DougPuchalski
Copy link

Thanks @kennethormandy for workaround

@kaptankorkut
Copy link

+1. By the way: Thanks @kennethormandy for the solution.

benesch added a commit to benesch/libsass that referenced this issue Aug 13, 2014
CSS filter effects [0] define several functions (invert, grayscale,
opacity, saturation) that collide with the names of built-in Sass
functions. Overload these functions with a no-op when the filter effects
function signature is discovered. This is compatible with Ruby Sass.

For example, calling `invert` with a color will return an inverted color
as before:

    color: invert(sass#333) => color: #cccccc

But calling `invert` with a percentage will pass through the function
call unharmed.

    filter: invert(30%) => filter: invert(30%)
    filter: invert(.03) => filter: invert(.03)

Fixes sass#151.

[0]: http://www.w3.org/TR/filter-effects/
@blackfalcon
Copy link

Just opened (and closed) an issue about this as well. It would be nice to get this cleaned up as there is a fundamental shift of CSS to start using more and more function like syntax with overlap.

Yeah @kennethormandy, thanks for the workaround idea, but when you do that, then you kill the actual grayscale() function and that sucks! I am hoping that a real fix to this comes soon.

@tamlyn
Copy link

tamlyn commented Sep 4, 2014

Another workaround: instead of filter: invert() use filter: #{"invert()"}. You can put whatever you want within the quotes and it will be output verbatim.

@HamptonMakes
Copy link
Member

Alright, let me see if we can get this in 3.0.

@HamptonMakes HamptonMakes added this to the 3.0 milestone Oct 3, 2014
benesch added a commit to benesch/libsass that referenced this issue Oct 6, 2014
CSS filter effects [0] define several functions (invert, grayscale,
opacity, saturation) that collide with the names of built-in Sass
functions. Overload these functions with a no-op when the filter effects
function signature is discovered. This is compatible with Ruby Sass.

For example, calling `invert` with a color will return an inverted color
as before:

    color: invert(sass#333) => color: #cccccc

But calling `invert` with a percentage will pass through the function
call unharmed.

    filter: invert(30%) => filter: invert(30%)
    filter: invert(.03) => filter: invert(.03)

Fixes sass#151.

[0]: http://www.w3.org/TR/filter-effects/
HamptonMakes added a commit to sass/sass-spec that referenced this issue Oct 6, 2014
benesch added a commit to benesch/libsass that referenced this issue Oct 7, 2014
CSS filter effects [0] define several functions (invert, grayscale,
opacity, saturation) that collide with the names of built-in Sass
functions. Overload these functions with a no-op when the filter effects
function signature is discovered. This is compatible with Ruby Sass.

For example, calling `invert` with a color will return an inverted color
as before:

    color: invert(sass#333) => color: #cccccc

But calling `invert` with a percentage will pass through the function
call unharmed.

    filter: invert(30%) => filter: invert(30%)
    filter: invert(.03) => filter: invert(.03)

Fixes sass#151.

[0]: http://www.w3.org/TR/filter-effects/
HamptonMakes pushed a commit to sass/sass-spec that referenced this issue Oct 12, 2014
@cdCorey
Copy link

cdCorey commented Nov 3, 2014

Thank you @tamlyn! I've been using Scout.app, which is apparently still on an old version of Sass, so your workaround is a fast, simple solution that actually works.

@MagicJoseph
Copy link

@function filters($filter, $value) {
@return #{$filter}#{"(" + $value + ")"}
}

$prefixes:
"-webkit-",
"-moz-",
"-ms-",
"-o-",
null;

@mixin prefixer($property, $value) {
@each $prefix in $prefixes {
#{$prefix}#{$property}: $value;
}
}

robinboehm pushed a commit to workshops-de/angular.de that referenced this issue Sep 20, 2017
robinboehm pushed a commit to workshops-de/angular.de that referenced this issue Sep 22, 2017
@rgdevme
Copy link

rgdevme commented Mar 22, 2019

@restlessdesign Hi folks, I know this it very late but, I just had this issue and my workaround was to quote the filter function and then use unquote() on it.

So I wrote:
* { filter: unquote("filter-function(values)") }

And the output works.

@inertlab
Copy link

why is this closed? the workaround is not a good solution. why can't you just change the name of the grayscale() sass function?

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