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