Skip to content
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

Adding !important on an inline style causes it to not be applied #191

Open
fwextensions opened this issue Sep 16, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@fwextensions
Copy link

fwextensions commented Sep 16, 2023

Adding !important to an inline style seems to cause it to be stripped from the style object and not applied to the component. For example:

<div style={{ color: "red !important" }}>this is not red</div>

That produces black text, and there doesn't appear to be any inline style on that div at all. But remove the !important from the string:

<div style={{ color: "red" }}>this is red</div>

And that's now red text, as expected.

I have no idea what might be causing this. Something weird in the build process, it seems.

@yuanqing
Copy link
Owner

Likely a bug or something that needs to be configured in postcss-modules. In the meantime, you would need to specify something like style="color: red !important". (Though ideally, you’d avoid using !important in the first place)

@yuanqing yuanqing added the bug Something isn't working label Sep 17, 2023
@fwextensions
Copy link
Author

I stumbled across this bug trying to override styles on an Inline component and flailing about trying to get any change to show up. I don't think CSS modules provides enough capability to override the styles the way I want, so I'll need to just create a different component.

@pbroom
Copy link

pbroom commented Jan 19, 2024

I ran into the same issue. It had to do with the fact that !important isn't supported in JSX inline styles. I used a class instead and dumped the CSS in my stylesheet. It worked as expected after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants