gpt4 book ai didi

reactjs - 如何更改 Material UI 选择边框和标签

转载 作者:行者123 更新时间:2023-12-03 18:44:17 29 4
gpt4 key购买 nike

我正在尝试更改 select 的边框来自 Material-UI 的组件。
到目前为止,我已经尝试过:

const styles = theme => ({
root: {
display: "flex",
flexWrap: "wrap",
backgroundColor: "lightgrey"
},
formControl: {
margin: theme.spacing.unit,
minWidth: 120
},
selectEmpty: {
marginTop: theme.spacing.unit * 2
},
cssLabel: {
color: "pink",
"&$cssFocused": {
color: "pink"
}
},
cssFocused: {
color: "pink"
},
underline: {
"&:after": {
borderBottom: "1px solid pink",
borderTop: "1px solid pink"
}
}
});

我可以定制 TextField等等,但经过许多小时后,我仍然无法自定义选择。我也试图通过 Input ,但随后您必须自定义 Input ,甚至更糟。

有人可以帮我处理这个沙箱吗?

https://codesandbox.io/s/material-demo-ecj1k

我真的很感激。

最佳答案

下面是覆盖默认、悬停和聚焦状态的边框 ( MuiOutlinedInput-notchedOutline )、标签 ( MuiInputLabel-root ) 和选定项目文本 ( MuiOutlinedInput-input ) 颜色的示例。

import React from "react";
import ReactDOM from "react-dom";

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

const useStyles = makeStyles({
root: {
width: 200,
"& .MuiOutlinedInput-input": {
color: "green"
},
"& .MuiInputLabel-root": {
color: "green"
},
"& .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
borderColor: "green"
},
"&:hover .MuiOutlinedInput-input": {
color: "red"
},
"&:hover .MuiInputLabel-root": {
color: "red"
},
"&:hover .MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline": {
borderColor: "red"
},
"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-input": {
color: "purple"
},
"& .MuiInputLabel-root.Mui-focused": {
color: "purple"
},
"& .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline": {
borderColor: "purple"
}
}
});

function App() {
const [age, setAge] = React.useState("");
const classes = useStyles();
return (
<div className="App">
<TextField
className={classes.root}
value={age}
onChange={e => setAge(e.target.value)}
variant="outlined"
label="My Label"
select
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</TextField>
</div>
);
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Edit TextField outlined

相关回答:
  • Change border color on Material-UI TextField
  • Is there a way to style the border color and text color of <TextField/> in Material-UI without using makeStyles
  • 关于reactjs - 如何更改 Material UI 选择边框和标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60459932/

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