(direction: 1 | -1, root: DOMElement)
| 108 | } |
| 109 | |
| 110 | private moveFocus(direction: 1 | -1, root: DOMElement): void { |
| 111 | if (!this.enabled) return |
| 112 | |
| 113 | const tabbable = collectTabbable(root) |
| 114 | if (tabbable.length === 0) return |
| 115 | |
| 116 | const currentIndex = this.activeElement |
| 117 | ? tabbable.indexOf(this.activeElement) |
| 118 | : -1 |
| 119 | |
| 120 | const nextIndex = |
| 121 | currentIndex === -1 |
| 122 | ? direction === 1 |
| 123 | ? 0 |
| 124 | : tabbable.length - 1 |
| 125 | : (currentIndex + direction + tabbable.length) % tabbable.length |
| 126 | |
| 127 | const next = tabbable[nextIndex] |
| 128 | if (next) { |
| 129 | this.focus(next) |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | function collectTabbable(root: DOMElement): DOMElement[] { |
no test coverage detected