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

Function onFocus

packages/react-aria/src/autocomplete/useAutocomplete.ts:511–527  ·  view source on GitHub ↗
(e: ReactFocusEvent)

Source from the content-addressed store, hash-verified

509 };
510
511 let onFocus = (e: ReactFocusEvent) => {
512 if (!e.isTrusted) {
513 return;
514 }
515
516 let curFocusedNode = queuedActiveDescendant.current
517 ? document.getElementById(queuedActiveDescendant.current)
518 : null;
519 if (curFocusedNode) {
520 let target = getEventTarget(e);
521 queueMicrotask(() => {
522 // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item
523 dispatchVirtualBlur(target, collectionRef.current);
524 dispatchVirtualFocus(collectionRef.current!, target);
525 });
526 }
527 };
528
529 // Clicking back into the input can happen after focus moved elsewhere in the dialog, while
530 // virtual focus is still on an option. Clear virtual focus on pointer down so mouse

Callers

nothing calls this directly

Calls 3

getEventTargetFunction · 0.90
dispatchVirtualBlurFunction · 0.90
dispatchVirtualFocusFunction · 0.90

Tested by

no test coverage detected