@react-aria/test-utils 1.0.0-alpha.7 → 1.0.0-beta.0

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 (64) hide show
  1. package/dist/combobox.main.js +5 -4
  2. package/dist/combobox.main.js.map +1 -1
  3. package/dist/combobox.mjs +5 -4
  4. package/dist/combobox.module.js +5 -4
  5. package/dist/combobox.module.js.map +1 -1
  6. package/dist/events.main.js +31 -1
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.mjs +30 -2
  9. package/dist/events.module.js +30 -2
  10. package/dist/events.module.js.map +1 -1
  11. package/dist/gridlist.main.js +23 -9
  12. package/dist/gridlist.main.js.map +1 -1
  13. package/dist/gridlist.mjs +24 -10
  14. package/dist/gridlist.module.js +24 -10
  15. package/dist/gridlist.module.js.map +1 -1
  16. package/dist/listbox.main.js +22 -13
  17. package/dist/listbox.main.js.map +1 -1
  18. package/dist/listbox.mjs +23 -14
  19. package/dist/listbox.module.js +23 -14
  20. package/dist/listbox.module.js.map +1 -1
  21. package/dist/menu.main.js +1 -1
  22. package/dist/menu.main.js.map +1 -1
  23. package/dist/menu.mjs +1 -1
  24. package/dist/menu.module.js +1 -1
  25. package/dist/menu.module.js.map +1 -1
  26. package/dist/select.main.js +7 -4
  27. package/dist/select.main.js.map +1 -1
  28. package/dist/select.mjs +7 -4
  29. package/dist/select.module.js +7 -4
  30. package/dist/select.module.js.map +1 -1
  31. package/dist/table.main.js +42 -9
  32. package/dist/table.main.js.map +1 -1
  33. package/dist/table.mjs +44 -11
  34. package/dist/table.module.js +44 -11
  35. package/dist/table.module.js.map +1 -1
  36. package/dist/tabs.main.js +1 -1
  37. package/dist/tabs.main.js.map +1 -1
  38. package/dist/tabs.mjs +1 -1
  39. package/dist/tabs.module.js +1 -1
  40. package/dist/tabs.module.js.map +1 -1
  41. package/dist/tree.main.js +27 -8
  42. package/dist/tree.main.js.map +1 -1
  43. package/dist/tree.mjs +28 -9
  44. package/dist/tree.module.js +28 -9
  45. package/dist/tree.module.js.map +1 -1
  46. package/dist/types.d.ts +29 -9
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/user.main.js.map +1 -1
  49. package/dist/user.module.js.map +1 -1
  50. package/dist/userEventMaps.main.js.map +1 -1
  51. package/dist/userEventMaps.module.js.map +1 -1
  52. package/package.json +7 -3
  53. package/src/combobox.ts +10 -7
  54. package/src/events.ts +34 -2
  55. package/src/gridlist.ts +35 -12
  56. package/src/listbox.ts +47 -19
  57. package/src/menu.ts +1 -1
  58. package/src/select.ts +10 -4
  59. package/src/table.ts +71 -10
  60. package/src/tabs.ts +1 -1
  61. package/src/tree.ts +40 -10
  62. package/src/types.ts +11 -1
  63. package/src/user.ts +10 -1
  64. package/src/userEventMaps.ts +1 -1
package/dist/gridlist.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
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
2
  import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
3
3
 
4
4
  /*
@@ -30,23 +30,29 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
30
30
  }
31
31
  // TODO: RTL
32
32
  async keyboardNavigateToRow(opts) {
33
- let { row: row } = opts;
33
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
34
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
34
35
  let rows = this.rows;
35
36
  let targetIndex = rows.indexOf(row);
36
37
  if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
37
- if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
38
- if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
38
+ if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
39
+ if (document.activeElement === this._gridlist) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
39
40
  else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
40
41
  while (document.activeElement.getAttribute('role') !== 'row');
41
42
  let currIndex = rows.indexOf(document.activeElement);
42
43
  if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
43
44
  let direction = targetIndex > currIndex ? 'down' : 'up';
45
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
44
46
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
47
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
45
48
  }
46
49
  /**
47
50
  * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
51
+ * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
48
52
  */ async toggleRowSelection(opts) {
49
- let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
53
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
54
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
55
+ let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
50
56
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
51
57
  rowIndexOrText: row
52
58
  });
@@ -57,11 +63,14 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
57
63
  if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
58
64
  // this would be better than the check to do nothing in events.ts
59
65
  // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
60
- if (interactionType === 'keyboard' && !checkboxSelection) {
66
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
61
67
  await this.keyboardNavigateToRow({
62
- row: row
68
+ row: row,
69
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
63
70
  });
64
- await this.user.keyboard('{Space}');
71
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
72
+ await this.user.keyboard('[Space]');
73
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
65
74
  return;
66
75
  }
67
76
  if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
@@ -77,7 +86,11 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
77
86
  pointerType: 'touch'
78
87
  }
79
88
  });
80
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
89
+ } else {
90
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
91
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
92
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
93
+ }
81
94
  }
82
95
  }
83
96
  // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
@@ -94,7 +107,8 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
94
107
  else if (interactionType === 'keyboard') {
95
108
  if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
96
109
  await this.keyboardNavigateToRow({
97
- row: row
110
+ row: row,
111
+ selectionOnNav: 'none'
98
112
  });
99
113
  await this.user.keyboard('[Enter]');
100
114
  } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
@@ -1,4 +1,4 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
1
+ import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
2
2
  import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
3
3
 
4
4
  /*
@@ -30,23 +30,29 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
30
30
  }
31
31
  // TODO: RTL
32
32
  async keyboardNavigateToRow(opts) {
33
- let { row: row } = opts;
33
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
34
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
34
35
  let rows = this.rows;
35
36
  let targetIndex = rows.indexOf(row);
36
37
  if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
37
- if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
38
- if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
38
+ if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
39
+ if (document.activeElement === this._gridlist) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
39
40
  else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
40
41
  while (document.activeElement.getAttribute('role') !== 'row');
41
42
  let currIndex = rows.indexOf(document.activeElement);
42
43
  if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
43
44
  let direction = targetIndex > currIndex ? 'down' : 'up';
45
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
44
46
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
47
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
45
48
  }
46
49
  /**
47
50
  * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
51
+ * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
48
52
  */ async toggleRowSelection(opts) {
49
- let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
53
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
54
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
55
+ let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
50
56
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
51
57
  rowIndexOrText: row
52
58
  });
@@ -57,11 +63,14 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
57
63
  if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
58
64
  // this would be better than the check to do nothing in events.ts
59
65
  // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
60
- if (interactionType === 'keyboard' && !checkboxSelection) {
66
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
61
67
  await this.keyboardNavigateToRow({
62
- row: row
68
+ row: row,
69
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
63
70
  });
64
- await this.user.keyboard('{Space}');
71
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
72
+ await this.user.keyboard('[Space]');
73
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
65
74
  return;
66
75
  }
67
76
  if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
@@ -77,7 +86,11 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
77
86
  pointerType: 'touch'
78
87
  }
79
88
  });
80
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
89
+ } else {
90
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
91
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
92
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
93
+ }
81
94
  }
82
95
  }
83
96
  // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
@@ -94,7 +107,8 @@ class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
94
107
  else if (interactionType === 'keyboard') {
95
108
  if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
96
109
  await this.keyboardNavigateToRow({
97
- row: row
110
+ row: row,
111
+ selectionOnNav: 'none'
98
112
  });
99
113
  await this.user.keyboard('[Enter]');
100
114
  } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ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ACpC,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,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;AA4KF","sources":["packages/@react-aria/test-utils/src/gridlist.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 {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement}) {\n let {row} = opts;\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n\n if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard('[ArrowDown]');\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\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 * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && !checkboxSelection) {\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllBy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AAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;AAmMF","sources":["packages/@react-aria/test-utils/src/gridlist.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 {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n\n if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\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 gridlist row. Defaults to using the interaction type set on the gridlist tester.\n * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getAltKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, 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, row, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.module.js.map"}
@@ -39,27 +39,28 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
39
39
  // TODO: this is basically the same as menu except for the error message, refactor later so that they share
40
40
  // TODO: this also doesn't support grid layout yet
41
41
  async keyboardNavigateToOption(opts) {
42
- var _document_activeElement;
43
- let { option: option } = opts;
42
+ let { option: option, selectionOnNav: selectionOnNav = 'default' } = opts;
43
+ let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
44
44
  let options = this.options();
45
45
  let targetIndex = options.indexOf(option);
46
46
  if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
47
- if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) (0, $bAxU9$testinglibraryreact.act)(()=>this._listbox.focus());
48
- await this.user.keyboard('[ArrowDown]');
49
- // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,
50
- // feels like it could break easily
51
- if (((_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getAttribute('role')) !== 'option') await (0, $bAxU9$testinglibraryreact.act)(async ()=>{
52
- option.focus();
53
- });
47
+ if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
48
+ (0, $bAxU9$testinglibraryreact.act)(()=>this._listbox.focus());
49
+ await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
50
+ }
54
51
  let currIndex = options.indexOf(document.activeElement);
55
52
  if (currIndex === -1) throw new Error('ActiveElement is not in the listbox');
56
53
  let direction = targetIndex > currIndex ? 'down' : 'up';
54
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
57
55
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
56
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
58
57
  }
59
58
  /**
60
59
  * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
61
60
  */ async toggleOptionSelection(opts) {
62
- let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType } = opts;
61
+ 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)();
63
64
  if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
