mirror of https://github.com/node-red/node-red.git
Merge pull request #5431 from piotrbogun/5430/TreeList/filtered-arrow-navigation
TreeList: Fix arrow navigation through filtered TreeListpull/5284/merge
commit
abe6593202
|
|
@ -172,8 +172,9 @@
|
|||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
if (focussed.children && Array.isArray(focussed.children) && focussed.children.length > 0 && focussed.treeList.container.hasClass("expanded")) {
|
||||
target = focussed.children[0];
|
||||
} else {
|
||||
target = that._getFirstVisibleChild(focussed);
|
||||
}
|
||||
if (!target) {
|
||||
target = that._getNextSibling(focussed);
|
||||
while (!target && focussed.parent) {
|
||||
focussed = focussed.parent;
|
||||
|
|
@ -228,12 +229,31 @@
|
|||
this.data(this.options.data);
|
||||
}
|
||||
},
|
||||
_isItemVisible: function(item) {
|
||||
return item.treeList && item.treeList.container && item.treeList.container.parent().css('display') !== 'none';
|
||||
},
|
||||
_getFirstVisibleChild: function(item) {
|
||||
if (!item.children || !Array.isArray(item.children)) {
|
||||
return null;
|
||||
}
|
||||
for (var i = 0; i < item.children.length; i++) {
|
||||
if (this._isItemVisible(item.children[i])) {
|
||||
return item.children[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
_getLastDescendant: function(item) {
|
||||
// Gets the last visible descendant of the item
|
||||
if (!item.children || !item.treeList.container.hasClass("expanded") || item.children.length === 0) {
|
||||
return item;
|
||||
}
|
||||
return this._getLastDescendant(item.children[item.children.length-1]);
|
||||
for (var i = item.children.length - 1; i >= 0; i--) {
|
||||
if (this._isItemVisible(item.children[i])) {
|
||||
return this._getLastDescendant(item.children[i]);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
},
|
||||
_getPreviousSibling: function(item) {
|
||||
var candidates;
|
||||
|
|
@ -243,11 +263,12 @@
|
|||
candidates = item.parent.children;
|
||||
}
|
||||
var index = candidates.indexOf(item);
|
||||
if (index === 0) {
|
||||
return null;
|
||||
} else {
|
||||
return candidates[index-1];
|
||||
for (var i = index - 1; i >= 0; i--) {
|
||||
if (this._isItemVisible(candidates[i])) {
|
||||
return candidates[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
_getNextSibling: function(item) {
|
||||
var candidates;
|
||||
|
|
@ -257,11 +278,12 @@
|
|||
candidates = item.parent.children;
|
||||
}
|
||||
var index = candidates.indexOf(item);
|
||||
if (index === candidates.length - 1) {
|
||||
return null;
|
||||
} else {
|
||||
return candidates[index+1];
|
||||
for (var i = index + 1; i < candidates.length; i++) {
|
||||
if (this._isItemVisible(candidates[i])) {
|
||||
return candidates[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
_addChildren: function(container,parent,children,depth,onCompleteChildren) {
|
||||
var that = this;
|
||||
|
|
|
|||
Loading…
Reference in New Issue