stuartjnelson / badger-accordion

An accessible vanilla JS accordion with extensible API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add method to re-initialize accordion

willfalcon opened this issue · comments

It'd be great to have a method to reinitialize the accordion.

For example, I'm using it on an "About" page, with a collapsible list of staff members, and floated images in some body copy... not sure if it's because of the floats or because the accordion scripts are finishing before the js that's loading in the images, but the calculated maxHeight that's being tacked onto the panel isn't accounting for those images, so they're being cut off at the bottom if the body copy isn't long enough.

It would be an easy fix to be able to just call a reinitialize method on the panel after the image loads in.

Might not be an easy implementation though haha, I don't really know. Just an idea.

Love the plugin as a whole though! Thanks!

Hi @willfalcon,

Thanks for getting in touch! I agree this could be useful for a host of reasons! I'm afraid right now I'm pretty slammed so won't be able to investigate for at least 3 weeks.

What I can suggest in the meantime would be to try the method _setPanelHeight(). If you have a look at src/js/badger-accordion.js you can see this method. At the moment it is a "private" method but I think it could serve your purpose. There is also an initalisedClass that is added to the container I don't know if that would help...

Sorry for the rushed reply. I'll let you know on here when i do get to it! If you'd like to have a go at it yourself feel free to submit a pull request!

Hi @willfalcon,

I had a quick look today and you can do this I just didn't document it... I created a new branch and updated my example in it for you. You can use either the init() or _setPanelHeight() method. I would use the later as i have in the example - link - I will document both for the future.

Thanks for pointing this out and helping to improve the plugin.