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

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 (133) hide show
  1. package/dist/import.mjs +5 -5
  2. package/dist/main.js +9 -9
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +5 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/private/checkboxgroup.cjs +104 -0
  7. package/dist/private/checkboxgroup.cjs.map +1 -0
  8. package/dist/private/checkboxgroup.js +99 -0
  9. package/dist/private/checkboxgroup.js.map +1 -0
  10. package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
  11. package/dist/private/combobox.cjs.map +1 -0
  12. package/dist/{combobox.mjs → private/combobox.js} +35 -35
  13. package/dist/private/combobox.js.map +1 -0
  14. package/dist/private/dialog.cjs +105 -0
  15. package/dist/private/dialog.cjs.map +1 -0
  16. package/dist/private/dialog.js +100 -0
  17. package/dist/private/dialog.js.map +1 -0
  18. package/dist/{events.main.js → private/events.cjs} +32 -34
  19. package/dist/private/events.cjs.map +1 -0
  20. package/dist/{events.mjs → private/events.js} +29 -31
  21. package/dist/private/events.js.map +1 -0
  22. package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
  23. package/dist/private/gridlist.cjs.map +1 -0
  24. package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
  25. package/dist/private/gridlist.js.map +1 -0
  26. package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
  27. package/dist/private/listbox.cjs.map +1 -0
  28. package/dist/{listbox.mjs → private/listbox.js} +24 -24
  29. package/dist/private/listbox.js.map +1 -0
  30. package/dist/{menu.main.js → private/menu.cjs} +46 -48
  31. package/dist/private/menu.cjs.map +1 -0
  32. package/dist/{menu.mjs → private/menu.js} +46 -48
  33. package/dist/private/menu.js.map +1 -0
  34. package/dist/private/radiogroup.cjs +120 -0
  35. package/dist/private/radiogroup.cjs.map +1 -0
  36. package/dist/private/radiogroup.js +115 -0
  37. package/dist/private/radiogroup.js.map +1 -0
  38. package/dist/{select.main.js → private/select.cjs} +31 -29
  39. package/dist/private/select.cjs.map +1 -0
  40. package/dist/{select.mjs → private/select.js} +31 -29
  41. package/dist/private/select.js.map +1 -0
  42. package/dist/{table.main.js → private/table.cjs} +82 -57
  43. package/dist/private/table.cjs.map +1 -0
  44. package/dist/{table.module.js → private/table.js} +82 -57
  45. package/dist/private/table.js.map +1 -0
  46. package/dist/{tabs.main.js → private/tabs.cjs} +24 -26
  47. package/dist/private/tabs.cjs.map +1 -0
  48. package/dist/{tabs.mjs → private/tabs.js} +24 -26
  49. package/dist/private/tabs.js.map +1 -0
  50. package/dist/private/testSetup.cjs +87 -0
  51. package/dist/private/testSetup.cjs.map +1 -0
  52. package/dist/private/testSetup.js +81 -0
  53. package/dist/private/testSetup.js.map +1 -0
  54. package/dist/{tree.main.js → private/tree.cjs} +34 -35
  55. package/dist/private/tree.cjs.map +1 -0
  56. package/dist/{tree.mjs → private/tree.js} +34 -35
  57. package/dist/private/tree.js.map +1 -0
  58. package/dist/private/user.cjs +85 -0
  59. package/dist/private/user.cjs.map +1 -0
  60. package/dist/private/user.js +76 -0
  61. package/dist/private/user.js.map +1 -0
  62. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  63. package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
  64. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  65. package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
  66. package/dist/types/src/checkboxgroup.d.ts +45 -0
  67. package/dist/types/src/combobox.d.ts +75 -0
  68. package/dist/types/src/dialog.d.ts +36 -0
  69. package/dist/types/src/events.d.ts +25 -0
  70. package/dist/types/src/gridlist.d.ts +51 -0
  71. package/dist/types/src/index.d.ts +16 -0
  72. package/dist/types/src/listbox.d.ts +80 -0
  73. package/dist/types/src/menu.d.ts +102 -0
  74. package/dist/types/src/radiogroup.d.ts +46 -0
  75. package/dist/types/src/select.d.ts +67 -0
  76. package/dist/types/src/table.d.ts +104 -0
  77. package/dist/types/src/tabs.d.ts +58 -0
  78. package/dist/types/src/testSetup.d.ts +6 -0
  79. package/dist/types/src/tree.d.ts +57 -0
  80. package/dist/types/src/types.d.ts +136 -0
  81. package/dist/types/src/user.d.ts +47 -0
  82. package/dist/types/src/userEventMaps.d.ts +2 -0
  83. package/package.json +7 -7
  84. package/src/checkboxgroup.ts +158 -0
  85. package/src/dialog.ts +143 -0
  86. package/src/index.ts +11 -0
  87. package/src/radiogroup.ts +176 -0
  88. package/src/select.ts +10 -2
  89. package/src/table.ts +46 -1
  90. package/src/tabs.ts +7 -2
  91. package/src/testSetup.ts +30 -28
  92. package/src/types.ts +21 -0
  93. package/src/user.ts +25 -7
  94. package/dist/combobox.main.js.map +0 -1
  95. package/dist/combobox.module.js +0 -167
  96. package/dist/combobox.module.js.map +0 -1
  97. package/dist/events.main.js.map +0 -1
  98. package/dist/events.module.js +0 -112
  99. package/dist/events.module.js.map +0 -1
  100. package/dist/gridlist.main.js.map +0 -1
  101. package/dist/gridlist.module.js +0 -149
  102. package/dist/gridlist.module.js.map +0 -1
  103. package/dist/listbox.main.js.map +0 -1
  104. package/dist/listbox.module.js +0 -138
  105. package/dist/listbox.module.js.map +0 -1
  106. package/dist/menu.main.js.map +0 -1
  107. package/dist/menu.module.js +0 -269
  108. package/dist/menu.module.js.map +0 -1
  109. package/dist/select.main.js.map +0 -1
  110. package/dist/select.module.js +0 -158
  111. package/dist/select.module.js.map +0 -1
  112. package/dist/table.main.js.map +0 -1
  113. package/dist/table.mjs +0 -290
  114. package/dist/table.module.js.map +0 -1
  115. package/dist/tabs.main.js.map +0 -1
  116. package/dist/tabs.module.js +0 -128
  117. package/dist/tabs.module.js.map +0 -1
  118. package/dist/testSetup.main.js +0 -78
  119. package/dist/testSetup.main.js.map +0 -1
  120. package/dist/testSetup.mjs +0 -72
  121. package/dist/testSetup.module.js +0 -72
  122. package/dist/testSetup.module.js.map +0 -1
  123. package/dist/tree.main.js.map +0 -1
  124. package/dist/tree.module.js +0 -179
  125. package/dist/tree.module.js.map +0 -1
  126. package/dist/types.d.ts +0 -694
  127. package/dist/types.d.ts.map +0 -1
  128. package/dist/user.main.js +0 -76
  129. package/dist/user.main.js.map +0 -1
  130. package/dist/user.mjs +0 -67
  131. package/dist/user.module.js +0 -67
  132. package/dist/user.module.js.map +0 -1
  133. package/dist/userEventMaps.module.js +0 -38
