Skip to content

Commit aa11f26

Browse files
author
bootstrap-vue-bot
committed
smoother collpase closes #118
1 parent e5e8739 commit aa11f26

File tree

1 file changed

+47
-69
lines changed

1 file changed

+47
-69
lines changed

components/collapse.vue

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,66 @@
11
<template>
2-
<div :class="classObject"
3-
:aria-expanded="show"
4-
:style="styleObject"
5-
>
6-
<slot></slot>
7-
</div>
2+
<transition name="collapse">
3+
<div :class="classObject" v-show="show">
4+
<slot></slot>
5+
</div>
6+
</transition>
87
</template>
98

10-
<script>
11-
import {TRANSITION_DURATION} from '../utils/helpers';
9+
<style scoped>
10+
.collapse-enter-active, .collapse-leave-active {
11+
transition: all .35s ease;
12+
overflow: hidden;
13+
max-height: 100vh;
14+
}
1215
13-
// export component object
14-
export default {
16+
.collapse-enter, .collapse-leave-to {
17+
max-height: 0;
18+
}
19+
</style>
1520

16-
data() {
17-
return {
18-
collapsing: false,
19-
show: false,
20-
height: 0
21-
};
22-
},
21+
<script>
22+
export default {
2323
24-
computed: {
25-
classObject() {
24+
data() {
2625
return {
27-
'navbar-collapse': this.isNav,
28-
collapsing: this.collapsing,
29-
collapse: !this.collapsing,
30-
show: this.show
26+
show: false,
3127
};
3228
},
3329
34-
styleObject() {
35-
const obj = {};
36-
if (this.collapsing && this.height) {
37-
obj.height = this.height + 'px';
38-
}
39-
return obj;
40-
},
41-
42-
scrollHeight() {
43-
return 100;// this.$el.scrollHeight;
44-
}
45-
},
46-
47-
props: {
48-
isNav: {
49-
type: Boolean,
50-
default: false
30+
computed: {
31+
classObject() {
32+
return {
33+
'navbar-collapse': this.isNav,
34+
show: this.show
35+
};
36+
},
5137
},
52-
id: {
53-
type: String,
54-
required: true
55-
}
56-
},
5738
58-
methods: {
59-
toggle() {
60-
if (this.collapsing) {
61-
return;
39+
props: {
40+
isNav: {
41+
type: Boolean,
42+
default: false
43+
},
44+
id: {
45+
type: String,
46+
required: true
6247
}
48+
},
6349
64-
this.collapsing = true;
65-
this.height = (this.show ? 0 : this.scrollHeight);
66-
67-
this._collapseAnimation = setTimeout(() => {
68-
this.collapsing = false;
50+
methods: {
51+
toggle() {
6952
this.show = !this.show;
70-
}, TRANSITION_DURATION);
71-
}
72-
},
73-
74-
created() {
75-
this.$root.$on('collapse::toggle', target => {
76-
if (target !== this.id) {
77-
return;
7853
}
79-
this.toggle();
80-
});
81-
},
54+
},
8255
83-
destroyed() {
84-
clearTimeout(this._collapseAnimation);
85-
}
86-
};
56+
created() {
57+
this.$root.$on('collapse::toggle', target => {
58+
if (target !== this.id) {
59+
return;
60+
}
61+
this.toggle();
62+
});
63+
},
64+
};
8765
8866
</script>

0 commit comments

Comments
 (0)