快捷键动态获取parentEle元素
This commit is contained in:
parent
b2ce3ba707
commit
fcc27437e1
|
@ -10,7 +10,7 @@ import Tree from '../../src';
|
|||
|
||||
const x = 6;
|
||||
const y = 5;
|
||||
const z = 1;
|
||||
const z = 2;
|
||||
const gData = [];
|
||||
|
||||
const generateData = (_level, _preKey, _tns) => {
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -11,6 +11,7 @@ import {
|
|||
getCheck,
|
||||
getStrictlyValue,
|
||||
arraysEqual,
|
||||
closest
|
||||
} from './util';
|
||||
import PropTypes from 'prop-types';
|
||||
import { KeyCode } from 'tinper-bee-core';
|
||||
|
@ -425,7 +426,8 @@ onExpand(treeNode,keyType) {
|
|||
//查询的下一个节点不为空的话,则选中
|
||||
if(nextTreeNode){
|
||||
const queryInfo = `a[pos="${nextPos}"]`;
|
||||
const focusEle = e.target.parentElement.parentElement.parentElement.parentElement.querySelector(queryInfo);
|
||||
const parentEle = closest(e.target,".u-tree")
|
||||
const focusEle = parentEle?parentEle.querySelector(queryInfo):null;
|
||||
focusEle && focusEle.focus()
|
||||
this.onSelect(nextTreeNode);
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ class TreeNode extends React.Component {
|
|||
// keyboard event support
|
||||
onKeyDown(e) {
|
||||
this.props.root.onKeyDown(e,this);
|
||||
if(e.keyCode !== KeyCode.TAB){
|
||||
if(e.keyCode == KeyCode.SPACE || e.keyCode == KeyCode.DOWN || e.keyCode == KeyCode.LEFT || e.keyCode == KeyCode.RIGHT ||e.keyCode == KeyCode.UP){
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
|
|
14
src/util.js
14
src/util.js
|
@ -284,3 +284,17 @@ export function arraysEqual(a, b) {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
export function closest(el, selector) {
|
||||
const matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
|
||||
|
||||
while (el) {
|
||||
if (matchesSelector.call(el, selector)) {
|
||||
return el;
|
||||
} else {
|
||||
el = el.parentElement;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
Loading…
Reference in New Issue