[Feature Request] Allow usage of CSS variables with global overlays #744
-
Describe the bugIf you want to define a CSS variable on a dialog, the dialog content slot will not have these variables set. To ReproduceAdded fork reproduction Steps to reproduce the behavior:
Expected behaviorCSS variable Additional contexthttps://polymer.slack.com/archives/CJGFWJN9J/p1591109345221700 |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
This would be hard to find a nice fix for. I don't know if there's a proper api for getting all css variables that are used in a certain dom tree (the content node being that tree). If you know what css variables to look for, you could theoretically read their values on the 'original' dom connection point and temporarily reapply them in the wrapper inside the connection point in the body: If you not know what to look for, it would probably mean you would have to traverse all styles in the content node (parse them and look for occurrrences of Another approachAnother approach would be to keep the contentNode at the original place in the dom and just apply a
Let me know what you think |
Beta Was this translation helpful? Give feedback.
-
I can indeed get variables and reapply them in my case because I know what are the variables to apply. Traverse all styles of the content node is possible but variables can be set in parent of the content node, they are only in computedStyle that can't be traversed. The other approach is the solution used by |
Beta Was this translation helpful? Give feedback.
-
Nice. Not the best developer experience if you have to do this manually, though, so maybe we can try to come up with something more automated 🙂
Not sure if I understand you correctly, but we can do the follwoing(?): const cssVarNames = findCssVarNamesInDomTree(contentNode); // ['--my-var1', '--my-var2', ...]
const cssVarMap = cssVarNames.map(name => {
const value = getComputedStyle(contentNode).getPropertyValue(name);
return { name, value };
});
Yeah, that would be interesting to look at 👍 |
Beta Was this translation helpful? Give feedback.
-
Update: the transform: scale(1); and/or overflow: hidden; |
Beta Was this translation helpful? Give feedback.
-
Yes, you can do this when you know the variables names, I don't think you can find the css variables names in dom tree ( |
Beta Was this translation helpful? Give feedback.
-
I was wrong, it seems it's possible to get variables with getComputedStyle or computedStyleMap (depending on the browser). I found that |
Beta Was this translation helpful? Give feedback.
I was wrong, it seems it's possible to get variables with getComputedStyle or computedStyleMap (depending on the browser).
I found that
getComputedStyle
is working to find variables on safari and firefox but not on chrome. Chrome can find the variables withcomputedStyleMap
.https://codepen.io/mathieupuech/pen/gOPpmMO