question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextField] Improve outlined variant customization

See original GitHub issue

The documentation doesn’t mention the class name to customize the outline when using a Textfield with the outlined variant.

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

In the Input api page, the CSS Api should list the notchedOutline class property name.

Current Behavior

Currently there is nothing in the documentation that allow us to know how to customize the outline.

Context

Changing the color of the border.

Your Environment

Tech Version
Material-UI v3.3.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

25reactions
oliviertassinaricommented, Oct 28, 2018

The customization story was overlooked when implementing this outlined variant. Right now, you can change the color like this:

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";

const styles = theme => ({
  notchedOutline: {},
  focused: {
    "& $notchedOutline": {
      borderColor: "yellow"
    }
  }
});

class OutlinedTextFields extends React.Component {
  state = {
    name: "Cat in the Hat"
  };

  handleChange = name => event => {
    this.setState({
      [name]: event.target.value
    });
  };

  render() {
    const { classes } = this.props;

    return (
      <form className={classes.container} noValidate autoComplete="off">
        <TextField
          id="outlined-name"
          label="Name"
          InputProps={{
            classes: {
              notchedOutline: classes.notchedOutline,
              focused: classes.focused
            }
          }}
          value={this.state.name}
          onChange={this.handleChange("name")}
          variant="outlined"
        />
      </form>
    );
  }
}

OutlinedTextFields.propTypes = {
  classes: PropTypes.object.isRequired
};

export default withStyles(styles)(OutlinedTextFields);

https://codesandbox.io/s/7jpl38xm1x

Going forward, I think that we should extract the state logic style out from the private NotchedOutline.js component and move it to the OutlinedInput.js component.

15reactions
oliviertassinaricommented, Nov 5, 2018

@serendipity1004: Let us know what you think:

import React from "react";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import purple from "@material-ui/core/colors/purple";

const styles = theme => ({
  root: {
    "&:hover:not($disabled):not($focused):not($error) $notchedOutline": {
      borderColor: purple[500]
    }
  },
  disabled: {},
  focused: {},
  error: {},
  notchedOutline: {}
});

function CustomizedInputs(props) {
  return (
    <TextField
      InputProps={{ classes: props.classes }}
      label="Custom CSS"
      variant="outlined"
      id="custom-css-outlined-input"
    />
  );
}

export default withStyles(styles)(CustomizedInputs);

https://codesandbox.io/s/ry26oj1rkq

Read more comments on GitHub >

github_iconTop Results From Across the Web

[TextField] Improve outlined variant customization #13347
The documentation doesn't mention the class name to customize the outline when using a Textfield with the outlined variant.
Read more >
Text fields - Material Design
Crane's outlined text fields use custom color on three elements: the input text, label text, and container. Element, Category, Attribute, Value. Input text ......
Read more >
material ui TextField variant outlined, problem with react-seles
I solved this with a zIndex on the <TextField : <TextField label="Points" type="number" min={1} max={999} value={props.question.value} ...
Read more >
Breaking changes in v5, part two: core components - Material UI
The label prop now fulfills the same purpose, using the CSS layout instead of JavaScript measurements to render the gap in the outlined...
Read more >
Text Field - Material Components for the Web
Variants. Full Width. Full width text fields are useful for in-depth tasks ... NOTE: Do not use mdc-text-field--outlined to style a full width...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found