I've been searching for a long time for a solution to this problem, but I can't seem to find the best solution for this problem. Basically I have an accordion which when a user open's it, it should slide down gently with a nice transition.
I'm pretty sure this is possible with only css. Please correct me if I'm wrong, but css transitions are performance wise better than js transitions.
So now the the HTML for the problem I'm facing:
<transition name="slide-down">
<ul v-if="isDisplayingOpeningHours" class="mt-2 text-sm flex flex-col space-y-2">
<li v-for="i in 10" :key="i"> <!-- just for testing purposes -->
element
</li>
</ul>
</transition>
And the css is:
.slide-down-enter-active, .slide-down-leave-active {
transition: all .5s;
}
.slide-down-enter-to, .slide-down-leave {
overflow: hidden;
max-height: 100%;
}
.slide-down-enter, .slide-down-leave-to {
overflow: hidden;
max-height: 0;
}
This results in a not fluent transition. Sliding down doesn't seem to be a problem, but when it slides up it's really janky and not fluent at all!. If I set the max-height: 10rem
it isn't making it any better. I'm hoping someone can debug help me with this problem and maybe educate me more about vue transitions and js vs css transitions.
Edit:
Just for clarification the transition itself should by css only. The opening of the accordion is with js which is fine. Also it would be nice to maybe see an example of a transition use with the native vue-transition component.
Edit 2:
Here is a codesandbox which has the same problem I have.
https://codesandbox.io/s/frosty-bash-lmc2f?file=/src/components/HelloWorld.vue