Semantic-ui: [Accordion] Cannot open nested accordion items using javascript

Created on 7 Jun 2017  路  5Comments  路  Source: Semantic-Org/Semantic-UI

When using nested accordions, programmatically opening an item in the nested accordion using JavaScript seems not to be working.

I've reproduced the problem here:
https://jsfiddle.net/y6o0p1Lz/1/

The accordion works correctly if you open items by clicking, but not using javascript

Confirmed Bug stale

Most helpful comment

Until this is fixed, if anyone is interested, I found that this simple workaround makes it work like intended:

var itemToOpen = 2;
$('#myAccordion .title').get(itemToOpen).click();

All 5 comments

Until this is fixed, if anyone is interested, I found that this simple workaround makes it work like intended:

var itemToOpen = 2;
$('#myAccordion .title').get(itemToOpen).click();

@tarockx in your example (https://jsfiddle.net/y6o0p1Lz/1/) the nested items can be opened by addressing the parent accordion with $(".ui.accordion").accordion('open', 2);

here's another fiddle with 3 layers of nested accordions: https://jsfiddle.net/mdhtr/mLwjr4zp/ showing how the use of the 'open' method on the top level accordion does not open the levels above the item that is opened.

@mdhtr : thanks for pointing this out. However, I must say I don't understand the reason why it's implemented like this, it seems needlessly convoluted to me.

Let me explain, maybe I'm missing something here and you can correct me: if I understand your fiddle correctly, to open an item in a nested accordion I need to recursively traverse the "tree of nested accordions" and count all the items that come before the one I want to open, in order to obtain the "global" index of the item, which I can then use to invoke 'open' on the root accordion.

That's much more complicated than calling the function on the accordion I'm interested in and just pass it the "local" index of the item. I don't understand the reasoning behind this choice.

Care of your DOM collision with Semantic UI classes (i.e. 'title', 'content', etc)

There has been no activity in this thread for 90 days. While we care about every issue and we鈥檇 love to see this fixed, the core team鈥檚 time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one.

However, PRs for this issue will of course be accepted and welcome!

If there is no more activity in the next 90 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks!

Was this page helpful?
0 / 5 - 0 ratings