@@ -1,12 +1,12 @@
1
- var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
- var $bAxU9$testinglibraryreact = require("@testing-library/react");
1
+ var $01a4eeee86094c77$exports = require("./events.cjs");
2
+ var $ivkeh$testinglibraryreact = require("@testing-library/react");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "ListBoxTester", () => $8ac94de7d2631d04$export$54c24f7ee8577f4f);
9
+ $parcel$export(module.exports, "ListBoxTester", function () { return $c0f7ae61eac30828$export$54c24f7ee8577f4f; });
10
10
  /*
11
11
  * Copyright 2024 Adobe. All rights reserved.
12
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,14 @@ $parcel$export(module.exports, "ListBoxTester", () => $8ac94de7d2631d04$export$5
19
19
  * governing permissions and limitations under the License.
20
20
  */
21
21
 
22
- class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
22
+ class $c0f7ae61eac30828$export$54c24f7ee8577f4f {
23
+ constructor(opts){
24
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
25
+ this.user = user;
26
+ this._interactionType = interactionType || 'mouse';
27
+ this._listbox = root;
28
+ this._advanceTimer = advanceTimer;
29
+ }
23
30
  /**
24
31
  * Set the interaction type used by the listbox tester.
25
32
  */ setInteractionType(type) {
@@ -33,19 +40,19 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
33
40
  let option;
34
41
  let options = this.options();
35
42
  if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
36
- else if (typeof optionIndexOrText === 'string') option = (0, $bAxU9$testinglibraryreact.within)(this.listbox).getByText(optionIndexOrText).closest('[role=option]');
43
+ else if (typeof optionIndexOrText === 'string') option = (0, $ivkeh$testinglibraryreact.within)(this.listbox).getByText(optionIndexOrText).closest('[role=option]');
37
44
  return option;
38
45
  }
39
46
  // TODO: this is basically the same as menu except for the error message, refactor later so that they share
40
47
  // TODO: this also doesn't support grid layout yet
41
48
  async keyboardNavigateToOption(opts) {
42
49
  let { option: option, selectionOnNav: selectionOnNav = 'default' } = opts;
43
- let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
50
+ let altKey = (0, $01a4eeee86094c77$exports.getAltKey)();
44
51
  let options = this.options();
45
52
  let targetIndex = options.indexOf(option);
46
53
  if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
47
54
  if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
48
- (0, $bAxU9$testinglibraryreact.act)(()=>this._listbox.focus());
55
+ (0, $ivkeh$testinglibraryreact.act)(()=>this._listbox.focus());
49
56
  await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
50
57
  }
51
58
  let currIndex = options.indexOf(document.activeElement);
@@ -59,14 +66,14 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
59
66
  * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
60
67
  */ async toggleOptionSelection(opts) {
61
68
  let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
62
- let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
63
- let metaKey = (0, $5a8bfe1663b8366d$exports.getMetaKey)();
69
+ let altKey = (0, $01a4eeee86094c77$exports.getAltKey)();
70
+ let metaKey = (0, $01a4eeee86094c77$exports.getMetaKey)();
64
71
  if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
65
72
  optionIndexOrText: option
66
73
  });
