mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-16 06:57:36 -07:00
14148f6c4a
Resolve #7779
27 lines
645 B
TypeScript
27 lines
645 B
TypeScript
export function focusPrev(el: Element | null, self = false, scroll = true) {
|
|
if (el == null) return;
|
|
if (!self) el = el.previousElementSibling;
|
|
if (el) {
|
|
if (el.hasAttribute('tabindex')) {
|
|
(el as HTMLElement).focus({
|
|
preventScroll: !scroll
|
|
});
|
|
} else {
|
|
focusPrev(el.previousElementSibling, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
export function focusNext(el: Element | null, self = false, scroll = true) {
|
|
if (el == null) return;
|
|
if (!self) el = el.nextElementSibling;
|
|
if (el) {
|
|
if (el.hasAttribute('tabindex')) {
|
|
(el as HTMLElement).focus({
|
|
preventScroll: !scroll
|
|
});
|
|
} else {
|
|
focusPrev(el.nextElementSibling, true);
|
|
}
|
|
}
|
|
}
|