Skip to content

Commit 102ad74

Browse files
authored
Merge pull request #302 from marcosmoura/improvement/mdList
fix expansion lists size on resize #278
2 parents 56dc8b9 + 3544f52 commit 102ad74

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/components/mdList/mdListExpand.vue

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="md-list-expand" :style="{ 'margin-bottom': height }" :class="classes" ref="expand">
2+
<div class="md-list-expand" :style="styles" :class="classes" ref="expand">
33
<slot></slot>
44
</div>
55
</template>
@@ -18,22 +18,29 @@
1818
return {
1919
'md-transition-off': this.transitionOff
2020
};
21+
},
22+
styles() {
23+
return {
24+
'margin-bottom': this.height
25+
};
2126
}
2227
},
2328
methods: {
2429
calculatePadding() {
25-
this.height = -this.$el.offsetHeight + 'px';
30+
window.requestAnimationFrame(() => {
31+
this.height = -this.$el.offsetHeight - 48 + 'px';
2632
27-
window.setTimeout(() => {
28-
this.transitionOff = false;
33+
window.setTimeout(() => {
34+
this.transitionOff = false;
35+
});
2936
});
3037
},
31-
recalculateAfterChildChange() {
38+
recalculateAfterChange() {
3239
this.transitionOff = true;
3340
this.calculatePadding();
3441
},
3542
observeChildChanges() {
36-
this.contentObserver = new MutationObserver(this.recalculateAfterChildChange);
43+
this.contentObserver = new MutationObserver(this.recalculateAfterChange);
3744
this.contentObserver.observe(this.$refs.expand, {
3845
childList: true,
3946
characterData: true,
@@ -44,11 +51,14 @@
4451
mounted() {
4552
this.calculatePadding();
4653
this.observeChildChanges();
54+
window.addEventListener('resize', this.recalculateAfterChange);
4755
},
4856
beforeDestroy() {
4957
if (this.contentObserver) {
5058
this.contentObserver.disconnect();
5159
}
60+
61+
window.removeEventListener('resize', this.recalculateAfterChange);
5262
}
5363
};
5464
</script>

0 commit comments

Comments
 (0)