gpt4 book ai didi

reactjs - Material UI - 覆盖 InputBase 的禁用样式

转载 作者:行者123 更新时间:2023-12-04 01:38:31 24 4
gpt4 key购买 nike

我似乎找不到在 InputBase 上覆盖以下规则的方法:

.MuiInputBase-root.Mui-disabled {
color: rgba(0, 0, 0, 0.38);
}

我要应用的规则是: color: "rgba(0, 0, 0, 0.75)"
我试过使用类名和类,但没有任何效果。有任何想法吗?
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
'&:disabled': {
color: "rgba(0, 0, 0, 0.75)"
}
},
disabled: {
color: "rgba(0, 0, 0, 0.75)",
'&:disabled': {
color: "rgba(0, 0, 0, 0.75)"
}
}

<TextField
disabled
id="outlined-disabled"
label="Disabled"
defaultValue="Hello World"
className={classes.textField}
classes={{
root: classes.disabled,
disabled: classes.disabled
}}
margin="normal"
variant="outlined"
/>

代码沙盒: https://codesandbox.io/s/material-demo-3xb7n

最佳答案

TextField不支持禁用规则名称。
您需要为 TextField 提供 InputProps,然后您可以提供禁用的规则名称:

import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";

const useStyles = makeStyles(theme => ({
container: {
display: "flex",
flexWrap: "wrap"
},
textField: {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1)
},
inputRoot: {
'&$disabled': {
color:'red'
},
},
disabled: {}
}));

export default function OutlinedTextFields() {
const classes = useStyles();

return (
<form className={classes.container} noValidate autoComplete="off">
<TextField
disabled
id="outlined-disabled"
label="Disabled"
defaultValue="Hello World"
InputProps={{
classes:{
root: classes.inputRoot,
disabled: classes.disabled
}
}}
margin="normal"
variant="outlined"
/>
</form>
);
}

Edit Invisible Backdrop

关于reactjs - Material UI - 覆盖 InputBase 的禁用样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58540364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com