Material-ui: How to change borderRadius of textfield variant=outline

Created on 11 Nov 2018  路  6Comments  路  Source: mui-org/material-ui

I tried this but without success. I want to change the rounded corners in the outlined textfield.
<TextField name="url" value={this.state.url} InputProps={{ inputProps: { style: { textAlign: 'center', padding: 10, borderRadius: 0 }, }, style: { borderRadius: 0 }, }} variant="outlined" onChange={this.handleChange} />

Most helpful comment

@nicolasiensen thank you for your reply. I could achieve the same with this:

textField: {
    [`& fieldset`]: {
      borderRadius: 0,
    },
}

Thank you!

All 6 comments

The border-radius property is not attributed to the input component, but to a fieldset element that wraps the input.

You can remove this property by overriding the fieldset style with a class:

.TextField-without-border-radius fieldset {
  border-radius: 0;
}
<div className="TextField-without-border-radius">
  <TextField
    name="url"
    variant="outlined"
  />
</div>

You can wrap this logic to your own version of the TextField component and reuse it across your app.

Alternatively, you can override the default theme of Material-UI to remove the border-radius from all components.

@nicolasiensen thank you for your reply. I could achieve the same with this:

textField: {
    [`& fieldset`]: {
      borderRadius: 0,
    },
}

Thank you!

Anybody now how to fix the light blue background when the textfield is autofilled?

Example

For what it's worth, this is a way to do it using withStyles.

const CustomTextField = withStyles({
  root: {
    '& .MuiOutlinedInput-root': {
      '& fieldset': {
        borderRadius: `4px 0 0 4px`,
      },
    },
  },
})(TextField);

If someone is using styled-components then you can do following:

``jsx export const TextFieldWrapper = styled(TextField)
fieldset {
border-radius: 50px;
}
`;
````

<TextField
  InputProps={{
    classes: {
      root: classes.input,
    },
  }}
/>;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

anthony-dandrea picture anthony-dandrea  路  3Comments

rbozan picture rbozan  路  3Comments

finaiized picture finaiized  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

sys13 picture sys13  路  3Comments