@react-aria/test-utils 1.0.0-beta.2 → 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.
- package/dist/import.mjs +5 -5
- package/dist/main.js +9 -9
- package/dist/module.js +5 -5
- package/dist/{checkboxgroup.main.js → private/checkboxgroup.cjs} +19 -19
- package/dist/private/checkboxgroup.cjs.map +1 -0
- package/dist/{checkboxgroup.mjs → private/checkboxgroup.js} +19 -19
- package/dist/private/checkboxgroup.js.map +1 -0
- package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
- package/dist/private/combobox.cjs.map +1 -0
- package/dist/{combobox.mjs → private/combobox.js} +35 -35
- package/dist/private/combobox.js.map +1 -0
- package/dist/{dialog.main.js → private/dialog.cjs} +19 -19
- package/dist/private/dialog.cjs.map +1 -0
- package/dist/{dialog.mjs → private/dialog.js} +19 -19
- package/dist/private/dialog.js.map +1 -0
- package/dist/{events.main.js → private/events.cjs} +32 -34
- package/dist/private/events.cjs.map +1 -0
- package/dist/{events.mjs → private/events.js} +29 -31
- package/dist/private/events.js.map +1 -0
- package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
- package/dist/private/gridlist.cjs.map +1 -0
- package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
- package/dist/private/gridlist.js.map +1 -0
- package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
- package/dist/private/listbox.cjs.map +1 -0
- package/dist/{listbox.mjs → private/listbox.js} +24 -24
- package/dist/private/listbox.js.map +1 -0
- package/dist/{menu.main.js → private/menu.cjs} +46 -48
- package/dist/private/menu.cjs.map +1 -0
- package/dist/{menu.mjs → private/menu.js} +46 -48
- package/dist/private/menu.js.map +1 -0
- package/dist/{radiogroup.main.js → private/radiogroup.cjs} +21 -24
- package/dist/private/radiogroup.cjs.map +1 -0
- package/dist/{radiogroup.mjs → private/radiogroup.js} +21 -24
- package/dist/private/radiogroup.js.map +1 -0
- package/dist/{select.main.js → private/select.cjs} +31 -29
- package/dist/private/select.cjs.map +1 -0
- package/dist/{select.module.js → private/select.js} +31 -29
- package/dist/private/select.js.map +1 -0
- package/dist/{table.main.js → private/table.cjs} +82 -57
- package/dist/private/table.cjs.map +1 -0
- package/dist/{table.module.js → private/table.js} +82 -57
- package/dist/private/table.js.map +1 -0
- package/dist/{tabs.main.js → private/tabs.cjs} +21 -25
- package/dist/private/tabs.cjs.map +1 -0
- package/dist/{tabs.mjs → private/tabs.js} +21 -25
- package/dist/private/tabs.js.map +1 -0
- package/dist/{testSetup.main.js → private/testSetup.cjs} +27 -19
- package/dist/private/testSetup.cjs.map +1 -0
- package/dist/{testSetup.module.js → private/testSetup.js} +26 -18
- package/dist/private/testSetup.js.map +1 -0
- package/dist/{tree.main.js → private/tree.cjs} +34 -35
- package/dist/private/tree.cjs.map +1 -0
- package/dist/{tree.mjs → private/tree.js} +34 -35
- package/dist/private/tree.js.map +1 -0
- package/dist/private/user.cjs +85 -0
- package/dist/private/user.cjs.map +1 -0
- package/dist/private/user.js +76 -0
- package/dist/private/user.js.map +1 -0
- package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
- package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
- package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
- package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
- package/dist/types/src/checkboxgroup.d.ts +45 -0
- package/dist/types/src/combobox.d.ts +75 -0
- package/dist/types/src/dialog.d.ts +36 -0
- package/dist/types/src/events.d.ts +25 -0
- package/dist/types/src/gridlist.d.ts +51 -0
- package/dist/types/src/index.d.ts +16 -0
- package/dist/types/src/listbox.d.ts +80 -0
- package/dist/types/src/menu.d.ts +102 -0
- package/dist/types/src/radiogroup.d.ts +46 -0
- package/dist/types/src/select.d.ts +67 -0
- package/dist/types/src/table.d.ts +104 -0
- package/dist/types/src/tabs.d.ts +58 -0
- package/dist/types/src/testSetup.d.ts +6 -0
- package/dist/types/src/tree.d.ts +57 -0
- package/dist/types/src/types.d.ts +136 -0
- package/dist/types/src/user.d.ts +47 -0
- package/dist/types/src/userEventMaps.d.ts +2 -0
- package/package.json +7 -7
- package/src/select.ts +10 -2
- package/src/table.ts +46 -1
- package/dist/checkboxgroup.main.js.map +0 -1
- package/dist/checkboxgroup.module.js +0 -99
- package/dist/checkboxgroup.module.js.map +0 -1
- package/dist/combobox.main.js.map +0 -1
- package/dist/combobox.module.js +0 -167
- package/dist/combobox.module.js.map +0 -1
- package/dist/dialog.main.js.map +0 -1
- package/dist/dialog.module.js +0 -100
- package/dist/dialog.module.js.map +0 -1
- package/dist/events.main.js.map +0 -1
- package/dist/events.module.js +0 -112
- package/dist/events.module.js.map +0 -1
- package/dist/gridlist.main.js.map +0 -1
- package/dist/gridlist.module.js +0 -149
- package/dist/gridlist.module.js.map +0 -1
- package/dist/listbox.main.js.map +0 -1
- package/dist/listbox.module.js +0 -138
- package/dist/listbox.module.js.map +0 -1
- package/dist/menu.main.js.map +0 -1
- package/dist/menu.module.js +0 -269
- package/dist/menu.module.js.map +0 -1
- package/dist/radiogroup.main.js.map +0 -1
- package/dist/radiogroup.module.js +0 -118
- package/dist/radiogroup.module.js.map +0 -1
- package/dist/select.main.js.map +0 -1
- package/dist/select.mjs +0 -158
- package/dist/select.module.js.map +0 -1
- package/dist/table.main.js.map +0 -1
- package/dist/table.mjs +0 -290
- package/dist/table.module.js.map +0 -1
- package/dist/tabs.main.js.map +0 -1
- package/dist/tabs.module.js +0 -130
- package/dist/tabs.module.js.map +0 -1
- package/dist/testSetup.main.js.map +0 -1
- package/dist/testSetup.mjs +0 -73
- package/dist/testSetup.module.js.map +0 -1
- package/dist/tree.main.js.map +0 -1
- package/dist/tree.module.js +0 -179
- package/dist/tree.module.js.map +0 -1
- package/dist/types.d.ts +0 -823
- package/dist/types.d.ts.map +0 -1
- package/dist/user.main.js +0 -85
- package/dist/user.main.js.map +0 -1
- package/dist/user.mjs +0 -76
- package/dist/user.module.js +0 -76
- package/dist/user.module.js.map +0 -1
- package/dist/userEventMaps.module.js +0 -38
package/src/select.ts
CHANGED
|
@@ -24,7 +24,12 @@ interface SelectTriggerOptionOpts extends SelectOpenOpts {
|
|
|
24
24
|
/**
|
|
25
25
|
* The index, text, or node of the option to select. Option nodes can be sourced via `options()`.
|
|
26
26
|
*/
|
|
27
|
-
option: number | string | HTMLElement
|
|
27
|
+
option: number | string | HTMLElement,
|
|
28
|
+
/**
|
|
29
|
+
* Whether or not the select closes on selection. Depends on select implementation and configuration.
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
closesOnSelect?: boolean
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export class SelectTester {
|
|
@@ -164,6 +169,7 @@ export class SelectTester {
|
|
|
164
169
|
async selectOption(opts: SelectTriggerOptionOpts): Promise<void> {
|
|
165
170
|
let {
|
|
166
171
|
option,
|
|
172
|
+
closesOnSelect,
|
|
167
173
|
interactionType = this._interactionType
|
|
168
174
|
} = opts || {};
|
|
169
175
|
let trigger = this.trigger;
|
|
@@ -185,6 +191,8 @@ export class SelectTester {
|
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
let isMultiSelect = listbox.getAttribute('aria-multiselectable') === 'true';
|
|
194
|
+
let isSingleSelect = !isMultiSelect;
|
|
195
|
+
closesOnSelect = closesOnSelect ?? isSingleSelect;
|
|
188
196
|
|
|
189
197
|
if (interactionType === 'keyboard') {
|
|
190
198
|
if (option?.getAttribute('aria-disabled') === 'true') {
|
|
@@ -205,7 +213,7 @@ export class SelectTester {
|
|
|
205
213
|
}
|
|
206
214
|
}
|
|
207
215
|
|
|
208
|
-
if (
|
|
216
|
+
if (closesOnSelect && option?.getAttribute('href') == null) {
|
|
209
217
|
await waitFor(() => {
|
|
210
218
|
if (document.activeElement !== this._trigger) {
|
|
211
219
|
throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);
|
package/src/table.ts
CHANGED
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {act, waitFor, within} from '@testing-library/react';
|
|
14
|
+
import {BaseGridRowInteractionOpts, GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';
|
|
14
15
|
import {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';
|
|
15
|
-
import {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';
|
|
16
16
|
|
|
17
17
|
interface TableToggleRowOpts extends ToggleGridRowOpts {}
|
|
18
|
+
interface TableToggleExpansionOpts extends BaseGridRowInteractionOpts {}
|
|
18
19
|
interface TableToggleSortOpts {
|
|
19
20
|
/**
|
|
20
21
|
* The index, text, or node of the column to toggle selection for.
|
|
@@ -162,6 +163,50 @@ export class TableTester {
|
|
|
162
163
|
}
|
|
163
164
|
};
|
|
164
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.
|
|
168
|
+
*/
|
|
169
|
+
async toggleRowExpansion(opts: TableToggleExpansionOpts): Promise<void> {
|
|
170
|
+
let {
|
|
171
|
+
row,
|
|
172
|
+
interactionType = this._interactionType
|
|
173
|
+
} = opts;
|
|
174
|
+
if (!this.table.contains(document.activeElement)) {
|
|
175
|
+
await act(async () => {
|
|
176
|
+
this.table.focus();
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (typeof row === 'string' || typeof row === 'number') {
|
|
181
|
+
row = this.findRow({rowIndexOrText: row});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (!row) {
|
|
185
|
+
throw new Error('Target row not found in the table.');
|
|
186
|
+
} else if (row.getAttribute('aria-expanded') == null) {
|
|
187
|
+
throw new Error('Target row is not expandable.');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (interactionType === 'mouse' || interactionType === 'touch') {
|
|
191
|
+
let rowExpander = within(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?
|
|
192
|
+
await pressElement(this.user, rowExpander, interactionType);
|
|
193
|
+
} else if (interactionType === 'keyboard') {
|
|
194
|
+
if (row?.getAttribute('aria-disabled') === 'true') {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed
|
|
199
|
+
// in selectionmode="replace"/highlight selection when navigating to the row that the user wants
|
|
200
|
+
// to expand. Discuss if this is useful or not
|
|
201
|
+
await this.keyboardNavigateToRow({row});
|
|
202
|
+
if (row.getAttribute('aria-expanded') === 'true') {
|
|
203
|
+
await this.user.keyboard('[ArrowLeft]');
|
|
204
|
+
} else {
|
|
205
|
+
await this.user.keyboard('[ArrowRight]');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
|
|
165
210
|
/**
|
|
166
211
|
* Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.
|
|
167
212
|
*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAkBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,aAAa,IAA4C,EAAe;QACtE,IAAI,uBACF,mBAAmB,EACpB,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,wBAAwB,UACjC,WAAW,IAAI,CAAC,UAAU,CAAC,oBAAoB;aAC1C,IAAI,OAAO,wBAAwB,UAAU;YAClD,IAAI,QAAQ,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC;YAEjD,6HAA6H;YAC7H,IAAI,OAAO;gBACT,WAAW,CAAA,GAAA,iCAAK,EAAE,OAAO,WAAW,CAAC;gBACrC,IAAI,CAAC,UAAU;oBACb,IAAI,eAAe,MAAM,OAAO,CAAC;oBACjC,IAAI,cACF,W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AQ;YAC/C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU;IAE5C;IAEA;;GAEC,GACD,IAAI,gBAA6B;QAC/B,OAAO,IAAI,CAAC,cAAc;IAC5B;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;IACnD;IAEA;;GAEC,GACD,IAAI,qBAAoC;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA,WAAY,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAChI;IA3HA,YAAY,IAA6B,CAAE;QACzC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,gBAAgB,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAChD,IAAI,cAAc,MAAM,GAAG,GACzB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,EAAE;IAE1C;AAkHF","sources":["packages/@react-aria/test-utils/src/checkboxgroup.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 {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the checkbox to toggle selection for.\n */\n checkbox: number | string | HTMLElement\n}\n\nexport class CheckboxGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _checkboxgroup: HTMLElement;\n\n\n constructor(opts: CheckboxGroupTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n this._checkboxgroup = root;\n let checkboxgroup = within(root).queryAllByRole('group');\n if (checkboxgroup.length > 0) {\n this._checkboxgroup = checkboxgroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the checkbox group tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a checkbox matching the specified index or text content.\n */\n findCheckbox(opts: {checkboxIndexOrText: number | string}): HTMLElement {\n let {\n checkboxIndexOrText\n } = opts;\n\n let checkbox;\n if (typeof checkboxIndexOrText === 'number') {\n checkbox = this.checkboxes[checkboxIndexOrText];\n } else if (typeof checkboxIndexOrText === 'string') {\n let label = within(this.checkboxgroup).getByText(checkboxIndexOrText);\n\n // Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it\n if (label) {\n checkbox = within(label).queryByRole('checkbox');\n if (!checkbox) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n checkbox = within(labelWrapper).queryByRole('checkbox');\n } else {\n checkbox = label.closest('[role=checkbox]');\n }\n }\n }\n }\n\n return checkbox;\n }\n\n private async keyboardNavigateToCheckbox(opts: {checkbox: HTMLElement}) {\n let {checkbox} = opts;\n let checkboxes = this.checkboxes;\n checkboxes = checkboxes.filter(checkbox => !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));\n if (checkboxes.length === 0) {\n throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');\n }\n\n let targetIndex = checkboxes.indexOf(checkbox);\n if (targetIndex === -1) {\n throw new Error('Checkbox provided is not in the checkbox group.');\n }\n\n if (!this.checkboxgroup.contains(document.activeElement)) {\n act(() => checkboxes[0].focus());\n }\n\n let currIndex = checkboxes.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the checkbox group.');\n }\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.tab({shift: targetIndex < currIndex});\n }\n };\n\n /**\n * Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {\n checkbox,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({checkboxIndexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error('Target checkbox not found in the checkboxgroup.');\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error('Target checkbox is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToCheckbox({checkbox});\n await this.user.keyboard('[Space]');\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns the checkboxgroup.\n */\n get checkboxgroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n get checkboxes(): HTMLElement[] {\n return within(this.checkboxgroup).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n get selectedCheckboxes(): HTMLElement[] {\n return this.checkboxes.filter(checkbox => (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true');\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.main.js.map"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
|
|
2
|
-
import {within as $jmBF6$within, act as $jmBF6$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 $8473f5d1df4c8eb7$export$f54f4bde770cc5a6 {
|
|
17
|
-
/**
|
|
18
|
-
* Set the interaction type used by the checkbox group tester.
|
|
19
|
-
*/ setInteractionType(type) {
|
|
20
|
-
this._interactionType = type;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns a checkbox matching the specified index or text content.
|
|
24
|
-
*/ findCheckbox(opts) {
|
|
25
|
-
let { checkboxIndexOrText: checkboxIndexOrText } = opts;
|
|
26
|
-
let checkbox;
|
|
27
|
-
if (typeof checkboxIndexOrText === 'number') checkbox = this.checkboxes[checkboxIndexOrText];
|
|
28
|
-
else if (typeof checkboxIndexOrText === 'string') {
|
|
29
|
-
let label = (0, $jmBF6$within)(this.checkboxgroup).getByText(checkboxIndexOrText);
|
|
30
|
-
// Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it
|
|
31
|
-
if (label) {
|
|
32
|
-
checkbox = (0, $jmBF6$within)(label).queryByRole('checkbox');
|
|
33
|
-
if (!checkbox) {
|
|
34
|
-
let labelWrapper = label.closest('label');
|
|
35
|
-
if (labelWrapper) checkbox = (0, $jmBF6$within)(labelWrapper).queryByRole('checkbox');
|
|
36
|
-
else checkbox = label.closest('[role=checkbox]');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return checkbox;
|
|
41
|
-
}
|
|
42
|
-
async keyboardNavigateToCheckbox(opts) {
|
|
43
|
-
let { checkbox: checkbox } = opts;
|
|
44
|
-
let checkboxes = this.checkboxes;
|
|
45
|
-
checkboxes = checkboxes.filter((checkbox)=>!(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));
|
|
46
|
-
if (checkboxes.length === 0) throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');
|
|
47
|
-
let targetIndex = checkboxes.indexOf(checkbox);
|
|
48
|
-
if (targetIndex === -1) throw new Error('Checkbox provided is not in the checkbox group.');
|
|
49
|
-
if (!this.checkboxgroup.contains(document.activeElement)) (0, $jmBF6$act)(()=>checkboxes[0].focus());
|
|
50
|
-
let currIndex = checkboxes.indexOf(document.activeElement);
|
|
51
|
-
if (currIndex === -1) throw new Error('Active element is not in the checkbox group.');
|
|
52
|
-
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.tab({
|
|
53
|
-
shift: targetIndex < currIndex
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.
|
|
58
|
-
*/ async toggleCheckbox(opts) {
|
|
59
|
-
let { checkbox: checkbox, interactionType: interactionType = this._interactionType } = opts;
|
|
60
|
-
if (typeof checkbox === 'string' || typeof checkbox === 'number') checkbox = this.findCheckbox({
|
|
61
|
-
checkboxIndexOrText: checkbox
|
|
62
|
-
});
|
|
63
|
-
if (!checkbox) throw new Error('Target checkbox not found in the checkboxgroup.');
|
|
64
|
-
else if (checkbox.hasAttribute('disabled')) throw new Error('Target checkbox is disabled.');
|
|
65
|
-
if (interactionType === 'keyboard') {
|
|
66
|
-
await this.keyboardNavigateToCheckbox({
|
|
67
|
-
checkbox: checkbox
|
|
68
|
-
});
|
|
69
|
-
await this.user.keyboard('[Space]');
|
|
70
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, checkbox, interactionType);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Returns the checkboxgroup.
|
|
74
|
-
*/ get checkboxgroup() {
|
|
75
|
-
return this._checkboxgroup;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Returns the checkboxes.
|
|
79
|
-
*/ get checkboxes() {
|
|
80
|
-
return (0, $jmBF6$within)(this.checkboxgroup).queryAllByRole('checkbox');
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns the currently selected checkboxes in the checkboxgroup if any.
|
|
84
|
-
*/ get selectedCheckboxes() {
|
|
85
|
-
return this.checkboxes.filter((checkbox)=>checkbox.checked || checkbox.getAttribute('aria-checked') === 'true');
|
|
86
|
-
}
|
|
87
|
-
constructor(opts){
|
|
88
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
89
|
-
this.user = user;
|
|
90
|
-
this._interactionType = interactionType || 'mouse';
|
|
91
|
-
this._checkboxgroup = root;
|
|
92
|
-
let checkboxgroup = (0, $jmBF6$within)(root).queryAllByRole('group');
|
|
93
|
-
if (checkboxgroup.length > 0) this._checkboxgroup = checkboxgroup[0];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export {$8473f5d1df4c8eb7$export$f54f4bde770cc5a6 as CheckboxGroupTester};
|
|
99
|
-
//# sourceMappingURL=checkboxgroup.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAiBM,MAAM;IAkBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,aAAa,IAA4C,EAAe;QACtE,IAAI,uBACF,mBAAmB,EACpB,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,wBAAwB,UACjC,WAAW,IAAI,CAAC,UAAU,CAAC,oB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,EACxC,GAAG;QAEJ,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,UACtD,WAAW,IAAI,CAAC,YAAY,CAAC;YAAC,qBAAqB;QAAQ;QAG7D,IAAI,CAAC,UACH,MAAM,IAAI,MAAM;aACX,IAAI,SAAS,YAAY,CAAC,aAC/B,MAAM,IAAI,MAAM;QAGlB,IAAI,oBAAoB,YAAY;YAClC,MAAM,IAAI,CAAC,0BAA0B,CAAC;0BAAC;YAAQ;YAC/C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU;IAE5C;IAEA;;GAEC,GACD,IAAI,gBAA6B;QAC/B,OAAO,IAAI,CAAC,cAAc;IAC5B;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC;IACnD;IAEA;;GAEC,GACD,IAAI,qBAAoC;QACtC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA,WAAY,AAAC,SAA8B,OAAO,IAAI,SAAS,YAAY,CAAC,oBAAoB;IAChI;IA3HA,YAAY,IAA6B,CAAE;QACzC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,IAAI,CAAC,cAAc,GAAG;QACtB,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAChD,IAAI,cAAc,MAAM,GAAG,GACzB,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,EAAE;IAE1C;AAkHF","sources":["packages/@react-aria/test-utils/src/checkboxgroup.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 {CheckboxGroupTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerCheckboxOptions {\n /**\n * What interaction type to use when triggering a checkbox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the checkbox to toggle selection for.\n */\n checkbox: number | string | HTMLElement\n}\n\nexport class CheckboxGroupTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _checkboxgroup: HTMLElement;\n\n\n constructor(opts: CheckboxGroupTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n this._checkboxgroup = root;\n let checkboxgroup = within(root).queryAllByRole('group');\n if (checkboxgroup.length > 0) {\n this._checkboxgroup = checkboxgroup[0];\n }\n }\n\n /**\n * Set the interaction type used by the checkbox group tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a checkbox matching the specified index or text content.\n */\n findCheckbox(opts: {checkboxIndexOrText: number | string}): HTMLElement {\n let {\n checkboxIndexOrText\n } = opts;\n\n let checkbox;\n if (typeof checkboxIndexOrText === 'number') {\n checkbox = this.checkboxes[checkboxIndexOrText];\n } else if (typeof checkboxIndexOrText === 'string') {\n let label = within(this.checkboxgroup).getByText(checkboxIndexOrText);\n\n // Label may wrap the checkbox, or the actual label may be a sibling span, or the checkbox div could have the label within it\n if (label) {\n checkbox = within(label).queryByRole('checkbox');\n if (!checkbox) {\n let labelWrapper = label.closest('label');\n if (labelWrapper) {\n checkbox = within(labelWrapper).queryByRole('checkbox');\n } else {\n checkbox = label.closest('[role=checkbox]');\n }\n }\n }\n }\n\n return checkbox;\n }\n\n private async keyboardNavigateToCheckbox(opts: {checkbox: HTMLElement}) {\n let {checkbox} = opts;\n let checkboxes = this.checkboxes;\n checkboxes = checkboxes.filter(checkbox => !(checkbox.hasAttribute('disabled') || checkbox.getAttribute('aria-disabled') === 'true'));\n if (checkboxes.length === 0) {\n throw new Error('Checkbox group doesnt have any non-disabled checkboxes. Please double check your checkbox group.');\n }\n\n let targetIndex = checkboxes.indexOf(checkbox);\n if (targetIndex === -1) {\n throw new Error('Checkbox provided is not in the checkbox group.');\n }\n\n if (!this.checkboxgroup.contains(document.activeElement)) {\n act(() => checkboxes[0].focus());\n }\n\n let currIndex = checkboxes.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Active element is not in the checkbox group.');\n }\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.tab({shift: targetIndex < currIndex});\n }\n };\n\n /**\n * Toggles the specified checkbox. Defaults to using the interaction type set on the checkbox tester.\n */\n async toggleCheckbox(opts: TriggerCheckboxOptions): Promise<void> {\n let {\n checkbox,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof checkbox === 'string' || typeof checkbox === 'number') {\n checkbox = this.findCheckbox({checkboxIndexOrText: checkbox});\n }\n\n if (!checkbox) {\n throw new Error('Target checkbox not found in the checkboxgroup.');\n } else if (checkbox.hasAttribute('disabled')) {\n throw new Error('Target checkbox is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n await this.keyboardNavigateToCheckbox({checkbox});\n await this.user.keyboard('[Space]');\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns the checkboxgroup.\n */\n get checkboxgroup(): HTMLElement {\n return this._checkboxgroup;\n }\n\n /**\n * Returns the checkboxes.\n */\n get checkboxes(): HTMLElement[] {\n return within(this.checkboxgroup).queryAllByRole('checkbox');\n }\n\n /**\n * Returns the currently selected checkboxes in the checkboxgroup if any.\n */\n get selectedCheckboxes(): HTMLElement[] {\n return this.checkboxes.filter(checkbox => (checkbox as HTMLInputElement).checked || checkbox.getAttribute('aria-checked') === 'true');\n }\n}\n"],"names":[],"version":3,"file":"checkboxgroup.module.js.map"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAqCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAiB;QACrD,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;eAEnB,IAAI,oBAAoB,cAAc,IAAI,CAAC,QAAQ,IAAI,MAAM;YAClE,CAAA,GAAA,8BAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAE,KAAK;YAC9B,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAE7B,OAAO,IAAI,oBAAoB;YAC7B,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAC,QAAQ;gBAAU,MAAM;YAAU;iBAE3D,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAC,QAAQ;gBAAS,MAAM;YAAU;;QAI9D,MAAM,CAAA,GAAA,kCAAM,EAAE;YACZ,IAAI,CAAC,cAAc,SAAS,YAAY,CAAC,oBAAoB,MAC3D,MAAM,IAAI,MAAM;iBAEhB,OAAO;Q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gBAAoC;QACtC,IAAI,kBAAkB,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACjD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;IA1NA,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,WAAE,OAAO,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QAC7C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAEjE,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,OAAO,CAAC,EAAE;iBACf,IAAI,QAAQ,MAAM,GAAG,GAC1B,UAAU,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;YAGvD,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,WAAW,IAAI,CAAC,SAAS;QAC3C;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.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 {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\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\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an 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 listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox 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: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\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 // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. 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 currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}
|
package/dist/combobox.module.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import {act as $1n52X$act, waitFor as $1n52X$waitFor, within as $1n52X$within} from "@testing-library/react";
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2024 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 $dab75f394483aa9c$export$f97e14e96d71ab3b {
|
|
15
|
-
/**
|
|
16
|
-
* Set the interaction type used by the combobox tester.
|
|
17
|
-
*/ setInteractionType(type) {
|
|
18
|
-
this._interactionType = type;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.
|
|
22
|
-
*/ async open(opts = {}) {
|
|
23
|
-
let { triggerBehavior: triggerBehavior = 'manual', interactionType: interactionType = this._interactionType } = opts;
|
|
24
|
-
let trigger = this.trigger;
|
|
25
|
-
let combobox = this.combobox;
|
|
26
|
-
let isDisabled = trigger.hasAttribute('disabled');
|
|
27
|
-
if (interactionType === 'mouse') {
|
|
28
|
-
if (triggerBehavior === 'focus') await this.user.click(combobox);
|
|
29
|
-
else await this.user.click(trigger);
|
|
30
|
-
} else if (interactionType === 'keyboard' && this._trigger != null) {
|
|
31
|
-
(0, $1n52X$act)(()=>this._trigger.focus());
|
|
32
|
-
if (triggerBehavior !== 'focus') await this.user.keyboard('{ArrowDown}');
|
|
33
|
-
} else if (interactionType === 'touch') {
|
|
34
|
-
if (triggerBehavior === 'focus') await this.user.pointer({
|
|
35
|
-
target: combobox,
|
|
36
|
-
keys: '[TouchA]'
|
|
37
|
-
});
|
|
38
|
-
else await this.user.pointer({
|
|
39
|
-
target: trigger,
|
|
40
|
-
keys: '[TouchA]'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
44
|
-
if (!isDisabled && combobox.getAttribute('aria-controls') == null) throw new Error('No aria-controls found on combobox trigger element.');
|
|
45
|
-
else return true;
|
|
46
|
-
});
|
|
47
|
-
let listBoxId = combobox.getAttribute('aria-controls');
|
|
48
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
49
|
-
if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) throw new Error(`Listbox with id of ${listBoxId} not found in document.`);
|
|
50
|
-
else return true;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Returns an option matching the specified index or text content.
|
|
55
|
-
*/ findOption(opts) {
|
|
56
|
-
let { optionIndexOrText: optionIndexOrText } = opts;
|
|
57
|
-
let option;
|
|
58
|
-
let options = this.options();
|
|
59
|
-
let listbox = this.listbox;
|
|
60
|
-
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
61
|
-
else if (typeof optionIndexOrText === 'string' && listbox != null) option = (0, $1n52X$within)(listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
62
|
-
return option;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.
|
|
66
|
-
* The desired option can be targeted via the option's node, the option's text, or the option's index.
|
|
67
|
-
*/ async selectOption(opts) {
|
|
68
|
-
let { option: option, triggerBehavior: triggerBehavior, interactionType: interactionType = this._interactionType } = opts;
|
|
69
|
-
if (!this.combobox.getAttribute('aria-controls')) await this.open({
|
|
70
|
-
triggerBehavior: triggerBehavior
|
|
71
|
-
});
|
|
72
|
-
let listbox = this.listbox;
|
|
73
|
-
if (!listbox) throw new Error('Combobox\'s listbox not found.');
|
|
74
|
-
if (listbox) {
|
|
75
|
-
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
76
|
-
optionIndexOrText: option
|
|
77
|
-
});
|
|
78
|
-
if (!option) throw new Error('Target option not found in the listbox.');
|
|
79
|
-
// TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow
|
|
80
|
-
// the required amount of times to reach the option. For now just click the option even in keyboard mode
|
|
81
|
-
if (interactionType === 'mouse' || interactionType === 'keyboard') await this.user.click(option);
|
|
82
|
-
else await this.user.pointer({
|
|
83
|
-
target: option,
|
|
84
|
-
keys: '[TouchA]'
|
|
85
|
-
});
|
|
86
|
-
if (option.getAttribute('href') == null) await (0, $1n52X$waitFor)(()=>{
|
|
87
|
-
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
88
|
-
else return true;
|
|
89
|
-
});
|
|
90
|
-
} else throw new Error("Attempted to select a option in the combobox, but the listbox wasn't found.");
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Closes the combobox dropdown.
|
|
94
|
-
*/ async close() {
|
|
95
|
-
let listbox = this.listbox;
|
|
96
|
-
if (listbox) {
|
|
97
|
-
(0, $1n52X$act)(()=>this.combobox.focus());
|
|
98
|
-
await this.user.keyboard('[Escape]');
|
|
99
|
-
await (0, $1n52X$waitFor)(()=>{
|
|
100
|
-
if (document.contains(listbox)) throw new Error('Expected listbox element to not be in the document after selecting an option');
|
|
101
|
-
else return true;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Returns the combobox.
|
|
107
|
-
*/ get combobox() {
|
|
108
|
-
return this._combobox;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Returns the combobox trigger button.
|
|
112
|
-
*/ get trigger() {
|
|
113
|
-
return this._trigger;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Returns the combobox's listbox if present.
|
|
117
|
-
*/ get listbox() {
|
|
118
|
-
let listBoxId = this.combobox.getAttribute('aria-controls');
|
|
119
|
-
return listBoxId ? document.getElementById(listBoxId) || null : null;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Returns the combobox's sections if present.
|
|
123
|
-
*/ get sections() {
|
|
124
|
-
let listbox = this.listbox;
|
|
125
|
-
return listbox ? (0, $1n52X$within)(listbox).queryAllByRole('group') : [];
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
129
|
-
*/ options(opts = {}) {
|
|
130
|
-
let { element: element = this.listbox } = opts;
|
|
131
|
-
let options = [];
|
|
132
|
-
if (element) options = (0, $1n52X$within)(element).queryAllByRole('option');
|
|
133
|
-
return options;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Returns the currently focused option in the combobox's dropdown if any.
|
|
137
|
-
*/ get focusedOption() {
|
|
138
|
-
let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');
|
|
139
|
-
return focusedOptionId ? document.getElementById(focusedOptionId) : null;
|
|
140
|
-
}
|
|
141
|
-
constructor(opts){
|
|
142
|
-
let { root: root, trigger: trigger, user: user, interactionType: interactionType } = opts;
|
|
143
|
-
this.user = user;
|
|
144
|
-
this._interactionType = interactionType || 'mouse';
|
|
145
|
-
// Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to
|
|
146
|
-
// query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis
|
|
147
|
-
this._combobox = root;
|
|
148
|
-
let combobox = (0, $1n52X$within)(root).queryByRole('combobox');
|
|
149
|
-
if (combobox) this._combobox = combobox;
|
|
150
|
-
// This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
|
|
151
|
-
if (trigger) this._trigger = trigger;
|
|
152
|
-
else {
|
|
153
|
-
let buttons = (0, $1n52X$within)(root).queryAllByRole('button', {
|
|
154
|
-
hidden: true
|
|
155
|
-
});
|
|
156
|
-
if (buttons.length === 1) trigger = buttons[0];
|
|
157
|
-
else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
158
|
-
// For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
|
|
159
|
-
// is also the trigger button
|
|
160
|
-
this._trigger = trigger || this._combobox;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
export {$dab75f394483aa9c$export$f97e14e96d71ab3b as ComboBoxTester};
|
|
167
|
-
//# sourceMappingURL=combobox.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAqCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAiB;QACrD,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;eAEnB,IAAI,oBAAoB,cAAc,IAAI,CAAC,QAAQ,IAAI,MAAM;YAClE,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAE,KAAK;Y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AW,IAAI,CAAC,SAAS;QAC3C;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.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 {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\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\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an 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 listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox 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: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\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 // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. 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 currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.module.js.map"}
|
package/dist/dialog.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,CAAC,QAAQ,YAAY,CAAC,aAAa;YACrC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBACjB,IAAI,oBAAoB,SAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAC,QAAQ;gBAAS,MAAM;YAAU;iBACrD,IAAI,oBAAoB,YAAY;gBACzC,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;gBACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YAC3B;YAEA,IAAI,IAAI,CAAC,YAAY,KAAK,WAAW;gBACnC,MAAM,CAAA,GAAA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O,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,iCAAK,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.main.js.map"}
|
package/dist/dialog.module.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,CAAC,QAAQ,YAAY,CAAC,aAAa;YACrC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBACjB,IAAI,oBAAoB,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,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/events.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AACvC,SAAS,mCAAa,EAAU;QAElB;IADZ,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS,IAAI,OACxD,GAAG,IAAI,CAAC,EAAA,kCAAA,OAAO,SAAS,CAAC,gBAAgB,cAAjC,sDAAA,gCAAmC,QAAQ,KAAI,OAAO,SAAS,CAAC,QAAQ,IAChF;AACN;AAEA,SAAS,6BAAO,EAAiB;IAC/B,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAC3B,OAAO;IAGT,IAAI,MAAsB;IAC1B,OAAO;QACL,IAAI,OAAO,MACT,MAAM;QAER,OAAO;IACT;AACF;AAEA,MAAM,8BAAQ,6BAAO;IACnB,OAAO,mCAAa;AACtB;AAEO,SAAS;IACd,OAAO,gCAAU,QAAQ;AAC3B;AAEO,SAAS;IACd,OAAO,gCAAU,aAAa;AAChC;AASO,eAAe,yCAAiB,IAA2H;IAChK,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;QAC9B;IAAlB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;QAAG,GAAG,WAAW;IAAA;AACrD;AAGO,eAAe,0CAAa,IAA8K,EAAE,OAAoB,EAAE,eAA4C;IACnR,IAAI,oBAAoB,SACtB,qEAAqE;IACrE,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;QAAe,QAAQ;YAAC,UAAU;QAAE;IAAC;SAC3E,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.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\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\nfunction testPlatform(re: RegExp) {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === 'test') {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(function () {\n return testPlatform(/^Mac/i);\n});\n\nexport function getAltKey(): 'Alt' | 'ControlLeft' {\n return isMac() ? 'Alt' : 'ControlLeft';\n}\n\nexport function getMetaKey(): 'MetaLeft' | 'ControlLeft' {\n return isMac() ? 'MetaLeft' : 'ControlLeft';\n}\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string, coords?: any}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n // Add coords with pressure so this isn't detected as a virtual click\n await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: .5}});\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.main.js.map"}
|