Skip to content

Commit

Permalink
fix(collapse): fix getBoundingClientRect (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
fennghuang authored Oct 25, 2023
1 parent 8ba5adf commit 234a983
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/collapse/collapse-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 234a983

Please sign in to comment.