Skip to content

fix: loadData using key navigation #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/examples/dynamic.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import Tree from 'rc-tree';
function generateTreeNodes(treeNode) {
const arr = [];
const key = treeNode.props.eventKey;
if (key === '0-1-0') {
return [];
}
for (let i = 0; i < 3; i += 1) {
arr.push({ title: `leaf ${key}-${i}`, key: `${key}-${i}` });
}
Expand Down
7 changes: 5 additions & 2 deletions src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ class Tree<TreeDataType extends DataNode | BasicDataNode = DataNode> extends Rea

onKeyDown: React.KeyboardEventHandler<HTMLDivElement> = event => {
const { activeKey, expandedKeys, checkedKeys, fieldNames } = this.state;
const { onKeyDown, checkable, selectable } = this.props;
const { onKeyDown, checkable, selectable, loadData } = this.props;

// >>>>>>>>>> Direction
switch (event.which) {
Expand All @@ -1239,7 +1239,10 @@ class Tree<TreeDataType extends DataNode | BasicDataNode = DataNode> extends Rea
const treeNodeRequiredProps = this.getTreeNodeRequiredProps();

const expandable =
activeItem.data.isLeaf === false || !!(activeItem.data[fieldNames.children] || []).length;
activeItem.data.isLeaf !== true &&
((!!loadData && !activeItem.data[fieldNames.children]) || // load data on expand
!!(activeItem.data[fieldNames.children] || []).length);

const eventNode = convertNodePropsToEventData<TreeDataType>({
...getTreeNodeProps(activeKey, treeNodeRequiredProps),
data: activeItem.data,
Expand Down