diff --git a/.eslintrc.js b/.eslintrc.js index ed6a5e14..30c5f197 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,5 +8,6 @@ module.exports = { 'react/require-default-props': 0, 'jsx-a11y/label-has-for': 0, 'jsx-a11y/label-has-associated-control': 0, + 'react/sort-comp': 0, }, }; \ No newline at end of file diff --git a/package.json b/package.json index 8f551520..f605c54e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-tree", - "version": "2.1.1", + "version": "2.1.4", "description": "tree ui component for react", "keywords": [ "react", @@ -12,6 +12,7 @@ "assets/*.css", "assets/*.png", "assets/*.gif", + "assets/*.less", "dist", "es", "lib" @@ -31,8 +32,8 @@ "scripts": { "start": "cross-env NODE_ENV=development father doc dev --storybook", "build": "father doc build --storybook", - "compile": "father build", - "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish", + "compile": "father build && lessc assets/index.less assets/index.css", + "prepublishOnly": "npm run compile && np --no-cleanup --yolo --no-publish --any-branch", "lint": "eslint src/ examples/ --ext .tsx,.ts,.jsx,.js", "test": "father test", "now-build": "npm run build" @@ -51,6 +52,7 @@ "enzyme-adapter-react-16": "^1.1.1", "enzyme-to-json": "^3.0.0", "father": "^2.13.2", + "less": "^3.10.3", "np": "^5.0.3", "rc-dialog": "^7.3.1", "rc-tools": "^9.x", diff --git a/src/Tree.tsx b/src/Tree.tsx index e919b7f1..d1ff05b5 100644 --- a/src/Tree.tsx +++ b/src/Tree.tsx @@ -342,11 +342,11 @@ class Tree extends React.Component { * But let's just keep it to avoid event trigger logic change. */ onNodeDragEnter = (event, node) => { - const { expandedKeys } = this.state; + const { expandedKeys, dragNodesKeys } = this.state; const { onDragEnter } = this.props; const { pos, eventKey } = node.props; - if (!this.dragNode) return; + if (!this.dragNode || dragNodesKeys.indexOf(eventKey) !== -1) return; const dropPosition = calcDropPosition(event, node); @@ -394,9 +394,14 @@ class Tree extends React.Component { }; onNodeDragOver = (event, node) => { + const { dragNodesKeys } = this.state; const { onDragOver } = this.props; const { eventKey } = node.props; + if (dragNodesKeys.indexOf(eventKey) !== -1) { + return; + } + // Update drag position if (this.dragNode && eventKey === this.state.dragOverNodeKey) { const dropPosition = calcDropPosition(event, node); diff --git a/src/util.tsx b/src/util.tsx index 47a3e325..5ef6b962 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -91,7 +91,7 @@ export function traverseTreeNodes( // Process children node Children.forEach(childList, (subNode, subIndex) => { - processNode(subNode, subIndex, { node, pos }); + processNode(subNode as NodeElement, subIndex, { node, pos }); }); } @@ -429,7 +429,7 @@ export function conductExpandParent(keyList: Key[], keyEntities: Record { it('update to expand parent node with autoExpandParent', () => { const wrapper = mount( - + @@ -129,6 +129,20 @@ describe('Tree Basic', () => { expect(childSwitcher.is(OPEN_CLASSNAME)).toBe(true); }); + it('skip only if disabled with autoExpandParent', () => { + const wrapper = mount( + + + + + + + , + ); + + expect(wrapper.state().expandedKeys.sort()).toEqual(['0-0-0', '0-0-0-0']); + }); + it('fires expand event', () => { const handleExpand = jest.fn(); const wrapper = mount(