| 368 | |
| 369 | // Handle the Tab key to contain focus within the scope |
| 370 | let onKeyDown = e => { |
| 371 | if ( |
| 372 | e.key !== 'Tab' || |
| 373 | e.altKey || |
| 374 | e.ctrlKey || |
| 375 | e.metaKey || |
| 376 | !shouldContainFocus(scopeRef) || |
| 377 | e.isComposing |
| 378 | ) { |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | let focusedElement = getActiveElement(ownerDocument); |
| 383 | let scope = scopeRef.current; |
| 384 | if (!scope || !isElementInScope(focusedElement, scope)) { |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | let scopeRoot = getScopeRoot(scope); |
| 389 | let walker = getFocusableTreeWalker(scopeRoot, {tabbable: true}, scope); |
| 390 | if (!focusedElement) { |
| 391 | return; |
| 392 | } |
| 393 | walker.currentNode = focusedElement; |
| 394 | let nextElement = ( |
| 395 | e.shiftKey ? walker.previousNode() : walker.nextNode() |
| 396 | ) as FocusableElement; |
| 397 | if (!nextElement) { |
| 398 | walker.currentNode = e.shiftKey |
| 399 | ? scope[scope.length - 1].nextElementSibling! |
| 400 | : scope[0].previousElementSibling!; |
| 401 | nextElement = (e.shiftKey ? walker.previousNode() : walker.nextNode()) as FocusableElement; |
| 402 | } |
| 403 | |
| 404 | e.preventDefault(); |
| 405 | if (nextElement) { |
| 406 | focusElement(nextElement, true); |
| 407 | if (nextElement instanceof getOwnerWindow(nextElement).HTMLInputElement) { |
| 408 | nextElement.select(); |
| 409 | } |
| 410 | } |
| 411 | }; |
| 412 | |
| 413 | let onFocus: EventListener = e => { |
| 414 | // If focusing an element in a child scope of the currently active scope, the child becomes active. |
nothing calls this directly
no test coverage detected