material-ui - material-ui textField 颜色
问题描述
我正在使用 MUI 4.1.2 下划线的 textField 颜色在不活动和悬停时如何控制?我已经更改了调色板 - 文本 - 主要,它控制悬停时的下划线,但我想更具体地做到这一点。
我已经尝试过覆盖/MuiInput/underline/backgroundColor 等的其他解决方案,但没有奏效。
palette: {
overrides {
MuiInput: {
underline: {
'&:hover:before': {
backgroundColor: "#fff"
}
}
}
}
解决方案
您可以通过将类传递给Input
组件(它是 的子组件TextField
)来覆盖下划线样式。这有点hacky,但是很好,它可以工作。
import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { makeStyles } from "@material-ui/styles";
const useStyles = makeStyles({
underline: {
// normal style
"&::before": {
borderBottom: "4px solid green"
},
// hover style
"&:hover:not(.Mui-disabled):before": {
borderBottom: "4px solid blue"
},
// focus style
"&::after": {
borderBottom: "4px solid red"
}
}
});
function App() {
const classes = useStyles();
return (
<TextField InputProps={{ className: classes.underline }} label="example" />
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
这是现场示例:
推荐阅读
- php - ACF 逗号分隔的数组值
- java - 当我安装了 jdk 13 但在 cmd 中它显示了 java 7 的版本
- javascript - 有没有办法从我的例子中检查和取消选中“复选框”?
- gridview - 如何在函数中使用 $categoryId
- python - Python - 字典 - 如果循环变量没有改变
- blob - react-native 将文件从本地存储上传到 firebase 网络请求失败
- python - 气流,从 dag 调用 dags 会导致重复的 dagruns
- java - 我想在 Android Studio 的 Retrofit 中将温度值从单位转换为英制
- visual-studio-2019 - Visual Studio 2019 在 .Net Core 3.1 解决方案中创建 .NetStandard 2.0.3 库而不是 2.1
- spring - 在 minikube 中安装后 Spring Cloud Dataflow UI 异常