Skip to content

Commit

Permalink
fix(collapse): wait for transition to finish to remove overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
lecoueyl committed Apr 27, 2021
1 parent 1bf53d0 commit 5b68b91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/components/collapse/Collapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
stroke-linecap="round"
fill="none"
role="presentation"
class="stroke-2 w-5 h-5 transform transition-transform duration-200"
:class="[
'stroke-2 w-5 h-5 transform transition-transform duration-200',
iconLeft ? 'mr-2' : 'ml-2',
{ 'rotate-180': !collapsed }
]"
Expand All @@ -42,7 +42,11 @@
</template>

<div
class="overflow-y-hidden transition-all duration-300 ease-in-out"
class=""
:class="[
' transition-all duration-300 ease-in-out',
{ 'overflow-y-hidden': !expandedCompleted }
]"
:style="{ maxHeight: maxHeight + 'px' }"
>
<div ref="content">
Expand All @@ -53,6 +57,8 @@
</template>

<script>
const collapseDurationMs = 300;
export default {
name: 'MijinCollapse',
Expand Down Expand Up @@ -81,6 +87,7 @@ export default {
data() {
return {
collapsed: !this.expanded,
expandedCompleted: false,
maxHeight: 0,
};
},
Expand All @@ -101,6 +108,13 @@ export default {
toggleExpand() {
if (this.disabled) return;
this.expandedCompleted = false;
if (this.collapsed) {
setTimeout(() => {
this.expandedCompleted = true;
}, collapseDurationMs);
}
this.collapsed = !this.collapsed;
this.$emit('toggle', this.collapsed);
this.resizeContent();
Expand Down
7 changes: 6 additions & 1 deletion src/components/collapse/collapse.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Collapse', () => {
expect(wrapper.vm.collapsed).toBe(false);
});

it('expands content', async () => {
it('expands content', async (done) => {
const wrapper = shallowMount(Collapse, {
slots: {
default: '<span>default</span>',
Expand All @@ -74,5 +74,10 @@ describe('Collapse', () => {
await wrapper.find('span').trigger('click');
expect(wrapper.vm.collapsed).toBe(false);
expect(wrapper.emitted('toggle')).toBeTruthy();
expect(wrapper.vm.expandedCompleted).toBe(false);
setTimeout(() => {
expect(wrapper.vm.expandedCompleted).toBe(true);
done();
}, 300);
});
});

0 comments on commit 5b68b91

Please sign in to comment.