-
-
Notifications
You must be signed in to change notification settings - Fork 70
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 Custom Properties not supported #89
Comments
If the point is to match For example, when I tried this in chrome: var styleObj = document.styleSheets[0].cssRules[0].style;
styleObj.cssText = "--hello-world: blue; background: var(--hello-world);"
console.log(styleObj.background)
// Output: var(--hello-world) It seems like custom properties just need to be set on the A custom property is defined as "any valid identifier that starts with two dashes, except -- itself" |
Honestly, why has this issue been open for so long? There are also multiple issues describing this problem in the jsdom repo, which go back multiple years.. I've been looking through the cssstyle source and it appears that this issue should be easy to solve. Correct me if I'm wrong, but the problem seems to be with the way properties are filtered: https://github.com/jsdom/cssstyle/blob/master/lib/CSSStyleDeclaration.js#L60
According to the spec:
So a solution could be:
Willing to provide a hand, not sure if I'm the right person for the job, since I'm completely unfamiliar with the source. |
@sheijne I agree we should get this one resolved. I think your suggestion is a good start, however the spec also states css custom properties are case sensitive so we need to account for that. I will try to put up a PR for this soon. In the meantime if you want to take a stab at it (including test cases) that would be awesome. |
We have added partial support for css custom properties in 2.2.0. Properties beginning with |
@jsakas, original example still doesn't work, is there any work being done to add this feature? |
Folks, any updates on this? |
I believe there are two issues here: 1.) Unable to set a value into a CSS variable via the style attribute. The first issue was fixed here by this code change: cssstyle/lib/CSSStyleDeclaration.js Lines 59 to 63 in b527ed7
This fix allowed a new CSS property to be declared, example:
However, this does not fix the second issue. If you attempt to reference a CSS variable, it is removed. Example:
I believe the code that removes it is as follows... When calling the setter on cssstyle/lib/CSSStyleDeclaration.js Line 51 in b527ed7
This code then attempts to call a setter for the CSS property onto cssstyle/lib/CSSStyleDeclaration.js Line 69 in b527ed7
For each type of CSS property there are setters defined. For example, the background goes through the cssstyle/lib/properties/background.js Line 15 in b527ed7
The Iterates here: Lines 543 to 552 in b527ed7
The possible cssstyle/lib/properties/background.js Lines 6 to 12 in b527ed7
It then attempts to check if the value is valid, via an The https://github.com/jsdom/cssstyle/blob/master/lib/properties/backgroundColor.js#L5-L21 Ultimately calls into Line 288 in b527ed7
The Thoughts on a potential fix In parsers, such as
This would need to be done for each parser that could potentially run on a value where a CSS variable is allowed. Also, in order to support CSS variables that are used as parts of things like a hsla color, for example:
The RegEx's used in the parsers, such as the one in Lines 31 to 35 in b527ed7
|
Any updates or plan to fix this? There doesn't seem to be a way currently to test style that reference a custom property as it's just silently dropped. |
CSS Custom properties are ignored as are the rules which use them.
Unlike the CSS color names PR, I have no idea how to resolve this issue.
I don't mind contributing to solve this issue, but I will likely need some help.
The text was updated successfully, but these errors were encountered: