react-bootstrap icon indicating copy to clipboard operation
react-bootstrap copied to clipboard

Document that ToggleButtonGroup doesn't work when Bootstrap JS is present

Open spiroski opened this issue 9 years ago • 22 comments

This is my code:

<ToggleButtonGroup
    name="eventType"
    type="radio"
    value={this.state.eventType}
    onChange={(eventType) => this.setState({eventType})}>
    <ToggleButton bsStyle="default-washed"
                  value="business">
        Business
    </ToggleButton>
    <ToggleButton bsStyle="default-washed"
                  value="leisure">Leisure
    </ToggleButton>
</ToggleButtonGroup>

The state is not being changed. However the selected value in the component itself changes as the active button changes. I've tested other places as well. This happens after I've updated from 0.31.0 to 0.31.2

spiroski avatar Aug 30 '17 13:08 spiroski

Same as https://github.com/react-bootstrap/react-bootstrap/issues/2734. We can't do anything without a runnable repro.

taion avatar Aug 30 '17 16:08 taion

i'm still fairly sure this is because of a bug in radio/checkboxes in React 15.6.1

jquense avatar Aug 30 '17 16:08 jquense

Still having this problem. @taion repro was posted in issue #2734 https://github.com/react-bootstrap/react-bootstrap/issues/2734#issuecomment-318102096

alexschilpp avatar Sep 13 '17 11:09 alexschilpp

As you can see from the following 2 posts in that thread, that was not actually repro.

taion avatar Sep 13 '17 11:09 taion

@taion sorry, it looks like the problem is not in your library.

Reproduced it and everything works fine https://codepen.io/alexschilpp/pen/PJwdxX

alexschilpp avatar Sep 14 '17 11:09 alexschilpp

@alexschilpp It seems the issue occurs when bootstrap js lib included https://codepen.io/kamote/pen/gGvadB

kamote avatar Oct 06 '17 12:10 kamote

@kamote I am having the same issue, my Checkbox is not being toggled while my non bootstrap checkbox works fine. I have regular bootstrap running for non react pages, besides for react-bootstrap. Any workaround?

avremel avatar Oct 17 '17 20:10 avremel

@kamote Probably, because react-BS adds a data-toggle="buttons" attribute, and BS attaches its handler to the elements that have those.

RKushnir avatar Oct 24 '17 14:10 RKushnir

@jquense Should we drop the data-toggle prop?

taion avatar Oct 24 '17 14:10 taion

It sounds like the resolution here is that users must not include the Bootstrap JS when using toggle groups here.

This would be a great addition to the docs, if anybody cares to PR.

taion avatar Nov 08 '17 20:11 taion

I am still having this problem with the BootstrapJS removed. Is there another fix?

iancullinane avatar Nov 09 '17 19:11 iancullinane

Same here

reduxdj avatar Dec 06 '17 04:12 reduxdj

There's also a workaround of setting an onClick handler on each individual ToggleButton. This worked for me (I'm working on an app where removing the bootstrap JS is not an option). This would be good to document as well.

mreishus avatar Dec 15 '17 17:12 mreishus

@mreishus this workaround makes my day. As you, I can't remove bootstrap JS. If this bug will be still there in the 1.0, it would be nice to document it (official doc, release notes, ...).

vinodsantharam avatar Jan 04 '18 10:01 vinodsantharam

@taion I'm happy to create a PR to update this documentation I can't see ToggleButtonGroup in the documentation anywhere. Am I missing something?

tomscott1 avatar Jan 08 '18 08:01 tomscott1

@jquense did this get dropped from the new docs?

taion avatar Jan 08 '18 16:01 taion

It's definitely possible

jquense avatar Jan 08 '18 16:01 jquense

So I was looking for this component, didn't see it in the docs. I typed import { Toggle... in vs code and saw it does exist. Then I started to lose my mind wondering why my onChange was not getting called. I read the source code and didn't see any reason. Moral of the story, never forget that Github issues >= documentation.

mattblackdev avatar Jan 11 '18 22:01 mattblackdev

I looked a little bit into the issue as I also have the need to have bootstrap.js and react-bootstrap in my application.

These are the problematic lines in (at least) boostrap-3.3.7: https://github.com/twbs/bootstrap/blob/v3.3.7/js/button.js#L66

Here checked is being change and with that, react-bootstrap does not see any change.

And in combination, this line is affecting the outcome as well: https://github.com/twbs/bootstrap/blob/v3.3.7/js/button.js#L115

If the event is not propagated, react-bootstrap does not see it.

Furthermore, I could not make onChange work on ToggleButton itself. Need to investigate this a bit further.

Edit: ToggleButton has exactly the same issues, as both lines in bootstrap lead to the same behaviour. So actually there is not way in my setup to use bootrstrap.js and react-bootstrap together (without hacking either one)

mobilutz avatar Jan 12 '18 14:01 mobilutz

this was fixed in #2956

taion avatar Mar 05 '18 17:03 taion