diff --git a/build/Tree.js b/build/Tree.js index b5fd679..b0069b6 100644 --- a/build/Tree.js +++ b/build/Tree.js @@ -457,7 +457,8 @@ var Tree = function (_React$Component) { //查询的下一个节点不为空的话,则选中 if (nextTreeNode) { var queryInfo = 'a[pos="' + nextPos + '"]'; - var focusEle = e.target.parentElement.parentElement.parentElement.parentElement.querySelector(queryInfo); + var parentEle = (0, _util.closest)(e.target, ".u-tree"); + var focusEle = parentEle ? parentEle.querySelector(queryInfo) : null; focusEle && focusEle.focus(); this.onSelect(nextTreeNode); } diff --git a/build/TreeNode.js b/build/TreeNode.js index 40af979..81d7e6c 100644 --- a/build/TreeNode.js +++ b/build/TreeNode.js @@ -198,7 +198,7 @@ var TreeNode = function (_React$Component) { TreeNode.prototype.onKeyDown = function onKeyDown(e) { this.props.root.onKeyDown(e, this); - if (e.keyCode !== _tinperBeeCore.KeyCode.TAB) { + if (e.keyCode == _tinperBeeCore.KeyCode.SPACE || e.keyCode == _tinperBeeCore.KeyCode.DOWN || e.keyCode == _tinperBeeCore.KeyCode.LEFT || e.keyCode == _tinperBeeCore.KeyCode.RIGHT || e.keyCode == _tinperBeeCore.KeyCode.UP) { e.preventDefault(); } }; diff --git a/build/util.js b/build/util.js index d26ad97..e75158e 100644 --- a/build/util.js +++ b/build/util.js @@ -12,6 +12,7 @@ exports.handleCheckState = handleCheckState; exports.getCheck = getCheck; exports.getStrictlyValue = getStrictlyValue; exports.arraysEqual = arraysEqual; +exports.closest = closest; var _react = require('react'); @@ -324,4 +325,17 @@ function arraysEqual(a, b) { if (a[i] !== b[i]) return false; } return true; +} + +function closest(el, selector) { + var matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector; + + while (el) { + if (matchesSelector.call(el, selector)) { + return el; + } else { + el = el.parentElement; + } + } + return null; } \ No newline at end of file diff --git a/package.json b/package.json index 1817f4c..4a7e67f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bee-tree", - "version": "1.1.9", + "version": "1.1.10", "description": "Tree ui component for react", "keywords": [ "react",