0

Im using material-ui with Reactjs. I want to apply on a TextField some custom styles using css. Specifically I want to change the color of the TextField underline and TextField label when I click the input.

I know that I could do it inline with the component but I want to use className and css.

Any ideas ?

Thanks

4
  • Look for styled-components. Commented Nov 16, 2017 at 11:56
  • which version of material-ui are you using? if you are using v1, then you can check this example material-ui-next.com/demos/text-fields Commented Nov 16, 2017 at 12:02
  • @talentedandrew Im using 0.19.4 Commented Nov 16, 2017 at 12:32
  • @talentedandrew In this case, I would prefer to wait to material-ui v1 when the alpha version will released Commented Nov 17, 2017 at 12:32

1 Answer 1

1

Since material-ui uses inline styles in JS, its not very convinient and easy to do a custom styling of components by css classes, but its still possible with !important keyword.

First you need to add cutom css class to TextField:

<TextField id="text-field-default" className="text-field-custom" defaultValue="Default Value" /> 

Then, for example, underline style can be overriden like that:

.text-field-custom>input:focus+div>hr { border-bottom: 2px solid rgb(0, 0, 0) !important; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.