MCPcopy Create free account
hub / github.com/adobe/react-spectrum / moveVirtualFocus

Function moveVirtualFocus

packages/react-aria/src/focus/virtualFocus.ts:4–14  ·  view source on GitHub ↗
(to: Element | null)

Source from the content-addressed store, hash-verified

2import {getOwnerDocument} from '../utils/domHelpers';
3
4export function moveVirtualFocus(to: Element | null): void {
5 let from = getVirtuallyFocusedElement(getOwnerDocument(to));
6 if (from !== to) {
7 if (from) {
8 dispatchVirtualBlur(from, to);
9 }
10 if (to) {
11 dispatchVirtualFocus(to, from);
12 }
13 }
14}
15
16export function dispatchVirtualBlur(from: Element, to: Element | null): void {
17 from.dispatchEvent(new FocusEvent('blur', {relatedTarget: to}));

Callers 3

useSelectableItemFunction · 0.90
useSelectableCollectionFunction · 0.90
useAutocompleteFunction · 0.90

Calls 4

getOwnerDocumentFunction · 0.90
dispatchVirtualBlurFunction · 0.85
dispatchVirtualFocusFunction · 0.85

Tested by

no test coverage detected