You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Best way to override styling found in module a based on module b. #394
I have a project in which uses CSS modules to isolate and scope styling as much as possible. However, I need to override certain style in a (nested) child component based on the classnames present on the parent. My project structure is somwhat like this:
In my Parent.tsx file, I use an animation library (React Transition Group) that triggers various class names over time. I want to use this classes to alter the appearance of an element in Child.tsx. Basically:
In CSS modules this doesn't work because the class names are transformed for isolation (makes sense), but how would I get access to such a child element to override it properly?
For now: using an @value importing an entire selector seems to work on some platforms (but we've seen problems on Windows).
One way I can think of is passing exposing classname of the topmost wrapper of your component to hook onto for overrides, or giving your component a static class name to be used for overrides (an override hook?). So something like this
If you instead wanted to override the styling for an element within the JSX structure, so not the topmost, then using a static class name (an override class name) for said element would be the only option I can think of at the moment. Hope this helps
Reacted by Jakub Kahovec and Enrique Redondo Cortés
Activity
OlaoluwaM commentedon Aug 30, 2023
One way I can think of is passing exposing classname of the topmost wrapper of your component to hook onto for overrides, or giving your component a static class name to be used for overrides (an override hook?). So something like this
or
If you instead wanted to override the styling for an element within the JSX structure, so not the topmost, then using a static class name (an override class name) for said element would be the only option I can think of at the moment. Hope this helps
ibm-cloud-storage189 commentedon Oct 10, 2025
@OlaoluwaM https://roynodejs-domains.github.io/ihjEqmAuKzQFW8tlGO6SlC80DSsvIOk1KpkUvdnhr8z1/