@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
@@ -156,13 +156,14 @@ class $15e4b71f2b6c4964$export$f97e14e96d71ab3b {
156
156
  // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
157
157
  if (trigger) this._trigger = trigger;
158
158
  else {
159
- let trigger = (0, $f8PS3$testinglibraryreact.within)(root).queryByRole('button', {
159
+ let buttons = (0, $f8PS3$testinglibraryreact.within)(root).queryAllByRole('button', {
160
160
  hidden: true
161
161
  });
162
- if (trigger) this._trigger = trigger;
163
- else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
162
+ if (buttons.length === 1) trigger = buttons[0];
163
+ else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
164
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
164
165
  // is also the trigger button
165
- this._trigger = this._combobox;
166
+ this._trigger = trigger || this._combobox;
166
167
  }
167
168
  }
168
169
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAkCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,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,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAC9D,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = this._combobox;\n }\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAqCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAiB;QACrD,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IA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EAAE,MAAM,cAAc,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAEjE,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,OAAO,CAAC,EAAE;iBACf,IAAI,QAAQ,MAAM,GAAG,GAC1B,UAAU,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;YAGvD,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,WAAW,IAAI,CAAC,SAAS;QAC3C;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.main.js.map"}
package/dist/combobox.mjs CHANGED
@@ -150,13 +150,14 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
150
150
  // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
151
151
  if (trigger) this._trigger = trigger;
152
152
  else {
153
- let trigger = (0, $1n52X$within)(root).queryByRole('button', {
153
+ let buttons = (0, $1n52X$within)(root).queryAllByRole('button', {
154
154
  hidden: true
155
155
  });
156
- if (trigger) this._trigger = trigger;
157
- else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
156
+ if (buttons.length === 1) trigger = buttons[0];
157
+ else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
158
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
158
159
  // is also the trigger button
159
- this._trigger = this._combobox;
160
+ this._trigger = trigger || this._combobox;
160
161
  }
161
162
  }
162
163
  }
@@ -150,13 +150,14 @@ class $dab75f394483aa9c$export$f97e14e96d71ab3b {
150
150
  // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)
151
151
  if (trigger) this._trigger = trigger;
152
152
  else {
153
- let trigger = (0, $1n52X$within)(root).queryByRole('button', {
153
+ let buttons = (0, $1n52X$within)(root).queryAllByRole('button', {
154
154
  hidden: true
155
155
  });
156
- if (trigger) this._trigger = trigger;
157
- else // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
156
+ if (buttons.length === 1) trigger = buttons[0];
157
+ else if (buttons.length > 1) trigger = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
158
+ // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox
158
159
  // is also the trigger button
159
- this._trigger = this._combobox;
160
+ this._trigger = trigger || this._combobox;
160
161
  }
161
162
  }
162
163
  }
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAkCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAiB;QACrD,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CA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7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,SAAS;QAElC;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let trigger = within(root).queryByRole('button', {hidden: true});\n if (trigger) {\n this._trigger = trigger;\n } else {\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = this._combobox;\n }\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAqCX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAyB,CAAC,CAAC,EAAiB;QACrD,IAAI,mBAAC,kBAAkB,2BAAU,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;QAC5E,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,WAAW,IAAI,CAAC,QAAQ;QAC5B,IAAI,aAAa,QAAS,YAAY,CAAC;QAEvC,IAAI,oBAAoB;YACtB,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;eAEnB,IAAI,oBAAoB,cAAc,IAAI,CAAC,QAAQ,IAAI,MAAM;YAClE,CAAA,GAAA,UAAE,EAAE,IAAM,IAAI,CAAC,QAAQ,CAAE,KAAK;YAC9B,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAE7B,OAAO,IAAI,oBAAoB;YAC7B,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC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D;IAEA;;GAEC,GACD,QAAQ,OAAgC,CAAC,CAAC,EAAiB;QACzD,IAAI,WAAC,UAAU,IAAI,CAAC,OAAO,EAAC,GAAG;QAC/B,IAAI,UAAU,EAAE;QAChB,IAAI,SACF,UAAU,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,gBAAoC;QACtC,IAAI,kBAAkB,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QACjD,OAAO,kBAAkB,SAAS,cAAc,CAAC,mBAAmB;IACtE;IA1NA,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,WAAE,OAAO,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QAC7C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAE3C,8IAA8I;QAC9I,2FAA2F;QAC3F,IAAI,CAAC,SAAS,GAAG;QACjB,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;QACxC,IAAI,UACF,IAAI,CAAC,SAAS,GAAG;QAGnB,6KAA6K;QAC7K,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC,UAAU;gBAAC,QAAQ;YAAI;YAEjE,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,OAAO,CAAC,EAAE;iBACf,IAAI,QAAQ,MAAM,GAAG,GAC1B,UAAU,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;YAGvD,qHAAqH;YACrH,6BAA6B;YAC7B,IAAI,CAAC,QAAQ,GAAG,WAAW,IAAI,CAAC,SAAS;QAC3C;IACF;AA8LF","sources":["packages/@react-aria/test-utils/src/combobox.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {ComboBoxTesterOpts, UserOpts} from './types';\n\ninterface ComboBoxOpenOpts {\n /**\n * Whether the combobox opens on focus or needs to be manually opened via user action.\n * @default 'manual'\n */\n triggerBehavior?: 'focus' | 'manual',\n /**\n * What interaction type to use when opening the combobox. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface ComboBoxSelectOpts extends ComboBoxOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement\n}\n\nexport class ComboBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _combobox: HTMLElement;\n private _trigger: HTMLElement;\n\n constructor(opts: ComboBoxTesterOpts) {\n let {root, trigger, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n\n // Handle case where element provided is a wrapper around the combobox. The expectation is that the user at least uses a ref/data attribute to\n // query their combobox/combobox wrapper (in the case of RSP) which they then pass to thhis\n this._combobox = root;\n let combobox = within(root).queryByRole('combobox');\n if (combobox) {\n this._combobox = combobox;\n }\n\n // This is for if user need to directly set the trigger button element (aka the element provided in setElement was the combobox input or the trigger is somewhere unexpected)\n if (trigger) {\n this._trigger = trigger;\n } else {\n let buttons = within(root).queryAllByRole('button', {hidden: true});\n\n if (buttons.length === 1) {\n trigger = buttons[0];\n } else if (buttons.length > 1) {\n trigger = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n // For cases like https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ where the combobox\n // is also the trigger button\n this._trigger = trigger || this._combobox;\n }\n }\n\n /**\n * Set the interaction type used by the combobox tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the combobox dropdown. Defaults to using the interaction type set on the combobox tester.\n */\n async open(opts: ComboBoxOpenOpts = {}): Promise<void> {\n let {triggerBehavior = 'manual', interactionType = this._interactionType} = opts;\n let trigger = this.trigger;\n let combobox = this.combobox;\n let isDisabled = trigger!.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n if (triggerBehavior === 'focus') {\n await this.user.click(combobox);\n } else {\n await this.user.click(trigger);\n }\n } else if (interactionType === 'keyboard' && this._trigger != null) {\n act(() => this._trigger!.focus());\n if (triggerBehavior !== 'focus') {\n await this.user.keyboard('{ArrowDown}');\n }\n } else if (interactionType === 'touch') {\n if (triggerBehavior === 'focus') {\n await this.user.pointer({target: combobox, keys: '[TouchA]'});\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n }\n\n await waitFor(() => {\n if (!isDisabled && combobox.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on combobox trigger element.');\n } else {\n return true;\n }\n });\n let listBoxId = combobox.getAttribute('aria-controls');\n await waitFor(() => {\n if (!isDisabled && (!listBoxId || document.getElementById(listBoxId) == null)) {\n throw new Error(`Listbox with id of ${listBoxId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n\n /**\n * Returns an option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let listbox = this.listbox;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && listbox != null) {\n option = (within(listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n /**\n * Selects the desired combobox option. Defaults to using the interaction type set on the combobox tester. If necessary, will open the combobox dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: ComboBoxSelectOpts): Promise<void> {\n let {option, triggerBehavior, interactionType = this._interactionType} = opts;\n if (!this.combobox.getAttribute('aria-controls')) {\n await this.open({triggerBehavior});\n }\n\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Combobox\\'s listbox not found.');\n }\n\n if (listbox) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n // TODO: keyboard method of selecting the the option is a bit tricky unless I simply simulate the user pressing the down arrow\n // the required amount of times to reach the option. For now just click the option even in keyboard mode\n if (interactionType === 'mouse' || interactionType === 'keyboard') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n\n if (option.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the combobox, but the listbox wasn't found.\");\n }\n }\n\n /**\n * Closes the combobox dropdown.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => this.combobox.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.contains(listbox)) {\n throw new Error('Expected listbox element to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns the combobox.\n */\n get combobox(): HTMLElement {\n return this._combobox;\n }\n\n /**\n * Returns the combobox trigger button.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the combobox's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.combobox.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) || null : null;\n }\n\n /**\n * Returns the combobox's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n\n /**\n * Returns the combobox's options if present. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the currently focused option in the combobox's dropdown if any.\n */\n get focusedOption(): HTMLElement | null {\n let focusedOptionId = this.combobox.getAttribute('aria-activedescendant');\n return focusedOptionId ? document.getElementById(focusedOptionId) : null;\n }\n}\n"],"names":[],"version":3,"file":"combobox.module.js.map"}
@@ -5,6 +5,8 @@ function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
+ $parcel$export(module.exports, "getAltKey", () => $5a8bfe1663b8366d$export$6fc0ccaebd758b9d);
9
+ $parcel$export(module.exports, "getMetaKey", () => $5a8bfe1663b8366d$export$7943c508934e27ce);
8
10
  $parcel$export(module.exports, "triggerLongPress", () => $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b);
9
11
  $parcel$export(module.exports, "pressElement", () => $5a8bfe1663b8366d$export$6ffa3eb717517feb);
10
12
  /*
@@ -19,6 +21,27 @@ $parcel$export(module.exports, "pressElement", () => $5a8bfe1663b8366d$export$6f
19
21
  * governing permissions and limitations under the License.
20
22
  */
21
23
  const $5a8bfe1663b8366d$export$4bd1d2d5ba6f5eaf = 500;
24
+ function $5a8bfe1663b8366d$var$testPlatform(re) {
25
+ var _window_navigator_userAgentData;
26
+ return typeof window !== 'undefined' && window.navigator != null ? re.test(((_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.platform) || window.navigator.platform) : false;
27
+ }
28
+ function $5a8bfe1663b8366d$var$cached(fn) {
29
+ if (process.env.NODE_ENV === 'test') return fn;
30
+ let res = null;
31
+ return ()=>{
32
+ if (res == null) res = fn();
33
+ return res;
34
+ };
35
+ }
36
+ const $5a8bfe1663b8366d$var$isMac = $5a8bfe1663b8366d$var$cached(function() {
37
+ return $5a8bfe1663b8366d$var$testPlatform(/^Mac/i);
38
+ });
39
+ function $5a8bfe1663b8366d$export$6fc0ccaebd758b9d() {
40
+ return $5a8bfe1663b8366d$var$isMac() ? 'Alt' : 'ControlLeft';
41
+ }
42
+ function $5a8bfe1663b8366d$export$7943c508934e27ce() {
43
+ return $5a8bfe1663b8366d$var$isMac() ? 'MetaLeft' : 'ControlLeft';
44
+ }
22
45
  async function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(opts) {
23
46
  // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
24
47
  // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
@@ -73,7 +96,14 @@ async function $5a8bfe1663b8366d$export$3a22a5a9bc0fd3b(opts) {
73
96
  });
74
97
  }
75
98
  async function $5a8bfe1663b8366d$export$6ffa3eb717517feb(user, element, interactionType) {
76
- if (interactionType === 'mouse') await user.click(element);
99
+ if (interactionType === 'mouse') // Add coords with pressure so this isn't detected as a virtual click
100
+ await user.pointer({
101
+ target: element,
102
+ keys: '[MouseLeft]',
103
+ coords: {
104
+ pressure: .5
105
+ }
106
+ });
77
107
  else if (interactionType === 'keyboard') {
78
108
  // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
79
109
  // stick to simulting an actual user's keyboard operations as closely as possible
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAA2H;IAChK,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;QAC9B;IAAlB,IAAI,cAAc,CAAA,2BAAA,YAAY,WAAW,cAAvB,sCAAA,2BAA2B;IAC7C,IAAI,gCAAgC,CAAA,GAAA,oCAAQ,EAAE,WAAW,CAAC,SAAS;qBAAC;QAAa,GAAG,WAAW;IAAA;I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AY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n await user.click(element);\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AACvC,SAAS,mCAAa,EAAU;QAElB;IADZ,OAAO,OAAO,WAAW,eAAe,OA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AAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;qBAAC;QAAa,GAAG,WAAW;IAAA;IACzD,IAAI,+BAA+B;QACjC,IAAI,gBAAgB,SAAS;YAC3B,cAAc,CAAA,GAAA,oCAAQ,EAAE,QAAQ,CAAC,SAAS;gBAAC,eAAe;oBAAC;wBAAC,YAAY,YAAY,SAAS;wBAAE,SAAS,YAAY,OAAO;wBAAE,SAAS,YAAY,OAAO;oBAAA;iBAAE;YAAA;YAC3J,cAAc,CAAA,GAAA,oCAAQ,EAAE,SAAS,CAAC,SAAS;YAC3C,IAAI,aACF,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;YAEzB,CAAA,GAAA,oCAAQ,EAAE,OAAO,CAAC,SAAS;QAC7B,OAAO,IAAI,gBAAgB,SACzB,CAAA,GAAA,oCAAQ,EAAE,OAAO,CAAC,SAAS;IAE/B;IACA,CAAA,GAAA,oCAAQ,EAAE,KAAK,CAAC,SAAS;QAAC,QAAQ;QAAG,GAAG,WAAW;IAAA;AACrD;AAGO,eAAe,0CAAa,IAA8K,EAAE,OAAoB,EAAE,eAA4C;IACnR,IAAI,oBAAoB,SACtB,qEAAqE;IACrE,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;QAAe,QAAQ;YAAC,UAAU;QAAE;IAAC;SAC3E,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,8BAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\nfunction testPlatform(re: RegExp) {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === 'test') {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(function () {\n return testPlatform(/^Mac/i);\n});\n\nexport function getAltKey(): 'Alt' | 'ControlLeft' {\n return isMac() ? 'Alt' : 'ControlLeft';\n}\n\nexport function getMetaKey(): 'MetaLeft' | 'ControlLeft' {\n return isMac() ? 'MetaLeft' : 'ControlLeft';\n}\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string, coords?: any}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n // Add coords with pressure so this isn't detected as a virtual click\n await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: .5}});\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.main.js.map"}
package/dist/events.mjs CHANGED
@@ -12,6 +12,27 @@ import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
  const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
+ function $5d1eca18f92ad0e6$var$testPlatform(re) {
16
+ var _window_navigator_userAgentData;
17
+ return typeof window !== 'undefined' && window.navigator != null ? re.test(((_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.platform) || window.navigator.platform) : false;
18
+ }
19
+ function $5d1eca18f92ad0e6$var$cached(fn) {
20
+ if (process.env.NODE_ENV === 'test') return fn;
21
+ let res = null;
22
+ return ()=>{
23
+ if (res == null) res = fn();
24
+ return res;
25
+ };
26
+ }
27
+ const $5d1eca18f92ad0e6$var$isMac = $5d1eca18f92ad0e6$var$cached(function() {
28
+ return $5d1eca18f92ad0e6$var$testPlatform(/^Mac/i);
29
+ });
30
+ function $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d() {
31
+ return $5d1eca18f92ad0e6$var$isMac() ? 'Alt' : 'ControlLeft';
32
+ }
33
+ function $5d1eca18f92ad0e6$export$7943c508934e27ce() {
34
+ return $5d1eca18f92ad0e6$var$isMac() ? 'MetaLeft' : 'ControlLeft';
35
+ }
15
36
  async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
16
37
  // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
17
38
  // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
@@ -66,7 +87,14 @@ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
66
87
  });
67
88
  }
68
89
  async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interactionType) {
69
- if (interactionType === 'mouse') await user.click(element);
90
+ if (interactionType === 'mouse') // Add coords with pressure so this isn't detected as a virtual click
91
+ await user.pointer({
92
+ target: element,
93
+ keys: '[MouseLeft]',
94
+ coords: {
95
+ pressure: .5
96
+ }
97
+ });
70
98
  else if (interactionType === 'keyboard') {
71
99
  // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
72
100
  // stick to simulting an actual user's keyboard operations as closely as possible
@@ -80,5 +108,5 @@ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interact
80
108
  }
81
109
 
82
110
 
83
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
111
+ export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d as getAltKey, $5d1eca18f92ad0e6$export$7943c508934e27ce as getMetaKey, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
84
112
  //# sourceMappingURL=events.module.js.map
@@ -12,6 +12,27 @@ import {fireEvent as $hhVmT$fireEvent, act as $hhVmT$act} from "@testing-library
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
  const $5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf = 500;
15
+ function $5d1eca18f92ad0e6$var$testPlatform(re) {
16
+ var _window_navigator_userAgentData;
17
+ return typeof window !== 'undefined' && window.navigator != null ? re.test(((_window_navigator_userAgentData = window.navigator['userAgentData']) === null || _window_navigator_userAgentData === void 0 ? void 0 : _window_navigator_userAgentData.platform) || window.navigator.platform) : false;
18
+ }
19
+ function $5d1eca18f92ad0e6$var$cached(fn) {
20
+ if (process.env.NODE_ENV === 'test') return fn;
21
+ let res = null;
22
+ return ()=>{
23
+ if (res == null) res = fn();
24
+ return res;
25
+ };
26
+ }
27
+ const $5d1eca18f92ad0e6$var$isMac = $5d1eca18f92ad0e6$var$cached(function() {
28
+ return $5d1eca18f92ad0e6$var$testPlatform(/^Mac/i);
29
+ });
30
+ function $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d() {
31
+ return $5d1eca18f92ad0e6$var$isMac() ? 'Alt' : 'ControlLeft';
32
+ }
33
+ function $5d1eca18f92ad0e6$export$7943c508934e27ce() {
34
+ return $5d1eca18f92ad0e6$var$isMac() ? 'MetaLeft' : 'ControlLeft';
35
+ }
15
36
  async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
16
37
  // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the
17
38
  // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the
@@ -66,7 +87,14 @@ async function $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b(opts) {
66
87
  });
67
88
  }
68
89
  async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interactionType) {
69
- if (interactionType === 'mouse') await user.click(element);
90
+ if (interactionType === 'mouse') // Add coords with pressure so this isn't detected as a virtual click
91
+ await user.pointer({
92
+ target: element,
93
+ keys: '[MouseLeft]',
94
+ coords: {
95
+ pressure: .5
96
+ }
97
+ });
70
98
  else if (interactionType === 'keyboard') {
71
99
  // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should
72
100
  // stick to simulting an actual user's keyboard operations as closely as possible
@@ -80,5 +108,5 @@ async function $5d1eca18f92ad0e6$export$6ffa3eb717517feb(user, element, interact
80
108
  }
81
109
 
82
110
 
83
- export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
111
+ export {$5d1eca18f92ad0e6$export$4bd1d2d5ba6f5eaf as DEFAULT_LONG_PRESS_TIME, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d as getAltKey, $5d1eca18f92ad0e6$export$7943c508934e27ce as getMetaKey, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b as triggerLongPress, $5d1eca18f92ad0e6$export$6ffa3eb717517feb as pressElement};
84
112
  //# sourceMappingURL=events.module.js.map
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AAShC,eAAe,yCAAiB,IAA2H;IAChK,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;QAC9B;IAAlB,IAAI,cAAc,CAAA,2BAAA,YAAY,WAAW,cAAvB,sCAAA,2BAA2B;IAC7C,IAAI,gCAAgC,CAAA,GAAA,gBAAQ,EAAE,WAAW,CAAC,SAAS;qBAAC;QAAa,GAAG,WAAW;IAAA;IAC/F,IAAI,cAAc;IAClB,IAAI,+BAA+B;QACjC,IAAI,gBAAgB,SAClB,cAAc,gCAAgC,CAAA,GAAA,gBAAQ,EAAE,UAAU,CAAC,SAAS;YAAC,eAAe;gBAAC;oBAAC,YAAY,YAAY,SAAS;oBAAE,SAAS,YAAY,OAAO;oBAAE,SAAS,YAAY,OAAO;gBAAA;aAAE;QAAA;aACxL,IAAI,gBAAgB,SAAS;YAClC,cAAc,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;YAC3C,IAAI,aACF,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;QAE3B;IACF;IACA,MAAM,CAAA,GAAA,UAAE,EAAE,UAAY,MAAM,aAAa;IACzC,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;qBAAC;QAAa,GAAG,WAAW;IAAA;IACzD,IAAI,+BAA+B;QACjC,IAAI,gBAAgB,SAAS;YAC3B,cAAc,CAAA,GAAA,gBAAQ,EAAE,QAAQ,CAAC,SAAS;gBAAC,eAAe;oBAAC;wBAAC,YAAY,YAAY,SAAS;wBAAE,SAAS,YAAY,OAAO;wBAAE,SAAS,YAAY,OAAO;oBAAA;iBAAE;YAAA;YAC3J,cAAc,CAAA,GAAA,gBAAQ,EAAE,SAAS,CAAC,SAAS;YAC3C,IAAI,aACF,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;YAEzB,CAAA,GAAA,gBAAQ,EAAE,OAAO,CAAC,SAAS;QAC7B,OAAO,IAAI,gBAAgB,SACzB,CAAA,GAAA,gBAAQ,EAAE,OAAO,CAAC,SAAS;IAE/B;IACA,CAAA,GAAA,gBAAQ,EAAE,KAAK,CAAC,SAAS;QAAC,QAAQ;QAAG,GAAG,WAAW;IAAA;AACrD;AAGO,eAAe,0CAAa,IAAgK,EAAE,OAAoB,EAAE,eAA4C;IACrQ,IAAI,oBAAoB,SACtB,MAAM,KAAK,KAAK,CAAC;SACZ,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n await user.click(element);\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,MAAM,4CAA0B;AACvC,SAAS,mCAAa,EAAU;QAElB;IADZ,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS,IAAI,OACxD,GAAG,IAAI,CAAC,EAAA,kCAAA,OAAO,SAAS,CAAC,gBAAgB,cAAjC,sDAAA,gCAAmC,QAAQ,KAAI,OAAO,SAAS,CAAC,QAAQ,IAChF;AACN;AAEA,SAAS,6BAAO,EAAiB;IAC/B,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,QAC3B,OAAO;IAGT,IAAI,MAAsB;IAC1B,OAAO;QACL,IAAI,OAAO,MACT,MAAM;QAER,OAAO;IACT;AACF;AAEA,MAAM,8BAAQ,6BAAO;IACnB,OAAO,mCAAa;AACtB;AAEO,SAAS;IACd,OAAO,gCAAU,QAAQ;AAC3B;AAEO,SAAS;IACd,OAAO,gCAAU,aAAa;AAChC;AASO,eAAe,yCAAiB,IAA2H;IAChK,kHAAkH;IAClH,gIAAgI;IAChI,0DAA0D;IAC1D,IAAI,WAAC,OAAO,gBAAE,YAAY,eAAE,cAAc,CAAC,GAAE,GAAG;QAC9B;IAAlB,IAAI,cAAc,CAAA,2BAAA,YAAY,WAAW,cAAvB,sCAAA,2BAA2B;IAC7C,IAAI,gCAAgC,CAAA,GAAA,gBA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oB,SACtB,qEAAqE;IACrE,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;QAAe,QAAQ;YAAC,UAAU;QAAE;IAAC;SAC3E,IAAI,oBAAoB,YAAY;QACzC,yIAAyI;QACzI,iFAAiF;QACjF,qIAAqI;QACrI,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;QACvB,MAAM,KAAK,QAAQ,CAAC;IACtB,OAAO,IAAI,oBAAoB,SAC7B,MAAM,KAAK,OAAO,CAAC;QAAC,QAAQ;QAAS,MAAM;IAAU;AAEzD","sources":["packages/@react-aria/test-utils/src/events.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, fireEvent} from '@testing-library/react';\nimport {UserOpts} from './types';\n\nexport const DEFAULT_LONG_PRESS_TIME = 500;\nfunction testPlatform(re: RegExp) {\n return typeof window !== 'undefined' && window.navigator != null\n ? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)\n : false;\n}\n\nfunction cached(fn: () => boolean) {\n if (process.env.NODE_ENV === 'test') {\n return fn;\n }\n\n let res: boolean | null = null;\n return () => {\n if (res == null) {\n res = fn();\n }\n return res;\n };\n}\n\nconst isMac = cached(function () {\n return testPlatform(/^Mac/i);\n});\n\nexport function getAltKey(): 'Alt' | 'ControlLeft' {\n return isMac() ? 'Alt' : 'ControlLeft';\n}\n\nexport function getMetaKey(): 'MetaLeft' | 'ControlLeft' {\n return isMac() ? 'MetaLeft' : 'ControlLeft';\n}\n\n/**\n * Simulates a \"long press\" event on a element.\n * @param opts - Options for the long press.\n * @param opts.element - Element to long press.\n * @param opts.advanceTimer - Function that when called advances the timers in your test suite by a specific amount of time(ms).\n * @param opts.pointeropts - Options to pass to the simulated event. Defaults to mouse. See https://testing-library.com/docs/dom-testing-library/api-events/#fireevent for more info.\n */\nexport async function triggerLongPress(opts: {element: HTMLElement, advanceTimer: (time: number) => unknown | Promise<unknown>, pointerOpts?: Record<string, any>}): Promise<void> {\n // TODO: note that this only works if the code from installPointerEvent is called somewhere in the test BEFORE the\n // render. Perhaps we should rely on the user setting that up since I'm not sure there is a great way to set that up here in the\n // util before first render. Will need to document it well\n let {element, advanceTimer, pointerOpts = {}} = opts;\n let pointerType = pointerOpts.pointerType ?? 'mouse';\n let shouldFireCompatibilityEvents = fireEvent.pointerDown(element, {pointerType, ...pointerOpts});\n let shouldFocus = true;\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = shouldFireCompatibilityEvents = fireEvent.touchStart(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n } else if (pointerType === 'mouse') {\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n }\n }\n await act(async () => await advanceTimer(DEFAULT_LONG_PRESS_TIME));\n fireEvent.pointerUp(element, {pointerType, ...pointerOpts});\n if (shouldFireCompatibilityEvents) {\n if (pointerType === 'touch') {\n shouldFocus = fireEvent.touchEnd(element, {targetTouches: [{identifier: pointerOpts.pointerId, clientX: pointerOpts.clientX, clientY: pointerOpts.clientY}]});\n shouldFocus = fireEvent.mouseDown(element, pointerOpts);\n if (shouldFocus) {\n act(() => element.focus());\n }\n fireEvent.mouseUp(element, pointerOpts);\n } else if (pointerType === 'mouse') {\n fireEvent.mouseUp(element, pointerOpts);\n }\n }\n fireEvent.click(element, {detail: 1, ...pointerOpts});\n}\n\n// Docs cannot handle the types that userEvent actually declares, so hopefully this sub set is okay\nexport async function pressElement(user: {click: (element: Element) => Promise<void>, keyboard: (keys: string) => Promise<void>, pointer: (opts: {target: Element, keys: string, coords?: any}) => Promise<void>}, element: HTMLElement, interactionType: UserOpts['interactionType']): Promise<void> {\n if (interactionType === 'mouse') {\n // Add coords with pressure so this isn't detected as a virtual click\n await user.pointer({target: element, keys: '[MouseLeft]', coords: {pressure: .5}});\n } else if (interactionType === 'keyboard') {\n // TODO: For the keyboard flow, I wonder if it would be reasonable to just do fireEvent directly on the obtained row node or if we should\n // stick to simulting an actual user's keyboard operations as closely as possible\n // There are problems when using this approach though, actions like trying to trigger the select all checkbox and stuff behave oddly.\n act(() => element.focus());\n await user.keyboard('[Space]');\n } else if (interactionType === 'touch') {\n await user.pointer({target: element, keys: '[TouchA]'});\n }\n}\n"],"names":[],"version":3,"file":"events.module.js.map"}
@@ -36,23 +36,29 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
36
36
  }
37
37
  // TODO: RTL
38
38
  async keyboardNavigateToRow(opts) {
39
- let { row: row } = opts;
39
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
40
+ let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
40
41
  let rows = this.rows;
41
42
  let targetIndex = rows.indexOf(row);
42
43
  if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
43
- if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $cgwRb$testinglibraryreact.act)(()=>this._gridlist.focus());
44
- if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
44
+ if (document.activeElement !== this._gridlist && !this._gridlist.contains(document.activeElement)) (0, $cgwRb$testinglibraryreact.act)(()=>this._gridlist.focus());
45
+ if (document.activeElement === this._gridlist) await this.user.keyboard(`${selectionOnNav === 'none' ? `[${altKey}>]` : ''}[ArrowDown]${selectionOnNav === 'none' ? `[/${altKey}]` : ''}`);
45
46
  else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
46
47
  while (document.activeElement.getAttribute('role') !== 'row');
47
48
  let currIndex = rows.indexOf(document.activeElement);
48
49
  if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
49
50
  let direction = targetIndex > currIndex ? 'down' : 'up';
51
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
50
52
  for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
53
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
51
54
  }
52
55
  /**
53
56
  * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
57
+ * Note that this will endevor to always add/remove JUST the provided row to the set of selected rows.
54
58
  */ async toggleRowSelection(opts) {
55
- let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
59
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
60
+ let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
61
+ let metaKey = (0, $5a8bfe1663b8366d$exports.getMetaKey)();
56
62
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
57
63
  rowIndexOrText: row
58
64
  });
@@ -63,11 +69,14 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
63
69
  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
70
  // this would be better than the check to do nothing in events.ts
65
71
  // 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) {
72
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
67
73
  await this.keyboardNavigateToRow({
68
- row: row
74
+ row: row,
75
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
69
76
  });
70
- await this.user.keyboard('{Space}');
77
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
78
+ await this.user.keyboard('[Space]');
79
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
71
80
  return;
72
81
  }
73
82
  if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
@@ -83,7 +92,11 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
83
92
  pointerType: 'touch'
84
93
  }
85
94
  });
86
- } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
95
+ } else {
96
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
97
+ await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
98
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
99
+ }
87
100
  }
88
101
  }
89
102
  // 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
@@ -100,7 +113,8 @@ class $30ee8e379774bea4$export$93a85aaed9fabd83 {
100
113
  else if (interactionType === 'keyboard') {
101
114
  if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
102
115
  await this.keyboardNavigateToRow({
103
- row: row
116
+ row: row,
117
+ selectionOnNav: 'none'
104
118
  });
105
119
  await this.user.keyboard('[Enter]');
106
120
  } else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;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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BAAgB,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).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;GAE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AAmB;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.main.js.map"}