Replies: 8 comments 6 replies
-
I think this is a duplicate of #373 based on the issue above (and the docs), this selector is not supported and there are no plans to support it in the future. |
Beta Was this translation helpful? Give feedback.
-
This is very basic, and shockingly, the limitation is impossible to support even in the future. It is a killer limitation because it is very useful to style inner elements, even more so with dynamic content. As the example in the #373:
Very, very necessary! I hope this feature can be done. 🙏 |
Beta Was this translation helpful? Give feedback.
-
To be more clear, how to style the inner content like this:
Based on the (encapsulation documentation)[https://stylexjs.com/docs/learn/thinking-in-stylex/#encapsulation]:
But we have some situations where it is very useful and necessary. We clearly need a hack or workaround for a complex StyleX project in real life because it is a very common situation. |
Beta Was this translation helpful? Give feedback.
-
You can style children using a bit of a hack by setting a css var on an element and consuming it in the child:
|
Beta Was this translation helpful? Give feedback.
-
@shawngustaw, many thanks for the suggestion, but it is not applicable. The situation is when you can't assign directly the child style because it is content injected dynamically; the child is not a React element. To be more precise is like, imagine the content is dynamic and comes from an API; then the simplification:
How in StyleX can we apply some style in the paragraphs!? Or, in other situations, we have a component with 100 or more paragraphs, like the texts in Terms and Conditions, Privacy Policy, etc... why need to apply the style to each paragraph when in pure CSS/LESS/SASS/SCSS, we can style all paragraphs at once without code repetition... I think there are so many cases where StyleX applies a giant limitation to real-life scenarios if it has no hack to work around these needs. And it is very strange to me to see this renomable project not supporting this basic feature. I do not see how, in an important project, we can live without styling the children at once. |
Beta Was this translation helpful? Give feedback.
-
We explain why in great detail in the documentation, as StyleX does not allow patterns that can break component style encapsulation. This is a fundamental feature - missing in almost every other styling library - that has become essential for Meta's web apps to remain performant and maintainable. When we have HTML content generated or provided by other systems, those systems must provide a way to add attributes to the HTML elements so that libraries like StyleX can add styles, accessibility props, logging attributes, etc. For example, Lexical has an API for doing this, so a rich text editor can be styled with StyleX. If your system doesn't support this, you won't be able to style the elements with StyleX and can continue to use whatever CSS/LESS/SASS/SCSS setup you've been using to set styles on an element that wraps all that content. |
Beta Was this translation helpful? Give feedback.
-
Many thanks @necolas! So, in some cases, we cannot use StyleX for everything, but a mix with CSS/LESS/SASS/SCSS is a way to go... I was convinced that it is better to focus on using only pure StyleX without another approach. But yes, we can mix techs; it is not the perfect way, but it is like a hack to work around in extreme conditions. Anyway, thank you again for your enlightenment over this. |
Beta Was this translation helpful? Give feedback.
-
I have tried const styles = stylex.create({
container: {
position: 'absolute',
height: '100px',
':not(#__unused__) > p': {
marginBottom: {
default: '1.2em',
'@media only screen and (max-width: 768px)': '1em'
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Describe the feature request
Hi there,
How can I apply styles in children's elements?
There is nothing about it in the documentation.
The situation is that I have many components with dynamic HTML content given by the API, and then I need to format them to a correct visualization.
Or if I have many paragraphs, how can I apply a style to all without assigning a pseudo-class to each one?
This project was in LESS working very well, and we want to give it a shot to see how StyleX works.
I tried many things, but here is what I think maybe has more logic:
Anything I try raises the error:
Invalid pseudo or at-rule.
Thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions