[Lab] ToggleButton Style backgroundColor override when selected={true}
See original GitHub issueWe tried to override the background color when ToggleButton is selected.
We found that no matter how we try, the background color would be controlled by .MuiToggleButton-root.Mui-selected:hover
We are sure that we targeted the right selected
Pseudo-class successfully by adding a border around each button when selected.
Our ToggleButton looks like this:
<ToggleButton
classes={{
root: classes.buttons,
selected: classes.buttons_selected
}}
value='PayPal'
selected={selectedButton==='PayPal'}
onClick={()=>{setSelectedButton('PayPal')}}
>
Our makeStyle:
const useStyles = makeStyles(theme => ({
buttons: {
border: '1px solid #9B9B9B',
borderRadius: 5,
marginBottom: 5,
marginTop: 5,
height: 56,
width: '100%',
justifyContent: 'space-between',
},
buttonsselected: {
border: '2px solid #4955C0',
"&:hover": {
backgroundColor: 'transparent'
}
},
}));
And in Chrome Dev we found the following styles generated by our code
.makeStyles-buttonsselected-27:hover {
background-color: transparent;
}
being overrided by the following:
.MuiToggleButton-root.Mui-selected:hover {
background-color: rgba(0, 0, 0, 0.15);
}
- I have searched the issues of this repository and believe that this is not a duplicate.
Summary 💡
We would like to be able to easily override the background color of ToggleButton when it is selected
.
Motivation 🔦
Make it a more easier to use element of Material UI
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
[Lab] ToggleButton Style backgroundColor override ... - GitHub
We tried to override the background color when ToggleButton is selected. We found that no matter how we try, the background color would...
Read more >Material UI Toggle Button - can't change background color ...
I'm using the classes prop on the ToggleButton component, and using the "selected" rule within that prop.
Read more >unable to change background of selected tab in userChrome.css
Here is my current attempt in userChrome.css: tab[selected="true"] { -moz-appearance:none !important; background-color:lime !important; ...
Read more >ToggleButton API - Material UI - MUI
The name MuiToggleButton can be used when providing default props or style overrides in the theme. Props. Props of the ButtonBase component are...
Read more >Toggle button background color? - NI Community
I want to toggel the background color of text button. For ON white and OFF gray. How to change the background color of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mbrookes Looks like the exact same question you asked me yesterday. I’m glad v5 API, by design, solve this issue.
@trcloud How did you solve this issue?
Edit: Solved by adding the empty
selected: {}
property to the styles declaration as the docs say: https://material-ui.com/customization/components/#use-rulename-to-reference-a-local-rule-within-the-same-style-sheet