Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change text, icon and underline color of Select in Material UI

So I want to change the text, icon and underline color of Material UI Select component from black to white, which looks like this:

enter image description here

The options text colors which are implemented by MenuItem are looking good by default, because they are grey on white:

enter image description here

I original documentation of Select does not help much, because it doesn't say which CSS class I should override in classes.

import React from "react";
import ReactDOM from "react-dom";
import { withStyles } from "@material-ui/core/styles";
import FormControl from "@material-ui/core/FormControl";
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";

const styles = theme => ({
  root: {
    background: "blue",
    backgroundColor: "blue"
  }
});

const OPTIONS = {
  A: "Option A",
  B: "Option B"
};

class App extends React.Component {
  state = {
    option: OPTIONS.A
  };
  handleOptionChange = event => {
    return this.setState({ option: event.target.value });
  };

  render() {
    const { classes } = this.props;
    return (
      <div className={classes.root}>
        <FormControl variant="outlined">
          <Select
            value={this.state.option}
            onChange={this.handleOptionChange}
            name="optionsDropdown"
          >
            <MenuItem value={OPTIONS.A}>{OPTIONS.A}</MenuItem>
            <MenuItem value={OPTIONS.B}>{OPTIONS.B}</MenuItem>
          </Select>
        </FormControl>
      </div>
    );
  }
}
const DemoApp = withStyles(styles)(App);
const rootElement = document.getElementById("root");
ReactDOM.render(<DemoApp />, rootElement);
like image 291
Eugenijus S. Avatar asked Mar 06 '19 11:03

Eugenijus S.


1 Answers

found a way to do that by overriding root and icon classes:

const styles = theme => ({
  root: {
    background: "blue",
  },
  whiteColor: {
    color: "white"
  }
});

 ... 

<Select
  classes={{
    root: classes.whiteColor,
    icon: classes.whiteColor
  }} 
/> 

https://codesandbox.io/s/x3j9lz9z2o

enter image description here

Only thing left to change is underline color.

like image 135
Eugenijus S. Avatar answered Sep 24 '22 09:09

Eugenijus S.