Skip to content

Commit

Permalink
fix(tree): throw exception when onLoad callback does not add children (
Browse files Browse the repository at this point in the history
…#786)

* fix(tree): throw exception when onLoad callback does not add children

* refactor(tree): not expand when node has no children

* refactor(tree): handle no-children expand error

* Update src/tree/src/Tree.tsx

* Update src/tree/src/TreeNode.tsx

Co-authored-by: 07akioni <[email protected]>
  • Loading branch information
bljessica and 07akioni authored Aug 25, 2021
1 parent 673a593 commit ed73168
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- Fix `n-image` not initializing `rorate` after switching images, closes [#921](https://github.com/TuSimple/naive-ui/issues/921).
- Fix `n-data-table`'s loading is not centered, closes [#929](https://github.com/TuSimple/naive-ui/issues/929).
- Fix `n-tree` throws an exception when onLoad callback does not add children, closes [#772](https://github.com/TuSimple/naive-ui/issues/772).
- Fix `n-input` will show placeholder and 0 simultaneously while passing `value=ref(0)` in n-input, closes [#914](https://github.com/TuSimple/naive-ui/issues/914).

## 2.16.5 (2021-08-20)
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

- 修复 `n-image` 切换图像后没有初始化 `rorate` 的问题,关闭 [#921](https://github.com/TuSimple/naive-ui/issues/921)
- 修复 `n-data-table`的 loading 不在中间,关闭 [#929](https://github.com/TuSimple/naive-ui/issues/929)
- 修复 `n-tree` 当 onLoad 回调没有添加 children 时抛出错误,关闭 [#772](https://github.com/TuSimple/naive-ui/issues/772)
- 修复 `n-input` 当传递 `value=ref(0)` 时,同时显示 0 和占位符问题,关闭 [#914](https://github.com/TuSimple/naive-ui/issues/914)

## 2.16.5 (2021-08-20)
Expand Down
4 changes: 4 additions & 0 deletions src/tree/src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ export default defineComponent({
expandedKeysAfterChange.splice(index, 1)
doUpdateExpandedKeys(expandedKeysAfterChange)
} else {
const nodeToBeExpanded = displayTreeMateRef.value!.getNode(key)
if (!nodeToBeExpanded?.isLeaf) {
return
}
doUpdateExpandedKeys(mergedExpandedKeys.concat(key))
}
}
Expand Down
19 changes: 12 additions & 7 deletions src/tree/src/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ const TreeNode = defineComponent({
onLoadRef: { value: onLoad }
} = NTree
if (onLoad) {
void onLoad(tmNode.rawNode).then(() => {
NTree.loadingKeysRef.value.splice(
NTree.loadingKeysRef.value.findIndex((key) => key === tmNode.key),
1
)
NTree.handleSwitcherClick(tmNode)
})
void onLoad(tmNode.rawNode)
.then(() => {
NTree.handleSwitcherClick(tmNode)
})
.finally(() => {
NTree.loadingKeysRef.value.splice(
NTree.loadingKeysRef.value.findIndex(
(key) => key === tmNode.key
),
1
)
})
}
} else {
NTree.handleSwitcherClick(tmNode)
Expand Down

0 comments on commit ed73168

Please sign in to comment.