1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-12-13 14:18:12 +09:00
hotomoe/packages/client/src/scripts/focus.ts
syuilo 0e4a111f81 refactoring
Resolve #7779
2021-11-12 02:02:25 +09:00

28 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);
}
}
}