Skip to content

Commit 0f7e28f

Browse files
VdustRmarcosmoura
authored andcommitted
feat(MdListItemExpand): reactive expansion (#1435)
new props `md-expanded` with sync to make expansion reactive fix #1425
1 parent e4af731 commit 0f7e28f

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

docs/app/pages/Components/List/examples/ListExpansion.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="full-control">
33
<md-list>
4-
<md-list-item md-expand>
4+
<md-list-item md-expand :md-expanded.sync="expandNews">
55
<md-icon>whatshot</md-icon>
66
<span class="md-list-item-text">News</span>
77

@@ -40,12 +40,19 @@
4040
<span class="md-list-item-text">Shop</span>
4141
</md-list-item>
4242
</md-list>
43+
<md-checkbox v-model="expandNews">Expand News</md-checkbox>
4344
</div>
4445
</template>
4546

4647
<script>
4748
export default {
48-
name: 'ListExpansion'
49+
name: 'ListExpansion',
50+
51+
data () {
52+
return {
53+
expandNews: false
54+
}
55+
}
4956
}
5057
</script>
5158

src/components/MdList/MdListItem/MdListItem.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
createElement(listComponent, {
6666
props,
6767
scopedSlots: resolveScopedSlot(props, children),
68-
staticClass: 'md-list-item-container md-button-clean'
68+
staticClass: 'md-list-item-container md-button-clean',
69+
on: listeners,
6970
}, children.default)
7071
])
7172
}

src/components/MdList/MdListItem/MdListItemExpand.vue

+50-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
expandStyles: {},
2828
showContent: false
2929
}),
30+
props: {
31+
mdExpanded: Boolean
32+
},
3033
computed: {
3134
expandClasses () {
3235
return {
@@ -45,17 +48,56 @@
4548
4649
return size
4750
},
48-
toggleExpand () {
49-
raf(() => {
50-
let fullHeight = 0
51+
fetchStyle () {
52+
return new Promise(resolve => {
53+
raf(() => {
54+
let fullHeight = 0
5155
52-
if (!this.showContent) {
53-
fullHeight = 'auto' // this.getChildrenSize() + 'px'
54-
}
56+
if (!this.showContent) {
57+
fullHeight = 'auto' // this.getChildrenSize() + 'px'
58+
}
5559
56-
this.expandStyles = { height: fullHeight }
57-
this.showContent = !this.showContent
60+
this.expandStyles = { height: fullHeight }
61+
resolve()
62+
})
5863
})
64+
},
65+
async toggleExpand () {
66+
await this.fetchStyle()
67+
this.showContent = !this.showContent
68+
},
69+
async open () {
70+
if (this.showContent) {
71+
return false
72+
}
73+
74+
await this.fetchStyle()
75+
this.showContent = true
76+
},
77+
async close () {
78+
if (!this.showContent) {
79+
return false
80+
}
81+
82+
await this.fetchStyle()
83+
this.showContent = false
84+
}
85+
},
86+
watch: {
87+
mdExpanded () {
88+
if (this.mdExpanded) {
89+
this.open()
90+
} else {
91+
this.close()
92+
}
93+
},
94+
showContent () {
95+
this.$emit('update:mdExpanded', this.showContent)
96+
}
97+
},
98+
mounted () {
99+
if (this.mdExpanded) {
100+
this.open()
59101
}
60102
}
61103
}

0 commit comments

Comments
 (0)