uikit / uikit

A lightweight and modular front-end framework for developing fast and powerful web interfaces

Home Page:http://getuikit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Open newly added sub-element in Accordion

sibdib opened this issue · comments

commented

UIkit Version

3.16.24

Actual & Expected Behavior

I create my accordion sub-elements dynamically with a createAccordionElement function that returns the accordion element. I then add it to the actual accordion element:
accordionContainer.appendChild(accordionElement);
This makes it so that I can add Elements dynamically.
Then I wish to have this newly added Element to be automatically opened, but when I use:
UIkit.accordion(accordionContainer).toggle(newNumber); where newNumber is the new index. It doesnt automatically open the new Element, but it rather defaults to 0 and it opens the first Element of the container. I thought this would open the newly created Element, but it doesn't.

Reproduction Link

Codepen
So, If I change the number here: UIkit.accordion(accordion).toggle(2); to 1, it will open the middle one and I havent been able to find a way of how I can do this for the new element

EDIT:
Issue was closed for V2(Not resolved), but never re-opened in V3

If you wrap the toggle() function in a setTimeout, you should be good.

commented

Thanks for the reply, that works. I would like to see this fixed, as I would consider it a bug, because dynamic content doesn't work properly.
I just noticed that there was a similar issue back in V2 but it got closed because the version got moved from 2 to 3.
If Im passing a DOM accordion element object to the accordion() function, then surely it can read the number of the accordion children it has and work with them, so that toggle() can recognize the newly added element.