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

Function onBlur

packages/react-aria/src/focus/FocusScope.tsx:422–453  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420 };
421
422 let onBlur: EventListener = e => {
423 // Firefox doesn't shift focus back to the Dialog properly without this
424 if (raf.current) {
425 cancelAnimationFrame(raf.current);
426 }
427 raf.current = requestAnimationFrame(() => {
428 // Patches infinite focus coersion loop for Android Talkback where the user isn't able to move the virtual cursor
429 // if within a containing focus scope. Bug filed against Chrome: https://issuetracker.google.com/issues/384844019.
430 // Note that this means focus can leave focus containing modals due to this, but it is isolated to Chrome Talkback.
431 let modality = getInteractionModality();
432 let shouldSkipFocusRestore =
433 (modality === 'virtual' || modality === null) && isAndroid() && isChrome();
434
435 // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
436 let activeElement = getActiveElement(ownerDocument);
437 if (
438 !shouldSkipFocusRestore &&
439 activeElement &&
440 shouldContainFocus(scopeRef) &&
441 !isElementInChildScope(activeElement, scopeRef)
442 ) {
443 activeScope = scopeRef;
444 let target = getEventTarget(e) as FocusableElement;
445 if (target && target.isConnected) {
446 focusedNode.current = target;
447 focusElement(focusedNode.current);
448 } else if (activeScope.current) {
449 focusFirstInScope(activeScope.current);
450 }
451 }
452 });
453 };
454
455 ownerDocument.addEventListener('keydown', onKeyDown, false);
456 ownerDocument.addEventListener('focusin', onFocus, false);

Callers

nothing calls this directly

Calls 7

getInteractionModalityFunction · 0.90
getActiveElementFunction · 0.90
getEventTargetFunction · 0.90
shouldContainFocusFunction · 0.85
isElementInChildScopeFunction · 0.85
focusElementFunction · 0.85
focusFirstInScopeFunction · 0.85

Tested by

no test coverage detected