Skip to content

Commit

Permalink
ActionList: Use bool isArrowUp param instead event.key
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 30, 2024
1 parent 0754767 commit 19f322b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions asset/js/widget/ActionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ define(["../notjQuery"], function ($) {
lastActivatedItem = activeItems[activeItems.length - 1];
}

let directionalNextItem = this.getDirectionalNext(lastActivatedItem, event.key);
let directionalNextItem = this.getDirectionalNext(lastActivatedItem, pressedArrowUpKey);

if (activeItems.length === 0) {
toActiveItem = directionalNextItem;
Expand All @@ -279,12 +279,12 @@ define(["../notjQuery"], function ($) {
// deactivate last activated by down to up select
this.clearSelection([lastActivatedItem]);
if (wasAllSelected) {
this.scrollItemIntoView(lastActivatedItem, event.key);
this.scrollItemIntoView(lastActivatedItem, pressedArrowUpKey);
}

toActiveItem = directionalNextItem;
} else {
[toActiveItem, markAsLastActive] = this.findToActiveItem(lastActivatedItem, event.key);
[toActiveItem, markAsLastActive] = this.findToActiveItem(lastActivatedItem, pressedArrowUpKey);
}
} else {
toActiveItem = directionalNextItem;
Expand All @@ -302,7 +302,7 @@ define(["../notjQuery"], function ($) {
this.setLastActivatedItemUrl(
markAsLastActive ? markAsLastActive.dataset.icingaDetailFilter : toActiveItem.dataset.icingaDetailFilter
);
this.scrollItemIntoView(toActiveItem, event.key);
this.scrollItemIntoView(toActiveItem, pressedArrowUpKey);
this.addSelectionCountToFooter();
this.loadDetailUrl();
}
Expand All @@ -311,13 +311,13 @@ define(["../notjQuery"], function ($) {
* Get the next list item according to the pressed key (`ArrowUp` or `ArrowDown`)
*
* @param item The list item from which we want the next item
* @param eventKey Pressed key (`ArrowUp` or `ArrowDown`)
* @param isArrowUp Whether the arrow up key is pressed, if not, arrow down key is assumed
*
* @returns {Element|null} Returns the next selectable list item or null if none found (list ends)
*/
getDirectionalNext(item, eventKey) {
getDirectionalNext(item, isArrowUp) {
if (! item) {
item = eventKey === 'ArrowUp' ? this.list.lastChild : this.list.firstChild;
item = isArrowUp ? this.list.lastChild : this.list.firstChild;

if (! item) {
return null;
Expand All @@ -331,7 +331,7 @@ define(["../notjQuery"], function ($) {
let nextItem = null;

do {
nextItem = eventKey === 'ArrowUp' ? item.previousElementSibling : item.nextElementSibling;
nextItem = isArrowUp ? item.previousElementSibling : item.nextElementSibling;
item = nextItem;
} while (nextItem && ! nextItem.hasAttribute(this.removeBrackets(LIST_ITEM_IDENTIFIER)))

Expand All @@ -342,28 +342,28 @@ define(["../notjQuery"], function ($) {
* Find the list item that should be activated next
*
* @param lastActivatedItem
* @param eventKey Pressed key (`ArrowUp` or `ArrowDown`)
* @param isArrowUp Whether the arrow up key is pressed, if not, arrow down key is assumed
*
* @returns {Element[]}
*/
findToActiveItem(lastActivatedItem, eventKey) {
findToActiveItem(lastActivatedItem, isArrowUp) {
let toActiveItem;
let markAsLastActive;

do {
toActiveItem = this.getDirectionalNext(lastActivatedItem, eventKey);
toActiveItem = this.getDirectionalNext(lastActivatedItem, isArrowUp);
lastActivatedItem = toActiveItem;
} while (toActiveItem && toActiveItem.classList.contains('active'))

markAsLastActive = toActiveItem;
// if the next/previous sibling element is already active,
// mark the last/first active element in list as last active
while (markAsLastActive && this.getDirectionalNext(markAsLastActive, eventKey)) {
if (! this.getDirectionalNext(markAsLastActive, eventKey).classList.contains('active')) {
while (markAsLastActive && this.getDirectionalNext(markAsLastActive, isArrowUp)) {
if (! this.getDirectionalNext(markAsLastActive, isArrowUp).classList.contains('active')) {
break;
}

markAsLastActive = this.getDirectionalNext(markAsLastActive, eventKey);
markAsLastActive = this.getDirectionalNext(markAsLastActive, isArrowUp);
}

return [toActiveItem, markAsLastActive];
Expand Down Expand Up @@ -403,11 +403,11 @@ define(["../notjQuery"], function ($) {
* Scroll the given item into view
*
* @param item Item to scroll into view
* @param pressedKey Pressed key (`ArrowUp` or `ArrowDown`)
* @param isArrowUp Whether the arrow up key is pressed, if not, arrow down key is assumed
*/
scrollItemIntoView(item, pressedKey) {
scrollItemIntoView(item, isArrowUp) {
item.scrollIntoView({block: "nearest"});
let directionalNext = this.getDirectionalNext(item, pressedKey);
let directionalNext = this.getDirectionalNext(item, isArrowUp);

if (directionalNext) {
directionalNext.scrollIntoView({block: "nearest"});
Expand Down

0 comments on commit 19f322b

Please sign in to comment.