From 44dfdb3bc2128d07d16e23cfa3b5e37273697f9f Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 29 Jul 2024 10:46:40 +0200 Subject: [PATCH] ActionList: getDirectionNext(): Return list's first/last elem if null is passed as item --- asset/js/widget/ActionList.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/asset/js/widget/ActionList.js b/asset/js/widget/ActionList.js index 17038465..191c5808 100644 --- a/asset/js/widget/ActionList.js +++ b/asset/js/widget/ActionList.js @@ -269,22 +269,14 @@ define(["../notjQuery"], function ($) { let directionalNextItem = this.getDirectionalNext(lastActivatedItem, event.key); if (activeItems.length === 0) { - toActiveItem = pressedArrowDownKey ? firstListItem : lastListItem; + toActiveItem = directionalNextItem; // reset all on manual page refresh this.clearSelection(activeItems); } else if (this.isMultiSelectable && event.shiftKey) { if (activeItems.length === 1) { toActiveItem = directionalNextItem; - } else if (wasAllSelected && ( - (lastActivatedItem !== firstListItem && pressedArrowDownKey) - || (lastActivatedItem !== lastListItem && pressedArrowUpKey) - )) { - if (pressedArrowDownKey) { - toActiveItem = lastActivatedItem === lastListItem ? null : lastListItem; - } else { - toActiveItem = lastActivatedItem === firstListItem ? null : lastListItem; - } - + } else if (wasAllSelected && (lastActivatedItem !== firstListItem && pressedArrowDownKey)) { + toActiveItem = lastActivatedItem === lastListItem ? null : lastListItem; } else if (directionalNextItem && directionalNextItem.classList.contains('active')) { // deactivate last activated by down to up select this.clearSelection([lastActivatedItem]); @@ -327,7 +319,15 @@ define(["../notjQuery"], function ($) { */ getDirectionalNext(item, eventKey) { if (! item) { - return null; + item = eventKey === 'ArrowUp' ? this.list.lastChild : this.list.firstChild; + + if (! item) { + return null; + } + + if (item.hasAttribute(this.removeBrackets(LIST_ITEM_IDENTIFIER))) { + return item; + } } let nextItem = null;