3

Hi so this looks simple but i haven't been able to find anything regarding this what i only want is for the following fields to look white:

enter image description here

To be specific the default labels and the border color. To further clarify i did manage to make the input text white itself by passing the class through InputProps. but am stuck with this. Please help me out here.

Hadi Pawar
  • 1,090
  • 1
  • 11
  • 23
  • 1
    Can you add your current code to the question? – 5eb Aug 21 '20 at 19:54
  • You have to make use of a ThemeProvider and add a theme object with your customization. https://material-ui.com/customization/theming/ We do not know anything about your implementation since you didn't share your code, so this is out of thin air. – evayly Aug 21 '20 at 20:08

2 Answers2

3

Ciao, to make the border color white you have to:

Define a Theme object in which you have to define a primary color and override the MuiOutlinedInput like this:

   const Theme = {
    palette: {
     primary: {
      contrastText: "#FFFFFF",
      dark: "#FFFFFF",
      main: "#FFFFFF",
      light: "#FFFFFF"
     }
   },
   overrides: {
    MuiOutlinedInput: {
      root: {
        position: "relative",
        "& $notchedOutline": {
          borderColor: "#FFFFFF"
        },
        "&:hover:not($disabled):not($focused):not($error) $notchedOutline": {
          borderColor: "#FFFFFF",
          "@media (hover: none)": {
            borderColor: "#FFFFFF"
          }
        },
        "&$focused $notchedOutline": {
          borderColor: "#FFFFFF",
          borderWidth: 1
        }
      }
     }
    }
   };

(I know, this will override all the MuiOutlinedInputs you will use in your project but I found only this way).

To pass this Theme to the TextField, you have to wrap it into a ThemeProvider and create a mui theme:

import { ThemeProvider, createMuiTheme } from "@material-ui/core/styles";
...
const theme = createMuiTheme(Theme);
...

return (
    <ThemeProvider theme={theme}>
      <div class={classes.root}>
        <TextField />
        ....
     </ThemeProvider>
);

For the text color and the default label, you have to use InputProps and InputLabelProps with a className like:

<TextField
   variant="outlined"
   id="fullName"
   label="Username"
   InputProps={{
     className: classes.input
   }}
   InputLabelProps={{
     className: classes.input
   }}
 />

The css will be:

const useStyles = makeStyles(() => ({
  input: {
    color: "white"
  }
}));

Here a codesandbox example.

Giovanni Esposito
  • 10,696
  • 1
  • 14
  • 30
1

I think @evayly is right and you should use a theme provider (see his comment above). If you just need a quick hack for a one-off then the follow CSS seems to suffice. However I really don't recommend it for anything that is meant to last.

.MuiOutlinedInput-notchedOutline {
    border-color: white;
}
.MuiFormLabel-root {
    color: white;
}
.MuiInputBase-input {
    color: white;
}
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71