Skip to content

Instantly share code, notes, and snippets.

@sporto
Last active August 17, 2016 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sporto/2b828673ba37ac9b2eeb91237ad8ce33 to your computer and use it in GitHub Desktop.
Save sporto/2b828673ba37ac9b2eeb91237ad8ce33 to your computer and use it in GitHub Desktop.

We have two components, parent and child. When user hovers over the parent we want to change an attribute on the child. We achieve this we are using a global class in the child so the parent can select it. But this breaks the modularity of css modules.

Is there a way to solve this in a nicer way without using global?

import styles from './Parent.js'
<Parent className={styles.root}>
...
<Child />
</Parent>
.root {
}
// on hover we want to change the bg of child
// we are using global for this
.root:hover :global(.childComponent){
background-color: red;
}
import styles from './Child.css'
<Child className={`${styles.root} childComponent`}>
...
</Child>
.root {
background-color: yellow;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment