51

I want the TextField to be naked(no underline) when using material-ui TextField. I do know that using InputBase from material-ui can achieve this, but I kinda need to use TextField API to achieve this but i did not find the way to do it in the API guide.

H.Zhao
  • 649
  • 1
  • 5
  • 6
  • Just remove the `variant` attribute, it's right in [the documentation](https://material-ui.com/components/text-fields/#customized-inputs) labeled "Naked Input". – Chris W. Sep 12 '19 at 21:38
  • 1
    @ChrisW. The "Naked Input" example is using `InputBase` directly (not `TextField`) -- the exact solution the question mentions wanting to avoid. – Ryan Cogswell Sep 12 '19 at 22:33

2 Answers2

163

You can also use the InputProps prop on the TextField component to achieve this by setting the disableUnderline property to true.

<TextField
  fullWidth
  placeholder="Search..."
  InputProps={{ disableUnderline: true }}
 />
lawrence-witt
  • 8,094
  • 3
  • 13
  • 32
Kofi Nartey
  • 2,529
  • 2
  • 9
  • 5
38

Even though this is currently the accepted answer, please see the other answer instead (using the disableUnderline prop). I wrote this answer after having recently written an answer about how to customize the underline (which uses approaches similar to this answer) and missed that there was a property specifically for removing the underline.


Below is an example of how to remove the underline. :before is used for the default and hover styling and :after is used for the focused styling, so the border needs to be removed for both of those cases.

The multiple ampersands (e.g. "&&&:before") increase the CSS specificity of the rule so that it wins over the default styling (e.g. &:hover:not($disabled):before).

import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles({
  underline: {
    "&&&:before": {
      borderBottom: "none"
    },
    "&&:after": {
      borderBottom: "none"
    }
  }
});
function App() {
  const classes = useStyles();
  return <TextField defaultValue="default text" InputProps={{ classes }} />;
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Edit TextField underline

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

Ryan Cogswell
  • 75,046
  • 9
  • 218
  • 198