Skip to content

Commit 4bf8d1e

Browse files
authored
fix: 🐛 修复Collapse折叠面板组件内容溢出问题 (#710)
1 parent 3cc1805 commit 4bf8d1e

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

src/uni_modules/wot-design-uni/components/wd-collapse-item/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export type CollapseItemExpose = {
3131
* @returns boolean
3232
*/
3333
getExpanded: () => boolean
34+
/**
35+
* 更新展开状态
36+
* @returns Promise<void>
37+
*/
38+
updateExpand: () => Promise<void>
3439
}
3540

3641
export type CollapseItemInstance = ComponentPublicInstance<CollapseItemProps, CollapseItemExpose>

src/uni_modules/wot-design-uni/components/wd-collapse-item/wd-collapse-item.vue

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,11 @@ const selected = computed(() => {
7474
}
7575
})
7676
77-
watch(
78-
() => selected.value,
79-
() => {
80-
if (!inited.value) {
81-
return
82-
}
83-
updateExpend()
84-
},
85-
{
86-
deep: true,
87-
immediate: true
88-
}
89-
)
90-
9177
onMounted(() => {
92-
updateExpend()
78+
updateExpand()
9379
})
9480
95-
function updateExpend() {
81+
function updateExpand() {
9682
return getRect(`#${collapseId.value}`, false, proxy).then((rect) => {
9783
const { height: rectHeight } = rect
9884
height.value = isDef(rectHeight) ? Number(rectHeight) : ''
@@ -136,24 +122,29 @@ function handleClick() {
136122
}
137123
if (isPromise(response)) {
138124
response.then(() => {
139-
collapse && collapse.toggle(name, !expanded.value)
125+
handleChangeExpand(name)
140126
})
141127
} else {
142-
collapse && collapse.toggle(name, !expanded.value)
128+
handleChangeExpand(name)
143129
}
144130
} else {
145-
collapse && collapse.toggle(name, !expanded.value)
131+
handleChangeExpand(name)
146132
}
147133
} else {
148-
collapse && collapse.toggle(name, !expanded.value)
134+
handleChangeExpand(name)
149135
}
150136
}
151137
152138
function getExpanded() {
153139
return expanded.value
154140
}
155141
156-
defineExpose<CollapseItemExpose>({ getExpanded })
142+
function handleChangeExpand(name: string) {
143+
updateExpand()
144+
collapse && collapse.toggle(name, !expanded.value)
145+
}
146+
147+
defineExpose<CollapseItemExpose>({ getExpanded, updateExpand })
157148
</script>
158149

159150
<style lang="scss" scoped>

src/uni_modules/wot-design-uni/components/wd-collapse/wd-collapse.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const toggleAll = (options: boolean | CollapseToggleAllOptions = {}) => {
126126
names.push(item.name || index)
127127
}
128128
} else {
129+
item.$.exposed!.updateExpand()
129130
if (isDef(expanded) ? expanded : !item.$.exposed!.getExpanded()) {
130131
names.push(item.name || index)
131132
}

0 commit comments

Comments
 (0)