How do I custom style the underline of Material-UI without using theme?

陌路散爱 提交于 2019-11-28 02:23:27

In order to determine how to do this, it is helpful to look at how the default styling is done within Input.

:before is used for the default and hover styling and :after is used for the focused styling.

Here is a working example of how to style it:

import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { withStyles } from "@material-ui/core/styles";
const styles = {
  underline: {
    "&:before": {
      borderBottom: "2px solid green"
    },
    "&:hover:not($disabled):not($focused):not($error):before": {
      borderBottom: "2px solid blue"
    },
    "&:after": {
      borderBottom: "3px solid purple"
    }
  },
  disabled: {},
  focused: {},
  error: {}
};
function App({ classes }) {
  return (
    <div className="App">
      <TextField InputProps={{ classes }} />
    </div>
  );
}
const StyledApp = withStyles(styles)(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<StyledApp />, rootElement);

Not sure which version of material-ui you are using, but you can override classes as needed, see the following API documentation:

https://material-ui.com/api/outlined-input/#demos

https://material-ui.com/api/outlined-input/

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