Skip to content

Commit c3f6eb0

Browse files
VdustRSamuell1
authored andcommitted
feat(MdCardExpandContent): reactive content (#1799)
fix #1795
1 parent 8670933 commit c3f6eb0

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/components/MdCard/MdCardExpand/MdCardExpandContent.vue

+39-6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
</template>
66

77
<script>
8+
import MdObserveElement from 'core/utils/MdObserveElement'
89
export default {
910
name: 'MdCardExpandContent',
1011
inject: ['MdCard'],
1112
data: () => ({
12-
marginTop: 0
13+
marginTop: 0,
14+
resizeObserver: null,
15+
transitionEnabled: true
1316
}),
1417
computed: {
1518
expand () {
@@ -18,21 +21,51 @@
1821
contentStyles () {
1922
return {
2023
'margin-top': `-${this.marginTop}px`,
21-
'opacity': this.marginTop === 0 ? 1 : 0
24+
'opacity': this.marginTop === 0 ? 1 : 0,
25+
'transition-property': this.transitionEnabled ? null : 'none'
2226
}
2327
}
2428
},
25-
watch: {
26-
expand (expand) {
27-
if (!expand) {
29+
methods: {
30+
calculateMarginTop () {
31+
if (!this.expand) {
2832
this.marginTop = this.$el.children[0].offsetHeight
2933
} else {
3034
this.marginTop = 0
3135
}
36+
},
37+
calculateMarginTopImmediately () {
38+
if (this.expand) {
39+
return
40+
}
41+
42+
this.transitionEnabled = false
43+
this.$nextTick(() => {
44+
this.calculateMarginTop()
45+
this.$nextTick(() => {
46+
// force reflow
47+
this.$el.offsetHeight
48+
this.transitionEnabled = true
49+
})
50+
})
51+
}
52+
},
53+
watch: {
54+
expand () {
55+
this.calculateMarginTop()
3256
}
3357
},
3458
mounted () {
35-
this.marginTop = this.$el.children[0].offsetHeight
59+
this.calculateMarginTopImmediately()
60+
61+
this.resizeObserver = MdObserveElement(this.$el, {
62+
childList: true,
63+
characterData: true,
64+
subtree: true
65+
}, this.calculateMarginTopImmediately)
66+
},
67+
beforeDestroy () {
68+
this.resizeObserver.disconnect()
3669
}
3770
}
3871
</script>

0 commit comments

Comments
 (0)