So I want to change the text, icon and underline color of Material UI Select component from black to white, which looks like this:
The options text colors which are implemented by MenuItem are looking good by default, because they are grey on white:
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);
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
Only thing left to change is underline color.
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