mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
use modulus in loop
This commit is contained in:
parent
6e06f9f5aa
commit
bbc0ed6824
@ -26,35 +26,14 @@ export const focusNext = (selector: (element: HTMLElement | SVGElement) => boole
|
|||||||
focusElements[0].focus();
|
focusElements[0].focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (forwardDirection) {
|
const totalElements = focusElements.length;
|
||||||
let i = index + 1;
|
let i = index;
|
||||||
while (i !== index) {
|
do {
|
||||||
const next = focusElements[i];
|
i = (i + (forwardDirection ? 1 : -1) + totalElements) % totalElements;
|
||||||
if (!isTabbable(next) || !selector(next)) {
|
const next = focusElements[i];
|
||||||
if (i === focusElements.length - 1) {
|
if (isTabbable(next) && selector(next)) {
|
||||||
i = 0;
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
next.focus();
|
next.focus();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} while (i !== index);
|
||||||
let i = index - 1;
|
|
||||||
while (i !== index && i >= 0) {
|
|
||||||
const next = focusElements[i];
|
|
||||||
if (!isTabbable(next) || !selector(next)) {
|
|
||||||
if (i === 0) {
|
|
||||||
i = focusElements.length - 1;
|
|
||||||
} else {
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
next.focus();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user