@react-aria/test-utils 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/checkboxgroup.main.js +104 -0
  2. package/dist/checkboxgroup.main.js.map +1 -0
  3. package/dist/checkboxgroup.mjs +99 -0
  4. package/dist/checkboxgroup.module.js +99 -0
  5. package/dist/checkboxgroup.module.js.map +1 -0
  6. package/dist/dialog.main.js +105 -0
  7. package/dist/dialog.main.js.map +1 -0
  8. package/dist/dialog.mjs +100 -0
  9. package/dist/dialog.module.js +100 -0
  10. package/dist/dialog.module.js.map +1 -0
  11. package/dist/main.js.map +1 -1
  12. package/dist/module.js.map +1 -1
  13. package/dist/radiogroup.main.js +123 -0
  14. package/dist/radiogroup.main.js.map +1 -0
  15. package/dist/radiogroup.mjs +118 -0
  16. package/dist/radiogroup.module.js +118 -0
  17. package/dist/radiogroup.module.js.map +1 -0
  18. package/dist/tabs.main.js +5 -3
  19. package/dist/tabs.main.js.map +1 -1
  20. package/dist/tabs.mjs +5 -3
  21. package/dist/tabs.module.js +5 -3
  22. package/dist/tabs.module.js.map +1 -1
  23. package/dist/testSetup.main.js +29 -28
  24. package/dist/testSetup.main.js.map +1 -1
  25. package/dist/testSetup.mjs +30 -29
  26. package/dist/testSetup.module.js +30 -29
  27. package/dist/testSetup.module.js.map +1 -1
  28. package/dist/types.d.ts +142 -13
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/user.main.js +12 -3
  31. package/dist/user.main.js.map +1 -1
  32. package/dist/user.mjs +12 -3
  33. package/dist/user.module.js +12 -3
  34. package/dist/user.module.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/checkboxgroup.ts +158 -0
  37. package/src/dialog.ts +143 -0
  38. package/src/index.ts +11 -0
  39. package/src/radiogroup.ts +176 -0
  40. package/src/tabs.ts +7 -2
  41. package/src/testSetup.ts +30 -28
  42. package/src/types.ts +21 -0
  43. package/src/user.ts +25 -7
@@ -0,0 +1,100 @@
1
+ import {act as $ikD9Y$act, waitFor as $ikD9Y$waitFor, within as $ikD9Y$within} from "@testing-library/react";
2
+
3
+ /*
4
+ * Copyright 2025 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ class $5bce5d4037467b58$export$e79328f5295cc2a1 {
15
+ /**
16
+ * Set the interaction type used by the dialog tester.
17
+ */ setInteractionType(type) {
18
+ this._interactionType = type;
19
+ }
20
+ /**
21
+ * Opens the dialog. Defaults to using the interaction type set on the dialog tester.
22
+ */ async open(opts = {}) {
23
+ let { interactionType: interactionType = this._interactionType } = opts;
24
+ let trigger = this.trigger;
25
+ if (!trigger.hasAttribute('disabled')) {
26
+ if (interactionType === 'mouse') await this.user.click(trigger);
27
+ else if (interactionType === 'touch') await this.user.pointer({
28
+ target: trigger,
29
+ keys: '[TouchA]'
30
+ });
31
+ else if (interactionType === 'keyboard') {
32
+ (0, $ikD9Y$act)(()=>trigger.focus());
33
+ await this.user.keyboard('[Enter]');
34
+ }
35
+ if (this._overlayType === 'popover') {
36
+ await (0, $ikD9Y$waitFor)(()=>{
37
+ if (trigger.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on dialog trigger element.');
38
+ else return true;
39
+ });
40
+ let dialogId = trigger.getAttribute('aria-controls');
41
+ await (0, $ikD9Y$waitFor)(()=>{
42
+ if (!dialogId || document.getElementById(dialogId) == null) throw new Error(`Dialog with id of ${dialogId} not found in document.`);
43
+ else {
44
+ this._dialog = document.getElementById(dialogId);
45
+ return true;
46
+ }
47
+ });
48
+ } else {
49
+ let dialog;
50
+ await (0, $ikD9Y$waitFor)(()=>{
51
+ dialog = document.querySelector('[role=dialog], [role=alertdialog]');
52
+ if (dialog == null) throw new Error('No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.');
53
+ else return true;
54
+ });
55
+ if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) this._dialog = dialog;
56
+ else throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Closes the dialog via the Escape key.
62
+ */ async close() {
63
+ let dialog = this._dialog;
64
+ if (dialog) {
65
+ await this.user.keyboard('[Escape]');
66
+ await (0, $ikD9Y$waitFor)(()=>{
67
+ if (document.contains(dialog)) throw new Error('Expected the dialog to not be in the document after closing it.');
68
+ else {
69
+ this._dialog = undefined;
70
+ return true;
71
+ }
72
+ });
73
+ }
74
+ }
75
+ /**
76
+ * Returns the dialog's trigger.
77
+ */ get trigger() {
78
+ if (!this._trigger) throw new Error('No trigger element found for dialog.');
79
+ return this._trigger;
80
+ }
81
+ /**
82
+ * Returns the dialog if present.
83
+ */ get dialog() {
84
+ return this._dialog && document.contains(this._dialog) ? this._dialog : null;
85
+ }
86
+ constructor(opts){
87
+ let { root: root, user: user, interactionType: interactionType, overlayType: overlayType } = opts;
88
+ this.user = user;
89
+ this._interactionType = interactionType || 'mouse';
90
+ this._overlayType = overlayType || 'modal';
91
+ // Handle case where element provided is a wrapper of the trigger button
92
+ let trigger = (0, $ikD9Y$within)(root).queryByRole('button');
93
+ if (trigger) this._trigger = trigger;
94
+ else this._trigger = root;
95
+ }
96
+ }
97
+
98
+
99
+ export {$5bce5d4037467b58$export$e79328f5295cc2a1 as DialogTester};
100
+ //# sourceMappingURL=dialog.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D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9F,IAAI,CAAC,OAAO,GAAG;qBAEf,MAAM,IAAI,MAAM;YAEpB;QACF;IACF;IAEA;;GAEC,GACD,MAAM,QAAuB;QAC3B,IAAI,SAAS,IAAI,CAAC,OAAO;QACzB,IAAI,QAAQ;YACV,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzB,MAAM,CAAA,GAAA,cAAM,EAAE;gBACZ,IAAI,SAAS,QAAQ,CAAC,SACpB,MAAM,IAAI,MAAM;qBACX;oBACL,IAAI,CAAC,OAAO,GAAG;oBACf,OAAO;gBACT;YACF;QACF;IACF;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAChB,MAAM,IAAI,MAAM;QAGlB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,IAAI,SAA6B;QAC/B,OAAO,IAAI,CAAC,OAAO,IAAI,SAAS,QAAQ,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG;IAC1E;IAhHA,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,eAAE,WAAW,EAAC,GAAG;QACjD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,YAAY,GAAG,eAAe;QAEnC,wEAAwE;QACxE,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aAEhB,IAAI,CAAC,QAAQ,GAAG;IAEpB;AAoGF","sources":["packages/@react-aria/test-utils/src/dialog.ts"],"sourcesContent":["/*\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {DialogTesterOpts, UserOpts} from './types';\n\ninterface DialogOpenOpts {\n /**\n * What interaction type to use when opening the dialog. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\nexport class DialogTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement | undefined;\n private _dialog: HTMLElement | undefined;\n private _overlayType: DialogTesterOpts['overlayType'];\n\n constructor(opts: DialogTesterOpts) {\n let {root, user, interactionType, overlayType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._overlayType = overlayType || 'modal';\n\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n /**\n * Set the interaction type used by the dialog tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the dialog. Defaults to using the interaction type set on the dialog tester.\n */\n async open(opts: DialogOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n if (!trigger.hasAttribute('disabled')) {\n if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n\n if (this._overlayType === 'popover') {\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on dialog trigger element.');\n } else {\n return true;\n }\n });\n\n let dialogId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!dialogId || document.getElementById(dialogId) == null) {\n throw new Error(`Dialog with id of ${dialogId} not found in document.`);\n } else {\n this._dialog = document.getElementById(dialogId)!;\n return true;\n }\n });\n } else {\n let dialog;\n await waitFor(() => {\n dialog = document.querySelector('[role=dialog], [role=alertdialog]');\n if (dialog == null) {\n throw new Error('No dialog of type role=\"dialog\" or role=\"alertdialog\" found after pressing the trigger.');\n } else {\n return true;\n }\n });\n\n if (dialog && document.activeElement !== this._trigger && dialog.contains(document.activeElement)) {\n this._dialog = dialog;\n } else {\n throw new Error('New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found');\n }\n }\n }\n }\n\n /**\n * Closes the dialog via the Escape key.\n */\n async close(): Promise<void> {\n let dialog = this._dialog;\n if (dialog) {\n await this.user.keyboard('[Escape]');\n await waitFor(() => {\n if (document.contains(dialog)) {\n throw new Error('Expected the dialog to not be in the document after closing it.');\n } else {\n this._dialog = undefined;\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the dialog's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for dialog.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the dialog if present.\n */\n get dialog(): HTMLElement | null {\n return this._dialog && document.contains(this._dialog) ? this._dialog : null;\n }\n}\n"],"names":[],"version":3,"file":"dialog.module.js.map"}
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\nexport type {CheckboxGroupTester} from './checkboxgroup';\nexport type {ComboBoxTester} from './combobox';\nexport type {DialogTester} from './dialog';\nexport type {GridListTester} from './gridlist';\nexport type {ListBoxTester} from './listbox';\nexport type {MenuTester} from './menu';\nexport type {RadioGroupTester} from './radiogroup';\nexport type {SelectTester} from './select';\nexport type {TableTester} from './table';\nexport type {TabsTester} from './tabs';\nexport type {TreeTester} from './tree';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/test-utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {triggerLongPress} from './events';\nexport {installMouseEvent, installPointerEvent} from './testSetup';\nexport {pointerMap} from './userEventMaps';\nexport {User} from './user';\nexport type {CheckboxGroupTester} from './checkboxgroup';\nexport type {ComboBoxTester} from './combobox';\nexport type {DialogTester} from './dialog';\nexport type {GridListTester} from './gridlist';\nexport type {ListBoxTester} from './listbox';\nexport type {MenuTester} from './menu';\nexport type {RadioGroupTester} from './radiogroup';\nexport type {SelectTester} from './select';\nexport type {TableTester} from './table';\nexport type {TabsTester} from './tabs';\nexport type {TreeTester} from './tree';\n\nexport type {UserOpts} from './types';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,123 @@
1
+ var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
+ var $bWf8L$testinglibraryreact = require("@testing-library/react");
3
+
4
+
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
+ }
8
+
9
+ $parcel$export(module.exports, "RadioGroupTester", () => $0e17c3c452120f8b$export$d66326e63d27e116);
10
+ /*
11
+ * Copyright 2025 Adobe. All rights reserved.
12
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License. You may obtain a copy
14
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software distributed under
17
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
+ * OF ANY KIND, either express or implied. See the License for the specific language
19
+ * governing permissions and limitations under the License.
20
+ */
21
+
22
+ class $0e17c3c452120f8b$export$d66326e63d27e116 {
23
+ /**
24
+ * Set the interaction type used by the radio tester.
25
+ */ setInteractionType(type) {
26
+ this._interactionType = type;
27
+ }
28
+ /**
29
+ * Returns a radio matching the specified index or text content.
30
+ */ findRadio(opts) {
31
+ let { radioIndexOrText: radioIndexOrText } = opts;
32
+ let radio;
33
+ if (typeof radioIndexOrText === 'number') radio = this.radios[radioIndexOrText];
34
+ else if (typeof radioIndexOrText === 'string') {
35
+ let label = (0, $bWf8L$testinglibraryreact.within)(this.radiogroup).getByText(radioIndexOrText);
36
+ // Label may wrap the radio, or the actual label may be a sibling span, or the radio div could have the label within it
37
+ if (label) {
38
+ radio = (0, $bWf8L$testinglibraryreact.within)(label).queryByRole('radio');
39
+ if (!radio) {
40
+ let labelWrapper = label.closest('label');
41
+ if (labelWrapper) radio = (0, $bWf8L$testinglibraryreact.within)(labelWrapper).queryByRole('radio');
42
+ else radio = label.closest('[role=radio]');
43
+ }
44
+ }
45
+ }
46
+ return radio;
47
+ }
48
+ async keyboardNavigateToRadio(opts) {
49
+ let { radio: radio, orientation: orientation = 'vertical' } = opts;
50
+ let radios = this.radios;
51
+ radios = radios.filter((radio)=>!(radio.hasAttribute('disabled') || radio.getAttribute('aria-disabled') === 'true'));
52
+ if (radios.length === 0) throw new Error('Radio group doesnt have any non-disabled radios. Please double check your radio group.');
53
+ let targetIndex = radios.indexOf(radio);
54
+ if (targetIndex === -1) throw new Error('Radio provided is not in the radio group.');
55
+ if (!this.radiogroup.contains(document.activeElement)) {
56
+ let selectedRadio = this.selectedRadio;
57
+ if (selectedRadio != null) (0, $bWf8L$testinglibraryreact.act)(()=>selectedRadio.focus());
58
+ else (0, $bWf8L$testinglibraryreact.act)(()=>{
59
+ var _radios_;
60
+ return (_radios_ = radios[0]) === null || _radios_ === void 0 ? void 0 : _radios_.focus();
61
+ });
62
+ }
63
+ let currIndex = radios.indexOf(document.activeElement);
64
+ if (currIndex === -1) throw new Error('Active element is not in the radio group.');
65
+ let arrowUp = 'ArrowUp';
66
+ let arrowDown = 'ArrowDown';
67
+ if (orientation === 'horizontal') {
68
+ if (this._direction === 'ltr') {
69
+ arrowUp = 'ArrowLeft';
70
+ arrowDown = 'ArrowRight';
71
+ } else {
72
+ arrowUp = 'ArrowRight';
73
+ arrowDown = 'ArrowLeft';
74
+ }
75
+ }
76
+ let movementDirection = targetIndex > currIndex ? 'down' : 'up';
77
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
78
+ }
79
+ /**
80
+ * Triggers the specified radio. Defaults to using the interaction type set on the radio tester.
81
+ */ async triggerRadio(opts) {
82
+ let { radio: radio, interactionType: interactionType = this._interactionType } = opts;
83
+ if (typeof radio === 'string' || typeof radio === 'number') radio = this.findRadio({
84
+ radioIndexOrText: radio
85
+ });
86
+ if (!radio) throw new Error('Target radio not found in the radio group.');
87
+ else if (radio.hasAttribute('disabled')) throw new Error('Target radio is disabled.');
88
+ if (interactionType === 'keyboard') {
89
+ let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';
90
+ await this.keyboardNavigateToRadio({
91
+ radio: radio,
92
+ orientation: radioOrientation
93
+ });
94
+ } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, radio, interactionType);
95
+ }
96
+ /**
97
+ * Returns the radiogroup.
98
+ */ get radiogroup() {
99
+ return this._radiogroup;
100
+ }
101
+ /**
102
+ * Returns the radios.
103
+ */ get radios() {
104
+ return (0, $bWf8L$testinglibraryreact.within)(this.radiogroup).queryAllByRole('radio');
105
+ }
106
+ /**
107
+ * Returns the currently selected radio in the radiogroup if any.
108
+ */ get selectedRadio() {
109
+ return this.radios.find((radio)=>radio.checked) || null;
110
+ }
111
+ constructor(opts){
112
+ let { root: root, user: user, interactionType: interactionType, direction: direction } = opts;
113
+ this.user = user;
114
+ this._interactionType = interactionType || 'mouse';
115
+ this._direction = direction || 'ltr';
116
+ this._radiogroup = root;
117
+ let radiogroup = (0, $bWf8L$testinglibraryreact.within)(root).queryAllByRole('radiogroup');
118
+ if (radiogroup.length > 0) this._radiogroup = radiogroup[0];
119
+ }
120
+ }
121
+
122
+
123
+ //# sourceMappingURL=radiogroup.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,UAAU,IAAyC,EAAe;QAChE,IAAI,oBACF,gBAAgB,EACjB,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,qBAAqB,UAC9B,QAAQ,IAAI,CAAC,MAAM,CAAC,iBAAiB;aAChC,IAAI,OAAO,qBAAqB,UAAU;YAC/C,IAAI,QAAQ,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC;YAC9C,uHAAuH;YACvH,IAAI,OAAO;gBACT,QAAQ,CAAA,GAAA,iCAAK,EAAE,OAAO,WAAW,CAAC;gBAClC,IAAI,CAAC,OAAO;oBACV,IAAI,eAAe,MAAM,OAAO,CAAC;oBACjC,IAAI,cACF,QAAQ,CAAA,GAAA,iCAAK,EAAE,cAAc,WAAW,CAAC;yBAEzC,QAAQ,MAAM,OAAO,CAAC;gBAE1B;YACF;QACF;QAEA,OAAO;IACT;IAEA,MAAc,wBAAwB,IAAqD,EAAE;QAC3F,IAAI,SAAC,KAAK,eAAE,cAAc,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IAAI,CAAC,SAAS,CAAC;YAAC,kBAAkB;QAAK;QAGjD,IAAI,CAAC,OACH,MAAM,IAAI,MAAM;aACX,IAAI,MAAM,YAAY,CAAC,aAC5B,MAAM,IAAI,MAAM;QAGlB,IAAI,oBAAoB,YAAY;YAClC,IAAI,mBAAmB,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,uBAAuB;YAC5E,MAAM,IAAI,CAAC,uBAAuB,CAAC;uBAAC;gBAAO,aAAa;YAA+B;QACzF,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO;IAEzC;IAEA;;GAEC,GACD,IAAI,aAA0B;QAC5B,OAAO,IAAI,CAAC,WAAW;IACzB;IAEA;;GAEC,GACD,IAAI,SAAwB;QAC1B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC;IAChD;IAEA;;GAEC,GACD,IAAI,gBAAoC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,QAAS,AAAC,MAA2B,OAAO,KAAK;IAC3E;IA7IA,YAAY,IAA0B,CAAE;QACtC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,aAAa,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC7C,IAAI,WAAW,MAAM,GAAG,GACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE;IAEpC;AAmIF","sources":["packages/@react-aria/test-utils/src/radiogroup.ts"],"sourcesContent":["/*\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerRadioOptions {\n /**\n * What interaction type to use when triggering a radio. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the radio to toggle selection for.\n */\n radio: number | string | HTMLElement\n}\n\nexport class RadioGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _radiogroup: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: RadioGroupTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._radiogroup = root;\n let radiogroup = within(root).queryAllByRole('radiogroup');\n if (radiogroup.length > 0) {\n this._radiogroup = radiogroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the radio tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a radio matching the specified index or text content.\n */\n findRadio(opts: {radioIndexOrText: number | string}): HTMLElement {\n let {\n radioIndexOrText\n } = opts;\n\n let radio;\n if (typeof radioIndexOrText === 'number') {\n radio = this.radios[radioIndexOrText];\n } else if (typeof radioIndexOrText === 'string') {\n let label = within(this.radiogroup).getByText(radioIndexOrText);\n // Label may wrap the radio, or the actual label may be a sibling span, or the radio div could have the label within it\n if (label) {\n radio = within(label).queryByRole('radio');\n if (!radio) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n radio = within(labelWrapper).queryByRole('radio');\n } else {\n radio = label.closest('[role=radio]');\n }\n }\n }\n }\n\n return radio;\n }\n\n private async keyboardNavigateToRadio(opts: {radio: HTMLElement, orientation?: Orientation}) {\n let {radio, orientation = 'vertical'} = opts;\n let radios = this.radios;\n radios = radios.filter(radio => !(radio.hasAttribute('disabled') || radio.getAttribute('aria-disabled') === 'true'));\n if (radios.length === 0) {\n throw new Error('Radio group doesnt have any non-disabled radios. Please double check your radio group.');\n }\n\n let targetIndex = radios.indexOf(radio);\n if (targetIndex === -1) {\n throw new Error('Radio provided is not in the radio group.');\n }\n\n if (!this.radiogroup.contains(document.activeElement)) {\n let selectedRadio = this.selectedRadio;\n if (selectedRadio != null) {\n act(() => selectedRadio.focus());\n } else {\n act(() => radios[0]?.focus());\n }\n }\n\n let currIndex = radios.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the radio group.');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified radio. Defaults to using the interaction type set on the radio tester.\n */\n async triggerRadio(opts: TriggerRadioOptions): Promise<void> {\n let {\n radio,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof radio === 'string' || typeof radio === 'number') {\n radio = this.findRadio({radioIndexOrText: radio});\n }\n\n if (!radio) {\n throw new Error('Target radio not found in the radio group.');\n } else if (radio.hasAttribute('disabled')) {\n throw new Error('Target radio is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToRadio({radio, orientation: radioOrientation as Orientation});\n } else {\n await pressElement(this.user, radio, interactionType);\n }\n }\n\n /**\n * Returns the radiogroup.\n */\n get radiogroup(): HTMLElement {\n return this._radiogroup;\n }\n\n /**\n * Returns the radios.\n */\n get radios(): HTMLElement[] {\n return within(this.radiogroup).queryAllByRole('radio');\n }\n\n /**\n * Returns the currently selected radio in the radiogroup if any.\n */\n get selectedRadio(): HTMLElement | null {\n return this.radios.find(radio => (radio as HTMLInputElement).checked) || null;\n }\n}\n"],"names":[],"version":3,"file":"radiogroup.main.js.map"}
@@ -0,0 +1,118 @@
1
+ import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.mjs";
2
+ import {within as $2clho$within, act as $2clho$act} from "@testing-library/react";
3
+
4
+ /*
5
+ * Copyright 2025 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $bf94dbe12a575fe8$export$d66326e63d27e116 {
17
+ /**
18
+ * Set the interaction type used by the radio tester.
19
+ */ setInteractionType(type) {
20
+ this._interactionType = type;
21
+ }
22
+ /**
23
+ * Returns a radio matching the specified index or text content.
24
+ */ findRadio(opts) {
25
+ let { radioIndexOrText: radioIndexOrText } = opts;
26
+ let radio;
27
+ if (typeof radioIndexOrText === 'number') radio = this.radios[radioIndexOrText];
28
+ else if (typeof radioIndexOrText === 'string') {
29
+ let label = (0, $2clho$within)(this.radiogroup).getByText(radioIndexOrText);
30
+ // Label may wrap the radio, or the actual label may be a sibling span, or the radio div could have the label within it
31
+ if (label) {
32
+ radio = (0, $2clho$within)(label).queryByRole('radio');
33
+ if (!radio) {
34
+ let labelWrapper = label.closest('label');
35
+ if (labelWrapper) radio = (0, $2clho$within)(labelWrapper).queryByRole('radio');
36
+ else radio = label.closest('[role=radio]');
37
+ }
38
+ }
39
+ }
40
+ return radio;
41
+ }
42
+ async keyboardNavigateToRadio(opts) {
43
+ let { radio: radio, orientation: orientation = 'vertical' } = opts;
44
+ let radios = this.radios;
45
+ radios = radios.filter((radio)=>!(radio.hasAttribute('disabled') || radio.getAttribute('aria-disabled') === 'true'));
46
+ if (radios.length === 0) throw new Error('Radio group doesnt have any non-disabled radios. Please double check your radio group.');
47
+ let targetIndex = radios.indexOf(radio);
48
+ if (targetIndex === -1) throw new Error('Radio provided is not in the radio group.');
49
+ if (!this.radiogroup.contains(document.activeElement)) {
50
+ let selectedRadio = this.selectedRadio;
51
+ if (selectedRadio != null) (0, $2clho$act)(()=>selectedRadio.focus());
52
+ else (0, $2clho$act)(()=>{
53
+ var _radios_;
54
+ return (_radios_ = radios[0]) === null || _radios_ === void 0 ? void 0 : _radios_.focus();
55
+ });
56
+ }
57
+ let currIndex = radios.indexOf(document.activeElement);
58
+ if (currIndex === -1) throw new Error('Active element is not in the radio group.');
59
+ let arrowUp = 'ArrowUp';
60
+ let arrowDown = 'ArrowDown';
61
+ if (orientation === 'horizontal') {
62
+ if (this._direction === 'ltr') {
63
+ arrowUp = 'ArrowLeft';
64
+ arrowDown = 'ArrowRight';
65
+ } else {
66
+ arrowUp = 'ArrowRight';
67
+ arrowDown = 'ArrowLeft';
68
+ }
69
+ }
70
+ let movementDirection = targetIndex > currIndex ? 'down' : 'up';
71
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
72
+ }
73
+ /**
74
+ * Triggers the specified radio. Defaults to using the interaction type set on the radio tester.
75
+ */ async triggerRadio(opts) {
76
+ let { radio: radio, interactionType: interactionType = this._interactionType } = opts;
77
+ if (typeof radio === 'string' || typeof radio === 'number') radio = this.findRadio({
78
+ radioIndexOrText: radio
79
+ });
80
+ if (!radio) throw new Error('Target radio not found in the radio group.');
81
+ else if (radio.hasAttribute('disabled')) throw new Error('Target radio is disabled.');
82
+ if (interactionType === 'keyboard') {
83
+ let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';
84
+ await this.keyboardNavigateToRadio({
85
+ radio: radio,
86
+ orientation: radioOrientation
87
+ });
88
+ } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, radio, interactionType);
89
+ }
90
+ /**
91
+ * Returns the radiogroup.
92
+ */ get radiogroup() {
93
+ return this._radiogroup;
94
+ }
95
+ /**
96
+ * Returns the radios.
97
+ */ get radios() {
98
+ return (0, $2clho$within)(this.radiogroup).queryAllByRole('radio');
99
+ }
100
+ /**
101
+ * Returns the currently selected radio in the radiogroup if any.
102
+ */ get selectedRadio() {
103
+ return this.radios.find((radio)=>radio.checked) || null;
104
+ }
105
+ constructor(opts){
106
+ let { root: root, user: user, interactionType: interactionType, direction: direction } = opts;
107
+ this.user = user;
108
+ this._interactionType = interactionType || 'mouse';
109
+ this._direction = direction || 'ltr';
110
+ this._radiogroup = root;
111
+ let radiogroup = (0, $2clho$within)(root).queryAllByRole('radiogroup');
112
+ if (radiogroup.length > 0) this._radiogroup = radiogroup[0];
113
+ }
114
+ }
115
+
116
+
117
+ export {$bf94dbe12a575fe8$export$d66326e63d27e116 as RadioGroupTester};
118
+ //# sourceMappingURL=radiogroup.module.js.map
@@ -0,0 +1,118 @@
1
+ import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
2
+ import {within as $2clho$within, act as $2clho$act} from "@testing-library/react";
3
+
4
+ /*
5
+ * Copyright 2025 Adobe. All rights reserved.
6
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License. You may obtain a copy
8
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software distributed under
11
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
+ * OF ANY KIND, either express or implied. See the License for the specific language
13
+ * governing permissions and limitations under the License.
14
+ */
15
+
16
+ class $bf94dbe12a575fe8$export$d66326e63d27e116 {
17
+ /**
18
+ * Set the interaction type used by the radio tester.
19
+ */ setInteractionType(type) {
20
+ this._interactionType = type;
21
+ }
22
+ /**
23
+ * Returns a radio matching the specified index or text content.
24
+ */ findRadio(opts) {
25
+ let { radioIndexOrText: radioIndexOrText } = opts;
26
+ let radio;
27
+ if (typeof radioIndexOrText === 'number') radio = this.radios[radioIndexOrText];
28
+ else if (typeof radioIndexOrText === 'string') {
29
+ let label = (0, $2clho$within)(this.radiogroup).getByText(radioIndexOrText);
30
+ // Label may wrap the radio, or the actual label may be a sibling span, or the radio div could have the label within it
31
+ if (label) {
32
+ radio = (0, $2clho$within)(label).queryByRole('radio');
33
+ if (!radio) {
34
+ let labelWrapper = label.closest('label');
35
+ if (labelWrapper) radio = (0, $2clho$within)(labelWrapper).queryByRole('radio');
36
+ else radio = label.closest('[role=radio]');
37
+ }
38
+ }
39
+ }
40
+ return radio;
41
+ }
42
+ async keyboardNavigateToRadio(opts) {
43
+ let { radio: radio, orientation: orientation = 'vertical' } = opts;
44
+ let radios = this.radios;
45
+ radios = radios.filter((radio)=>!(radio.hasAttribute('disabled') || radio.getAttribute('aria-disabled') === 'true'));
46
+ if (radios.length === 0) throw new Error('Radio group doesnt have any non-disabled radios. Please double check your radio group.');
47
+ let targetIndex = radios.indexOf(radio);
48
+ if (targetIndex === -1) throw new Error('Radio provided is not in the radio group.');
49
+ if (!this.radiogroup.contains(document.activeElement)) {
50
+ let selectedRadio = this.selectedRadio;
51
+ if (selectedRadio != null) (0, $2clho$act)(()=>selectedRadio.focus());
52
+ else (0, $2clho$act)(()=>{
53
+ var _radios_;
54
+ return (_radios_ = radios[0]) === null || _radios_ === void 0 ? void 0 : _radios_.focus();
55
+ });
56
+ }
57
+ let currIndex = radios.indexOf(document.activeElement);
58
+ if (currIndex === -1) throw new Error('Active element is not in the radio group.');
59
+ let arrowUp = 'ArrowUp';
60
+ let arrowDown = 'ArrowDown';
61
+ if (orientation === 'horizontal') {
62
+ if (this._direction === 'ltr') {
63
+ arrowUp = 'ArrowLeft';
64
+ arrowDown = 'ArrowRight';
65
+ } else {
66
+ arrowUp = 'ArrowRight';
67
+ arrowDown = 'ArrowLeft';
68
+ }
69
+ }
70
+ let movementDirection = targetIndex > currIndex ? 'down' : 'up';
71
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
72
+ }
73
+ /**
74
+ * Triggers the specified radio. Defaults to using the interaction type set on the radio tester.
75
+ */ async triggerRadio(opts) {
76
+ let { radio: radio, interactionType: interactionType = this._interactionType } = opts;
77
+ if (typeof radio === 'string' || typeof radio === 'number') radio = this.findRadio({
78
+ radioIndexOrText: radio
79
+ });
80
+ if (!radio) throw new Error('Target radio not found in the radio group.');
81
+ else if (radio.hasAttribute('disabled')) throw new Error('Target radio is disabled.');
82
+ if (interactionType === 'keyboard') {
83
+ let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';
84
+ await this.keyboardNavigateToRadio({
85
+ radio: radio,
86
+ orientation: radioOrientation
87
+ });
88
+ } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, radio, interactionType);
89
+ }
90
+ /**
91
+ * Returns the radiogroup.
92
+ */ get radiogroup() {
93
+ return this._radiogroup;
94
+ }
95
+ /**
96
+ * Returns the radios.
97
+ */ get radios() {
98
+ return (0, $2clho$within)(this.radiogroup).queryAllByRole('radio');
99
+ }
100
+ /**
101
+ * Returns the currently selected radio in the radiogroup if any.
102
+ */ get selectedRadio() {
103
+ return this.radios.find((radio)=>radio.checked) || null;
104
+ }
105
+ constructor(opts){
106
+ let { root: root, user: user, interactionType: interactionType, direction: direction } = opts;
107
+ this.user = user;
108
+ this._interactionType = interactionType || 'mouse';
109
+ this._direction = direction || 'ltr';
110
+ this._radiogroup = root;
111
+ let radiogroup = (0, $2clho$within)(root).queryAllByRole('radiogroup');
112
+ if (radiogroup.length > 0) this._radiogroup = radiogroup[0];
113
+ }
114
+ }
115
+
116
+
117
+ export {$bf94dbe12a575fe8$export$d66326e63d27e116 as RadioGroupTester};
118
+ //# sourceMappingURL=radiogroup.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,UAAU,IAAyC,EAAe;QAChE,IAAI,oBACF,gBAAgB,EACjB,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,qBAAqB,UAC9B,QAAQ,IAAI,CAAC,MAAM,CAAC,iBAAiB;aAChC,IAAI,OAAO,qBAAqB,UAAU;YAC/C,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC;YAC9C,uHAAuH;YACvH,IAAI,OAAO;gBACT,QAAQ,CAAA,GAAA,aAAK,EAAE,OAAO,WAAW,CAAC;gBAClC,IAAI,CAAC,OAAO;oBACV,IAAI,eAAe,MAAM,OAAO,CAAC;oBACjC,IAAI,cACF,QAAQ,CAAA,GAAA,aAAK,EAAE,cAAc,WAAW,CAAC;yBAEzC,QAAQ,MAAM,OAAO,CAAC;gBAE1B;YACF;QACF;QAEA,OAAO;IACT;IAEA,MAAc,wBAAwB,IAAqD,EAAE;QAC3F,IAAI,SAAC,KAAK,eAAE,cAAc,YAAW,GAAG;QACxC,IAAI,SAAS,IAAI,CAAC,MAAM;QACxB,SAAS,OAAO,MAAM,CAAC,CAAA,QAAS,CAAE,CAAA,MAAM,YAAY,CAAC,eAAe,MAAM,YAAY,CAAC,qBAAqB,MAAK;QACjH,IAAI,OAAO,MAAM,KAAK,GACpB,MAAM,IAAI,MAAM;QAGlB,IAAI,cAAc,OAAO,OAA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M,IAAI,CAAC,uBAAuB,CAAC;uBAAC;gBAAO,aAAa;YAA+B;QACzF,OACE,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO;IAEzC;IAEA;;GAEC,GACD,IAAI,aAA0B;QAC5B,OAAO,IAAI,CAAC,WAAW;IACzB;IAEA;;GAEC,GACD,IAAI,SAAwB;QAC1B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC;IAChD;IAEA;;GAEC,GACD,IAAI,gBAAoC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA,QAAS,AAAC,MAA2B,OAAO,KAAK;IAC3E;IA7IA,YAAY,IAA0B,CAAE;QACtC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,aAAa,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC7C,IAAI,WAAW,MAAM,GAAG,GACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,EAAE;IAEpC;AAmIF","sources":["packages/@react-aria/test-utils/src/radiogroup.ts"],"sourcesContent":["/*\n * Copyright 2025 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, RadioGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerRadioOptions {\n /**\n * What interaction type to use when triggering a radio. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the radio to toggle selection for.\n */\n radio: number | string | HTMLElement\n}\n\nexport class RadioGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _radiogroup: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: RadioGroupTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._radiogroup = root;\n let radiogroup = within(root).queryAllByRole('radiogroup');\n if (radiogroup.length > 0) {\n this._radiogroup = radiogroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the radio tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a radio matching the specified index or text content.\n */\n findRadio(opts: {radioIndexOrText: number | string}): HTMLElement {\n let {\n radioIndexOrText\n } = opts;\n\n let radio;\n if (typeof radioIndexOrText === 'number') {\n radio = this.radios[radioIndexOrText];\n } else if (typeof radioIndexOrText === 'string') {\n let label = within(this.radiogroup).getByText(radioIndexOrText);\n // Label may wrap the radio, or the actual label may be a sibling span, or the radio div could have the label within it\n if (label) {\n radio = within(label).queryByRole('radio');\n if (!radio) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n radio = within(labelWrapper).queryByRole('radio');\n } else {\n radio = label.closest('[role=radio]');\n }\n }\n }\n }\n\n return radio;\n }\n\n private async keyboardNavigateToRadio(opts: {radio: HTMLElement, orientation?: Orientation}) {\n let {radio, orientation = 'vertical'} = opts;\n let radios = this.radios;\n radios = radios.filter(radio => !(radio.hasAttribute('disabled') || radio.getAttribute('aria-disabled') === 'true'));\n if (radios.length === 0) {\n throw new Error('Radio group doesnt have any non-disabled radios. Please double check your radio group.');\n }\n\n let targetIndex = radios.indexOf(radio);\n if (targetIndex === -1) {\n throw new Error('Radio provided is not in the radio group.');\n }\n\n if (!this.radiogroup.contains(document.activeElement)) {\n let selectedRadio = this.selectedRadio;\n if (selectedRadio != null) {\n act(() => selectedRadio.focus());\n } else {\n act(() => radios[0]?.focus());\n }\n }\n\n let currIndex = radios.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the radio group.');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified radio. Defaults to using the interaction type set on the radio tester.\n */\n async triggerRadio(opts: TriggerRadioOptions): Promise<void> {\n let {\n radio,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof radio === 'string' || typeof radio === 'number') {\n radio = this.findRadio({radioIndexOrText: radio});\n }\n\n if (!radio) {\n throw new Error('Target radio not found in the radio group.');\n } else if (radio.hasAttribute('disabled')) {\n throw new Error('Target radio is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n let radioOrientation = this._radiogroup.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToRadio({radio, orientation: radioOrientation as Orientation});\n } else {\n await pressElement(this.user, radio, interactionType);\n }\n }\n\n /**\n * Returns the radiogroup.\n */\n get radiogroup(): HTMLElement {\n return this._radiogroup;\n }\n\n /**\n * Returns the radios.\n */\n get radios(): HTMLElement[] {\n return within(this.radiogroup).queryAllByRole('radio');\n }\n\n /**\n * Returns the currently selected radio in the radiogroup if any.\n */\n get selectedRadio(): HTMLElement | null {\n return this.radios.find(radio => (radio as HTMLInputElement).checked) || null;\n }\n}\n"],"names":[],"version":3,"file":"radiogroup.module.js.map"}
package/dist/tabs.main.js CHANGED
@@ -40,17 +40,19 @@ class $19633c03aff25ae5$export$f1539bff3fc7d485 {
40
40
  async keyboardNavigateToTab(opts) {
41
41
  let { tab: tab, orientation: orientation = 'vertical' } = opts;
42
42
  let tabs = this.tabs;
43
+ tabs = tabs.filter((tab)=>!(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'));
44
+ if (tabs.length === 0) throw new Error('Tablist doesnt have any non-disabled tabs. Please double check your tabs implementation.');
43
45
  let targetIndex = tabs.indexOf(tab);
44
46
  if (targetIndex === -1) throw new Error('Tab provided is not in the tablist');
45
47
  if (!this._tablist.contains(document.activeElement)) {
46
48
  let selectedTab = this.selectedTab;
47
49
  if (selectedTab != null) (0, $1inx6$testinglibraryreact.act)(()=>selectedTab.focus());
48
50
  else (0, $1inx6$testinglibraryreact.act)(()=>{
49
- var _tabs_find;
50
- return (_tabs_find = tabs.find((tab)=>!(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))) === null || _tabs_find === void 0 ? void 0 : _tabs_find.focus();
51
+ var _tabs_;
52
+ return (_tabs_ = tabs[0]) === null || _tabs_ === void 0 ? void 0 : _tabs_.focus();
51
53
  });
52
54
  }
53
- let currIndex = this.tabs.indexOf(document.activeElement);
55
+ let currIndex = tabs.indexOf(document.activeElement);
54
56
  if (currIndex === -1) throw new Error('ActiveElement is not in the tablist');
55
57
  let arrowUp = 'ArrowUp';
56
58
  let arrowDown = 'ArrowDown';
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI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,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC;IAC7C;IAEA;;GAEC,GACD,IAAI,cAAkC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB,WAAW;IAChF;IAEA;;GAEC,GACD,IAAI,iBAAqC;YAChB;QAAvB,IAAI,oBAAmB,oBAAA,IAAI,CAAC,WAAW,cAAhB,wCAAA,kBAAkB,YAAY,CAAC;QACtD,OAAO,mBAAmB,SAAS,cAAc,CAAC,oBAAoB;IACxE;IA/JA,YAAY,IAAoB,CAAE;QAChC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AAqJF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGjE,OAAO;IACT;IAEA,+FAA+F;IAC/F,MAAc,sBAAsB,IAAmD,EAAE;QACvF,IAAI,OAAC,GAAG,eAAE,cAAc,YAAW,GAAG;QACtC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,OAAO,KAAK,MAAM,CAAC,CAAA,MAAO,CAAE,CAAA,IAAI,YAAY,CAAC,eAAe,IAAI,YAAY,CAAC,qBAAqB,MAAK;QACvG,IAAI,KAAK,MAAM,KAAK,GAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;YACnD,IAAI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AQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AA0JF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n tabs = tabs.filter(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'));\n if (tabs.length === 0) {\n throw new Error('Tablist doesnt have any non-disabled tabs. Please double check your tabs implementation.');\n }\n\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs[0]?.focus());\n }\n }\n\n let currIndex = tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}