Skip to content
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

Accordion with Collapse: show() doesn't hide the other accordions #8400

Closed
d-ph opened this issue Jul 6, 2013 · 4 comments
Closed

Accordion with Collapse: show() doesn't hide the other accordions #8400

d-ph opened this issue Jul 6, 2013 · 4 comments

Comments

@d-ph
Copy link

d-ph commented Jul 6, 2013

Hello,

straight to the point:

To reproduce:

  1. Go to Bootstrap website, collapse secition: link
  2. Open up webdeveloper tools (I use Google Chrome), go to Console tab and execute: $("#collapse .accordion-body:last").collapse("show");
  3. Result: The last accordion opens, but the first isn't closed.

The problem (briefly):
The third accordion doesn't have parent option set, because we didn't provide it.

The workaround solution:
Start the third accordion with parent option set, and after that try to show() it. Note, that hide() and toggle() also triggers this bug.

The proper solution:
Collapse constructor should look for parent setting (and all other too) in data- attributes of the $() element, as a fallback. If user doesn't provide these options, he obviously wants the Collapse to read those from data- attributes.

The cry story:
Wasted a couple of hours, why the accordion didn't work after show(). It's super counter intuitive, that the options aren't read from data- attributes, when you start the Collapse manual way. I suppose all other plugins inherit the same behaviour (starting by data- attributes reads options from these attributes, where starting manual way don't).

Kind regards

-------- Edit

It's funny when you notice your own mistake only after you cry about it.

Of course accordion-body doesn't have data- attributes to read from, so the The proper solution isn't quite working. But the problem remains. How do we mix the auto data- usage with the manual usage. I.e. how to achieve such a workflow:

  1. Start the accordion/collapse through data- attributes.
  2. open(), hide(), toggle(), whatever() the accordion manually (occasionally) later on.

?

-------- Edit

Ok, it was quite easy: $("#collapse .accordion-body:last").collapse({parent: "#accordion2"}, "show");. But, can you see the notobviousleness of this solution? If I wanna show() an accordion, I don't wanna think to which parent it belongs, since I've already provided the information in the accordion-toggle. I just want the damn thing to show itself properly ;p. Also note the information duplication in this solution, which simply leads to maintenance hell in the future.

@317070
Copy link

317070 commented Jul 22, 2013

I have the same problem.

@fat
Copy link
Member

fat commented Jul 26, 2013

best to just fire click on the toggle you want when using the accordion

$("#collapse [data-toggle=collapse]:last").click()

@fat fat closed this as completed Jul 26, 2013
@317070
Copy link

317070 commented Jul 26, 2013

Except such a click would fire many more things in my case. I had to solve this issue by dropping the parent argument from collapse() and manually closing all the other accordions.

@d-ph
Copy link
Author

d-ph commented Jul 26, 2013

Wouldn't it be just simpler, if we could define at the parent element a data- attribute, that tells, that all the accordion-groups below the parent node are part of one accordion, that allows only one accordion-group to be opened at any time? Collapse plugin could search for the immediate parent of current accordion-group (in which the collapsable accordion-body resides) and check, whether it has the data- atrribute. By the way we could get rid of code duplication in every accordion-toggle's data-parent attribute,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants