create-figma-plugin icon indicating copy to clipboard operation
create-figma-plugin copied to clipboard

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

Open fwextensions opened this issue 1 year ago • 3 comments

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.

fwextensions avatar Sep 16 '23 23:09 fwextensions

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 avatar Sep 17 '23 02:09 yuanqing

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.

fwextensions avatar Sep 18 '23 00:09 fwextensions

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.

pbroom avatar Jan 19 '24 16:01 pbroom