Alhadis / Accordion

Silky-smooth accordion widgets with no external dependencies.
https://www.npmjs.com/package/accordion
ISC License
32 stars 11 forks source link

Great Plugin #9

Closed schellenbergk closed 6 years ago

schellenbergk commented 6 years ago

Is there an easy way to keep first item expanded by default. Also when expanding a new element collapse the previous one? Thanks.

Alhadis commented 6 years ago

:wave: Hey mate,

  1. Yes, just add the open class to the first fold before creating the Accordion instance.

  2. To collapse other elements when expanding a new one, add this to your Accordion's instance:

onToggle: function(target){
    target.accordion.folds.forEach(fold => {
        if(fold !== target)
            old.open = false;
    });
}
schellenbergk commented 6 years ago

thanks!!, just correct that mistake old.open = false; ;)

Alhadis commented 6 years ago

@schellenbergk I'm glad I could help. Since you're not the first person to ask about this, I think I will make this a core option after all. Looking back, my decision to optimise space by omitting a modal option really doesn't justify the added effort required of authors.

Expect a new release in the near future that will allow you to implement the above behaviour simply by passing modal: true as an option. =)