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