67
74
  if (!option) throw new Error('Target option not found in the listbox.');
68
75
  if (interactionType === 'keyboard') {
69
- if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
76
+ if (option?.getAttribute('aria-disabled') === 'true') return;
70
77
  await this.keyboardNavigateToOption({
71
78
  option: option,
72
79
  selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
@@ -76,7 +83,7 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
76
83
  if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
77
84
  } else if (needsLongPress && interactionType === 'touch') {
78
85
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
79
- await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
86
+ await (0, $01a4eeee86094c77$exports.triggerLongPress)({
80
87
  element: option,
81
88
  advanceTimer: this._advanceTimer,
82
89
  pointerOpts: {
@@ -85,7 +92,7 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
85
92
  });
86
93
  } else {
87
94
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
88
- await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
95
+ await (0, $01a4eeee86094c77$exports.pressElement)(this.user, option, interactionType);
89
96
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
90
97
  }
91
98
  }
@@ -99,13 +106,13 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
99
106
  if (!option) throw new Error('Target option not found in the listbox.');
100
107
  if (needsDoubleClick) await this.user.dblClick(option);
101
108
  else if (interactionType === 'keyboard') {
102
- if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
109
+ if (option?.getAttribute('aria-disabled') === 'true') return;
103
110
  await this.keyboardNavigateToOption({
104
111
  option: option,
105
112
  selectionOnNav: 'none'
106
113
  });
107
114
  await this.user.keyboard('[Enter]');
108
- } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
115
+ } else await (0, $01a4eeee86094c77$exports.pressElement)(this.user, option, interactionType);
109
116
  }
110
117
  /**
111
118
  * Returns the listbox.
@@ -117,7 +124,7 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
117
124
  */ options(opts = {}) {
118
125
  let { element: element = this._listbox } = opts;
119
126
  let options = [];
120
- if (element) options = (0, $bAxU9$testinglibraryreact.within)(element).queryAllByRole('option');
127
+ if (element) options = (0, $ivkeh$testinglibraryreact.within)(element).queryAllByRole('option');
121
128
  return options;
122
129
  }
123
130
  /**
@@ -128,16 +135,9 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
128
135
  /**
129
136
  * Returns the listbox's sections if any.
130
137
  */ get sections() {
131
- return (0, $bAxU9$testinglibraryreact.within)(this._listbox).queryAllByRole('group');
132
- }
133
- constructor(opts){
134
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
135
- this.user = user;
136
- this._interactionType = interactionType || 'mouse';
137
- this._listbox = root;
138
- this._advanceTimer = advanceTimer;
138
+ return (0, $ivkeh$testinglibraryreact.within)(this._listbox).queryAllByRole('group');
139
139
  }
140
140
  }
141
141
 
142
142
 
