fix(动态获取parentEle):

This commit is contained in:
wanghaoo 2018-12-26 10:10:15 +08:00
parent fcc27437e1
commit 8b0bea5ed7
4 changed files with 18 additions and 3 deletions

View File

@ -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);
}

View File

@ -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();
}
};

View File

@ -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;
}

View File

@ -1,6 +1,6 @@
{
"name": "bee-tree",
"version": "1.1.9",
"version": "1.1.10",
"description": "Tree ui component for react",
"keywords": [
"react",