css - Material 界面 : How can I change the border color of the Select component?

标签 css reactjs material-ui

我正在尝试从 Material UI 自定义 Select 组件。
这是它的样子:
enter image description here
However, when the select component is focused, I want to change the border-color from material UI's blue to a custom red color.
我尝试设置样式,但它根本没有做任何事情

import FormControl from '@material-ui/core/FormControl';
import InputLabel from '@material-ui/core/InputLabel';
import MuiSelect from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem';
import { makeStyles } from '@material-ui/core/styles';

const useStyles = makeStyles((theme) => ({
  formControl: {
    margin: theme.spacing(1),
    minWidth: 120,
  },
  select: {
    borderColor: '#FF0000',      //<------------ this does nothing
  },
}));

const Select = () => {
  const classes = useStyles();
  return (
    <FormControl variant="outlined" className={classes.formControl}>
      <InputLabel>Months</InputLabel>
      <MuiSelect label="Months" className={classes.select}>
        <MenuItem value="1">January</MenuItem>
        <MenuItem value="2">February</MenuItem>
        <MenuItem value="3">March</MenuItem>
        <MenuItem value="4">April</MenuItem>
      </MuiSelect>
    </FormControl>
  );
};

Select.propTypes = {};

export default Select;

最佳答案

尝试这个:

const useStyles = makeStyles((theme) => ({
  formControl: {
    margin: theme.spacing(1),
    minWidth: 120,
  },
  select: {
    '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
        borderColor: 'red',
    },
  },
}));

关于css - Material 界面 : How can I change the border color of the Select component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67710051/

相关文章:

Javascript Pie Ch

javascript - 在 "store"的上下文或 props 中找不到 "Connect(App)"

reactjs - 如何在 Service Worker 中使用 ApplicationInsights-JS?

reactjs - 是否可以将 Material UI 库与 React Native 一起使用?

javascript - 我如何使用React中的Material ui库从自动完成框中进行选择

jquery - 输入文本 在占位符中添加其他颜色的星号

javascript - 网站没有加载所有内容

Javascript 修复表头

css - 无法在 React 应用程序中导入 css 样式

reactjs - React Material UI 一切都大写