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.

How to style TextFields input color?

See original GitHub issue

There is no guidance on how to change the text colour of these inputs https://material-ui-next.com/demos/text-fields/

Do we just use external css to do this?

I also tried this but it doesn’t pass TypeScript checks:

 <TextField
          inputProps={{ style: { fontFamily: 'Arial', color: 'white'}}}
          style={{ flex: 1, margin: '0 20px 0 0', color: 'white'}}
          onChange={(e: ChangeEvent<HTMLInputElement>) => changeSearch(e.target.value)}
          type="text"
          value={reducerState.search}
        />

(50,11): error TS2339: Property 'inputProps' does not exist on type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.

image

This might be purely a TypeScript types issue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

95reactions
oliviertassinaricommented, Oct 8, 2019

@QuantumInformation I’m glad you found a solution. I would encourage people to do it this way:

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 = {
  root: {
    background: "black"
  },
  input: {
    color: "white"
  }
};

function CustomizedInputs(props) {
  const { classes } = props;

  return (
    <TextField
      defaultValue="color"
      className={classes.root}
      InputProps={{
        className: classes.input
      }}
    />
  );
}

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

export default withStyles(styles)(CustomizedInputs);

https://codesandbox.io/s/1370v7y4zj

capture d ecran 2018-12-06 a 19 31 05

Notice that you can also target the global class names (.MuiInputBase-root and .MuiInputBase-input).

35reactions
sandy0096commented, Dec 6, 2018

Does not work in "@material-ui/core"

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I change the color of an string-input in a TextField?
In the example bellow, text is 'red' and the background of the TextField is 'orange'.
Read more >
Change TextField Text Color in Flutter - The RIGHT Way [2022]
You can change TextField text color in Flutter, by adding style to the TextField widget. Basically, you provide the styling instructions by ...
Read more >
How to style TextFields input color? · Issue #9574 - GitHub
There is no guidance on how to change the text colour of these inputs https://material-ui-next.com/demos/text-fields/.
Read more >
<input type="color"> - HTML: HyperText Markup Language
<input> elements of type color provide a user interface element that lets a user specify a color, either by using a visual color...
Read more >
How to Set MUI TextField Text Alignment, Text Color, and ...
Material-UI TextField Text Color can be customized using either the root level sx or with InputProps . I chose to use a selector...
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