question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Lab] ToggleButton Style backgroundColor override when selected={true}

See original GitHub issue

We 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:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Nov 30, 2020

@mbrookes Looks like the exact same question you asked me yesterday. I’m glad v5 API, by design, solve this issue.

1reaction
montogeekcommented, Nov 30, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found