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-values-5][css-mixins-1] Add an if-test for local variables #11455

Open
andruud opened this issue Jan 7, 2025 · 1 comment
Open

[css-values-5][css-mixins-1] Add an if-test for local variables #11455

andruud opened this issue Jan 7, 2025 · 1 comment

Comments

@andruud
Copy link
Member

andruud commented Jan 7, 2025

Within a custom function, var() can refer to a local variable / parameter, e.g:

@function --add-one(--x) {
  result: calc(var(--x) + 1px);
}

The if() function has a style() test, which accepts a <style-query>. We should have a test which can reach local variables / parameters as well, such that you can do e.g.:

@function --select(--option) {
  result: if(
    test(--option: one): foo; 
    test(--option: two): bar;
    else: baz;
  );
}

One option could be to spec that if(style()) targets locals within a function context (i.e. it sees the same thing var() sees), but this might stretch the definition of "style". Otherwise, I guess we'll need to invent a new test.

@tabatkins
Copy link
Member

I think just using style() is the right way to go. Local variables fully shadow custom properties in other contexts; it feels weird for style() to be able to pierce thru that and see all the way to the element. Also, the variable shadowing behavior is very intentionally meant to be able to let a caller override what a callee sees for custom props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: FTF agenda items
Development

No branches or pull requests

2 participants