How can I eliminate the border appearance from a textfield fieldset component in Material-UI?

I have been struggling to remove the border using CSS code I found on Stack Overflow, but unfortunately, the issue persists. If anyone could kindly assist me in fixing this problem, I would be extremely grateful.

Can someone please advise me on the specific CSS code required to eliminate the border?

https://i.sstatic.net/ScsYo.png

<TextField
  variant="outlined"
  margin="normal"
  required
  fullWidth
  id="phoneNumber"
  disableUnderline={false}
  // label="Phone Number"
  name="phoneNumber"
  autoComplete="phoneNumber"
  autoFocus

  onChange={handlePhoneNumberChange}
  className={classes.textField}
  placeholder="Phone Number"
  InputProps={{
    startAdornment: (
      <InputAdornment position="start">
        <AccountCircle />
      </InputAdornment>
    ),
  }}
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.1.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.1.1/umd/react-dom.production.min.js"></script>

Answer №1

This borderless text-field solution is exactly what I needed...

<TextField
  variant="standard" // <== modified this line
  margin="normal"
  required
  fullWidth
  id="phoneNumber"
  name="phoneNumber"
  autoComplete="phoneNumber"
  autoFocus
  onChange={handlePhoneNumberChange}
  placeholder="Phone Number"
  InputProps={{
    startAdornment: <AccountCircle />, // <== made a tweak here
    disableUnderline: true, // <== introduced this attribute
  }}
/>

These two properties appear to be crucial...

variant="standard"
 InputProps={{
        disableUnderline: true,
      }}

Answer №2

If you want to eliminate the border in a TextField fieldset using MUI 5, just include the code snippet below.

    sx={{
      "& fieldset": { borderWidth: '0px' },
    }}

Answer №3

InputProps can be utilized to style the different variants of inputs. In the case of an outlined input, a class named .MuiOutlinedInput-notchedOutline is responsible for setting the border. To customize this class, apply styles to the notchedOutline prop within the InputProps section.


const useStyles = makeStyles(() => ({
  noBorder: {
    border: "none",
  },
}));

const TextInput = props => {
  const { onChange, type} = props;
  const classes = useStyles();

  return (
    <TextField
      variant="outlined"
      margin="normal"
      required
      fullWidth
      id="phoneNumber"
      disableUnderline={false}
      // label="Phone Number"
      name="phoneNumber"
      autoComplete="phoneNumber"
      autoFocus
      classes={{notchedOutline:classes.input}}

      // onChange={handlePhoneNumberChange}
      className={classes.textField}
      placeholder="Phone Number"
      InputProps={{
        startAdornment: (
          <InputAdornment position="start">
            <AccountCircle />
          </InputAdornment>
        ),
        classes:{notchedOutline:classes.noBorder}
      }}
    />
  );
};

Access the demo on CodeSandbox here: https://codesandbox.io/s/material-demo-forked-nhlde

Answer №4

Customize TextField Outlines

To customize the outlines of your text field, you can add the following code snippet to your TextField component:

 sx={{border: 'none',"& fieldset": { border: 'none' },}}

Below is an example of how to implement this code:

 <TextField
  variant="outlined"
  sx={{border: 'none', "& fieldset": { border: 'none' },}}
  margin="normal"
  required
  fullWidth
  id="phoneNumber"
  disableUnderline={false}
  // label="Phone Number"
  name="phoneNumber"
  autoComplete="phoneNumber"
  autoFocus
  onChange={handlePhoneNumberChange}
  className={classes.textField}
  placeholder="Phone Number"
  InputProps={{
    startAdornment: (
      <InputAdornment position="start">
        <AccountCircle />
      </InputAdornment>
    ),
  }}
/>

Customize Standard TextField Underlines

If you want to remove the underline from a standard text field, you can use the following code snippet:

InputProps={{ disableUnderline: true }}

Here is an example code snippet demonstrating how to achieve this:

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

Answer №5

After exploring the features of the InputBase component, I must say it functions impeccably. This is definitely a top choice.

I also noticed they offer a helpful sandbox environment for experimentation: Sandbox InputBase

If you want to remove the border, simply use this code snippet:

<InputBase placeholder="Hello.." />

Answer №6

To enhance your textField design, include outline: 'none'

Answer №7

By the year 2022, if you are utilizing MUI version 5 or higher, there are solutions available for this issue. Currently, there is no documentation on how to achieve this in Textfield.

Another excellent component provided by MUI is Input, and fortunately, it accepts nearly all the props that can be passed to Textfield. By setting disableUnderline={false}, it will function as expected.

    <Input
      disableUnderline={true}
      variant="standard"
      autoFocus
      onChange={yourChangeHandler}
      value={value}
      placeholder="Title"
      fullWidth
    />

Answer №8

At last, this css code is effective (2022)

  '& .MuiInput-root': {
    '&:before, :after, :hover:not(.Mui-disabled):before': {
      borderBottom: 0,
    },
  },

Answer №9

Simply include

".MuiOutlinedInput-notchedOutline": { border: "none" },

in the sx attribute.

This solution is applicable to both MUI Select and Textfield components.

Answer №10

I successfully implemented the sx prop with the specified attributes in TextField and it functioned properly.

 <TextField
      sx={{
        input: {
          border: "none",
        },
        "::placeholder": { color: "white" },
      }}
 
    />

Answer №11

Struggling with the lack of guidance in the documentation? Don't worry, you can simply target the Mui selector for that element and make direct modifications. I found success with this approach. Feel free to override the CSS as needed.

<TextField
  id="outlined-basic"
  label="Outlined"
  variant="outlined"
  sx={{ "& .MuiOutlinedInput-notchedOutline": { border: "none" } }}
 />
     
