bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

"collapsed" class is not added correctly to accordion toggles

Open chenghong opened this issue 14 years ago • 7 comments

This issue can be viewed on the official documentation page for Collapse at http://twitter.github.com/bootstrap/javascript.html#collapse

When I click on an accordian-toggle to expand its body, the "collapsed" class should be applied to all other accordian-toggles within the same accordion, as they will now become collapsed.

Currently, Bootstrap only applies the "collapsed" class to an accordion-toggle element when that element is explicitly clicked on to collapse its expanded body.

chenghong avatar Oct 31 '12 15:10 chenghong

if you need this immediately, check out my fork with this quickfix: https://github.com/tiefenb/bootstrap/commit/a58cccd6545c76fccfd7c47ddb0d506b5e99ba4d

tiefenb avatar Nov 06 '12 08:11 tiefenb

Fix by @tiefenb works great.

stevenklein avatar Nov 19 '12 03:11 stevenklein

The fix by @tiefenb worked well, but one of my cases had accordions nested in accordions, sort of like what's shown here:

http://jsfiddle.net/A7fQp/

The quickfix caused the accordions nested within the expanded accordion to have their "collapsed" class removed, too, even though they were not yet opened. This is because every single ".accordion-toggle" under the one clicked is found by the "find". The very first one is the only one, I think, that should have "collapsed" removed or added (it's the upper-most of all results from the "find" method, based on what I've seen on Firefox, Safari, and Chrome). I have an update on the fix by @tiefenb below, which appears to remedy that scenario I described:

https://github.com/althaitran/bootstrap/commit/99411c15622188f24fb6714752bd5574874996c2

althaitran avatar Feb 02 '13 11:02 althaitran

Oh yeah, I'm a bit new here, so I couldn't really figure out how to commit to the 2.3.0-durchblicker branch, @tiefenb, or if I'm even allowed to. I have referenced that much of the code on my patch is based on yours, though, but let me know if you don't feel comfortable with me having it there, or if I could just append to your fix on that durchblicker branch.

althaitran avatar Feb 02 '13 11:02 althaitran

it is added how it was intended

fat avatar Feb 08 '13 04:02 fat

sorry, i can't see the commit, where the fix happend... :-(

tiefenb avatar Feb 08 '13 09:02 tiefenb

Basically, instead of this:

$(item.parentNode).find('.accordion-toggle').addClass('collapsed')

I used this in my commit for js/bootstrap-collapse.js (lines 86 and 72):

$(item.parentNode).find('.accordion-toggle').first().addClass('collapsed')

Similar thing applies to removeClass.

althaitran avatar Feb 08 '13 10:02 althaitran