64
65
  optionIndexOrText: option
65
66
  });
@@ -67,9 +68,12 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
67
68
  if (interactionType === 'keyboard') {
68
69
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
69
70
  await this.keyboardNavigateToOption({
70
- option: option
71
+ option: option,
72
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
71
73
  });
74
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
72
75
  await this.user.keyboard(`[${keyboardActivation}]`);
76
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
73
77
  } else if (needsLongPress && interactionType === 'touch') {
74
78
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
75
79
  await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
@@ -79,7 +83,11 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
79
83
  pointerType: 'touch'
80
84
  }
81
85
  });
82
- } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
86
+ } else {
87
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
88
+ await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
89
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
90
+ }
83
91
  }
84
92
  /**
85
93
  * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
@@ -93,7 +101,8 @@ class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
93
101
  else if (interactionType === 'keyboard') {
94
102
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
95
103
  await this.keyboardNavigateToOption({
96
- option: option
104
+ option: option,
105
+ selectionOnNav: 'none'
97
106
  });
98
107
  await this.user.keyboard('[Enter]');
99
108
  } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiCM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,wFAAwF;IACxF;;GAEC,GACD,WAAW,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AQ,YAAY,CAAC,sBAAqB,QAC5C;YAGF,MAAM,IAAI,CAAC,wBAAwB,CAAC;wBAAC;YAAM;YAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OACE,MAAM,CAAA,GAAA,sCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ;IAE1C;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,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;IAzKA,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;AAoKF","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 {ListBoxTesterOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\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\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}) {\n let {option} = opts;\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 }\n\n await this.user.keyboard('[ArrowDown]');\n\n // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,\n // feels like it could break easily\n if (document.activeElement?.getAttribute('role') !== 'option') {\n await act(async () => {\n option.focus();\n });\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 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 * 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 {option, needsLongPress, keyboardActivation = 'Enter', interactionType = this._interactionType} = 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 (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\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 await pressElement(this.user, option, interactionType);\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});\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.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0CM,MAAM;IAcX;;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,IAAI,OAAO,sBAAsB,UAC/B,SAAS,OAAO,CAAC,kBAAkB;aAC9B,IAAI,OAAO,sBAAsB,UACtC,SAAU,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,OA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qBAAqB;IAC5E;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC9C;IA5LA,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;AAuLF","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.main.js.map"}
package/dist/listbox.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
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
2
  import {within as $fzAUL$within, act as $fzAUL$act} from "@testing-library/react";
3
3
 
4
4
  /*
@@ -33,27 +33,28 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
33
33
  // TODO: this is basically the same as menu except for the error message, refactor later so that they share
34
34
  // TODO: this also doesn't support grid layout yet
35
35
  async keyboardNavigateToOption(opts) {
36
- var _document_activeElement;
37
- let { option: option } = opts;
36
+ let { option: option, selectionOnNav: selectionOnNav = 'default' } = opts;
37
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
38
38
  let options = this.options();
39
39
  let targetIndex = options.indexOf(option);
40
40
  if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
41
- if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) (0, $fzAUL$act)(()=>this._listbox.focus());
42
- await this.user.keyboard('[ArrowDown]');
43
- // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,
44
- // feels like it could break easily
45
- if (((_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getAttribute('role')) !== 'option') await (0, $fzAUL$act)(async ()=>{
46
- option.focus();
47
- });
41
+ if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
42
+ (0, $fzAUL$act)(()=>this._listbox.focus());
43
+ await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
44
+ }
48
45
  let currIndex = options.indexOf(document.activeElement);
49
46
  if (currIndex === -1) throw new Error('ActiveElement is not in the listbox');
50
47
  let direction = targetIndex > currIndex ? 'down' : 'up';
48
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
51
49
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
50
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
52
51
  }
53
52
  /**
54
53
  * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
55
54
  */ async toggleOptionSelection(opts) {
56
- let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType } = opts;
55
+ 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)();
57
58
  if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
58
59
  optionIndexOrText: option
59
60
  });
@@ -61,9 +62,12 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
61
62
  if (interactionType === 'keyboard') {
62
63
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
63
64
  await this.keyboardNavigateToOption({
64
- option: option
65
+ option: option,
66
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
65
67
  });
68
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
66
69
  await this.user.keyboard(`[${keyboardActivation}]`);
70
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
67
71
  } else if (needsLongPress && interactionType === 'touch') {
68
72
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
69
73
  await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
@@ -73,7 +77,11 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
73
77
  pointerType: 'touch'
74
78
  }
