Skip to content

Cascading vars: Plugin works correctly? Or browsers do not work correctly? #78

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

Closed
belozer opened this issue Jul 24, 2018 · 4 comments
Closed

Comments

@belozer
Copy link

belozer commented Jul 24, 2018

I'am not found specs with examples abount cascading vars. But try this case https://github.com/MadLittleMods/postcss-css-variables#caveats native in Browser on CodePen. (without plugin)

<div class="component">
    Black

    <h1 class="title">
        Blue

        <p class="decoration">
            Green

            <h1 class="title">Blue with this plugin, but green per spec</h1>
        </p>
    </h1>
</div>
.component {
  --text-color: blue;
}

.component .title {
  color: var(--text-color);
}

.component .decoration {
  --text-color: green;
  color: var(--text-color);
}

image

It turns out that the plugin works correctly? Or browsers do not work correctly?

@belozer belozer changed the title Plugin works correctly? Or browsers do not work correctly? Cascading vars: Plugin works correctly? Or browsers do not work correctly? Jul 24, 2018
@belozer
Copy link
Author

belozer commented Jul 24, 2018

Or is this an incorrect example?

And need next

<div class='block theme'>
  Blue
  <h1 class='block__title'>
    Red in plugin, but blue in spec
  </h1>
</div>
:root { --color: red }

.theme { --color: blue }

.block, 
.block__title {
  color: var(--color)
}

@MadLittleMods
Copy link
Owner

MadLittleMods commented Jul 24, 2018

Thanks for noticing. I think it is an incorrect example, https://github.com/MadLittleMods/postcss-css-variables/blob/a817fb90a23eb9dbf7b3848583b67e0299250c3e/README.md#caveats and perhaps had falsely assumed custom properties were inherited/cascading. The --text-color: green; only applies to .decoration.

Your second example, #78 (comment) compiles as expected (all red btw) because we only take into account explicit relationships.


We can simplify the example to the following (feel free to create a PR)

<div class="block theme-blue">
  Red in plugin, but blue in spec
</div>
:root { --color: red }
.theme-blue { --color: blue }

.block {
  color: var(--color);
}

@belozer
Copy link
Author

belozer commented Jul 24, 2018

@MadLittleMods PR Ready :) #79

@MadLittleMods
Copy link
Owner

MadLittleMods commented Jul 24, 2018

Thanks for the PR @belozer. From my extra digging, I think we just need to change everything to <div>. Sorry for the confusion

✔️ I looked some more info to verify and CSS custom properties do inherit, https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables#Inheritance_of_CSS_Variables

❌ The problem with the example is the nesting of <p> and <h1>. <p> can't contain other block-level elements.


We can update the example to be the following,

<div class="component">
    Black

    <div class="title">
        Blue

        <div class="decoration">
            Green

            <div class="title">Blue with this plugin, but green per spec</div>
        </div>
    </div>
</div>
.component {
  --text-color: blue;
}

.component .title {
  color: var(--text-color);
}

.component .decoration {
  --text-color: green;
  color: var(--text-color);
}

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