From 234a983e879773770c38cf3df536f528c181ed46 Mon Sep 17 00:00:00 2001 From: fennghuang <89014758+fennghuang@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:37:00 +0800 Subject: [PATCH] fix(collapse): fix getBoundingClientRect (#1140) --- src/collapse/collapse-panel.vue | 41 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/collapse/collapse-panel.vue b/src/collapse/collapse-panel.vue index 68bf8d35a..a1a87a70a 100644 --- a/src/collapse/collapse-panel.vue +++ b/src/collapse/collapse-panel.vue @@ -93,30 +93,39 @@ export default defineComponent({ const headRef = ref(); const wrapperHeight = ref(''); const updatePanelState = () => { - if (!wrapRef.value) { - return; - } - const { height: headHeight } = headRef.value.getBoundingClientRect(); - if (!isActive.value) { - wrapperHeight.value = `${headHeight}px`; - return; - } - const { height: bodyHeight } = bodyRef.value.getBoundingClientRect(); - const height = headHeight + bodyHeight; - wrapperHeight.value = `${height}px`; - }; - - watch(isActive, () => { nextTick(() => { - updatePanelState(); + if (!wrapRef.value) { + return; + } + const { height: headHeight } = headRef.value.getBoundingClientRect(); + if (!isActive.value) { + wrapperHeight.value = `${headHeight}px`; + return; + } + const { height: bodyHeight } = bodyRef.value.getBoundingClientRect(); + const height = headHeight + bodyHeight; + wrapperHeight.value = `${height}px`; }); + }; + + watch( + isActive, + () => { + nextTick(() => updatePanelState()); + }, + { + immediate: true, + }, + ); + + watch(panelContent, () => { + nextTick(() => updatePanelState()); }); onMounted(() => { if (parent?.defaultExpandAll) { updatePanelValue(); } - updatePanelState(); }); return {