75
79
  });
76
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
80
+ } else {
81
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
82
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
83
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
84
+ }
77
85
  }
78
86
  /**
79
87
  * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
@@ -87,7 +95,8 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
87
95
  else if (interactionType === 'keyboard') {
88
96
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
89
97
  await this.keyboardNavigateToOption({
90
- option: option
98
+ option: option,
99
+ selectionOnNav: 'none'
91
100
  });
92
101
  await this.user.keyboard('[Enter]');
93
102
  } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
@@ -1,4 +1,4 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
1
+ import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
2
2
  import {within as $fzAUL$within, act as $fzAUL$act} from "@testing-library/react";
3
3
 
4
4
  /*
@@ -33,27 +33,28 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
33
33
  // TODO: this is basically the same as menu except for the error message, refactor later so that they share
34
34
  // TODO: this also doesn't support grid layout yet
35
35
  async keyboardNavigateToOption(opts) {
36
- var _document_activeElement;
37
- let { option: option } = opts;
36
+ let { option: option, selectionOnNav: selectionOnNav = 'default' } = opts;
37
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
38
38
  let options = this.options();
39
39
  let targetIndex = options.indexOf(option);
40
40
  if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
41
- if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) (0, $fzAUL$act)(()=>this._listbox.focus());
42
- await this.user.keyboard('[ArrowDown]');
43
- // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,
44
- // feels like it could break easily
45
- if (((_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getAttribute('role')) !== 'option') await (0, $fzAUL$act)(async ()=>{
46
- option.focus();
47
- });
41
+ if (document.activeElement !== this._listbox && !this._listbox.contains(document.activeElement)) {
42
+ (0, $fzAUL$act)(()=>this._listbox.focus());
43
+ await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
44
+ }
48
45
  let currIndex = options.indexOf(document.activeElement);
49
46
  if (currIndex === -1) throw new Error('ActiveElement is not in the listbox');
50
47
  let direction = targetIndex > currIndex ? 'down' : 'up';
48
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
51
49
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
50
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
52
51
  }
53
52
  /**
54
53
  * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
55
54
  */ async toggleOptionSelection(opts) {
56
- let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType } = opts;
55
+ 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)();
57
58
  if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
58
59
  optionIndexOrText: option
59
60
  });
@@ -61,9 +62,12 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
61
62
  if (interactionType === 'keyboard') {
62
63
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
63
64
  await this.keyboardNavigateToOption({
64
- option: option
65
+ option: option,
66
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
65
67
  });
68
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
66
69
  await this.user.keyboard(`[${keyboardActivation}]`);
70
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
67
71
  } else if (needsLongPress && interactionType === 'touch') {
68
72
  if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
69
73
  await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
@@ -73,7 +77,11 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
73
77
  pointerType: 'touch'
74
78
  }
75
79
  });
76
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
80
+ } else {
81
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
82
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, option, interactionType);
83
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
84
+ }
77
85
  }
78
86
  /**
79
87
  * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
@@ -87,7 +95,8 @@ class $bbf72b714b632b99$export$54c24f7ee8577f4f {
87
95
  else if (interactionType === 'keyboard') {
88
96
  if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
89
97
  await this.keyboardNavigateToOption({
90
- option: option
98
+ option: option,
99
+ selectionOnNav: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AChB,IAAI,CAAC,aAAa,GAAG;IACvB;AAoKF","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 {ListBoxTesterOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\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\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}) {\n let {option} = opts;\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 }\n\n await this.user.keyboard('[ArrowDown]');\n\n // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,\n // feels like it could break easily\n if (document.activeElement?.getAttribute('role') !== 'option') {\n await act(async () => {\n option.focus();\n });\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 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 * 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 {option, needsLongPress, keyboardActivation = 'Enter', interactionType = this._interactionType} = 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 (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\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 await pressElement(this.user, option, interactionType);\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});\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.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0CM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IA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;QACzD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,EAAC,GAAG;QAChC,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,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,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC9C;IA5LA,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;AAuLF","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.module.js.map"}
package/dist/menu.main.js CHANGED
@@ -104,7 +104,7 @@ class $31965f39292c8e99$export$f73bbc9212ed861e {
104
104
  if (!option) throw new Error('Target option not found in the menu.');
105
105
  if (interactionType === 'keyboard') {
106
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());
107
+ if (document.activeElement !== menu && !menu.contains(document.activeElement)) (0, $l5sJH$testinglibraryreact.act)(()=>menu.focus());
108
108
  await this.keyboardNavigateToOption({
109
109
  option: option
110
110
  });