Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material UI | How to change the font colour of a disabled input text field?

The colour of a disabled input text field created using material UI is light grey by default and it is not very visible against a white background. Is there any way to change the font colour of a disabled input text field?

like image 849
JayaniH Avatar asked Jan 09 '20 18:01

JayaniH


People also ask

How do I remove the border from TextField material UI?

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.


1 Answers

Below is an example of how to do this showing the customized version next to the default styling.

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

const DarkerDisabledTextField = withStyles({
  root: {
    marginRight: 8,
    "& .MuiInputBase-root.Mui-disabled": {
      color: "rgba(0, 0, 0, 0.6)" // (default alpha is 0.38)
    }
  }
})(TextField);

export default function Demo() {
  const [disabled, setDisabled] = React.useState(true);
  return (
    <>
      <Button onClick={() => setDisabled(!disabled)}>Toggle Disabled</Button>
      <br />
      <br />
      <DarkerDisabledTextField
        disabled={disabled}
        id="outlined-basic"
        label="Custom"
        value={`Disabled = ${disabled}`}
        variant="outlined"
      />
      <TextField
        disabled={disabled}
        id="outlined-basic"
        label="Default"
        value={`Disabled = ${disabled}`}
        variant="outlined"
      />
    </>
  );
}

Edit Disabled text color

like image 108
Ryan Cogswell Avatar answered Sep 28 '22 07:09

Ryan Cogswell