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?
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.
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.
const styles = theme => ({ textField: { width: '90%', marginLeft: 'auto', marginRight: 'auto', color: 'white', paddingBottom: 0, marginTop: 0, fontWeight: 500 }, });
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.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With