有没有一种方法可以在Material-UI中设置<TextField />的边框颜色和文本颜色的样式,而无需使用makeStyles

时间:2020-02-11 00:02:37

标签: css reactjs styles material-ui

是否可以在不使用makeStyles功能(例如CSS)的情况下为Material-UI设置样式?只是想了解Material-UI样式的工作原理。

底部的红色样式是我试图通过此处的简单CSS实现的样式。

enter image description here

1 个答案:

答案 0 :(得分:0)

下面是一个示例,该示例说明了如何使用简单的CSS自定义概述选择中的各种颜色。

styles.css

.customSelect {
  width: 200px;
}
.customSelect .MuiInputLabel-root {
  color: red;
}
.customSelect .MuiInputBase-input {
  color: green;
}
.customSelect .MuiOutlinedInput-notchedOutline {
  border-color: red;
}
.customSelect:hover .MuiOutlinedInput-notchedOutline {
  border-color: orange;
}
.customSelect
  .MuiOutlinedInput-root.Mui-focused
  .MuiOutlinedInput-notchedOutline {
  border-color: purple;
}
.customSelectMenu .MuiMenuItem-root {
  color: blue;
}

App.js

import React from "react";
import "./styles.css";
import TextField from "@material-ui/core/TextField";
import MenuItem from "@material-ui/core/MenuItem";

export default function App() {
  const [value, setValue] = React.useState("");
  return (
    <TextField
      className="customSelect"
      label="Sale Type"
      required
      select
      value={value}
      onChange={event => setValue(event.target.value)}
      variant="outlined"
      SelectProps={{ MenuProps: { className: "customSelectMenu" } }}
    >
      <MenuItem value={1}>Sale Type 1</MenuItem>
      <MenuItem value={2}>Sale Type 2</MenuItem>
    </TextField>
  );
}

Edit Customize TextField via CSS

相关答案: