MCPcopy Index your code
hub / github.com/adobe/react-spectrum / triggerTab

Method triggerTab

packages/@react-aria/test-utils/src/tabs.ts:129–158  ·  view source on GitHub ↗

* Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.

(opts: TriggerTabOptions)

Source from the content-addressed store, hash-verified

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.

Callers 3

Tabs.test.jsFile · 0.80
Tabs.test.jsFile · 0.80

Calls 7

findTabMethod · 0.95
keyboardNavigateToTabMethod · 0.95
formatTargetNodeFunction · 0.90
actFunction · 0.90
pressElementFunction · 0.90
hasAttributeMethod · 0.80
focusMethod · 0.80

Tested by

no test coverage detected