Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove border in textfield fieldset in material ui

I need to remove the border. I used some css from stack overflow but the issue is not fixed yet . If any one please help me to fixed this issue .I shall be very thank full.

what css I write to remove the border.

enter image description here

<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>
like image 537
Shahab Khan Avatar asked Dec 05 '20 20:12

Shahab Khan


People also ask

How do you remove border from TextField?

To hide the border when TextField is having an error: Inside the InputDecoration, add the errorBorder property and set it to InputBorder. none.

How do you remove the autocomplete border in MUI?

Style MUI TextField with No Border The easiest way to remove the border from a Material-UI TextField is to use the 'standard' variant instead of the default 'outlined' variant.

How do I customize TextField in material UI?

To make a controlled text field, we can add the value and onChange props to the TextField . We have the name state which is passed into the value prop. And the handleChange function which is passed into the onChange prop.


7 Answers

I was looking for a borderless text-field and this is working for me...

<TextField
  variant="standard" // <== changed this
  margin="normal"
  required
  fullWidth
  id="phoneNumber"
  name="phoneNumber"
  autoComplete="phoneNumber"
  autoFocus
  onChange={handlePhoneNumberChange}
  placeholder="Phone Number"
  InputProps={{
    startAdornment: <AccountCircle />, // <== adjusted this
    disableUnderline: true, // <== added this
  }}
/>

These 2 props seem to be the key...

variant="standard"
 InputProps={{
        disableUnderline: true,
      }}
like image 101
Brian Kiernan Avatar answered Oct 19 '22 13:10

Brian Kiernan


InputProps can be passed to the style the variants of the inputs. For outlined input there a class named .MuiOutlinedInput-notchedOutline which sets the border in this question's case. To modify this class, pass the styles to the notchedOutline prop in InputProps.


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}
      }}
    />
  );
};

Here is the working sandbox link: https://codesandbox.io/s/material-demo-forked-nhlde

like image 37
Rajiv Avatar answered Oct 19 '22 14:10

Rajiv


In your textField style add outline: 'none'

like image 20
tim-carey-code Avatar answered Oct 19 '22 14:10

tim-carey-code


I tried all the answers here.

Doesn't work

I found this InputBase It works very nicely. This is exactly what you should use.

They have provided the sandbox too Sandbox InputBase

like image 7
Abhishek kumar Avatar answered Oct 19 '22 13:10

Abhishek kumar


to remove border in TextField fieldset in MUI 5,

simply add following.

    sx={{
      "& fieldset": { border: 'none' },
    }}
like image 7
Yang Avatar answered Oct 19 '22 15:10

Yang


As at 2022, if your using MUI >= version 5, you can use some solutions here, and currently there's no where in the doc on how do this in Textfield.

Another nice component MUI provides is the Input, and luckily for us it accepts almost all props passed to Textfield, that's where you can do disableUnderline={false} and it will work as expected.

    <Input
      disableUnderline={true}
      variant="standard"
      autoFocus
      onChange={yourChangeHandler}
      value={value}
      placeholder="Title"
      fullWidth
    />
like image 3
Chukwuemeka Maduekwe Avatar answered Oct 19 '22 14:10

Chukwuemeka Maduekwe


Finally, the following css works (2022)

  '& .MuiInput-root': {
    '&:before, :after, :hover:not(.Mui-disabled):before': {
      borderBottom: 0,
    },
  },
like image 2
Kristiyan Tsvetanov Avatar answered Oct 19 '22 14:10

Kristiyan Tsvetanov