| 394 | }; |
| 395 | |
| 396 | let onFocus: EventListener = e => { |
| 397 | // If focusing an element in a child scope of the currently active scope, the child becomes active. |
| 398 | // Moving out of the active scope to an ancestor is not allowed. |
| 399 | if ( |
| 400 | (!activeScope || isAncestorScope(activeScope, scopeRef)) && |
| 401 | isElementInScope(getEventTarget(e) as Element, scopeRef.current) |
| 402 | ) { |
| 403 | activeScope = scopeRef; |
| 404 | focusedNode.current = getEventTarget(e) as FocusableElement; |
| 405 | } else if ( |
| 406 | shouldContainFocus(scopeRef) && |
| 407 | !isElementInChildScope(getEventTarget(e) as Element, scopeRef) |
| 408 | ) { |
| 409 | // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar), |
| 410 | // restore focus to the previously focused node or the first tabbable element in the active scope. |
| 411 | if (focusedNode.current) { |
| 412 | focusedNode.current.focus(); |
| 413 | } else if (activeScope && activeScope.current) { |
| 414 | focusFirstInScope(activeScope.current); |
| 415 | } |
| 416 | } else if (shouldContainFocus(scopeRef)) { |
| 417 | focusedNode.current = getEventTarget(e) as FocusableElement; |
| 418 | } |
| 419 | }; |
| 420 | |
| 421 | let onBlur: EventListener = e => { |
| 422 | // Firefox doesn't shift focus back to the Dialog properly without this |
nothing calls this directly
no test coverage detected