(scope: Element[], tabbable = true)
| 539 | } |
| 540 | |
| 541 | function getFirstInScope(scope: Element[], tabbable = true) { |
| 542 | let sentinel = scope[0].previousElementSibling!; |
| 543 | let scopeRoot = getScopeRoot(scope); |
| 544 | let walker = getFocusableTreeWalker(scopeRoot, {tabbable}, scope); |
| 545 | walker.currentNode = sentinel; |
| 546 | let nextNode = walker.nextNode(); |
| 547 | |
| 548 | // If the scope does not contain a tabbable element, use the first focusable element. |
| 549 | if (tabbable && !nextNode) { |
| 550 | scopeRoot = getScopeRoot(scope); |
| 551 | walker = getFocusableTreeWalker(scopeRoot, {tabbable: false}, scope); |
| 552 | walker.currentNode = sentinel; |
| 553 | nextNode = walker.nextNode(); |
| 554 | } |
| 555 | |
| 556 | return nextNode as FocusableElement; |
| 557 | } |
| 558 | |
| 559 | function focusFirstInScope(scope: Element[], tabbable: boolean = true) { |
| 560 | focusElement(getFirstInScope(scope, tabbable)); |
no test coverage detected