Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change TextField font color in MUI?

Tags:

I'm currently using MUI.

And I'm having issues trying to change the font color of the multiline TextField.

<TextField className = "textfield"            fullWidth            multiline            label   = "Debugger"            rows    = "10"            margin  = "normal"/> 

And the CSS:

.textfield {     background-color: #000;     color: green; } 

However, somehow I only get the black background and the font is still black. Does anyone know how to properly change the font color of a TextField using MUI?

like image 519
sub_o Avatar asked May 08 '18 07:05

sub_o


People also ask

How do you change font color in Mui TextField?

To change the text field font color in React Material UI, we call the makeStyles function with an object with the styles we want to apply. to call makeStyles with an object that has the input property that's set to an object with the color property set to 'blue' . Next, we call useStyles to return the classes object.

How do I change TextField style in MUI?

To style a React Material UI text field, we can call the makeStyles function with a function that returns an object that specifies the styles. Then we can set the InputProps prop of the TextField to specify the styles of the input element in the text field.

How do I customize TextField in material UI?

const styles = theme => ({ textField: { width: '90%', marginLeft: 'auto', marginRight: 'auto', color: 'white', paddingBottom: 0, marginTop: 0, fontWeight: 500 }, });


2 Answers

I referred this page TextField API

And I override the TextField using Classes

const styles = theme => ({     multilineColor:{         color:'red'     } }); 

Apply the class to TextField using InputProps.

<TextField    className = "textfield"   fullWidth   multiline   InputProps={{     className: classes.multilineColor   }}   label   = "Debugger"   rows    = "10"   margin  = "normal" /> 

EDIT In older version you have to specify the key input

<TextField      className = "textfield"     fullWidth     multiline     InputProps={{         classes: {             input: classes.multilineColor         }     }}     label   = "Debugger"     rows    = "10"     margin  = "normal" /> 

Hope this will work.

like image 84
anonymous_siva Avatar answered Oct 22 '22 15:10

anonymous_siva


In MUI v5, you can just do this using sx prop:

<TextField sx={{ input: { color: 'red' } }} /> 

A bit longer approach if you want something more reusable:

const options = {   shouldForwardProp: (prop) => prop !== 'fontColor', }; const StyledTextField = styled(   TextField,   options, )(({ fontColor }) => ({   input: {     color: fontColor,   }, })); 
<StyledTextField label="Outlined" fontColor="green" /> <StyledTextField label="Outlined" fontColor="purple" /> 

Live Demo

Codesandbox Demo

like image 39
NearHuscarl Avatar answered Oct 22 '22 17:10

NearHuscarl