143
- //# sourceMappingURL=listbox.main.js.map
143
+ //# sourceMappingURL=listbox.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0CM,MAAM;IAMX,YAAY,IAAuB,CAAE;QACnC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,Q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OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,QAAQ,OAAgC,CAAC,CAAC,EAAiB;QACzD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,EAAC,GAAG;QAChC,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,kBAAiC;QACnC,OAAO,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IAC5E;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC9C;AACF","sources":["packages/@react-aria/test-utils/src/listbox.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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {ListBoxTesterOpts, UserOpts} from './types';\n\ninterface ListBoxToggleOptionOpts {\n /**\n * What interaction type to use when toggling selection for an option. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the option to toggle selection for.\n */\n option: number | string | HTMLElement,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter',\n /**\n * Whether the option needs to be long pressed to be selected. Depends on the listbox's implementation.\n */\n needsLongPress?: boolean,\n /**\n * Whether the listbox has a selectionBehavior of \"toggle\" or \"replace\" (aka highlight selection). This affects the user operations\n * required to toggle option selection by adding modifier keys during user actions, useful when performing multi-option selection in a \"selectionBehavior: 'replace'\" listbox.\n * If you would like to still simulate user actions (aka press) without these modifiers keys for a \"selectionBehavior: replace\" listbox, simply omit this option.\n * See the [RAC Listbox docs](https://react-spectrum.adobe.com/react-aria/ListBox.html#selection-behavior) for more info on this behavior.\n *\n * @default 'toggle'\n */\n selectionBehavior?: 'toggle' | 'replace'\n}\n\ninterface ListBoxOptionActionOpts extends Omit<ListBoxToggleOptionOpts, 'keyboardActivation' | 'needsLongPress'> {\n /**\n * Whether or not the option needs a double click to trigger the option action. Depends on the listbox's implementation.\n */\n needsDoubleClick?: boolean\n}\n\nexport class ListBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _listbox: HTMLElement;\n\n constructor(opts: ListBoxTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._listbox = root;\n this._advanceTimer = advanceTimer;\n }\n\n /**\n * Set the interaction type used by the listbox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: now that we have listbox, perhaps select can make use of this tester internally\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string') {\n option = (within(this.listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: this is basically the same as menu except for the error message, refactor later so that they share\n // TODO: this also doesn't support grid layout yet\n private async keyboardNavigateToOption(opts: {option: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {option, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n\n if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {\n act(() => this._listbox.focus());\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n }\n\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n\n let direction = targetIndex > currIndex ? 'down' : 'up';\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async toggleOptionSelection(opts: ListBoxToggleOptionOpts): Promise<void> {\n let {\n option,\n needsLongPress,\n keyboardActivation = 'Enter',\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard(`[${keyboardActivation}]`);\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n } else {\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n await triggerLongPress({element: option, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, option, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n /**\n * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async triggerOptionAction(opts: ListBoxOptionActionOpts): Promise<void> {\n let {\n option,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(option);\n } else if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, option, interactionType);\n }\n }\n\n /**\n * Returns the listbox.\n */\n get listbox(): HTMLElement {\n return this._listbox;\n }\n\n /**\n * Returns the listbox options. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this._listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the listbox's selected options if any.\n */\n get selectedOptions(): HTMLElement[] {\n return this.options().filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the listbox's sections if any.\n */\n get sections(): HTMLElement[] {\n return within(this._listbox).queryAllByRole('group');\n }\n}\n"],"names":[],"version":3,"file":"listbox.cjs.map"}
@@ -1,5 +1,5 @@
1
- import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
2
- import {within as $fzAUL$within, act as $fzAUL$act} from "@testing-library/react";
1
+ import {getAltKey as $22d7d9b763402afa$export$6fc0ccaebd758b9d, getMetaKey as $22d7d9b763402afa$export$7943c508934e27ce, pressElement as $22d7d9b763402afa$export$6ffa3eb717517feb, triggerLongPress as $22d7d9b763402afa$export$3a22a5a9bc0fd3b} from "./events.js";
2
+ import {within as $6BrfQ$within, act as $6BrfQ$act} from "@testing-library/react";
3
3
 
4
4
  /*
5
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -13,7 +13,14 @@ import {within as $fzAUL$within, act as $fzAUL$act} from "@testing-library/react
13
13
  * governing permissions and limitations under the License.
14
14
  */
15
15
 
16
- class $bbf72b714b632b99$export$54c24f7ee8577f4f {
16
+ class $8d2aea0e455eb460$export$54c24f7ee8577f4f {
17
+ constructor(opts){
18
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
19
+ this.user = user;
20
+ this._interactionType = interactionType || 'mouse';
21
+ this._listbox = root;
22
+ this._advanceTimer = advanceTimer;
23
+ }
17
24
  /**
18
25
  * Set the interaction type used by the listbox tester.
19
26
  */ setInteractionType(type) {
@@ -27,19 +34,19 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
27
34
  let option;
28
35
  let options = this.options();
29
36
  if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
30
- else if (typeof optionIndexOrText === 'string') option = (0, $fzAUL$within)(this.listbox).getByText(optionIndexOrText).closest('[role=option]');
37
+ else if (typeof optionIndexOrText === 'string') option = (0, $6BrfQ$within)(this.listbox).getByText(optionIndexOrText).closest('[role=option]');
31
38
  return option;
32
39
  }
33
40
  // TODO: this is basically the same as menu except for the error message, refactor later so that they share
34
41
  // TODO: this also doesn't support grid layout yet
35
42
  async keyboardNavigateToOption(opts) {
36
43
  let { option: option, selectionOnNav: selectionOnNav = 'default' } = opts;
37
- let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
44
+ let altKey = (0, $22d7d9b763402afa$export$6fc0ccaebd758b9d)();
38
45
  let options = this.options();
39
46
  let targetIndex = options.indexOf(option);
40
47
  if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
41
48
  if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
42
- (0, $fzAUL$act)(()=>this._listbox.focus());
49
+ (0, $6BrfQ$act)(()=>this._listbox.focus());
43
50
  await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
44
51
  }
45
52
  let currIndex = options.indexOf(document.activeElement);
@@ -53,14 +60,14 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
53
60
  * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
54
61
  */ async toggleOptionSelection(opts) {
55
62
  let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
56
- let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
57
- let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
63
+ let altKey = (0, $22d7d9b763402afa$export$6fc0ccaebd758b9d)();
64
+ let metaKey = (0, $22d7d9b763402afa$export$7943c508934e27ce)();
58
65
  if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
59
66
  optionIndexOrText: option
60
67
  });
61
68
  if (!option) throw new Error('Target option not found in the listbox.');
62
69
  if (interactionType === 'keyboard') {
63
- if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
70
+ if (option?.getAttribute('aria-disabled') === 'true') return;
64
71
  await this.keyboardNavigateToOption({
65
72
  option: option,
66
73
  selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
@@ -70,7 +77,7 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
70
77
  if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
71
78
  } else if (needsLongPress && interactionType === 'touch') {
72
79
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
73
- await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
80
+ await (0, $22d7d9b763402afa$export$3a22a5a9bc0fd3b)({
74
81
  element: option,
75
82
  advanceTimer: this._advanceTimer,
76
83
  pointerOpts: {
@@ -79,7 +86,7 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
79
86
  });
80
87
  } else {
81
88
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
82
- await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
89
+ await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, option, interactionType);
83
90
  if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
84
91
  }
85
92
  }
@@ -93,13 +100,13 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
93
100
  if (!option) throw new Error('Target option not found in the listbox.');
94
101
  if (needsDoubleClick) await this.user.dblClick(option);
95
102
  else if (interactionType === 'keyboard') {
96
- if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
103
+ if (option?.getAttribute('aria-disabled') === 'true') return;
97
104
  await this.keyboardNavigateToOption({
98
105
  option: option,
99
106
  selectionOnNav: 'none'
100
107
  });
101
108
  await this.user.keyboard('[Enter]');
102
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
109
+ } else await (0, $22d7d9b763402afa$export$6ffa3eb717517feb)(this.user, option, interactionType);
103
110
  }
104
111
  /**
105
112
  * Returns the listbox.
@@ -111,7 +118,7 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
111
118
  */ options(opts = {}) {
112
119
  let { element: element = this._listbox } = opts;
113
120
  let options = [];
114
- if (element) options = (0, $fzAUL$within)(element).queryAllByRole('option');
121
+ if (element) options = (0, $6BrfQ$within)(element).queryAllByRole('option');
115
122
  return options;
116
123
  }
117
124
  /**
@@ -122,17 +129,10 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
122
129
  /**
123
130
  * Returns the listbox's sections if any.
124
131
  */ get sections() {
125
- return (0, $fzAUL$within)(this._listbox).queryAllByRole('group');
126
- }
127
- constructor(opts){
128
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
129
- this.user = user;
130
- this._interactionType = interactionType || 'mouse';
131
- this._listbox = root;
132
- this._advanceTimer = advanceTimer;
132
+ return (0, $6BrfQ$within)(this._listbox).queryAllByRole('group');
133
133
  }
134
134
  }
135
135
 
136
136
 
137
- export {$bbf72b714b632b99$export$54c24f7ee8577f4f as ListBoxTester};
138
- //# sourceMappingURL=listbox.module.js.map
137
+ export {$8d2aea0e455eb460$export$54c24f7ee8577f4f as ListBoxTester};
138
+ //# sourceMappingURL=listbox.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0CM,MAAM;IAMX,YAAY,IAAuB,CAAE;QACnC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,CAAC,aAAa,GAAG;IACvB;IAEA;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,wFAAwF;IACxF;;GAEC,GACD,WAAW,IAA0C,EAAe;QAClE,IAAI,qBACF,iBAAiB,EAClB,GAAG;QAEJ,IAAI;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAE1B,IA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C,OAAO,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IAC5E;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC9C;AACF","sources":["packages/@react-aria/test-utils/src/listbox.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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {ListBoxTesterOpts, UserOpts} from './types';\n\ninterface ListBoxToggleOptionOpts {\n /**\n * What interaction type to use when toggling selection for an option. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the option to toggle selection for.\n */\n option: number | string | HTMLElement,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter',\n /**\n * Whether the option needs to be long pressed to be selected. Depends on the listbox's implementation.\n */\n needsLongPress?: boolean,\n /**\n * Whether the listbox has a selectionBehavior of \"toggle\" or \"replace\" (aka highlight selection). This affects the user operations\n * required to toggle option selection by adding modifier keys during user actions, useful when performing multi-option selection in a \"selectionBehavior: 'replace'\" listbox.\n * If you would like to still simulate user actions (aka press) without these modifiers keys for a \"selectionBehavior: replace\" listbox, simply omit this option.\n * See the [RAC Listbox docs](https://react-spectrum.adobe.com/react-aria/ListBox.html#selection-behavior) for more info on this behavior.\n *\n * @default 'toggle'\n */\n selectionBehavior?: 'toggle' | 'replace'\n}\n\ninterface ListBoxOptionActionOpts extends Omit<ListBoxToggleOptionOpts, 'keyboardActivation' | 'needsLongPress'> {\n /**\n * Whether or not the option needs a double click to trigger the option action. Depends on the listbox's implementation.\n */\n needsDoubleClick?: boolean\n}\n\nexport class ListBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _listbox: HTMLElement;\n\n constructor(opts: ListBoxTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._listbox = root;\n this._advanceTimer = advanceTimer;\n }\n\n /**\n * Set the interaction type used by the listbox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: now that we have listbox, perhaps select can make use of this tester internally\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string') {\n option = (within(this.listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: this is basically the same as menu except for the error message, refactor later so that they share\n // TODO: this also doesn't support grid layout yet\n private async keyboardNavigateToOption(opts: {option: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {option, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n\n if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {\n act(() => this._listbox.focus());\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n }\n\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n\n let direction = targetIndex > currIndex ? 'down' : 'up';\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async toggleOptionSelection(opts: ListBoxToggleOptionOpts): Promise<void> {\n let {\n option,\n needsLongPress,\n keyboardActivation = 'Enter',\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard(`[${keyboardActivation}]`);\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n } else {\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n await triggerLongPress({element: option, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, option, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n /**\n * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async triggerOptionAction(opts: ListBoxOptionActionOpts): Promise<void> {\n let {\n option,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(option);\n } else if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, option, interactionType);\n }\n }\n\n /**\n * Returns the listbox.\n */\n get listbox(): HTMLElement {\n return this._listbox;\n }\n\n /**\n * Returns the listbox options. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this._listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the listbox's selected options if any.\n */\n get selectedOptions(): HTMLElement[] {\n return this.options().filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the listbox's sections if any.\n */\n get sections(): HTMLElement[] {\n return within(this._listbox).queryAllByRole('group');\n }\n}\n"],"names":[],"version":3,"file":"listbox.js.map"}
@@ -1,12 +1,12 @@
1
- var $5a8bfe1663b8366d$exports = require("./events.main.js");
2
- var $l5sJH$testinglibraryreact = require("@testing-library/react");
1
+ var $01a4eeee86094c77$exports = require("./events.cjs");
2
+ var $k2SXY$testinglibraryreact = require("@testing-library/react");
3
3
 
4
4
 
5
5
  function $parcel$export(e, n, v, s) {
6
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
7
  }
8
8
 
9
- $parcel$export(module.exports, "MenuTester", () => $31965f39292c8e99$export$f73bbc9212ed861e);
9
+ $parcel$export(module.exports, "MenuTester", function () { return $72b6079685b45ac0$export$f73bbc9212ed861e; });
10
10
  /*
11
11
  * Copyright 2024 Adobe. All rights reserved.
12
12
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,24 @@ $parcel$export(module.exports, "MenuTester", () => $31965f39292c8e99$export$f73b
19
19
  * governing permissions and limitations under the License.
20
20
  */
21
21
 
22
- class $31965f39292c8e99$export$f73bbc9212ed861e {
22
+ class $72b6079685b45ac0$export$f73bbc9212ed861e {
23
+ constructor(opts){
24
+ this._isSubmenu = false;
25
+ let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer, isSubmenu: isSubmenu, rootMenu: rootMenu } = opts;
26
+ this.user = user;
27
+ this._interactionType = interactionType || 'mouse';
28
+ this._advanceTimer = advanceTimer;
29
+ // Handle case where a submenu trigger is provided to the tester
30
+ if (root.getAttribute('role') === 'menuitem') this._trigger = root;
31
+ else {
32
+ // Handle case where element provided is a wrapper of the trigger button
33
+ let trigger = (0, $k2SXY$testinglibraryreact.within)(root).queryByRole('button');
34
+ if (trigger) this._trigger = trigger;
35
+ else this._trigger = root;
36
+ }
37
+ this._isSubmenu = isSubmenu || false;
38
+ this._rootMenu = rootMenu;
39
+ }
23
40
  /**
24
41
  * Set the interaction type used by the menu tester.
25
42
  */ setInteractionType(type) {
@@ -37,7 +54,7 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
37
54
  if (needsLongPress) {
38
55
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
39
56
  let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';
40
- await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
57
+ await (0, $01a4eeee86094c77$exports.triggerLongPress)({
41
58
  element: trigger,
42
59
  advanceTimer: this._advanceTimer,
43
60
  pointerOpts: {
@@ -51,23 +68,23 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
51
68
  });
52
69
  } else if (interactionType === 'keyboard' && !isDisabled) {
53
70
  if (direction === 'up') {
54
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
71
+ (0, $k2SXY$testinglibraryreact.act)(()=>trigger.focus());
55
72
  await this.user.keyboard('[ArrowUp]');
56
73
  } else if (direction === 'down') {
57
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
74
+ (0, $k2SXY$testinglibraryreact.act)(()=>trigger.focus());
58
75
  await this.user.keyboard('[ArrowDown]');
59
76
  } else {
60
- (0, $l5sJH$testinglibraryreact.act)(()=>trigger.focus());
77
+ (0, $k2SXY$testinglibraryreact.act)(()=>trigger.focus());
61
78
  await this.user.keyboard('[Enter]');
62
79
  }
63
80
  }
64
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
81
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
65
82
  if (trigger.getAttribute('aria-controls') == null && !isDisabled) throw new Error('No aria-controls found on menu trigger element.');
66
83
  else return true;
67
84
  });
68
85
  if (!isDisabled) {
69
86
  let menuId = trigger.getAttribute('aria-controls');
70
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
87
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
71
88
  if (!menuId || document.getElementById(menuId) == null) throw new Error(`Menu with id of ${menuId} not found in document.`);
72
89
  else return true;
73
90
  });
