Files
NapCatQQ/.pnpm-store/v3/files/e9/7da2e1cf4c26595eb72eba70ccfd84f63e05924413bbd1076fbadd38696c3e9f2671d1fa4ef60faba4b56bd3051c0808b9d03630ea4c31ae31c582dee522a5
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

34 lines
1.1 KiB
Plaintext

import {getActiveElement, getOwnerDocument} from '@react-aria/utils';
export function moveVirtualFocus(to: Element | null): void {
let from = getVirtuallyFocusedElement(getOwnerDocument(to));
if (from !== to) {
if (from) {
dispatchVirtualBlur(from, to);
}
if (to) {
dispatchVirtualFocus(to, from);
}
}
}
export function dispatchVirtualBlur(from: Element, to: Element | null): void {
from.dispatchEvent(new FocusEvent('blur', {relatedTarget: to}));
from.dispatchEvent(new FocusEvent('focusout', {bubbles: true, relatedTarget: to}));
}
export function dispatchVirtualFocus(to: Element, from: Element | null): void {
to.dispatchEvent(new FocusEvent('focus', {relatedTarget: from}));
to.dispatchEvent(new FocusEvent('focusin', {bubbles: true, relatedTarget: from}));
}
export function getVirtuallyFocusedElement(document: Document): Element | null {
let activeElement = getActiveElement(document);
let activeDescendant = activeElement?.getAttribute('aria-activedescendant');
if (activeDescendant) {
return document.getElementById(activeDescendant) || activeElement;
}
return activeElement;
}