* Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.
(opts: TriggerTabOptions)
| 127 | * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester. |
| 128 | */ |
| 129 | async triggerTab(opts: TriggerTabOptions): Promise<void> { |
| 130 | let {tab, interactionType = this._interactionType, manualActivation} = opts; |
| 131 | |
| 132 | if (typeof tab === 'string' || typeof tab === 'number') { |
| 133 | tab = this.findTab({indexOrText: tab}); |
| 134 | } |
| 135 | |
| 136 | if (!tab) { |
| 137 | throw new Error(`Target tab "${formatTargetNode(opts.tab)}" not found in the tablist.`); |
| 138 | } else if (tab.hasAttribute('disabled')) { |
| 139 | throw new Error(`Target tab "${formatTargetNode(opts.tab)}" is disabled.`); |
| 140 | } |
| 141 | |
| 142 | if (interactionType === 'keyboard') { |
| 143 | if ( |
| 144 | document.activeElement !== this._tablist && |
| 145 | !this._tablist.contains(document.activeElement) |
| 146 | ) { |
| 147 | act(() => this._tablist.focus()); |
| 148 | } |
| 149 | |
| 150 | let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal'; |
| 151 | await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation}); |
| 152 | if (manualActivation) { |
| 153 | await this.user.keyboard('[Enter]'); |
| 154 | } |
| 155 | } else { |
| 156 | await pressElement(this.user, tab, interactionType); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Returns the tablist. |
no test coverage detected