I'm trying to create an accordion using flexbox and transitions, adding and removing a collapse class with jQuery. The problem I'm having is if I set flex-basis as auto for the expanded divs, the animation doesn't work. See http://jsfiddle.net/vbLqg40h/ for an example. If I change the flex-basis from auto to 500px, the height of the flex container, the animation works ( http://jsfiddle.net/vbLqg40h/2/ )...I don't know why.
html
<div id="wrapper">
    <div id="box1" class="expand"></div>
    <div id="box2" class="expand collapse"></div>
    <div id="box3" class="expand collapse"></div>
</div>
css
#wrapper {
    height: 500px;
    display: flex;
    flex-direction: column;
}
.expand {
    flex: 1 1 auto;
    transition: all 2s;
}
.collapse {
    flex: 0 1 25px;
}
#box1 {
    background-color: yellow;
}
#box2 {
    background-color: green;
}
#box3 {
    background-color: blue;
}
javascript
$('.expand').click(function() {
  var expandId = $(this).attr('id');
  $('.expand').each(function() {
   var thisId = $(this).attr('id');
   if (expandId != thisId) {
     $('#' + thisId).addClass('collapse');
   } else {
     $('#' + thisId).removeClass('collapse');
   }
 });
});
 
     
     
    