Is there a way to eliminate the underline in TextField components in Material-UI?

Is there a way to remove the underline from a material-ui TextField without using InputBase? I would prefer to stick with the TextField API, but have not been able to find a solution in the documentation.

Answer №1

If you want to accomplish this, you have the option of using the InputProps attribute with the TextField component. Simply set the disableUnderline property to true.

<TextField
  fullWidth
  placeholder="Search..."
  InputProps={{ disableUnderline: true }}
 />

Answer №2

Although this answer has been marked as accepted, I recommend checking out the alternate solution (which involves using the disableUnderline prop). I realized that there is a specific property for removing the underline after writing another answer on customizing underlines similar to this one.


Here's an example of how to eliminate the underline. The use of :before is for default and hover styles, while :after is for focused styling, necessitating the removal of the border in both cases.

The repetition of ampersands (e.g., "&&&:before") increases the CSS specificity of the rule, ensuring it overrides 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);

https://codesandbox.io/s/textfield-underline-exocc?fontsize=14

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the possibility of utilizing the talks.js library to develop a chat feature within a React application

I'm currently working on integrating the talks.js library to set up a chat feature in my React project. I've followed all the instructions provided at , but unfortunately, it's not functioning as expected. I'm not quite sure what I migh ...

What's the process of enabling NodeJS within React Code in Electron?

How can I incorporate NodeJS into my React Code within Electron? What steps do I need to follow in order to access the file system component normally accessed in node using: const fs = require('fs'); When I attempted to use this code in my Reac ...

Having trouble getting the NextAuth Custom Sign In Page to function properly when using multiple tabs simultaneously

I've been incorporating the credential feature of nextauth into my website. However, I've encountered an issue: When I create a custom sign-in page and submit the data using the signIn feature, everything works smoothly. But the problem arises wh ...

"Can anyone provide guidance on how to customize form fields in Angular Material 16, such as removing borders, changing colors, and other

After upgrading my angular material to version 16, all the UI elements I had in place became distorted due to the introduction of mdc. The CSS code I was using before to customize elements like this: ::ng-deep .mat-form-field-appearance-outline .mat-form- ...

Why does the col-sm-* class affect the appearance on extra small screens?

For a current project, I have incorporated bootstrap into my design and have set up varying column widths for xs, sm, and md screens. Initially, I utilized col-xs-* and col-md-* to ensure the columns resized appropriately for xs, md, and lg screens. Howeve ...

What is the best way to set conditions for document side script?

I'm struggling to disable the horizontal scroll when the viewport width is 480px or less. The script that controls the scroll behavior on my website looks like this: <script> $(function () { $("#wrapper").wrapInner("< ...

What is stopping me from updating the state within the componentDidUpdate method, even when a condition is met?

Currently, I am comparing props within the componentDidUpdate and attempting to update the state. Following that, I need to fetch some data which is dependent on certain state parameters. componentDidUpdate(prevProps) { if (prevProps.location.search.sp ...

What is the best way to share material-ui-classes beyond my components?

In order to enhance user experience, we primarily utilize Material UI in our applications. However, a major challenge lies in syncing the styles between Material UI and plain HTML. Is there a way to expose Material-UI CSS classes so they can be used withi ...

In a Next.js application directory, how can you retrieve the router.asPath value within a function that utilizes the Next.js navigation feature?

import { useRoute } from "next/navigation" const route = useRoute() const updateData = () => { route.replace(route.asPath); } I attempted using next/router but it was unsuccessful ...

Menu Options in Material UI Navbar

I am currently working on incorporating an icon in my navbar that, when clicked, will reveal a dropdown list of notifications. Although I have come across several code examples for dropdown menus, none of them have completely assisted me or provided specif ...

What is the best way to wrap a div in a vertical orientation?

I'm looking to create a vertical div around an image that fluidly changes width: |_________________| | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | |-----------------| The cont ...

utilizing the identical characteristics of the parent component

In order for the properties in InputGroup.js to be accessible as this.props in lower-level components like TextInput.js, Checkbox.js, I have created a simple component called InputComponent.js. In this component, I assign this.props to this.prpt so that it ...

An error occurred in ReactJS when attempting to parse an unexpected token < while working with Django

https://i.sstatic.net/hDUZi.png I have been working on deploying my Django and React application on an Azure virtual machine. Initially, everything seemed to be working fine when I used: python manage.py runserver 0.0.0.0:8000 However, when I switched ...

Angular application experiencing issues with loading React web component: encountering error when attempting to search for 'adoptedCallback' using 'in' operator with undefined value

I recently created a basic web component using React import React from "react"; import ReactDOM from "react-dom/client"; import reactToWebComponent from 'react-to-webcomponent'; function Test() { return ( <h1> He ...

_dirname does not have a defined scope within ES modules

After updating the package.json file and changing the type to "module", I ran into an issue with a reference error that said "_dirname is not defined in ES module scope". Does anyone have a solution for this problem? import { fileURLToPath } from "u ...

Efficient Django Template: Accurate Conversion of Values through Dictionary Searching

I have an object with an attribute that has specific choices defined in its class: class StashURLJobRequest(models.Model): STATUS_CHOICES = ((0,"Requested"),(1,"Done"),(2,"Failed")) url = models.URLField() created = models.DateTimeField(auto_n ...

Exploring the dichotomy between controlled and uncontrolled elements within React. The _class attribute causing unexpected changes in an un

I created a custom Checkbox component that is essentially a styled checkbox with a 'fake element' acting as the original one. Custom Checkbox Component import React, {Component} from 'react'; import FormGroup from 'react-bootstra ...

Top tips for setting up node_modules for a ReactJS application on Azure Linux Web App

My React web app, specifically built on NextJS, is currently running on a Linux Azure Web App Server. I have successfully deployed it using GitHub Actions, but now I am struggling to find the most efficient way to deploy the node_modules. This is what I h ...

What could be causing my scrollable div to not function properly within a Bootstrap modal?

I am facing a frustrating issue. I have a simple DIV element that I want to make scrollable, containing a table inside it. The process should be straightforward as I have a separate .html file with the code that functions correctly. Here is an excerpt of ...

Identifying and implementing page language in nextJS: Solving the ReferenceError "window is not defined" issue

I am currently working on developing a website that can automatically detect the user's country and set the language accordingly. In React, I usually achieve this by using window.navigator.language. Here is a snippet of the code: import * as pt from ...