-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open collapse element does not close when calling $.collapse('show') on sibling #16360
Comments
Based on #9933 (comment) and #8400 (comment) , and the lack of a unit test to the contrary, my guess is that this is working as intended. Getting mutex accordion-style behavior requires emitting a click event on the trigger element (typically an |
That's a little counter-intuitive, but I understand wanting to keep discrete show/hide methods public without making assumptions about maintaining the click behavior. Triggering a click event is a decent work-around, but I wish there were a way to achieve the behavior programmatically without deferring to the click handler. I may have other events bound to the click event that shouldn't fire at the moment I'm calling |
I agree it's not the best design, but I think we'd probably need to break backward compatibility to sanely fix it. I'll add an entry to our "Consider for Bootstrap v4" list. |
Another option would be allowing a callback function to be passed as a second argument to
This would be a nice to have for all of the Bootstrap methods. |
We use Events for such things instead; e.g. http://getbootstrap.com/javascript/#collapse-events |
Right, but then I'd need to set up an event that drills up a level from the target
|
Actually there is a bit easier solution. If you are using the javascript api you can simply initialize the elements as an accordion first with the following code: $('#accordion .panel-collapse').collapse({
parent: '#accordion',
toggle: false
}) This will let all the targets know that they have a parent to worry about. Now when you run your initial code: $('#collapseTwo').collapse('show') You get the expected behavior. The problem is that if you're relying on just the data api, the api lazy instantiates, something which .collapse('show') doesn't take into account. That should address your problem, please reopen the issue if you have any more questions, etc. Thanks! |
Given a Collapse Accordion, where only one item should be open at a time:
Expected behavior:
Only Item B should be open.
To test:
Using the Collapse Accordion example. Click the first item, then enter
$('#collapseTwo').collapse('show')
in your browser console.Browser: Mac OSX Chrome 42.0.2311.90
The text was updated successfully, but these errors were encountered: