Alhadis / Accordion

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

Option to allow only one fold to be open at a time #6

Closed blimpmason closed 8 years ago

blimpmason commented 8 years ago

Is there a method I could use on the onToggle callback to collapse all other folds when one is expanded? So if you open one, any open section collapses.

Alhadis commented 8 years ago

Hey buddy,

Not out-of-the-box, I'm afraid. Try using this as your onToggle callback:

onToggle: function(target){
    target.accordion.folds.forEach(fold => {
        if(fold !== target)
            fold.open = false;
    });
}

I thought to include a modal option, but wanted the core code to be as minimal as possible. Though I should probably make a note of this snippet in the readme, since modal accordions are that common. =)

blimpmason commented 8 years ago

Perfect, thanks! Much appreciated.

Alhadis commented 8 years ago

No problem! Glad I could help. =)