@@ -81,7 +98,7 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
81
98
  let options = this.options();
82
99
  let menu = this.menu;
83
100
  if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
84
- else if (typeof optionIndexOrText === 'string' && menu != null) option = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
101
+ else if (typeof optionIndexOrText === 'string' && menu != null) option = (0, $k2SXY$testinglibraryreact.within)(menu).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]');
85
102
  return option;
86
103
  }
87
104
  // TODO: also very similar to select, barring potential long press support
@@ -103,8 +120,8 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
103
120
  });
104
121
  if (!option) throw new Error('Target option not found in the menu.');
105
122
  if (interactionType === 'keyboard') {
106
- if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
107
- if (document.activeElement !== menu && !menu.contains(document.activeElement)) (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
123
+ if (option?.getAttribute('aria-disabled') === 'true') return;
124
+ if (document.activeElement !== menu && !menu.contains(document.activeElement)) (0, $k2SXY$testinglibraryreact.act)(()=>menu.focus());
108
125
  await this.keyboardNavigateToOption({
109
126
  option: option
110
127
  });
@@ -119,26 +136,25 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
119
136
  if (!(menuSelectionMode === 'single' && !closesOnSelect) && !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))) {
120
137
  // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait
121
138
  // for focus to be coerced to somewhere else in place of running all timers.
122
- if (this._isSubmenu) await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
139
+ if (this._isSubmenu) await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
123
140
  if (document.activeElement === document.body) throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');
124
141
  else return true;
125
142
  });
126
143
  // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that
127
144
  // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes
128
145
  // but we can't really know where so just make sure it doesn't get lost to the body.
129
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
146
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
130
147
  if (document.activeElement === option) throw new Error('Expected focus after selecting an option to move away from the option.');
131
148
  else return true;
132
149
  });
133
150
  // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should
134
151
  // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu
135
- if (this._isSubmenu) await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
136
- var _this__rootMenu;
137
- if (document.activeElement === this.trigger || ((_this__rootMenu = this._rootMenu) === null || _this__rootMenu === void 0 ? void 0 : _this__rootMenu.contains(document.activeElement))) throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');
152
+ if (this._isSubmenu) await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
153
+ if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');
138
154
  else return true;
139
155
  });
140
156
  // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM
141
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
157
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
142
158
  if (document.activeElement === document.body) throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');
143
159
  else return true;
144
160
  });
@@ -158,8 +174,8 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
158
174
  if (!isDisabled) {
159
175
  let menu = this.menu;
160
176
  if (menu) {
161
- if (typeof submenuTrigger === 'string') submenuTrigger = (0, $l5sJH$testinglibraryreact.within)(menu).getByText(submenuTrigger).closest('[role=menuitem]');
162
- let submenuTriggerTester = new $31965f39292c8e99$export$f73bbc9212ed861e({
177
+ if (typeof submenuTrigger === 'string') submenuTrigger = (0, $k2SXY$testinglibraryreact.within)(menu).getByText(submenuTrigger).closest('[role=menuitem]');
178
+ let submenuTriggerTester = new $72b6079685b45ac0$export$f73bbc9212ed861e({
163
179
  user: this.user,
164
180
  interactionType: this._interactionType,
165
181
  root: submenuTrigger,
@@ -176,9 +192,8 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
176
192
  });
177
193
  await this.user.keyboard('[ArrowRight]');
178
194
  } else await submenuTriggerTester.open();
179
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
180
- var _submenuTriggerTester__trigger;
181
- if (((_submenuTriggerTester__trigger = submenuTriggerTester._trigger) === null || _submenuTriggerTester__trigger === void 0 ? void 0 : _submenuTriggerTester__trigger.getAttribute('aria-expanded')) !== 'true') throw new Error('aria-expanded for the submenu trigger wasn\'t changed to "true", unable to confirm the existance of the submenu');
195
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
196
+ if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') throw new Error('aria-expanded for the submenu trigger wasn\'t changed to "true", unable to confirm the existance of the submenu');
182
197
  else return true;
183
198
  });
184
199
  return submenuTriggerTester;
