Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material-UI changing the color of inputs floating label

I want to change the color of a floating title for Material-UI's TextField.

As stated in documentation, I pass the object color as floatingLabelStyle:

<TextField floatingLabelStyle={{color: somecolor }} />

But this applies to both states of the label - hovering above the input and on the input while out of focus, when it's supposed to be grey.

I guess that I'm overwriting some kind of CSS transition, but have no idea how to make it work. Any suggestions?

like image 551
Łukasz Smoczyński Avatar asked Mar 03 '16 19:03

Łukasz Smoczyński


People also ask

How do I change the color of TextField labels?

You can change the Textfield label color globally by defining the inputDecorationTheme and then adding the labelStyle widget.

How do I change the color of TextField in material UI?

Material-UI TextField Text Color can be customized using either the root level sx or with InputProps . I chose to use a selector at the root level. I targeted MuiInputBase-root with the nested selector. Notice the spacing between the & and the class name.

How do you change the color of a label in HTML?

To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.

How do you customize TextField in MUI?

Set MUI Width and Height with 'InputProps' Another method for setting Material-UI TextField width and height is a combination of sx at the TextField root and passing sx styling values to the composing Input component via InputProps . The width is set with TextField prop sx={{width: 300}} .


3 Answers

This does the tick

  InputLabelProps={{
    style: { color: '#fff' },
  }}
like image 136
Malte Schulze-Boeing Avatar answered Oct 13 '22 10:10

Malte Schulze-Boeing


You should set style of InputLabel:

const styles = {
    floatingLabelFocusStyle: {
        color: "somecolor"
    }
}

<TextField
    label="Test"
    id="test"
    InputLabelProps={{
        className: classes.floatingLabelFocusStyle,
    }}
/>
like image 22
Borzh Avatar answered Oct 13 '22 10:10

Borzh


If you're working from a theme, I found that adding this to the overrides section did it

overrides: {
    MuiInputLabel: {
      root: {
        color: "rgba(255, 255, 255, 0.87)",
      },
    },
  },
like image 41
Jody S Avatar answered Oct 13 '22 10:10

Jody S