Is there a way to style the border color and text color of <TextField/> in Material-UI without using makeStyles

允我心安 提交于 2021-02-10 14:14:46

问题


Is it possible to style Material-UI without using the makeStyles feature, for example, css? Just trying to understand how Material-UI style works.

The red style on the bottom is the style I'm trying to achieve with simple css here.


回答1:


Below is an example of how to customize the various colors in an outlined select using simple 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>
  );
}

Related answers:

  • Change border color on Material-UI TextField
  • Global outlined override
  • Change outline for OutlinedInput with React material-ui


来源:https://stackoverflow.com/questions/60160225/is-there-a-way-to-style-the-border-color-and-text-color-of-textfield-in-mater

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!