@@ -202,9 +217,9 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
202
217
  */ async close() {
203
218
  let menu = this.menu;
204
219
  if (menu) {
205
- (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
220
+ (0, $k2SXY$testinglibraryreact.act)(()=>menu.focus());
206
221
  await this.user.keyboard('[Escape]');
207
- await (0, $l5sJH$testinglibraryreact.waitFor)(()=>{
222
+ await (0, $k2SXY$testinglibraryreact.waitFor)(()=>{
208
223
  if (document.activeElement !== this.trigger) throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);
209
224
  else return true;
210
225
  });
@@ -227,7 +242,7 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
227
242
  * Returns the menu's sections if any.
228
243
  */ get sections() {
229
244
  let menu = this.menu;
230
- if (menu) return (0, $l5sJH$testinglibraryreact.within)(menu).queryAllByRole('group');
245
+ if (menu) return (0, $k2SXY$testinglibraryreact.within)(menu).queryAllByRole('group');
231
246
  else return [];
232
247
  }
233
248
  /**
@@ -236,10 +251,10 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
236
251
  let { element: element = this.menu } = opts;
237
252
  let options = [];
238
253
  if (element) {
239
- options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitem');
254
+ options = (0, $k2SXY$testinglibraryreact.within)(element).queryAllByRole('menuitem');
240
255
  if (options.length === 0) {
241
- options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitemradio');
242
- if (options.length === 0) options = (0, $l5sJH$testinglibraryreact.within)(element).queryAllByRole('menuitemcheckbox');
256
+ options = (0, $k2SXY$testinglibraryreact.within)(element).queryAllByRole('menuitemradio');
257
+ if (options.length === 0) options = (0, $k2SXY$testinglibraryreact.within)(element).queryAllByRole('menuitemcheckbox');
243
258
  }
244
259
  }
245
260
  return options;
@@ -251,24 +266,7 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
251
266
  if (options.length > 0) return options.filter((item)=>item.getAttribute('aria-haspopup') != null);
252
267
  return [];
253
268
  }
254
- constructor(opts){
255
- this._isSubmenu = false;
256
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer, isSubmenu: isSubmenu, rootMenu: rootMenu } = opts;
257
- this.user = user;
258
- this._interactionType = interactionType || 'mouse';
259
- this._advanceTimer = advanceTimer;
260
- // Handle case where a submenu trigger is provided to the tester
261
- if (root.getAttribute('role') === 'menuitem') this._trigger = root;
262
- else {
263
- // Handle case where element provided is a wrapper of the trigger button
264
- let trigger = (0, $l5sJH$testinglibraryreact.within)(root).queryByRole('button');
265
- if (trigger) this._trigger = trigger;
266
- else this._trigger = root;
267
- }
268
- this._isSubmenu = isSubmenu || false;
269
- this._rootMenu = rootMenu;
270
- }
271
269
  }
272
270
 
273
271
 
274
- //# sourceMappingURL=menu.main.js.map
272
+ //# sourceMappingURL=menu.cjs.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkDM,MAAM;IAQX,YAAY,IAAoB,CAAE;aAH1B,aAAsB;QAI5B,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,aAAE,SAAS,YAAE,QAAQ,EAAC,GAAG;QACvE,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QAErB,gEAAgE;QAChE,IAAI,KAAK,YAAY,CAAC,YAAY,YAChC,IAAI,CAA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ACnC,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,QAAQ,MAAM,GAAG,GACnB,OAAO,QAAQ,MAAM,CAAC,CAAA,OAAQ,KAAK,YAAY,CAAC,oBAAoB;QAGtE,OAAO,EAAE;IACX;AACF","sources":["packages/@react-aria/test-utils/src/menu.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, waitFor, within} from '@testing-library/react';\nimport {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n private _rootMenu: HTMLElement | undefined;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu, rootMenu} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\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 this._isSubmenu = isSubmenu || false;\n this._rootMenu = rootMenu;\n }\n\n /**\n * Set the interaction type used by the menu tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}): Promise<void> {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts): Promise<void> {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu && !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n // This chain of waitFors is needed in place of running all timers since we don't know how long transitions may take, or what action\n // the menu option select may trigger.\n if (\n !(menuSelectionMode === 'single' && !closesOnSelect) &&\n !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))\n ) {\n // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait\n // for focus to be coerced to somewhere else in place of running all timers.\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');\n } else {\n return true;\n }\n });\n }\n\n // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that\n // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes\n // but we can't really know where so just make sure it doesn't get lost to the body.\n await waitFor(() => {\n if (document.activeElement === option) {\n throw new Error('Expected focus after selecting an option to move away from the option.');\n } else {\n return true;\n }\n });\n\n // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should\n // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {\n throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');\n } else {\n return true;\n }\n });\n }\n\n // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n }\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n /**\n * Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({\n user: this.user,\n interactionType: this._interactionType,\n root: submenuTrigger,\n isSubmenu: true,\n advanceTimer: this._advanceTimer,\n rootMenu: (this._isSubmenu ? this._rootMenu : this.menu) || undefined\n });\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n } else {\n await submenuTriggerTester.open();\n }\n\n await waitFor(() => {\n if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') {\n throw new Error('aria-expanded for the submenu trigger wasn\\'t changed to \"true\", unable to confirm the existance of the submenu');\n } else {\n return true;\n }\n });\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close(): Promise<void> {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n }\n\n /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.cjs.map"}