How can I remove the underline of TextField from Material-UI?

H.Zhao

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.

Ryan Cogswell

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?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to remove the underline of material-ui select?

How to remove the arrows icons from a Material UI TextField

How to customize material-ui TextField Input underline:after?

ReactJS - How can I set a value for textfield from material-ui?

How can I imitate the look of the outline and label from Material-UI's outlined textfield?

How Can I Mask My Material-UI TextField?

material ui next dialog textfield underline color

material ui next textfield underline color

How to remove curved border and inset box shadow from Material UI TextField React component?

How to remove the underline in a TextField in CODENAME ONE?

JSX syntax for dynamic width of Material UI TextField underline React

How can I set an static outlined div similar to Material-UI's outlined textfield?

How can I center-align Material-ui TextField text and also set a min number value?

How can I set material-ui TextField to accept only Hexidecimal characters

How can I make TextField in Javafx to look as beautiful as Android or material UI

How I can change the input color of Material UI TextField when is input is disabled [MUI v: 5.0.8]

how can i change TextField hover border effect in material-ui?

Can't type in TextField Input from React Material-ui

How can I style a Select from Material UI with styled components?

How can I submit the value of an autocomplete from material ui?

How can I use Icons from material-ui icons?

How can I open Material UI Modal from parent component?

Remove underline from Input component Material UI (v1.0 Beta)

how can I remove underline text in my code?

How to change Material UI input underline colour?

How to remove visual material entry underline

How Do I Set The Current Date In A Material-UI TextField

HTML: How do I remove hyperlink underline from an Image and text?

How to invalidate a TextField in Material UI

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive