Style off parent element state #589
Replies: 3 comments 1 reply
-
In StyleX you would generally just write JavaScript to solve this. The other alternative is using CSS variables but that's kind of a trick and not really what you're looking for. If you look through the docs, StyleX is all about preventing side effects at a distance which is more or less what you're code is trying to do. Instead, you might want to author a variant like isOpen, isClosed, etc. and put your conditional styles there, then when the state is active, you use active && styles.isOpen or whatever you like to express the relationship. |
Beta Was this translation helpful? Give feedback.
-
@zaydek yep 100% agree, but the component library i'm using, In addition most other UI libraries that are headless also use this method for styling based on state, |
Beta Was this translation helpful? Give feedback.
-
Currently the answer to this is to define a variable on the button itself and use that button value for the child elemement icon. We have an RFC open to discuss this further. |
Beta Was this translation helpful? Give feedback.
-
Hi i'm using radix primitives specifically the accordion. They set data-state on the trigger element, I have a child icon of a chevron that i'd like to rotate depending on the state.
I have the following styles, i'm trying to target the icon parent(this is the trigger) data state and rotate based on it:
This isn't working, any suggestion on how to get this to work?
Beta Was this translation helpful? Give feedback.
All reactions