MadLittleMods / postcss-css-variables

PostCSS plugin to transform CSS Custom Properties(CSS variables) syntax into a static representation
https://madlittlemods.github.io/postcss-css-variables/playground/
Other
536 stars 62 forks source link

Variable fallback not working #102

Open alexhaines123 opened 5 years ago

alexhaines123 commented 5 years ago

I'm using postcss-css-variables with a JSON file with this data:

{
    "variables" : {
        "--color-form-selected" : "red",
        "--color-positive-green" : "green"
   }
}

On this css which uses variable fallbacks but oddly it chooses the last variable provided instead of the first.

.a-checkbox__input:checked ~ .a-checkbox__label {
    background-color: var(--color-form-selected);
    border-color: var(--color-positive-green, var(--color-form-selected));
}

But it outputs

.a-checkbox__input:checked ~ .a-checkbox__label {
    background-color: red;
     border-color: red;
}

Expected

.a-checkbox__input:checked ~ .a-checkbox__label {
    background-color: red;
    border-color: green;
}
MadLittleMods commented 4 years ago

For reference, the following example works as expected. I would expect that https://github.com/MadLittleMods/postcss-css-variables/issues/37 fixed the problem which was released in v0.7.0. Which version are you using?

Input:

:root {
    --color-form-selected: red;
    --color-positive-green: green;
}

.a-checkbox__input:checked ~ .a-checkbox__label {
    background-color: var(--color-form-selected);
    border-color: var(--color-positive-green, var(--color-form-selected));
}

Output:

.a-checkbox__input:checked ~ .a-checkbox__label {
    background-color: red;
    border-color: green;
}