There is no guidance on how to change the text colour of these inputs https://material-ui-next.com/demos/text-fields/
Do we just use external css to do this?
I also tried this but it doesn't pass TypeScript checks:
<TextField
inputProps={{ style: { fontFamily: 'Arial', color: 'white'}}}
style={{ flex: 1, margin: '0 20px 0 0', color: 'white'}}
onChange={(e: ChangeEvent<HTMLInputElement>) => changeSearch(e.target.value)}
type="text"
value={reducerState.search}
/>
(50,11): error TS2339: Property 'inputProps' does not exist on type 'IntrinsicAttributes & TextFieldProps & { children?: ReactNode; }'.
This might be purely a TypeScript types issue
I just done it with external css
.something input {
color: white;
}
@QuantumInformation I'm glad you found a solution. I would encourage people to do it this way:
import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
const styles = {
root: {
background: "black"
},
input: {
color: "white"
}
};
function CustomizedInputs(props) {
const { classes } = props;
return (
<TextField
defaultValue="color"
className={classes.root}
InputProps={{
className: classes.input
}}
/>
);
}
CustomizedInputs.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(CustomizedInputs);
https://codesandbox.io/s/1370v7y4zj
Notice that you can also target the global class names (.MuiInputBase-root
and .MuiInputBase-input
).
Does not work in "@material-ui/core"
Any updates, how to make it working with @material-ui/core
? I'm badly stuck at this
@pankajparkar I have updated my previous answer to work with the latest version: https://github.com/mui-org/material-ui/issues/9574#issuecomment-353179532. I hope that help, let me know! Alternatively, we have a customization demo in https://material-ui.com/demos/text-fields/#customized-inputs.
@oliviertassinari thanks alot. I had to remove label
to make it working.
Do you have any solution / workaround to make it working with label. I understand why label gets overlay (I kind of partially sorted it by applying z-index
, but that led to different problems).
Problem codepen here
thank you very much
Dang, never realised how unpopular my initial answer was
@oliviertassinari thanks alot. I had to remove
label
to make it working.
Do you have any solution / workaround to make it working with label. I understand why label gets overlay (I kind of partially sorted it by applyingz-index
, but that led to different problems).Problem codepen here
I also need exactly the same!
Most helpful comment
@QuantumInformation I'm glad you found a solution. I would encourage people to do it this way:
https://codesandbox.io/s/1370v7y4zj
Notice that you can also target the global class names (
.MuiInputBase-root
and.MuiInputBase-input
).