[英]Material ui contained button styling being overidden by MuiButtonBase-root
I am using material-ui with react.我正在使用 material-ui 进行反应。 I have a simple contained button using
我有一个简单的包含按钮使用
<Button variant='contained' color='primary'> Edit</Button>
However the button does not look like a contained button.但是,该按钮看起来不像包含的按钮。 As seen in this screenshot here .
如这里的屏幕截图所示。
Upon further investigation I found out the the.MuiButton-containedPrimary style is being overidden by the.MuiButtonBase-root styling as seen in this screenshot taken from chrome dev tools .经过进一步调查,我发现 .MuiButton-containedPrimary 样式被 .MuiButtonBase-root 样式覆盖,如从 chrome dev tools 截取的屏幕截图所示。
Please can someone let me know how to fix this?请问有人可以让我知道如何解决这个问题吗?
This issue happened to me when part of my app relied on a component library that also used Material UI.当我的应用程序的一部分依赖于一个也使用 Material UI 的组件库时,这个问题发生在我身上。 My app and dependency used different versions of Material UI which led to the duplicated
.MuiButtonBase-root
style.我的应用程序和依赖项使用了不同版本的 Material UI,这导致了重复的
.MuiButtonBase-root
样式。
I solved this by moving @material-ui/core
out of dependencies
and into peerDependencies
in my package.json
.我通过将
@material-ui/core
从dependencies
项中移出并进入我的peerDependencies
中的package.json
解决了这个问题。
This issue can also occur if you double nest an import.如果您双重嵌套导入,也会出现此问题。 For example:
例如:
import Button from '@material-ui/core/Button/Button'; // Bad
Should be:应该:
import Button from '@material-ui/core/Button'; // Good
There's a very helpful thread on this issue in the Material-UI GitHub: https://github.com/mui-org/material-ui/issues/15610 Material-UI GitHub 中有一个非常有用的线程: https://github.com/mui-org/material-ui/issues/15610
.MuiButton-root
should be the one holding color code, not the .MuiButtonBase-root
.MuiButton-root
应该是一个持有颜色代码,而不是.MuiButtonBase-root
Are your button example actually the one you use in your code?您的按钮示例实际上是您在代码中使用的示例吗? I can see that is has primary class which would imply usage of prop
color
which would result in:我可以看到它具有主要的 class 这意味着使用道具
color
会导致:
<Button variant="contained" color="primary">
Edit
</Button>
Recheck added classNames
and determine which one is actually overwriting color.重新检查添加的
classNames
并确定哪一个实际上覆盖了颜色。
In my case I have use new material ie mui and material-table.就我而言,我使用了新材料,即 mui 和材料表。 When I remove material-table everything is fine but with material-table something is overriding the styles.
当我删除材料表时,一切都很好,但材料表的某些东西会覆盖 styles。
Try to move @material-ui/core to devDependencies:尝试将@material-ui/core移动到 devDependencies:
"devDependencies": {
"@material-ui/core": "^4.12.0",
and also add it to peerDependencies:并将其添加到 peerDependencies:
"peerDependencies": {
"@material-ui/core": "^4.12.0"
},
It helped me to remove duplication of MuiButtonBase-root class它帮助我删除了重复的 MuiButtonBase-root class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.