admin管理员组文章数量:1430636
I am using makeStyles for adding styles to button, but in app there is included some other third party css file that overrides my styles without '!important'. I tried this approach, but it's not working, property is not generated in browser:
const useStyles = makeStyles({
button: {
backgroundColor: props => props.actionBackgroundColor,
borderColor: props => props.actionBackgroundColor,
color: props => {
if (props.actionTextColor) {
return `${props.actionTextColor} !important`;
}
return null;
},
'&:hover': {
backgroundColor: props => props.actionHoverColor,
borderColor: props => props.actionHoverColor,
color: props => {
if (props.actionHoverTextColor) {
return `${props.actionHoverTextColor ? props.actionHoverTextColor : props.actionTextColor ? props.actionTextColor : null} !important`;
}
return null;
}
}
}
});
I am using makeStyles for adding styles to button, but in app there is included some other third party css file that overrides my styles without '!important'. I tried this approach, but it's not working, property is not generated in browser:
const useStyles = makeStyles({
button: {
backgroundColor: props => props.actionBackgroundColor,
borderColor: props => props.actionBackgroundColor,
color: props => {
if (props.actionTextColor) {
return `${props.actionTextColor} !important`;
}
return null;
},
'&:hover': {
backgroundColor: props => props.actionHoverColor,
borderColor: props => props.actionHoverColor,
color: props => {
if (props.actionHoverTextColor) {
return `${props.actionHoverTextColor ? props.actionHoverTextColor : props.actionTextColor ? props.actionTextColor : null} !important`;
}
return null;
}
}
}
});
is there any workaround?
Share Improve this question asked Dec 24, 2019 at 8:43 vakho papidzevakho papidze 4653 silver badges13 bronze badges 2- Are this styles that you want to override ing from the material-ui ponents that you are trying to use? – yuri Commented Dec 24, 2019 at 8:46
- no, As I said it's some custom third party library, just css file. – vakho papidze Commented Dec 24, 2019 at 8:54
2 Answers
Reset to default 2Can u please check this sandbox. There is a CustomButton ponent where I implemented your solution and it's working fine.
Code Sandbox
Seems I was using old version of material ui;
"@material-ui/core": "^3.9.2", "@material-ui/styles": "^4.4.1",
That's issue, seems '!important' does not work with that version. So I need to upgrade it.
本文标签: javascriptreactMaterial ui makeStyles with 39important39Stack Overflow
版权声明:本文标题:javascript - react + Material ui makeStyles with '!important' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745482458a2660236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论