Javascript 无法更改材料UI OutlinedInput的边框颜色
我正在尝试更改v4.13的边框颜色。然而,我没有得到任何工作时,试图覆盖CSS 我尝试了对每个元素应用多个CSS规则,选择和OutlinedInput,下面两个是最新的。我做错了什么Javascript 无法更改材料UI OutlinedInput的边框颜色,javascript,css,reactjs,material-ui,Javascript,Css,Reactjs,Material Ui,我正在尝试更改v4.13的边框颜色。然而,我没有得到任何工作时,试图覆盖CSS 我尝试了对每个元素应用多个CSS规则,选择和OutlinedInput,下面两个是最新的。我做错了什么 const styles = () => createStyles({ select: { "&:before": { borderColor: "red" }, "&:after": { borderColor:
const styles = () =>
createStyles({
select: {
"&:before": {
borderColor: "red"
},
"&:after": {
borderColor: "red"
},
},
outline: {
"&:before": {
borderColor: "red"
},
"&:after": {
borderColor: "red"
},
}
});
<Select
label={label}
fullWidth={true}
error={touched && invalid}
className={inputStyles}
classes={{ root: classes.select }}
input={
<OutlinedInput
{...input}
fullWidth={true}
id={input.name}
labelWidth={this.state.labelWidth}
classes={{notchedOutline: classes.outline}}
/>
}
{...custom}
>
{children}
</Select>
我可以在这里看到正在设置边框颜色的位置,但无法覆盖它
下面是一个示例,演示如何执行此操作:
import React from "react";
import { makeStyles } from "@material-ui/core/styles";
import OutlinedInput from "@material-ui/core/OutlinedInput";
import InputLabel from "@material-ui/core/InputLabel";
import MenuItem from "@material-ui/core/MenuItem";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
const useStyles = makeStyles(theme => ({
root: {
display: "flex",
flexWrap: "wrap"
},
formControl: {
margin: theme.spacing(1),
minWidth: 120
},
selectEmpty: {
marginTop: theme.spacing(2)
}
}));
const useOutlinedInputStyles = makeStyles(theme => ({
root: {
"& $notchedOutline": {
borderColor: "red"
},
"&:hover $notchedOutline": {
borderColor: "blue"
},
"&$focused $notchedOutline": {
borderColor: "green"
}
},
focused: {},
notchedOutline: {}
}));
export default function SimpleSelect() {
const classes = useStyles();
const outlinedInputClasses = useOutlinedInputStyles();
const [values, setValues] = React.useState({
age: "",
});
const inputLabel = React.useRef(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current.offsetWidth);
}, []);
function handleChange(event) {
setValues(oldValues => ({
...oldValues,
[event.target.name]: event.target.value
}));
}
return (
<form className={classes.root} autoComplete="off">
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} htmlFor="outlined-age-simple">
Age
</InputLabel>
<Select
value={values.age}
onChange={handleChange}
input={
<OutlinedInput
labelWidth={labelWidth}
name="age"
id="outlined-age-simple"
classes={outlinedInputClasses}
/>
}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</form>
);
}
您可以在我的相关答案中了解更多信息: