[英]How to override global border color styles for disabled Material UI TextField?
I'm trying to override the global style for the Mui TextField components that are disabled, but I can't get the border color to change.我正在尝试覆盖已禁用的 Mui TextField 组件的全局样式,但我无法更改边框颜色。
I've managed to change the label color if the field is disabled, but not the border color.如果该字段被禁用,我已经设法更改 label 颜色,但不是边框颜色。 Here is what I have so far:
这是我到目前为止所拥有的:
export const theme = createMuiTheme({
overrides: {
// For label
MuiInputLabel: {
root: {
'&$disabled': {
color: '#000000',
},
},
},
// For border color of field (doesn't work)
MuiTextField: {
root: {
'&$disabled': {
borderColor: '#FFFFFF'
},
},
},
},
});
I've tried all kinds of variations, including,我尝试了各种变化,包括,
MuiOutlinedInput: {
root: {
fieldset: {
borderColor: '#FFFFFF',
},
}
}
But this only changes the border color of non-disabled fields.但这只会改变非禁用字段的边框颜色。 What am I doing wrong here?
我在这里做错了什么? Here is how it looks:
这是它的外观:
The border is getting from the fieldset
element.边框来自
fieldset
元素。 You can style if based on your needs:如果根据您的需要,您可以设置样式:
MuiInputBase: {
root: {
"&$disabled": {
'& fieldset.MuiOutlinedInput-notchedOutline': {
borderColor: "blue",
background: "grey"
}
}
}
}
You can find a working example here: https://codesandbox.io/s/material-styling-disabled-textfield-ckp14?file=/demo.js您可以在这里找到一个工作示例: https://codesandbox.io/s/material-styling-disabled-textfield-ckp14?file=/demo.js
Here is a "walkthrough" for how to do it yourself:以下是如何自己做的“演练”:
div.MuiInputBase
, which is also disabled, so I had to add the &$disabled
on the root of the MuiInputBase
.div.MuiInputBase
内部,它也被禁用,所以我必须在MuiInputBase
的根目录上添加&$disabled
。& fieldset
- the fieldset
element is a child-element fo the MuiInputBase
- so the space between the &
and the tag-name means this is a child-element.& fieldset
- fieldset
元素是MuiInputBase
的子元素 - 所以&
和标签名之间的空格意味着这是一个子元素。MuiOutlinedInput-notchedOutline
so I used it as the relevant selector. MuiOutlinedInput-notchedOutline
,因此我将其用作相关选择器。 You could probably just use .MuiOutlinedInput-root.Mui-disabled fieldset
without the last-selector..MuiOutlinedInput-root.Mui-disabled fieldset
。 Try it:-).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.