-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Can't style based on global parent class #702
Comments
For the record, I ended up working around this by adding the conditional styles to the parent container. It's not great, because it breaks the component boundaries, but it was the neatest solution I could find. For example: const styles = {
contents: {
background: 'red',
},
tetherContainer: {
'&.tether-target-attached-top > [data-tether-contents]': {
background: 'green',
},
},
} (Then I made sure that the contents always have the |
@gilmoreorless Sorry for the delay. So, in general, the & is not a placeholder for the current class in Fela as this breaks with the idea of component-centric styles in my opinion. Sadly, there's no better way to work around this for now as we believe toggling classes is not the "right" way to do it at all. Knowing that many libs do this anyways, I think your solution is fine enough for this specific use case. As there's not going to be a better solution anytime soon, I'd love to close this one. Feel free to reopen if there's anything left you'd like to discuss! |
Type: Bug
Description
I'm trying to integrate with a third-party library (Tether), which adds dynamic classes to a container component. These classes can be added and removed at any time, based on its position adapting to window size.
I'd like to style a component (entirely within the Tether container) based on the container's current classes. This doesn't seem to be possible with Fela.
The docs say:
From what I can tell,
&
only works when it's at the start of the selector (hence calling it "&-prefix"). But I need to use it after the Tether class, like.tether-element-attached-top &
. This works in tools such as Sass and Styled Components.This is not just a problem when using Tether, but affects integration with any library that adds CSS classes to the
body
element as part of its API (e.g. font preloading scripts which add afonts-loaded
class tobody
for conditional styling).As a simplified example, I have a component with these basic styles:
On its own the component should have a red background. If used within a Tether element, it should be either blue or green, depending on Tether's positioning calculations. When used within Tether, the markup is effectively this:
However when I do this, the element is always red, and Fela adds the following warning in the console:
The object key ".tether-element-attached-top &" is not a valid nested key in Fela.
The text was updated successfully, but these errors were encountered: