fix: 🐛 修复Collapse折叠面板组件内容溢出问题 (#710)

This commit is contained in:
Gahotx 2024-11-21 19:11:54 +08:00 committed by GitHub
parent 3cc18058ae
commit 4bf8d1e300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 21 deletions

View File

@ -31,6 +31,11 @@ export type CollapseItemExpose = {
* @returns boolean
*/
getExpanded: () => boolean
/**
*
* @returns Promise<void>
*/
updateExpand: () => Promise<void>
}
export type CollapseItemInstance = ComponentPublicInstance<CollapseItemProps, CollapseItemExpose>

View File

@ -74,25 +74,11 @@ const selected = computed(() => {
}
})
watch(
() => selected.value,
() => {
if (!inited.value) {
return
}
updateExpend()
},
{
deep: true,
immediate: true
}
)
onMounted(() => {
updateExpend()
updateExpand()
})
function updateExpend() {
function updateExpand() {
return getRect(`#${collapseId.value}`, false, proxy).then((rect) => {
const { height: rectHeight } = rect
height.value = isDef(rectHeight) ? Number(rectHeight) : ''
@ -136,16 +122,16 @@ function handleClick() {
}
if (isPromise(response)) {
response.then(() => {
collapse && collapse.toggle(name, !expanded.value)
handleChangeExpand(name)
})
} else {
collapse && collapse.toggle(name, !expanded.value)
handleChangeExpand(name)
}
} else {
collapse && collapse.toggle(name, !expanded.value)
handleChangeExpand(name)
}
} else {
collapse && collapse.toggle(name, !expanded.value)
handleChangeExpand(name)
}
}
@ -153,7 +139,12 @@ function getExpanded() {
return expanded.value
}
defineExpose<CollapseItemExpose>({ getExpanded })
function handleChangeExpand(name: string) {
updateExpand()
collapse && collapse.toggle(name, !expanded.value)
}
defineExpose<CollapseItemExpose>({ getExpanded, updateExpand })
</script>
<style lang="scss" scoped>

View File

@ -126,6 +126,7 @@ const toggleAll = (options: boolean | CollapseToggleAllOptions = {}) => {
names.push(item.name || index)
}
} else {
item.$.exposed!.updateExpand()
if (isDef(expanded) ? expanded : !item.$.exposed!.getExpanded()) {
names.push(item.name || index)
}