How to use global parent selector with CSS modules

I use CSS modules in a React application. I also have a dropdown component with some global styles (which I am pleased with as common styles that I want to reuse).

When the dropdown is active, the CSS ( .dropdown--active) class is applied . Is there any way to include this global class along with my locally restricted style components? that is, I want this to work:

.myClass {
  color: red;
}

:global .dropdown--active .myClass {
  color: blue;
}

However, this syntax makes the entire selector global, which is not what I need: I want to .myClassbe bound to the component.

+4
source share
1 answer

just specify the desired global class in parens:

:global(.dropdown--active) .myClass {
  color: blue;
}
+3
source

Source: https://habr.com/ru/post/1655637/


All Articles