Skip to content

Commit

Permalink
fix(BaseTreeSelect): update tree when children props updates
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Jan 6, 2024
1 parent a126335 commit 426c310
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions components/form/BaseTreeSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ const openMap = ref<Record<number, boolean>>(getDefaultOpenMap(props.children))
const _children = computed<TreeViewItemNode[] | undefined>(
() => subtreeState.value?.tree,
)
watch(() => props.children, initChildren)
watch(() => props.children, initChildren, {
immediate: true,
})
defineExpose({
/**
Expand Down Expand Up @@ -246,11 +248,19 @@ defineExpose({
unselectAllChildren,
})
await initChildren()
// api
async function initChildren() {
// clear the treeMap if the children prop change
treeState.treeMap = new WeakMap()
if (props.children) {
treeState.treeMap.set(props.children, {
tree: [],
pending: false,
loaded: false,
})
}
await loadTree(props.children)
openMap.value = getDefaultOpenMap(props.children)
}
Expand All @@ -268,14 +278,6 @@ function useTreeState() {
provide(treeSymbol, treeState)
}
if (props.children && !treeState.treeMap.has(props.children)) {
treeState.treeMap.set(props.children, {
tree: [],
pending: false,
loaded: false,
})
}
return treeState
}
Expand Down

0 comments on commit 426c310

Please sign in to comment.