<TextField
   id="filled-basic"
   label="Filled"
   variant="filled"
   sx={{
          "& .MuiFilledInput-underline:before": {
            borderBottom: "none",
          },
          "& .MuiFilledInput-underline:after": {
            borderBottom: "none",
          },
          "& .MuiFilledInput-underline:hover:not(.Mui-disabled):before": {
            borderBottom: "none",
          },
        }}
 />

For a live demonstration, visit codesandbox

Answer №12

Underline Disablement Feature
If activated, the input field will not have an underline.

<Input
            variant="standard"
            disableUnderline={true}
            required
            color="info"
            fullWidth
            margin="dense"
            focused
          />

API

Answer №13

To eliminate the border from all MuiOutlinedInput elements, simply include the following code in your theme's components section:

export const customTheme = createTheme({
  // ...
  components: {
    // ...
    MuiOutlinedInput: {
      styleOverrides: {
        notchedOutline: {
          border: 'none',
        },
      },
    },
  },
})

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

Tabulator: the process of loading an extensive amount of data requires a significant amount of time

Currently, I am encountering an issue with loading data using a tabulator on my webpage. There are 38 tables that need to be populated, each containing approximately 2000 rows of data. The problem lies in the fact that it is taking an excessive amount of t ...

What is the process for implementing dynamic routing in Next.js using slugs pulled from a GraphQL API?

Struggling with understanding dynamic routing based on variables? Having difficulty retrieving individual items and their fields for a single page with Next.js? You're not alone. Background Operating a KeystoneJS headless CMS with a GraphQL API, the ...

I'm having trouble inserting text into a three.js scene

I recently started working with three.js and I'm experimenting with some basic code. However, I keep encountering the same error message. I was under the impression that I added the object to the scene after using the loader.load function, so I'm ...

Accessing a variable from an external JavaScript file using jQuery

Can someone help me out with this issue I'm facing? I am having trouble getting a string returned to a variable in my embedded Javascript code. token.js: function token () { return "mysecretstring"; } HTML Code: <!DOCTYPE html> <h ...

Leverage a JavaScript function to manipulate the behavior of the browser's back button

Is there a way to trigger the Javascript function "backPrev(-1)" when the back button of the browser is clicked? Appreciate any help, thank you. ...

Small web app encounters error 501, indicating not implemented functionality

I've been working on uploading images to an S3 bucket using react and expressjs. However, whenever I try to upload the image, I keep getting a 501 Not Implemented Error. My approach involves using axios to communicate with the endpoint created in the ...

Form validation using jQuery and AJAX

I've implemented validation in my ResetPassword function and it seems to be working fine. However, I'm facing an issue where the ResetPassword function stops working once the validation is added. Can someone guide me on how to resolve this issue? ...

Browser Compatibility in Three.js

Could someone assist me with activating webgl on Internet Explorer version 8? I am able to use Firefox and Chrome without any issues. Your help would be greatly appreciated. ...

New to React: Arrow Function Example that Might Puzzle You

As a beginner in React/ES6, I came across this code snippet for handling a checkbox within a custom component that contains a material-ui CheckBox. My goal is to expand the custom component by adding more fields, such as a textbox where users can provide a ...

React Native error: Component variable not found

In my react-native project, I am trying to link 3 different files together: File 1 Data: Contains the test data File 2 Products: Handles the styling and layout of product items File 3 ProductListScreen: Displays the list of products Although importing ...

Tips for transferring a value from a view to a controller using AngularJS

I've created a controller that dynamically generates tables based on data retrieved from the backend using $http.get. I'm wondering how I can pass a value to this controller from the view, indicating which URL it should use to fetch the data for ...

Vue component input form not providing expected result

Here is the code snippet for my "ecedata" component with an input field: <template> <div class="col-l-4"> <p style="text-align: center">Data/day (GB)</p> <div class="form-input-set" style="background: white"& ...

Is there a way to use CSS to make a div expand as much as it can?

I am attempting to accomplish the following; Do you think this is achievable? ...

Creating a Functional Right Arrow on a Pure CSS Select Menu/Dropdown

I have implemented a custom select/dropdown menu by following the solution provided here: The functionality works well, but I am facing an issue where the dropdown options only appear when clicking on the box. Clicking on the 'arrow' located on ...

Is there a way to create a duplicate form without any pre-filled text when clicking the "next" button using JavaScript?

This form contains the details that I would like to display on the page again when clicking the "Add Another Module" button. <div> <form class="in-line" id="module_info"></form> <div style="display: flex;"> < ...

I'm currently troubleshooting the code for the Gallery project. The gallery is supposed to have 4x4 grids, but for some reason, the grids are

It seems like I am struggling to identify the exact issue. The display on mobile looks fine but not on desktop. I attempted to tweak the isotope configuration without success. Even manipulating the server-side code didn't reveal any obvious problems. ...

Eliminating an element from an object containing nested arrays

Greetings, I am currently working with an object structured like the following: var obj= { _id: string; name: string; loc: [{ locname: string; locId: string; locadd: [{ st: string; zip: str ...

AngularJS view does not wait for the completion of $http.get request

Within my controller, the code snippet below is present... $scope.products = dataService.getJsonData(); console.log($scope.products); The corresponding code in my dataservice is as follows: .service('dataService', function ($http) { t ...

Ignore one specific file when importing all files in Angular 7

In my Angular 7 project, I am utilizing C3 and importing all the necessary files at the beginning of my .ts component file using a wildcard. import * as c3 from 'c3'; While this method works well overall, I encountered an issue where my CSS ove ...

What could be the reason for the container div's height not being properly refreshed?

When adding elements to a container div with an initial height of 'auto', I assumed that the height would adjust based on the children elements added. However, this is not happening. Can anyone assist me in ensuring that the container div's ...