Can't override Open-Props custom property

I've been using Open-Props in my Svelte projects recently. I've tried overriding --shadow-color and noticed that I'm not able to. Here is my code:
.meter-bar {
--shadow-color: 50 100% 50%;
box-shadow: var(--shadow-5);
}
.meter-bar {
--shadow-color: 50 100% 50%;
box-shadow: var(--shadow-5);
}
I've looked at Open-Props' stackblitz playgrounds and noticed I can't override the color there either. Dev tools show it should be getting used. It's not Svelte's fault because I tried doing this in a raw codepen with no success. This issue persists across browsers (Firefox Dev, Chrome Canary, Arc) What am I doing wrong?
93 Replies
Venyl
VenylOP5mo ago
In my dev tools it seems like this override is working with the open-props style being crossed out
No description
Venyl
VenylOP5mo ago
However when I edit this crossed-out style then that actually makes changes to my shadow's color (tested on Chrome and Arc)
ἔρως
ἔρως5mo ago
it kinda feels like that the sub-values are being interpreted as compile type
Venyl
VenylOP5mo ago
I don't understand Can you elaborate?
ἔρως
ἔρως5mo ago
when svelte generates the css, it seems that nested var and calc are calculated before the generation
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
This is in the SASS + Open-Props stackblitz playground
ἔρως
ἔρως5mo ago
that's the original code, not the compiled code
Venyl
VenylOP5mo ago
still doesn't work
ἔρως
ἔρως5mo ago
from my terrible understanding, it should work
Venyl
VenylOP5mo ago
So Svelte probably isn't at fault here, if anything maybe it's Vite
ἔρως
ἔρως5mo ago
try using !important by the way, try setting the shadow color in the html element before the code is compiled
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
tried on a raw codepen, still nothing doesn't work
ἔρως
ἔρως5mo ago
im out of ideas then the documentation for this is below hot steamy summer-time milky dumpster juice https://open-props.style/#shadows <-- nothing about the shadow color
Venyl
VenylOP5mo ago
you can override it I'm sure of that, it's just a css variable
ἔρως
ἔρως5mo ago
that's not the final result that the browser presents
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
modified demo from Adam Argyle, somehow works here https://stackblitz.com/edit/open-props-light-only?file=index.css here is the unmodified version
ἔρως
ἔρως5mo ago
basically, it's re-writing the entire shadow definition, not changing the color that's like rebuilding the entire house because you want to rotate a slice of bread but hey, it's a valid approach
Venyl
VenylOP5mo ago
wait you're right, if I remove that --shadow-5 declaration the shadow goes back to the default color
ἔρως
ἔρως5mo ago
exactly
Venyl
VenylOP5mo ago
why does it work like that? it makes no sense to me even the dev tools are confused
ἔρως
ἔρως5mo ago
well, compare the value that the browser uses with the value that's in that css
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
the browser just uses the variable
ἔρως
ἔρως5mo ago
what i saw in some stackblitz examples wasn't that and based on the color and alignment, that's not the element inspector
Venyl
VenylOP5mo ago
it is just Chrome Canary
ἔρως
ἔρως5mo ago
looks weird
Venyl
VenylOP5mo ago
idk if normal Chrome has the theming etc
ἔρως
ἔρως5mo ago
nah, it's just white
Venyl
VenylOP5mo ago
anyway, it uses the variable and if I modify that original variable then the color gets changed
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
bruh...
ἔρως
ἔρως5mo ago
it makes no sense is that a svelte example?
Venyl
VenylOP5mo ago
just a codepen
ἔρως
ἔρως5mo ago
then you're comparing onions and apples
Venyl
VenylOP5mo ago
what? it should work in a codepen first and foremost
ἔρως
ἔρως5mo ago
your original problem was svelte + open props does codepen support svelte?
Venyl
VenylOP5mo ago
but it turns out it doesn't even work outside of svelte so that's what we should focus on first but I'm out of ideas
ἔρως
ἔρως5mo ago
im out of ideas too the documentation doesn't talk about it, so, i will assume that it isn't a supported case (which should be)
Venyl
VenylOP5mo ago
but Adam Argyle himself made that demo where he did it and that works somehow by redeclaring the style
ἔρως
ἔρως5mo ago
which demo?
ἔρως
ἔρως5mo ago
the demo re-defines everything
Venyl
VenylOP5mo ago
yes I know, but this still doesn't make sense
ἔρως
ἔρως5mo ago
can you send your example?
Venyl
VenylOP5mo ago
Which one?
Venyl
VenylOP5mo ago
No description
Venyl
VenylOP5mo ago
this is the entire codepen code
ἔρως
ἔρως5mo ago
that's not a comparable example you're not using vite
Venyl
VenylOP5mo ago
doesn't matter though it should still be working
ἔρως
ἔρως5mo ago
it does matter vite compiles the css
Venyl
VenylOP5mo ago
as I said we should first figure out why this doesn't work in a normal codepen
ἔρως
ἔρως5mo ago
alright, send the link then
ἔρως
ἔρως5mo ago
look at the css
No description
ἔρως
ἔρως5mo ago
it seems that the css is compiled without that variable
Venyl
VenylOP5mo ago
then change the default --shadow-color variable which open-props provides (there's a 2nd one if you use dark mode) it uses the variable, nothing gets compiled
ἔρως
ἔρως5mo ago
something bizarre is going on
ἔρως
ἔρως5mo ago
this is the css that should be applying in the browser
No description
Venyl
VenylOP5mo ago
I don't think this even is an open-props problem I think this is just a problem with my understanding of CSS
ἔρως
ἔρως5mo ago
i think it's a chrome problem
ἔρως
ἔρως5mo ago
No description
ἔρως
ἔρως5mo ago
firefox works just fine
Venyl
VenylOP5mo ago
this doesn't work, the shadow should be blue
ἔρως
ἔρως5mo ago
you're right
Venyl
VenylOP5mo ago
I think the main issue is that --shadow-6 gets computed from the global --shadow-color and not the local one
ἔρως
ἔρως5mo ago
it sounds like some sort of optimization to avoid too deep nesting
Venyl
VenylOP5mo ago
And there seems to be no other fix than to redefine the --shadow-6 property in my button selector Which sucks because that property is way too long
ἔρως
ἔρως5mo ago
i wouldn't worry about the size of it
Venyl
VenylOP5mo ago
I mean it's just very impractical To redefine that entire property each time I want a custom shadow color
ἔρως
ἔρως5mo ago
it is very impractical
Venyl
VenylOP5mo ago
My final solution is to just redeclare the shadow properties in a universal selector Works fine
ἔρως
ἔρως5mo ago
put it in the :root it's a lot fewer re-calculations if :root doesn't work, use html
Venyl
VenylOP5mo ago
no, that's the entire problem, the color won't update because --shadow-6 gets computed inside :root instead of on a per-element basis @Kevin if you haven't already, perhaps you could make a short video about this topic, since this is the first time I've encountered such a problem and honestly I'm still not sure what EXACTLY is going on and it's really difficult to find any information on this matter online
ἔρως
ἔρως5mo ago
that's why you go down to html then body instead of putting it everywhere
Venyl
VenylOP5mo ago
it won't work that way, --shadow-6 needs to be re-declared for every element which also wants to change --shadow-color since --shadow-6 is derived from --shadow-color, so if you don't redeclare --shadow-6 then it will just use the old --shadow-color value
ἔρως
ἔρως5mo ago
you're right
ἔρως
ἔρως5mo ago
Edit fiddle - JSFiddle - Code Playground
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Kevin Powell
Kevin Powell5mo ago
This is a good article on the issue, and also one of the solutions is *, where Chris says it's not really an option because of the performance implications
Venyl
VenylOP5mo ago
What article are you mentioning here?
Kevin Powell
Kevin Powell5mo ago
Chris Coyier
CSS-Tricks
The Big Gotcha With Custom Properties | CSS-Tricks
I've seen this confuse more than a handful of people recently, including myself, so I'm making sure it's written down.
Venyl
VenylOP5mo ago
Oh, thanks a lot :) I'll read it right away So all the fixes this article mentions are ok for some use-cases, but for me redeclaring an entire property for a shadow is too bothersome, since those can get quite long, maybe I could use solution #2 and comma-separate the selectors, but that still isn't as nice as using *, do you know of any other solutions which could fix this problem? Maybe even a pre-processor of some sort would do the job?
Kevin Powell
Kevin Powell5mo ago
Nope, its just one of the limitations around how custom properties are computed. Well, a Sass or Less variable would work the way you want, I think. As long as you don't mind using their variables instead of a custom property Err, I think. Worth quickly testing anyway
Venyl
VenylOP5mo ago
Oh, a Sass variable you say? I'll definitely check that out Thank you
Venyl
VenylOP5mo ago
Unfortunately doesn't work
No description
Venyl
VenylOP5mo ago
Well I guess I'll need to write my own pre-processor if I want both a good DX and a good UX haha
Kevin Powell
Kevin Powell5mo ago
Yeah, same limitation there. Goes to where it's defined, and uses that version.
Venyl
VenylOP5mo ago
I'm just gonna make a pre-processor, never made one, but I'll try it works
Venyl
VenylOP5mo ago
Venyl
VenylOP5mo ago
super crude and not that optimized but also should be better than using a universal selector
Want results from more Discord servers?
Add your server