Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the background color of a selected react-bootstrap ToggleButton?

I'm using react-bootstrap and am trying to change the background color of a selected <ToggleButton> to blue.

e.g.:

<ButtonToolbar>
  <ToggleButtonGroup
    type="radio"
    name="options"
    value={...}
    onChange={...}>
    <ToggleButton ... />
    <ToggleButton ... />
    <ToggleButton ... />
  </ToggleButtonGroup>
</ButtonToolbar>

So instead of the dark grey you see below for M/W/F I'd like blue. I've tried a billion CSS tricks and just can't get it to take. Thanks!

togglebuttonexample

like image 783
Dave Cole Avatar asked Nov 28 '18 00:11

Dave Cole


2 Answers

You can do this is CSS by adding the following class and style rule.

!important is needed to override the react-bootstrap library's style.

.Btn-Blue-BG.active {
  background-color: blue !important;
}

and

<ToggleButton className="Btn-Blue-BG" ...>

See demonstration below:

https://codesandbox.io/s/6nwkwnn29z

like image 166
Shawn Andrews Avatar answered Sep 20 '22 04:09

Shawn Andrews


Did you try adding bsStyle="primary" ?

<ButtonToolbar>
    <ToggleButtonGroup
        type="radio"
        name="options"
        value={...}
        onChange={...}>
        <ToggleButton ... />
        <ToggleButton bsStyle="primary" />
        <ToggleButton ... />
        <ToggleButton bsStyle="primary" />
        <ToggleButton ... />
        <ToggleButton bsStyle="primary" />
        <ToggleButton ... />
      </ToggleButtonGroup>
    </ButtonToolbar>
like image 38
AbhaY Avatar answered Sep 17 '22 04:09

AbhaY