Skip to content

Commit 23e8794

Browse files
committed
fix ant-design/ant-design#11492. Pos isParent is meanless in the tree drag check
1 parent 35307ff commit 23e8794

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
],
6262
"transform": {
6363
"\\.jsx?$": "./node_modules/rc-tools/scripts/jestPreprocessor.js"
64-
}
64+
},
65+
"testURL": "http://localhost"
6566
},
6667
"devDependencies": {
6768
"cross-env": "^5.2.0",

src/util.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,8 @@ export function getDragNodesKeys(treeNodes, node) {
123123
const { eventKey, pos } = node.props;
124124
const dragNodesKeys = [];
125125

126-
traverseTreeNodes(treeNodes, ({ pos: nodePos, key }) => {
127-
if (isParent(pos, nodePos)) {
128-
dragNodesKeys.push(key);
129-
}
126+
traverseTreeNodes(treeNodes, ({ key }) => {
127+
dragNodesKeys.push(key);
130128
});
131129
dragNodesKeys.push(eventKey || pos);
132130
return dragNodesKeys;

tests/util.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable no-undef, react/no-multi-comp, react/no-unused-state, react/prop-types, no-return-assign */
22
import React from 'react';
3+
import { mount } from 'enzyme';
34
import Tree from '../src/Tree';
45
import TreeNode from '../src/TreeNode';
56
import {
67
convertDataToTree, convertTreeToEntities,
78
conductCheck, conductExpandParent,
9+
getDragNodesKeys,
810
} from '../src/util';
911
import { convertTreeToData } from './util';
1012

@@ -193,4 +195,25 @@ describe('Util', () => {
193195
const keys = conductExpandParent(['good'], keyEntities);
194196
expect(keys.sort()).toEqual(['bamboo', 'is', 'good'].sort());
195197
});
198+
199+
it('getDragNodesKeys', () => {
200+
const tree = mount(
201+
<Tree defaultExpandAll>
202+
<TreeNode key="000">
203+
<TreeNode key="111">
204+
<TreeNode key="222" />
205+
<TreeNode key="333" />
206+
</TreeNode>
207+
</TreeNode>
208+
</Tree>
209+
);
210+
211+
const treeNode0 = tree.find(TreeNode).at(0).instance();
212+
const keys0 = getDragNodesKeys(treeNode0.props.children, treeNode0);
213+
expect(keys0.sort()).toEqual(['000', '111', '222', '333'].sort());
214+
215+
const treeNode1 = tree.find(TreeNode).at(1).instance();
216+
const keys1 = getDragNodesKeys(treeNode1.props.children, treeNode1);
217+
expect(keys1.sort()).toEqual(['111', '222', '333'].sort());
218+
});
196219
});

0 commit comments

Comments
 (0)