@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.
Files changed (130) hide show
  1. package/dist/import.mjs +5 -5
  2. package/dist/main.js +9 -9
  3. package/dist/module.js +5 -5
  4. package/dist/{checkboxgroup.main.js → private/checkboxgroup.cjs} +19 -19
  5. package/dist/private/checkboxgroup.cjs.map +1 -0
  6. package/dist/{checkboxgroup.mjs → private/checkboxgroup.js} +19 -19
  7. package/dist/private/checkboxgroup.js.map +1 -0
  8. package/dist/{combobox.main.js → private/combobox.cjs} +35 -35
  9. package/dist/private/combobox.cjs.map +1 -0
  10. package/dist/{combobox.mjs → private/combobox.js} +35 -35
  11. package/dist/private/combobox.js.map +1 -0
  12. package/dist/{dialog.main.js → private/dialog.cjs} +19 -19
  13. package/dist/private/dialog.cjs.map +1 -0
  14. package/dist/{dialog.mjs → private/dialog.js} +19 -19
  15. package/dist/private/dialog.js.map +1 -0
  16. package/dist/{events.main.js → private/events.cjs} +32 -34
  17. package/dist/private/events.cjs.map +1 -0
  18. package/dist/{events.mjs → private/events.js} +29 -31
  19. package/dist/private/events.js.map +1 -0
  20. package/dist/{gridlist.main.js → private/gridlist.cjs} +27 -28
  21. package/dist/private/gridlist.cjs.map +1 -0
  22. package/dist/{gridlist.mjs → private/gridlist.js} +27 -28
  23. package/dist/private/gridlist.js.map +1 -0
  24. package/dist/{listbox.main.js → private/listbox.cjs} +24 -24
  25. package/dist/private/listbox.cjs.map +1 -0
  26. package/dist/{listbox.mjs → private/listbox.js} +24 -24
  27. package/dist/private/listbox.js.map +1 -0
  28. package/dist/{menu.main.js → private/menu.cjs} +46 -48
  29. package/dist/private/menu.cjs.map +1 -0
  30. package/dist/{menu.mjs → private/menu.js} +46 -48
  31. package/dist/private/menu.js.map +1 -0
  32. package/dist/{radiogroup.main.js → private/radiogroup.cjs} +21 -24
  33. package/dist/private/radiogroup.cjs.map +1 -0
  34. package/dist/{radiogroup.mjs → private/radiogroup.js} +21 -24
  35. package/dist/private/radiogroup.js.map +1 -0
  36. package/dist/{select.main.js → private/select.cjs} +31 -29
  37. package/dist/private/select.cjs.map +1 -0
  38. package/dist/{select.module.js → private/select.js} +31 -29
  39. package/dist/private/select.js.map +1 -0
  40. package/dist/{table.main.js → private/table.cjs} +82 -57
  41. package/dist/private/table.cjs.map +1 -0
  42. package/dist/{table.module.js → private/table.js} +82 -57
  43. package/dist/private/table.js.map +1 -0
  44. package/dist/{tabs.main.js → private/tabs.cjs} +21 -25
  45. package/dist/private/tabs.cjs.map +1 -0
  46. package/dist/{tabs.mjs → private/tabs.js} +21 -25
  47. package/dist/private/tabs.js.map +1 -0
  48. package/dist/{testSetup.main.js → private/testSetup.cjs} +27 -19
  49. package/dist/private/testSetup.cjs.map +1 -0
  50. package/dist/{testSetup.module.js → private/testSetup.js} +26 -18
  51. package/dist/private/testSetup.js.map +1 -0
  52. package/dist/{tree.main.js → private/tree.cjs} +34 -35
  53. package/dist/private/tree.cjs.map +1 -0
  54. package/dist/{tree.mjs → private/tree.js} +34 -35
  55. package/dist/private/tree.js.map +1 -0
  56. package/dist/private/user.cjs +85 -0
  57. package/dist/private/user.cjs.map +1 -0
  58. package/dist/private/user.js +76 -0
  59. package/dist/private/user.js.map +1 -0
  60. package/dist/{userEventMaps.main.js → private/userEventMaps.cjs} +3 -3
  61. package/dist/{userEventMaps.main.js.map → private/userEventMaps.cjs.map} +1 -1
  62. package/dist/{userEventMaps.mjs → private/userEventMaps.js} +3 -3
  63. package/dist/{userEventMaps.module.js.map → private/userEventMaps.js.map} +1 -1
  64. package/dist/types/src/checkboxgroup.d.ts +45 -0
  65. package/dist/types/src/combobox.d.ts +75 -0
  66. package/dist/types/src/dialog.d.ts +36 -0
  67. package/dist/types/src/events.d.ts +25 -0
  68. package/dist/types/src/gridlist.d.ts +51 -0
  69. package/dist/types/src/index.d.ts +16 -0
  70. package/dist/types/src/listbox.d.ts +80 -0
  71. package/dist/types/src/menu.d.ts +102 -0
  72. package/dist/types/src/radiogroup.d.ts +46 -0
  73. package/dist/types/src/select.d.ts +67 -0
  74. package/dist/types/src/table.d.ts +104 -0
  75. package/dist/types/src/tabs.d.ts +58 -0
  76. package/dist/types/src/testSetup.d.ts +6 -0
  77. package/dist/types/src/tree.d.ts +57 -0
  78. package/dist/types/src/types.d.ts +136 -0
  79. package/dist/types/src/user.d.ts +47 -0
  80. package/dist/types/src/userEventMaps.d.ts +2 -0
  81. package/package.json +7 -7
  82. package/src/select.ts +10 -2
  83. package/src/table.ts +46 -1
  84. package/dist/checkboxgroup.main.js.map +0 -1
  85. package/dist/checkboxgroup.module.js +0 -99
  86. package/dist/checkboxgroup.module.js.map +0 -1
  87. package/dist/combobox.main.js.map +0 -1
  88. package/dist/combobox.module.js +0 -167
  89. package/dist/combobox.module.js.map +0 -1
  90. package/dist/dialog.main.js.map +0 -1
  91. package/dist/dialog.module.js +0 -100
  92. package/dist/dialog.module.js.map +0 -1
  93. package/dist/events.main.js.map +0 -1
  94. package/dist/events.module.js +0 -112
  95. package/dist/events.module.js.map +0 -1
  96. package/dist/gridlist.main.js.map +0 -1
  97. package/dist/gridlist.module.js +0 -149
  98. package/dist/gridlist.module.js.map +0 -1
  99. package/dist/listbox.main.js.map +0 -1
  100. package/dist/listbox.module.js +0 -138
  101. package/dist/listbox.module.js.map +0 -1
  102. package/dist/menu.main.js.map +0 -1
  103. package/dist/menu.module.js +0 -269
  104. package/dist/menu.module.js.map +0 -1
  105. package/dist/radiogroup.main.js.map +0 -1
  106. package/dist/radiogroup.module.js +0 -118
  107. package/dist/radiogroup.module.js.map +0 -1
  108. package/dist/select.main.js.map +0 -1
  109. package/dist/select.mjs +0 -158
  110. package/dist/select.module.js.map +0 -1
  111. package/dist/table.main.js.map +0 -1
  112. package/dist/table.mjs +0 -290
  113. package/dist/table.module.js.map +0 -1
  114. package/dist/tabs.main.js.map +0 -1
  115. package/dist/tabs.module.js +0 -130
  116. package/dist/tabs.module.js.map +0 -1
  117. package/dist/testSetup.main.js.map +0 -1
  118. package/dist/testSetup.mjs +0 -73
  119. package/dist/testSetup.module.js.map +0 -1
  120. package/dist/tree.main.js.map +0 -1
  121. package/dist/tree.module.js +0 -179
  122. package/dist/tree.module.js.map +0 -1
  123. package/dist/types.d.ts +0 -823
  124. package/dist/types.d.ts.map +0 -1
  125. package/dist/user.main.js +0 -85
  126. package/dist/user.main.js.map +0 -1
  127. package/dist/user.mjs +0 -76
  128. package/dist/user.module.js +0 -76
  129. package/dist/user.module.js.map +0 -1
  130. package/dist/userEventMaps.module.js +0 -38
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGjE,OAAO;IACT;IAEA,+FAA+F;IAC/F,MAAc,sBAAsB,IAAmD,EAAE;QACvF,IAAI,OAAC,GAAG,eAAE,cAAc,YAAW,GAAG;QACtC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,OAAO,KAAK,MAAM,CAAC,CAAA,MAAO,CAAE,CAAA,IAAI,YAAY,CAAC,eAAe,IAAI,YAAY,CAAC,qBAAqB,MAAK;QACvG,IAAI,KAAK,MAAM,KAAK,GAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAA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C,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AA0JF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n tabs = tabs.filter(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'));\n if (tabs.length === 0) {\n throw new Error('Tablist doesnt have any non-disabled tabs. Please double check your tabs implementation.');\n }\n\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs[0]?.focus());\n }\n }\n\n let currIndex = tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}
@@ -1,130 +0,0 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
2
- import {within as $im2y9$within, act as $im2y9$act} from "@testing-library/react";
3
-
4
- /*
5
- * Copyright 2024 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 $e615c34a00448a49$export$f1539bff3fc7d485 {
17
- /**
18
- * Set the interaction type used by the tabs tester.
19
- */ setInteractionType(type) {
20
- this._interactionType = type;
21
- }
22
- // TODO: This is pretty similar across most the utils, refactor to make it generic?
23
- /**
24
- * Returns a tab matching the specified index or text content.
25
- */ findTab(opts) {
26
- let { tabIndexOrText: tabIndexOrText } = opts;
27
- let tab;
28
- let tabs = this.tabs;
29
- if (typeof tabIndexOrText === 'number') tab = tabs[tabIndexOrText];
30
- else if (typeof tabIndexOrText === 'string') tab = (0, $im2y9$within)(this._tablist).getByText(tabIndexOrText).closest('[role=tab]');
31
- return tab;
32
- }
33
- // TODO: also quite similar across more utils albeit with orientation, refactor to make generic
34
- async keyboardNavigateToTab(opts) {
35
- let { tab: tab, orientation: orientation = 'vertical' } = opts;
36
- let tabs = this.tabs;
37
- tabs = tabs.filter((tab)=>!(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'));
38
- if (tabs.length === 0) throw new Error('Tablist doesnt have any non-disabled tabs. Please double check your tabs implementation.');
39
- let targetIndex = tabs.indexOf(tab);
40
- if (targetIndex === -1) throw new Error('Tab provided is not in the tablist');
41
- if (!this._tablist.contains(document.activeElement)) {
42
- let selectedTab = this.selectedTab;
43
- if (selectedTab != null) (0, $im2y9$act)(()=>selectedTab.focus());
44
- else (0, $im2y9$act)(()=>{
45
- var _tabs_;
46
- return (_tabs_ = tabs[0]) === null || _tabs_ === void 0 ? void 0 : _tabs_.focus();
47
- });
48
- }
49
- let currIndex = tabs.indexOf(document.activeElement);
50
- if (currIndex === -1) throw new Error('ActiveElement is not in the tablist');
51
- let arrowUp = 'ArrowUp';
52
- let arrowDown = 'ArrowDown';
53
- if (orientation === 'horizontal') {
54
- if (this._direction === 'ltr') {
55
- arrowUp = 'ArrowLeft';
56
- arrowDown = 'ArrowRight';
57
- } else {
58
- arrowUp = 'ArrowRight';
59
- arrowDown = 'ArrowLeft';
60
- }
61
- }
62
- let movementDirection = targetIndex > currIndex ? 'down' : 'up';
63
- for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);
64
- }
65
- /**
66
- * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.
67
- */ async triggerTab(opts) {
68
- let { tab: tab, interactionType: interactionType = this._interactionType, manualActivation: manualActivation } = opts;
69
- if (typeof tab === 'string' || typeof tab === 'number') tab = this.findTab({
70
- tabIndexOrText: tab
71
- });
72
- if (!tab) throw new Error('Target tab not found in the tablist.');
73
- else if (tab.hasAttribute('disabled')) throw new Error('Target tab is disabled.');
74
- if (interactionType === 'keyboard') {
75
- if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) (0, $im2y9$act)(()=>this._tablist.focus());
76
- let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
77
- await this.keyboardNavigateToTab({
78
- tab: tab,
79
- orientation: tabsOrientation
80
- });
81
- if (manualActivation) await this.user.keyboard('[Enter]');
82
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, tab, interactionType);
83
- }
84
- /**
85
- * Returns the tablist.
86
- */ get tablist() {
87
- return this._tablist;
88
- }
89
- /**
90
- * Returns the tabpanels.
91
- */ get tabpanels() {
92
- let tabpanels = [];
93
- for (let tab of this.tabs){
94
- let controlId = tab.getAttribute('aria-controls');
95
- let panel = controlId != null ? document.getElementById(controlId) : null;
96
- if (panel != null) tabpanels.push(panel);
97
- }
98
- return tabpanels;
99
- }
100
- /**
101
- * Returns the tabs in the tablist.
102
- */ get tabs() {
103
- return (0, $im2y9$within)(this.tablist).queryAllByRole('tab');
104
- }
105
- /**
106
- * Returns the currently selected tab in the tablist if any.
107
- */ get selectedTab() {
108
- return this.tabs.find((tab)=>tab.getAttribute('aria-selected') === 'true') || null;
109
- }
110
- /**
111
- * Returns the currently active tabpanel if any.
112
- */ get activeTabpanel() {
113
- var _this_selectedTab;
114
- let activeTabpanelId = (_this_selectedTab = this.selectedTab) === null || _this_selectedTab === void 0 ? void 0 : _this_selectedTab.getAttribute('aria-controls');
115
- return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;
116
- }
117
- constructor(opts){
118
- let { root: root, user: user, interactionType: interactionType, direction: direction } = opts;
119
- this.user = user;
120
- this._interactionType = interactionType || 'mouse';
121
- this._direction = direction || 'ltr';
122
- this._tablist = root;
123
- let tablist = (0, $im2y9$within)(root).queryAllByRole('tablist');
124
- if (tablist.length > 0) this._tablist = tablist[0];
125
- }
126
- }
127
-
128
-
129
- export {$e615c34a00448a49$export$f1539bff3fc7d485 as TabsTester};
130
- //# sourceMappingURL=tabs.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGjE,OAAO;IACT;IAEA,+FAA+F;IA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AAO,IAAI,YAAY,CAAC,qBAAqB,WAAW;IAChF;IAEA;;GAEC,GACD,IAAI,iBAAqC;YAChB;QAAvB,IAAI,oBAAmB,oBAAA,IAAI,CAAC,WAAW,cAAhB,wCAAA,kBAAkB,YAAY,CAAC;QACtD,OAAO,mBAAmB,SAAS,cAAc,CAAC,oBAAoB;IACxE;IApKA,YAAY,IAAoB,CAAE;QAChC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AA0JF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n tabs = tabs.filter(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'));\n if (tabs.length === 0) {\n throw new Error('Tablist doesnt have any non-disabled tabs. Please double check your tabs implementation.');\n }\n\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs[0]?.focus());\n }\n }\n\n let currIndex = tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.module.js.map"}
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS;IACd,IAAI,gBAAgB;IACpB,UAAU;QACR,eAAO,UAAU,GAAG,MAAM,uBAAuB;YAM/C,IAAI,QAAQ;gBACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;YACzB;YACA,IAAI,QAAQ;gBACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;YACzB;YATA,YAAY,IAAI,EAAE,IAAI,CAAE;gBACtB,KAAK,CAAC,MAAM;gBACZ,IAAI,CAAC,KAAK,GAAG;YACf;QAOF;IACF;IACA,SAAS;QACP,eAAO,UAAU,GAAG;IACtB;AACF;AAEO,SAAS;IACd,aAAa;IACb,eAAO,YAAY,GAAG,MAAM,yBAAyB;QAMnD,IAAI,cAAc;gBACT;YAAP,OAAO,CAAA,0BAAA,IAAI,CAAC,KAAK,CAAC,WAAW,cAAtB,qCAAA,0BAA0B;QACnC;QACA,IAAI,YAAY;YACd,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;QAC7B;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,SAAS;YACX,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM;QAC1B;QArBA,YAAY,IAAI,EAAE,IAAI,CAAE;YACtB,KAAK,CAAC,MAAM;YACZ,IAAI,CAAC,KAAK,GAAG;QACf;IAmBF;AACF;AAEO,SAAS;IACd,UAAU;IACV,SAAS;QACP,aAAa;QACb,OAAO,eAAO,YAAY;IAC5B;AACF","sources":["packages/@react-aria/test-utils/src/testSetup.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\n/**\n * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).\n */\nexport function installMouseEvent(): void {\n let oldMouseEvent = MouseEvent;\n beforeAll(() => {\n global.MouseEvent = class FakeMouseEvent extends MouseEvent {\n _init: {pageX: number, pageY: number};\n constructor(name, init) {\n super(name, init);\n this._init = init;\n }\n get pageX() {\n return this._init.pageX;\n }\n get pageY() {\n return this._init.pageY;\n }\n };\n });\n afterAll(() => {\n global.MouseEvent = oldMouseEvent;\n });\n}\n\nexport function definePointerEvent(): void {\n // @ts-ignore\n global.PointerEvent = class FakePointerEvent extends MouseEvent {\n _init: {pageX: number, pageY: number, pointerType: string, pointerId: number, width: number, height: number};\n constructor(name, init) {\n super(name, init);\n this._init = init;\n }\n get pointerType() {\n return this._init.pointerType ?? 'mouse';\n }\n get pointerId() {\n return this._init.pointerId;\n }\n get pageX() {\n return this._init.pageX;\n }\n get pageY() {\n return this._init.pageY;\n }\n get width() {\n return this._init.width;\n }\n get height() {\n return this._init.height;\n }\n };\n}\n\nexport function installPointerEvent(): void {\n beforeAll(definePointerEvent);\n afterAll(() => {\n // @ts-ignore\n delete global.PointerEvent;\n });\n}\n"],"names":[],"version":3,"file":"testSetup.main.js.map"}
@@ -1,73 +0,0 @@
1
-
2
- var $parcel$global = globalThis;
3
- /*
4
- * Copyright 2023 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
- * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).
15
- */ function $68df97871cfb5e33$export$de31e3987c917741() {
16
- let oldMouseEvent = MouseEvent;
17
- beforeAll(()=>{
18
- $parcel$global.MouseEvent = class FakeMouseEvent extends MouseEvent {
19
- get pageX() {
20
- return this._init.pageX;
21
- }
22
- get pageY() {
23
- return this._init.pageY;
24
- }
25
- constructor(name, init){
26
- super(name, init);
27
- this._init = init;
28
- }
29
- };
30
- });
31
- afterAll(()=>{
32
- $parcel$global.MouseEvent = oldMouseEvent;
33
- });
34
- }
35
- function $68df97871cfb5e33$export$93965c727ae9548a() {
36
- // @ts-ignore
37
- $parcel$global.PointerEvent = class FakePointerEvent extends MouseEvent {
38
- get pointerType() {
39
- var _this__init_pointerType;
40
- return (_this__init_pointerType = this._init.pointerType) !== null && _this__init_pointerType !== void 0 ? _this__init_pointerType : 'mouse';
41
- }
42
- get pointerId() {
43
- return this._init.pointerId;
44
- }
45
- get pageX() {
46
- return this._init.pageX;
47
- }
48
- get pageY() {
49
- return this._init.pageY;
50
- }
51
- get width() {
52
- return this._init.width;
53
- }
54
- get height() {
55
- return this._init.height;
56
- }
57
- constructor(name, init){
58
- super(name, init);
59
- this._init = init;
60
- }
61
- };
62
- }
63
- function $68df97871cfb5e33$export$82f0b04c1d69a901() {
64
- beforeAll($68df97871cfb5e33$export$93965c727ae9548a);
65
- afterAll(()=>{
66
- // @ts-ignore
67
- delete $parcel$global.PointerEvent;
68
- });
69
- }
70
-
71
-
72
- export {$68df97871cfb5e33$export$de31e3987c917741 as installMouseEvent, $68df97871cfb5e33$export$93965c727ae9548a as definePointerEvent, $68df97871cfb5e33$export$82f0b04c1d69a901 as installPointerEvent};
73
- //# sourceMappingURL=testSetup.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS;IACd,IAAI,gBAAgB;IACpB,UAAU;QACR,eAAO,UAAU,GAAG,MAAM,uBAAuB;YAM/C,IAAI,QAAQ;gBACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;YACzB;YACA,IAAI,QAAQ;gBACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;YACzB;YATA,YAAY,IAAI,EAAE,IAAI,CAAE;gBACtB,KAAK,CAAC,MAAM;gBACZ,IAAI,CAAC,KAAK,GAAG;YACf;QAOF;IACF;IACA,SAAS;QACP,eAAO,UAAU,GAAG;IACtB;AACF;AAEO,SAAS;IACd,aAAa;IACb,eAAO,YAAY,GAAG,MAAM,yBAAyB;QAMnD,IAAI,cAAc;gBACT;YAAP,OAAO,CAAA,0BAAA,IAAI,CAAC,KAAK,CAAC,WAAW,cAAtB,qCAAA,0BAA0B;QACnC;QACA,IAAI,YAAY;YACd,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;QAC7B;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK;QACzB;QACA,IAAI,SAAS;YACX,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM;QAC1B;QArBA,YAAY,IAAI,EAAE,IAAI,CAAE;YACtB,KAAK,CAAC,MAAM;YACZ,IAAI,CAAC,KAAK,GAAG;QACf;IAmBF;AACF;AAEO,SAAS;IACd,UAAU;IACV,SAAS;QACP,aAAa;QACb,OAAO,eAAO,YAAY;IAC5B;AACF","sources":["packages/@react-aria/test-utils/src/testSetup.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\n/**\n * Enables reading pageX/pageY from fireEvent.mouse*(..., {pageX: ..., pageY: ...}).\n */\nexport function installMouseEvent(): void {\n let oldMouseEvent = MouseEvent;\n beforeAll(() => {\n global.MouseEvent = class FakeMouseEvent extends MouseEvent {\n _init: {pageX: number, pageY: number};\n constructor(name, init) {\n super(name, init);\n this._init = init;\n }\n get pageX() {\n return this._init.pageX;\n }\n get pageY() {\n return this._init.pageY;\n }\n };\n });\n afterAll(() => {\n global.MouseEvent = oldMouseEvent;\n });\n}\n\nexport function definePointerEvent(): void {\n // @ts-ignore\n global.PointerEvent = class FakePointerEvent extends MouseEvent {\n _init: {pageX: number, pageY: number, pointerType: string, pointerId: number, width: number, height: number};\n constructor(name, init) {\n super(name, init);\n this._init = init;\n }\n get pointerType() {\n return this._init.pointerType ?? 'mouse';\n }\n get pointerId() {\n return this._init.pointerId;\n }\n get pageX() {\n return this._init.pageX;\n }\n get pageY() {\n return this._init.pageY;\n }\n get width() {\n return this._init.width;\n }\n get height() {\n return this._init.height;\n }\n };\n}\n\nexport function installPointerEvent(): void {\n beforeAll(definePointerEvent);\n afterAll(() => {\n // @ts-ignore\n delete global.PointerEvent;\n });\n}\n"],"names":[],"version":3,"file":"testSetup.module.js.map"}
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,MAAM;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AK,GAAG;IAEjB;AAgPF","sources":["packages/@react-aria/test-utils/src/tree.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 {BaseGridRowInteractionOpts, GridRowActionOpts, ToggleGridRowOpts, TreeTesterOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\n\ninterface TreeToggleExpansionOpts extends BaseGridRowInteractionOpts {}\ninterface TreeToggleRowOpts extends ToggleGridRowOpts {}\ninterface TreeRowActionOpts extends GridRowActionOpts {}\n\n// TODO: this ended up being pretty much the same as gridlist, refactor so it extends from gridlist\nexport class TreeTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _tree: HTMLElement;\n\n constructor(opts: TreeTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._tree = root;\n // TODO: should all helpers do this?\n let tree = within(root).queryByRole('treegrid');\n if (root.getAttribute('role') !== 'treegrid' && tree) {\n this._tree = tree;\n }\n }\n\n /**\n * Set the interaction type used by the tree 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.tree!).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 tree');\n }\n\n if (document.activeElement !== this._tree && !this._tree.contains(document.activeElement)) {\n act(() => this._tree.focus());\n }\n\n if (document.activeElement === this.tree) {\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n } else if (this._tree.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 tree');\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 tree row. Defaults to using the interaction type set on the tree 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: TreeToggleRowOpts): 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 tree.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox 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 // TODO add modifiers here? Maybe move into pressElement if we get more cases for different types of modifier keys\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 /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TreeToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.tree.contains(document.activeElement)) {\n await act(async () => {\n this.tree.focus();\n });\n }\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 tree.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\n }\n\n if (interactionType === 'mouse' || interactionType === 'touch') {\n let rowExpander = within(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?\n await pressElement(this.user, rowExpander, interactionType);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Triggers the action for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async triggerRowAction(opts: TreeRowActionOpts): 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 tree.');\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 // TODO: same as above, uses the modifier key to make sure we don't modify selection state on row focus\n // as we keyboard navigate to the row we want activate\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 tree.\n */\n get tree(): HTMLElement {\n return this._tree;\n }\n\n /**\n * Returns the tree's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.tree).queryAllByRole('row');\n }\n\n /**\n * Returns the tree'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 tree'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.tree} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"tree.main.js.map"}
@@ -1,179 +0,0 @@
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
- import {within as $3mnbZ$within, act as $3mnbZ$act} from "@testing-library/react";
3
-
4
- /*
5
- * Copyright 2024 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 $962758aa2f16f1a4$export$4445864b14128396 {
17
- /**
18
- * Set the interaction type used by the tree tester.
19
- */ setInteractionType(type) {
20
- this._interactionType = type;
21
- }
22
- /**
23
- * Returns a row matching the specified index or text content.
24
- */ findRow(opts) {
25
- let { rowIndexOrText: rowIndexOrText } = opts;
26
- let row;
27
- if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
28
- else if (typeof rowIndexOrText === 'string') row = (0, $3mnbZ$within)(this.tree).getByText(rowIndexOrText).closest('[role=row]');
29
- return row;
30
- }
31
- // TODO: RTL
32
- async keyboardNavigateToRow(opts) {
33
- let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
34
- let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
35
- let rows = this.rows;
36
- let targetIndex = rows.indexOf(row);
37
- if (targetIndex === -1) throw new Error('Option provided is not in the tree');
38
- if (document.activeElement !== this._tree && !this._tree.contains(document.activeElement)) (0, $3mnbZ$act)(()=>this._tree.focus());
39
- if (document.activeElement === this.tree) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
40
- else if (this._tree.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
41
- while (document.activeElement.getAttribute('role') !== 'row');
42
- let currIndex = rows.indexOf(document.activeElement);
43
- if (currIndex === -1) throw new Error('ActiveElement is not in the tree');
44
- let direction = targetIndex > currIndex ? 'down' : 'up';
45
- if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
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}]`);
48
- }
49
- /**
50
- * Toggles the selection for the specified tree row. Defaults to using the interaction type set on the tree tester.
51
- * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
52
- */ async toggleRowSelection(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)();
56
- if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
57
- rowIndexOrText: row
58
- });
59
- if (!row) throw new Error('Target row not found in the tree.');
60
- let rowCheckbox = (0, $3mnbZ$within)(row).queryByRole('checkbox');
61
- // TODO: we early return here because the checkbox can't be keyboard navigated to if the row is disabled usually
62
- // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
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;
64
- // this would be better than the check to do nothing in events.ts
65
- // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
66
- if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
67
- await this.keyboardNavigateToRow({
68
- row: row,
69
- selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
70
- });
71
- if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
72
- await this.user.keyboard('[Space]');
73
- if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
74
- return;
75
- }
76
- if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
77
- else {
78
- let cell = (0, $3mnbZ$within)(row).getAllByRole('gridcell')[0];
79
- if (needsLongPress && interactionType === 'touch') {
80
- if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
81
- // Note that long press interactions with rows is strictly touch only for grid rows
82
- await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
83
- element: cell,
84
- advanceTimer: this._advanceTimer,
85
- pointerOpts: {
86
- pointerType: 'touch'
87
- }
88
- });
89
- } else {
90
- // TODO add modifiers here? Maybe move into pressElement if we get more cases for different types of modifier keys
91
- if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
92
- await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
93
- if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
94
- }
95
- }
96
- }
97
- /**
98
- * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.
99
- */ async toggleRowExpansion(opts) {
100
- let { row: row, interactionType: interactionType = this._interactionType } = opts;
101
- if (!this.tree.contains(document.activeElement)) await (0, $3mnbZ$act)(async ()=>{
102
- this.tree.focus();
103
- });
104
- if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
105
- rowIndexOrText: row
106
- });
107
- if (!row) throw new Error('Target row not found in the tree.');
108
- else if (row.getAttribute('aria-expanded') == null) throw new Error('Target row is not expandable.');
109
- if (interactionType === 'mouse' || interactionType === 'touch') {
110
- let rowExpander = (0, $3mnbZ$within)(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?
111
- await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowExpander, interactionType);
112
- } else if (interactionType === 'keyboard') {
113
- if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
114
- // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed
115
- // in selectionmode="replace"/highlight selection when navigating to the row that the user wants
116
- // to expand. Discuss if this is useful or not
117
- await this.keyboardNavigateToRow({
118
- row: row
119
- });
120
- if (row.getAttribute('aria-expanded') === 'true') await this.user.keyboard('[ArrowLeft]');
121
- else await this.user.keyboard('[ArrowRight]');
122
- }
123
- }
124
- /**
125
- * Triggers the action for the specified tree row. Defaults to using the interaction type set on the tree tester.
126
- */ async triggerRowAction(opts) {
127
- let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
128
- if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
129
- rowIndexOrText: row
130
- });
131
- if (!row) throw new Error('Target row not found in the tree.');
132
- if (needsDoubleClick) await this.user.dblClick(row);
133
- else if (interactionType === 'keyboard') {
134
- if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
135
- // TODO: same as above, uses the modifier key to make sure we don't modify selection state on row focus
136
- // as we keyboard navigate to the row we want activate
137
- await this.keyboardNavigateToRow({
138
- row: row
139
- });
140
- await this.user.keyboard('[Enter]');
141
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
142
- }
143
- /**
144
- * Returns the tree.
145
- */ get tree() {
146
- return this._tree;
147
- }
148
- /**
149
- * Returns the tree's rows if any.
150
- */ get rows() {
151
- var _this;
152
- return (0, $3mnbZ$within)((_this = this) === null || _this === void 0 ? void 0 : _this.tree).queryAllByRole('row');
153
- }
154
- /**
155
- * Returns the tree's selected rows if any.
156
- */ get selectedRows() {
157
- return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
158
- }
159
- /**
160
- * Returns the tree's cells if any. Can be filtered against a specific row if provided via `element`.
161
- */ cells(opts = {}) {
162
- let { element: element = this.tree } = opts;
163
- return (0, $3mnbZ$within)(element).queryAllByRole('gridcell');
164
- }
165
- constructor(opts){
166
- let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
167
- this.user = user;
168
- this._interactionType = interactionType || 'mouse';
169
- this._advanceTimer = advanceTimer;
170
- this._tree = root;
171
- // TODO: should all helpers do this?
172
- let tree = (0, $3mnbZ$within)(root).queryByRole('treegrid');
173
- if (root.getAttribute('role') !== 'treegrid' && tree) this._tree = tree;
174
- }
175
- }
176
-
177
-
178
- export {$962758aa2f16f1a4$export$4445864b14128396 as TreeTester};
179
- //# sourceMappingURL=tree.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAWM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe;aAC1B,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,IAAI,EAAG,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAG9D,OAAO;IACT;IAE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AAqB;QACvB,OAAO,IAAI,CAAC,KAAK;IACnB;IAEA;;GAEC,GACD,IAAI,OAAsB;YACV;QAAd,OAAO,CAAA,GAAA,aAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,IAAI,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,IAAI,EAAC,GAAG;QAC5B,OAAO,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA1PA,YAAY,IAAoB,CAAE;QAChC,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,KAAK,GAAG;QACb,oCAAoC;QACpC,IAAI,OAAO,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACpC,IAAI,KAAK,YAAY,CAAC,YAAY,cAAc,MAC9C,IAAI,CAAC,KAAK,GAAG;IAEjB;AAgPF","sources":["packages/@react-aria/test-utils/src/tree.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 {BaseGridRowInteractionOpts, GridRowActionOpts, ToggleGridRowOpts, TreeTesterOpts, UserOpts} from './types';\nimport {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\n\ninterface TreeToggleExpansionOpts extends BaseGridRowInteractionOpts {}\ninterface TreeToggleRowOpts extends ToggleGridRowOpts {}\ninterface TreeRowActionOpts extends GridRowActionOpts {}\n\n// TODO: this ended up being pretty much the same as gridlist, refactor so it extends from gridlist\nexport class TreeTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _tree: HTMLElement;\n\n constructor(opts: TreeTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._tree = root;\n // TODO: should all helpers do this?\n let tree = within(root).queryByRole('treegrid');\n if (root.getAttribute('role') !== 'treegrid' && tree) {\n this._tree = tree;\n }\n }\n\n /**\n * Set the interaction type used by the tree 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.tree!).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 tree');\n }\n\n if (document.activeElement !== this._tree && !this._tree.contains(document.activeElement)) {\n act(() => this._tree.focus());\n }\n\n if (document.activeElement === this.tree) {\n await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);\n } else if (this._tree.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 tree');\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 tree row. Defaults to using the interaction type set on the tree 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: TreeToggleRowOpts): 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 tree.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox 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 // TODO add modifiers here? Maybe move into pressElement if we get more cases for different types of modifier keys\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 /**\n * Toggles the expansion for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async toggleRowExpansion(opts: TreeToggleExpansionOpts): Promise<void> {\n let {\n row,\n interactionType = this._interactionType\n } = opts;\n if (!this.tree.contains(document.activeElement)) {\n await act(async () => {\n this.tree.focus();\n });\n }\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 tree.');\n } else if (row.getAttribute('aria-expanded') == null) {\n throw new Error('Target row is not expandable.');\n }\n\n if (interactionType === 'mouse' || interactionType === 'touch') {\n let rowExpander = within(row).getAllByRole('button')[0]; // what happens if the button is not first? how can we differentiate?\n await pressElement(this.user, rowExpander, interactionType);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n // TODO: We always Use Option/Ctrl when keyboard navigating so selection isn't changed\n // in selectionmode=\"replace\"/highlight selection when navigating to the row that the user wants\n // to expand. Discuss if this is useful or not\n await this.keyboardNavigateToRow({row});\n if (row.getAttribute('aria-expanded') === 'true') {\n await this.user.keyboard('[ArrowLeft]');\n } else {\n await this.user.keyboard('[ArrowRight]');\n }\n }\n };\n\n /**\n * Triggers the action for the specified tree row. Defaults to using the interaction type set on the tree tester.\n */\n async triggerRowAction(opts: TreeRowActionOpts): 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 tree.');\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 // TODO: same as above, uses the modifier key to make sure we don't modify selection state on row focus\n // as we keyboard navigate to the row we want activate\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 tree.\n */\n get tree(): HTMLElement {\n return this._tree;\n }\n\n /**\n * Returns the tree's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.tree).queryAllByRole('row');\n }\n\n /**\n * Returns the tree'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 tree'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.tree} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"tree.module.js.map"}