I'm trying to re-style the Switch component, but having trouble finding a way to style the bar in the background the button.
N/A
N/A
N/A
When the Switch component is checked the following styling is applied:
.MuiSwitch.checked-1 + .MuiSwitch.bar-1 {
opacity: 0.5;
backgroud-color: #3f51b5;
}
When creating an theme, how does one override the background color in the style above?
const theme = createMuiTheme({
overrides: {
checked: {
color: lightBlue['A700'] // changes switch handle
},
bar: {
// changing the backgroundColor here changes it for disabled & checked
}
}
});
I can change it by overriding palette.primary.500. I'm wondering if it's possible in the override section?
| Tech | Version |
|--------------|---------|
| Material-UI | 1.0.0-beta.11 |
| React | 15.6.1 |
| browser | chrome |
You have many alternatives.
If you want to do it with the overrides key, here is the way:
const theme = createMuiTheme({
overrides: {
MuiSwitch: {
checked: {
color: orange[500],
'& + $bar': {
backgroundColor: orange[500],
},
},
},
},
});

Thanks! A good pattern to know for those fringe cases.
I know this issue is closed, but I am having trouble styling the switch. I have followed @oliviertassinari 's instructions but the override is not being applied. I have also tried to uses classes to style this component. Shall I open a new issue?
@s-wynter This issue is outdated. Follow our examples in the selection control documentation.
@s-wynter you may need to add color: 'default' to Switch component props, checkout https://material-ui.com/api/switch/ and you can see it will default to the secondary from theme
Most helpful comment
You have many alternatives.
If you want to do it with the
overrideskey, here is the way: