@react-aria/test-utils 1.0.0-alpha.7 → 1.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/combobox.main.js +5 -4
- package/dist/combobox.main.js.map +1 -1
- package/dist/combobox.mjs +5 -4
- package/dist/combobox.module.js +5 -4
- package/dist/combobox.module.js.map +1 -1
- package/dist/events.main.js +31 -1
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +30 -2
- package/dist/events.module.js +30 -2
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +23 -9
- package/dist/gridlist.main.js.map +1 -1
- package/dist/gridlist.mjs +24 -10
- package/dist/gridlist.module.js +24 -10
- package/dist/gridlist.module.js.map +1 -1
- package/dist/listbox.main.js +22 -13
- package/dist/listbox.main.js.map +1 -1
- package/dist/listbox.mjs +23 -14
- package/dist/listbox.module.js +23 -14
- package/dist/listbox.module.js.map +1 -1
- package/dist/menu.main.js +1 -1
- package/dist/menu.main.js.map +1 -1
- package/dist/menu.mjs +1 -1
- package/dist/menu.module.js +1 -1
- package/dist/menu.module.js.map +1 -1
- package/dist/select.main.js +7 -4
- package/dist/select.main.js.map +1 -1
- package/dist/select.mjs +7 -4
- package/dist/select.module.js +7 -4
- package/dist/select.module.js.map +1 -1
- package/dist/table.main.js +42 -9
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +44 -11
- package/dist/table.module.js +44 -11
- package/dist/table.module.js.map +1 -1
- package/dist/tabs.main.js +1 -1
- package/dist/tabs.main.js.map +1 -1
- package/dist/tabs.mjs +1 -1
- package/dist/tabs.module.js +1 -1
- package/dist/tabs.module.js.map +1 -1
- package/dist/tree.main.js +27 -8
- package/dist/tree.main.js.map +1 -1
- package/dist/tree.mjs +28 -9
- package/dist/tree.module.js +28 -9
- package/dist/tree.module.js.map +1 -1
- package/dist/types.d.ts +21 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/userEventMaps.main.js.map +1 -1
- package/dist/userEventMaps.module.js.map +1 -1
- package/package.json +7 -3
- package/src/combobox.ts +10 -7
- package/src/events.ts +34 -2
- package/src/gridlist.ts +35 -12
- package/src/listbox.ts +47 -19
- package/src/menu.ts +1 -1
- package/src/select.ts +10 -4
- package/src/table.ts +71 -10
- package/src/tabs.ts +1 -1
- package/src/tree.ts +40 -10
- package/src/types.ts +11 -1
- package/src/userEventMaps.ts +1 -1
package/dist/menu.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkDM,MAAM;IA+BX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,6IAA6I;IAC7I,6DAA6D;IAC7D;;GAEC,GACD,MAAM,KAAK,OAAqB,CAAC,CAAC,EAAiB;QACjD,IAAI,kBACF,cAAc,mBACd,kBAAkB,IAAI,CAAC,gBAAgB,aACvC,SAAS,EACV,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QACtC,IAAI,oBAAoB,WAAW,oBAAoB,SAAS;YAC9D,IAAI,gBAAgB;gBAClB,IAAI,IAAI,CAAC,aAAa,IAAI,MACxB,MAAM,IAAI,MAAM;gBAElB,IAAI,cAAc,oBAAoB,UAAU,UAAU;gBAC1D,MAAM,CAAA,GAAA,0CAAe,EAAE;oBAAC,SAAS;oBAAS,cAAc,IAAI,CAAC,aAAa;oBAAE,aAAa;qCAAC;oBAAW;gBAAC;YACxG,OAAO,IAAI,oBAAoB,SAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;iBAEtB,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;gBAAC,QAAQ;gBAAS,MAAM;YAAU;QAE9D,OAAO,IAAI,oBAAoB,cAAc,CAAC,YAAY;YACxD,IAAI,cAAc,MAAM;gBACtB,CAAA,GAAA,8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AQ,MAAM,KAAK,GAAG;gBACxB,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;gBACzC,IAAI,QAAQ,MAAM,KAAK,GACrB,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;YAE7C;QACF;QAEA,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,kBAAiC;QACnC,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,QAAQ,MAAM,GAAG,GACnB,OAAO,QAAQ,MAAM,CAAC,CAAA,OAAQ,KAAK,YAAY,CAAC,oBAAoB;QAGtE,OAAO,EAAE;IACX;IA1XA,YAAY,IAAoB,CAAE;aAH1B,aAAsB;QAI5B,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,aAAE,SAAS,YAAE,QAAQ,EAAC,GAAG;QACvE,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QAErB,gEAAgE;QAChE,IAAI,KAAK,YAAY,CAAC,YAAY,YAChC,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,wEAAwE;YACxE,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;YACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,IAAI,CAAC,QAAQ,GAAG;QAEpB;QAEA,IAAI,CAAC,UAAU,GAAG,aAAa;QAC/B,IAAI,CAAC,SAAS,GAAG;IACnB;AAsWF","sources":["packages/@react-aria/test-utils/src/menu.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n private _rootMenu: HTMLElement | undefined;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu, rootMenu} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n this._isSubmenu = isSubmenu || false;\n this._rootMenu = rootMenu;\n }\n\n /**\n * Set the interaction type used by the menu tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}): Promise<void> {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts): Promise<void> {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n // This chain of waitFors is needed in place of running all timers since we don't know how long transitions may take, or what action\n // the menu option select may trigger.\n if (\n !(menuSelectionMode === 'single' && !closesOnSelect) &&\n !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))\n ) {\n // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait\n // for focus to be coerced to somewhere else in place of running all timers.\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');\n } else {\n return true;\n }\n });\n }\n\n // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that\n // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes\n // but we can't really know where so just make sure it doesn't get lost to the body.\n await waitFor(() => {\n if (document.activeElement === option) {\n throw new Error('Expected focus after selecting an option to move away from the option.');\n } else {\n return true;\n }\n });\n\n // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should\n // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {\n throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');\n } else {\n return true;\n }\n });\n }\n\n // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n }\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n /**\n * Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({\n user: this.user,\n interactionType: this._interactionType,\n root: submenuTrigger,\n isSubmenu: true,\n advanceTimer: this._advanceTimer,\n rootMenu: (this._isSubmenu ? this._rootMenu : this.menu) || undefined\n });\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n } else {\n await submenuTriggerTester.open();\n }\n\n await waitFor(() => {\n if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') {\n throw new Error('aria-expanded for the submenu trigger wasn\\'t changed to \"true\", unable to confirm the existance of the submenu');\n } else {\n return true;\n }\n });\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close(): Promise<void> {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n }\n\n /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkDM,MAAM;IA+BX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,6IAA6I;IAC7I,6DAA6D;IAC7D;;GAEC,GACD,MAAM,KAAK,OAAqB,CAAC,CAAC,EAAiB;QACjD,IAAI,kBACF,cAAc,mBACd,kBAAkB,IAAI,CAAC,gBAAgB,aACvC,SAAS,EACV,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QACtC,IAAI,oBAAoB,WAAW,oBAAoB,SAAS;YAC9D,IAAI,gBAAgB;gBAClB,IAAI,IAAI,CAAC,aAAa,IAAI,MACxB,MAAM,IAAI,MAAM;gBAElB,IAAI,cAAc,oBAAoB,UAAU,UAA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QAAQ,GAAG;QAEpB;QAEA,IAAI,CAAC,UAAU,GAAG,aAAa;QAC/B,IAAI,CAAC,SAAS,GAAG;IACnB;AAsWF","sources":["packages/@react-aria/test-utils/src/menu.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n private _rootMenu: HTMLElement | undefined;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu, rootMenu} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n this._isSubmenu = isSubmenu || false;\n this._rootMenu = rootMenu;\n }\n\n /**\n * Set the interaction type used by the menu tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}): Promise<void> {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts): Promise<void> {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu && !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n // This chain of waitFors is needed in place of running all timers since we don't know how long transitions may take, or what action\n // the menu option select may trigger.\n if (\n !(menuSelectionMode === 'single' && !closesOnSelect) &&\n !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))\n ) {\n // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait\n // for focus to be coerced to somewhere else in place of running all timers.\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');\n } else {\n return true;\n }\n });\n }\n\n // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that\n // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes\n // but we can't really know where so just make sure it doesn't get lost to the body.\n await waitFor(() => {\n if (document.activeElement === option) {\n throw new Error('Expected focus after selecting an option to move away from the option.');\n } else {\n return true;\n }\n });\n\n // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should\n // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {\n throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');\n } else {\n return true;\n }\n });\n }\n\n // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n }\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n /**\n * Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({\n user: this.user,\n interactionType: this._interactionType,\n root: submenuTrigger,\n isSubmenu: true,\n advanceTimer: this._advanceTimer,\n rootMenu: (this._isSubmenu ? this._rootMenu : this.menu) || undefined\n });\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n } else {\n await submenuTriggerTester.open();\n }\n\n await waitFor(() => {\n if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') {\n throw new Error('aria-expanded for the submenu trigger wasn\\'t changed to \"true\", unable to confirm the existance of the submenu');\n } else {\n return true;\n }\n });\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close(): Promise<void> {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n }\n\n /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.main.js.map"}
|
package/dist/menu.mjs
CHANGED
|
@@ -98,7 +98,7 @@ class $74b93f0617179929$export$f73bbc9212ed861e {
|
|
|
98
98
|
if (!option) throw new Error('Target option not found in the menu.');
|
|
99
99
|
if (interactionType === 'keyboard') {
|
|
100
100
|
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
101
|
-
if (document.activeElement !== menu
|
|
101
|
+
if (document.activeElement !== menu && !menu.contains(document.activeElement)) (0, $gS6KO$act)(()=>menu.focus());
|
|
102
102
|
await this.keyboardNavigateToOption({
|
|
103
103
|
option: option
|
|
104
104
|
});
|
package/dist/menu.module.js
CHANGED
|
@@ -98,7 +98,7 @@ class $74b93f0617179929$export$f73bbc9212ed861e {
|
|
|
98
98
|
if (!option) throw new Error('Target option not found in the menu.');
|
|
99
99
|
if (interactionType === 'keyboard') {
|
|
100
100
|
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
101
|
-
if (document.activeElement !== menu
|
|
101
|
+
if (document.activeElement !== menu && !menu.contains(document.activeElement)) (0, $gS6KO$act)(()=>menu.focus());
|
|
102
102
|
await this.keyboardNavigateToOption({
|
|
103
103
|
option: option
|
|
104
104
|
});
|
package/dist/menu.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkDM,MAAM;IA+BX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,6IAA6I;IAC7I,6DAA6D;IAC7D;;GAEC,GACD,MAAM,KAAK,OAAqB,CAAC,CAAC,EAAiB;QACjD,IAAI,kBACF,cAAc,mBACd,kBAAkB,IAAI,CAAC,gBAAgB,aACvC,SAAS,EACV,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QACtC,IAAI,oBAAoB,WAAW,oBAAoB,SAAS;YAC9D,IAAI,gBAAgB;gBAClB,IAAI,IAAI,CAAC,aAAa,IAAI,MACxB,MAAM,IAAI,MAAM;gBAElB,IAAI,cAAc,oBAAoB,UAAU,UAAU;gBAC1D,MAAM,CAAA,GAAA,wCAAe,EAAE;oBAAC,SAAS;oBAAS,c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IACnB;AAsWF","sources":["packages/@react-aria/test-utils/src/menu.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n private _rootMenu: HTMLElement | undefined;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu, rootMenu} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n this._isSubmenu = isSubmenu || false;\n this._rootMenu = rootMenu;\n }\n\n /**\n * Set the interaction type used by the menu tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}): Promise<void> {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts): Promise<void> {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu || !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n // This chain of waitFors is needed in place of running all timers since we don't know how long transitions may take, or what action\n // the menu option select may trigger.\n if (\n !(menuSelectionMode === 'single' && !closesOnSelect) &&\n !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))\n ) {\n // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait\n // for focus to be coerced to somewhere else in place of running all timers.\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');\n } else {\n return true;\n }\n });\n }\n\n // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that\n // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes\n // but we can't really know where so just make sure it doesn't get lost to the body.\n await waitFor(() => {\n if (document.activeElement === option) {\n throw new Error('Expected focus after selecting an option to move away from the option.');\n } else {\n return true;\n }\n });\n\n // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should\n // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {\n throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');\n } else {\n return true;\n }\n });\n }\n\n // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n }\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n /**\n * Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({\n user: this.user,\n interactionType: this._interactionType,\n root: submenuTrigger,\n isSubmenu: true,\n advanceTimer: this._advanceTimer,\n rootMenu: (this._isSubmenu ? this._rootMenu : this.menu) || undefined\n });\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n } else {\n await submenuTriggerTester.open();\n }\n\n await waitFor(() => {\n if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') {\n throw new Error('aria-expanded for the submenu trigger wasn\\'t changed to \"true\", unable to confirm the existance of the submenu');\n } else {\n return true;\n }\n });\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close(): Promise<void> {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n }\n\n /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkDM,MAAM;IA+BX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,6IAA6I;IAC7I,6DAA6D;IAC7D;;GAEC,GACD,MAAM,KAAK,OAAqB,CAAC,CAAC,EAAiB;QACjD,IAAI,kBACF,cAAc,mBACd,kBAAkB,IA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AC3C,IAAI,CAAC,aAAa,GAAG;QAErB,gEAAgE;QAChE,IAAI,KAAK,YAAY,CAAC,YAAY,YAChC,IAAI,CAAC,QAAQ,GAAG;aACX;YACL,wEAAwE;YACxE,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,WAAW,CAAC;YACvC,IAAI,SACF,IAAI,CAAC,QAAQ,GAAG;iBAEhB,IAAI,CAAC,QAAQ,GAAG;QAEpB;QAEA,IAAI,CAAC,UAAU,GAAG,aAAa;QAC/B,IAAI,CAAC,SAAS,GAAG;IACnB;AAsWF","sources":["packages/@react-aria/test-utils/src/menu.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, waitFor, within} from '@testing-library/react';\nimport {MenuTesterOpts, UserOpts} from './types';\nimport {triggerLongPress} from './events';\n\ninterface MenuOpenOpts {\n /**\n * Whether the menu needs to be long pressed to open.\n */\n needsLongPress?: boolean,\n /**\n * What interaction type to use when opening the menu. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * Whether to open the menu via ArrowUp or ArrowDown if in keyboard modality.\n */\n direction?: 'up' | 'down'\n}\n\ninterface MenuSelectOpts extends MenuOpenOpts {\n /**\n * The index, text, or node of the option to select. Option nodes can be sourced via `options()`.\n */\n option: number | string | HTMLElement,\n /**\n * The menu's selection mode. Will affect whether or not the menu is expected to be closed upon option selection.\n * @default 'single'\n */\n menuSelectionMode?: 'single' | 'multiple',\n /**\n * Whether or not the menu closes on select. Depends on menu implementation and configuration.\n * @default true\n */\n closesOnSelect?: boolean,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter'\n}\n\ninterface MenuOpenSubmenuOpts extends MenuOpenOpts {\n /**\n * The text or node of the submenu trigger to open. Available submenu trigger nodes can be sourced via `submenuTriggers`.\n */\n submenuTrigger: string | HTMLElement\n}\n\nexport class MenuTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _trigger: HTMLElement | undefined;\n private _isSubmenu: boolean = false;\n private _rootMenu: HTMLElement | undefined;\n\n constructor(opts: MenuTesterOpts) {\n let {root, user, interactionType, advanceTimer, isSubmenu, rootMenu} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n\n // Handle case where a submenu trigger is provided to the tester\n if (root.getAttribute('role') === 'menuitem') {\n this._trigger = root;\n } else {\n // Handle case where element provided is a wrapper of the trigger button\n let trigger = within(root).queryByRole('button');\n if (trigger) {\n this._trigger = trigger;\n } else {\n this._trigger = root;\n }\n }\n\n this._isSubmenu = isSubmenu || false;\n this._rootMenu = rootMenu;\n }\n\n /**\n * Set the interaction type used by the menu tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: this has been common to select as well, maybe make select use it? Or make a generic method. Will need to make error messages generic\n // One difference will be that it supports long press as well\n /**\n * Opens the menu. Defaults to using the interaction type set on the menu tester.\n */\n async open(opts: MenuOpenOpts = {}): Promise<void> {\n let {\n needsLongPress,\n interactionType = this._interactionType,\n direction\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (interactionType === 'mouse' || interactionType === 'touch') {\n if (needsLongPress) {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n let pointerType = interactionType === 'mouse' ? 'mouse' : 'touch';\n await triggerLongPress({element: trigger, advanceTimer: this._advanceTimer, pointerOpts: {pointerType}});\n } else if (interactionType === 'mouse') {\n await this.user.click(trigger);\n } else {\n await this.user.pointer({target: trigger, keys: '[TouchA]'});\n }\n } else if (interactionType === 'keyboard' && !isDisabled) {\n if (direction === 'up') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowUp]');\n } else if (direction === 'down') {\n act(() => trigger.focus());\n await this.user.keyboard('[ArrowDown]');\n } else {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n }\n }\n\n await waitFor(() => {\n if (trigger.getAttribute('aria-controls') == null && !isDisabled) {\n throw new Error('No aria-controls found on menu trigger element.');\n } else {\n return true;\n }\n });\n if (!isDisabled) {\n let menuId = trigger.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let menu = this.menu;\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string' && menu != null) {\n option = (within(menu!).getByText(optionIndexOrText).closest('[role=menuitem], [role=menuitemradio], [role=menuitemcheckbox]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: also very similar to select, barring potential long press support\n // Close on select is also kinda specific?\n /**\n * Selects the desired menu option. Defaults to using the interaction type set on the menu tester. If necessary, will open the menu dropdown beforehand.\n * The desired option can be targeted via the option's node, the option's text, or the option's index.\n */\n async selectOption(opts: MenuSelectOpts): Promise<void> {\n let {\n menuSelectionMode = 'single',\n needsLongPress,\n closesOnSelect = true,\n option,\n interactionType = this._interactionType,\n keyboardActivation = 'Enter'\n } = opts;\n let trigger = this.trigger;\n\n if (!trigger.getAttribute('aria-controls') && !trigger.hasAttribute('aria-expanded')) {\n await this.open({needsLongPress});\n }\n\n let menu = this.menu;\n\n if (!menu) {\n throw new Error('Menu not found.');\n }\n\n if (menu) {\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the menu.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== menu && !menu.contains(document.activeElement)) {\n act(() => menu.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n // This chain of waitFors is needed in place of running all timers since we don't know how long transitions may take, or what action\n // the menu option select may trigger.\n if (\n !(menuSelectionMode === 'single' && !closesOnSelect) &&\n !(menuSelectionMode === 'multiple' && (keyboardActivation === 'Space' || interactionType === 'mouse'))\n ) {\n // For RSP, clicking on a submenu option seems to briefly lose focus to the body before moving to the clicked option in the test so we need to wait\n // for focus to be coerced to somewhere else in place of running all timers.\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a submenu option.');\n } else {\n return true;\n }\n });\n }\n\n // If user isn't trying to select multiple menu options or closeOnSelect is true then we can assume that\n // the menu will close or some action is triggered. In cases like that focus should move somewhere after the menu closes\n // but we can't really know where so just make sure it doesn't get lost to the body.\n await waitFor(() => {\n if (document.activeElement === option) {\n throw new Error('Expected focus after selecting an option to move away from the option.');\n } else {\n return true;\n }\n });\n\n // We'll also want to wait for focus to move away from the original submenu trigger since the entire submenu tree should\n // close. In React 16, focus actually makes it all the way to the root menu's submenu trigger so we need check the root menu\n if (this._isSubmenu) {\n await waitFor(() => {\n if (document.activeElement === this.trigger || this._rootMenu?.contains(document.activeElement)) {\n throw new Error('Expected focus after selecting an submenu option to move away from the original submenu trigger.');\n } else {\n return true;\n }\n });\n }\n\n // Finally wait for focus to be coerced somewhere final when the menu tree is removed from the DOM\n await waitFor(() => {\n if (document.activeElement === document.body) {\n throw new Error('Expected focus to move to somewhere other than the body after selecting a menu option.');\n } else {\n return true;\n }\n });\n }\n } else {\n throw new Error(\"Attempted to select a option in the menu, but menu wasn't found.\");\n }\n }\n\n // TODO: update this to remove needsLongPress if we wanna make the user call open first always\n /**\n * Opens the submenu. Defaults to using the interaction type set on the menu tester. The submenu trigger can be targeted via the trigger's node or the trigger's text.\n */\n async openSubmenu(opts: MenuOpenSubmenuOpts): Promise<MenuTester | null> {\n let {\n submenuTrigger,\n needsLongPress,\n interactionType = this._interactionType\n } = opts;\n\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n if (!trigger.getAttribute('aria-controls') && !isDisabled) {\n await this.open({needsLongPress});\n }\n if (!isDisabled) {\n let menu = this.menu;\n if (menu) {\n if (typeof submenuTrigger === 'string') {\n submenuTrigger = (within(menu!).getByText(submenuTrigger).closest('[role=menuitem]'))! as HTMLElement;\n }\n\n let submenuTriggerTester = new MenuTester({\n user: this.user,\n interactionType: this._interactionType,\n root: submenuTrigger,\n isSubmenu: true,\n advanceTimer: this._advanceTimer,\n rootMenu: (this._isSubmenu ? this._rootMenu : this.menu) || undefined\n });\n if (interactionType === 'mouse') {\n await this.user.pointer({target: submenuTrigger});\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToOption({option: submenuTrigger});\n await this.user.keyboard('[ArrowRight]');\n } else {\n await submenuTriggerTester.open();\n }\n\n await waitFor(() => {\n if (submenuTriggerTester._trigger?.getAttribute('aria-expanded') !== 'true') {\n throw new Error('aria-expanded for the submenu trigger wasn\\'t changed to \"true\", unable to confirm the existance of the submenu');\n } else {\n return true;\n }\n });\n\n return submenuTriggerTester;\n }\n }\n\n return null;\n }\n\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.findIndex(opt => (opt === option) || opt.contains(option));\n\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the menu');\n }\n if (document.activeElement === this.menu) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the menu');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Closes the menu.\n */\n async close(): Promise<void> {\n let menu = this.menu;\n if (menu) {\n act(() => menu.focus());\n await this.user.keyboard('[Escape]');\n\n await waitFor(() => {\n if (document.activeElement !== this.trigger) {\n throw new Error(`Expected the document.activeElement after closing the menu to be the menu trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(menu)) {\n throw new Error('Expected the menu to not be in the document after closing it.');\n }\n }\n }\n\n /**\n * Returns the menu's trigger.\n */\n get trigger(): HTMLElement {\n if (!this._trigger) {\n throw new Error('No trigger element found for menu.');\n }\n\n return this._trigger;\n }\n\n /**\n * Returns the menu if present.\n */\n get menu(): HTMLElement | null {\n let menuId = this.trigger.getAttribute('aria-controls');\n return menuId ? document.getElementById(menuId) : null;\n }\n\n /**\n * Returns the menu's sections if any.\n */\n get sections(): HTMLElement[] {\n let menu = this.menu;\n if (menu) {\n return within(menu).queryAllByRole('group');\n } else {\n return [];\n }\n }\n\n /**\n * Returns the menu's options if present. Can be filtered to a subsection of the menu if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.menu} = opts;\n let options: HTMLElement[] = [];\n if (element) {\n options = within(element).queryAllByRole('menuitem');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemradio');\n if (options.length === 0) {\n options = within(element).queryAllByRole('menuitemcheckbox');\n }\n }\n }\n\n return options;\n }\n\n /**\n * Returns the menu's submenu triggers if any.\n */\n get submenuTriggers(): HTMLElement[] {\n let options = this.options();\n if (options.length > 0) {\n return options.filter(item => item.getAttribute('aria-haspopup') != null);\n }\n\n return [];\n }\n}\n"],"names":[],"version":3,"file":"menu.module.js.map"}
|
package/dist/select.main.js
CHANGED
|
@@ -99,7 +99,7 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
99
99
|
if (!option) throw new Error('Target option not found in the listbox.');
|
|
100
100
|
if (interactionType === 'keyboard') {
|
|
101
101
|
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
102
|
-
if (document.activeElement !== listbox
|
|
102
|
+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $bBwW0$testinglibraryreact.act)(()=>listbox.focus());
|
|
103
103
|
await this.keyboardNavigateToOption({
|
|
104
104
|
option: option
|
|
105
105
|
});
|
|
@@ -149,9 +149,12 @@ class $b97d5a42df7c75b2$export$d1859707465446a9 {
|
|
|
149
149
|
this.user = user;
|
|
150
150
|
this._interactionType = interactionType || 'mouse';
|
|
151
151
|
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
152
|
-
let
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
let buttons = (0, $bBwW0$testinglibraryreact.within)(root).queryAllByRole('button');
|
|
153
|
+
let triggerButton;
|
|
154
|
+
if (buttons.length === 0) triggerButton = root;
|
|
155
|
+
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
156
|
+
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
157
|
+
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
155
158
|
}
|
|
156
159
|
}
|
|
157
160
|
|
package/dist/select.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAgBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;Q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EAAE,SAAS,cAAc,CAAC;QAG3C,OAAO;IACT;IAEA;;GAEC,GACD,IAAI,UAAuB;QACzB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA;;GAEC,GACD,IAAI,UAA8B;QAChC,IAAI,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IAvNA,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,gBAAgB,CAAA,GAAA,iCAAK,EAAE,MAAM,WAAW,CAAC;QAC7C,IAAI,iBAAiB,MACnB,gBAAgB;QAElB,IAAI,CAAC,QAAQ,GAAG;IAClB;AA8MF","sources":["packages/@react-aria/test-utils/src/select.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 {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let triggerButton = within(root).queryByRole('button');\n if (triggerButton == null) {\n triggerButton = root;\n }\n this._trigger = triggerButton;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.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 * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QAEtC,IAAI,oBAAoB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,YAAY,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;QAC1C,OAAO,YAAY,SAAS,cAAc,CAAC,aAAa;IAC1D;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,OAAO,UAAU,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC,WAAW,EAAE;IAC/D;IA7NA,YAAY,IAAsB,CAAE;QAClC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,8FAA8F;QAC9F,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI;QACJ,IAAI,QAAQ,MAAM,KAAK,GACrB,gBAAgB;aACX,IAAI,QAAQ,MAAM,KAAK,GAC5B,gBAAgB,OAAO,CAAC,EAAE;aAE1B,gBAAgB,QAAQ,IAAI,CAAC,CAAA,SAAU,OAAO,YAAY,CAAC;QAG7D,IAAI,CAAC,QAAQ,GAAG,0BAAA,2BAAA,gBAAiB;IACnC;AA8MF","sources":["packages/@react-aria/test-utils/src/select.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 {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\n if (buttons.length === 0) {\n triggerButton = root;\n } else if (buttons.length === 1) {\n triggerButton = buttons[0];\n } else {\n triggerButton = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.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 * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.main.js.map"}
|
package/dist/select.mjs
CHANGED
|
@@ -93,7 +93,7 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
93
93
|
if (!option) throw new Error('Target option not found in the listbox.');
|
|
94
94
|
if (interactionType === 'keyboard') {
|
|
95
95
|
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
96
|
-
if (document.activeElement !== listbox
|
|
96
|
+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
97
97
|
await this.keyboardNavigateToOption({
|
|
98
98
|
option: option
|
|
99
99
|
});
|
|
@@ -143,9 +143,12 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
143
143
|
this.user = user;
|
|
144
144
|
this._interactionType = interactionType || 'mouse';
|
|
145
145
|
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
let buttons = (0, $7v0pZ$within)(root).queryAllByRole('button');
|
|
147
|
+
let triggerButton;
|
|
148
|
+
if (buttons.length === 0) triggerButton = root;
|
|
149
|
+
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
150
|
+
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
151
|
+
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
package/dist/select.module.js
CHANGED
|
@@ -93,7 +93,7 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
93
93
|
if (!option) throw new Error('Target option not found in the listbox.');
|
|
94
94
|
if (interactionType === 'keyboard') {
|
|
95
95
|
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
96
|
-
if (document.activeElement !== listbox
|
|
96
|
+
if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) (0, $7v0pZ$act)(()=>listbox.focus());
|
|
97
97
|
await this.keyboardNavigateToOption({
|
|
98
98
|
option: option
|
|
99
99
|
});
|
|
@@ -143,9 +143,12 @@ class $4350df3e19e40e36$export$d1859707465446a9 {
|
|
|
143
143
|
this.user = user;
|
|
144
144
|
this._interactionType = interactionType || 'mouse';
|
|
145
145
|
// Handle case where the wrapper element is provided rather than the Select's button (aka RAC)
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
let buttons = (0, $7v0pZ$within)(root).queryAllByRole('button');
|
|
147
|
+
let triggerButton;
|
|
148
|
+
if (buttons.length === 0) triggerButton = root;
|
|
149
|
+
else if (buttons.length === 1) triggerButton = buttons[0];
|
|
150
|
+
else triggerButton = buttons.find((button)=>button.hasAttribute('aria-haspopup'));
|
|
151
|
+
this._trigger = triggerButton !== null && triggerButton !== void 0 ? triggerButton : root;
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAgBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QAEtC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ;aAC9B,IAAI,oBAAoB,YAAY;YACzC,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;YACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,IAAI,oBAAoB,SAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAAC,QAAQ,IAAI,CAAC,QAAQ;YAAE,MAAM;QAAU;QAGlE,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,cAAc,QAAQ,YAAY,CAAC,oBAAoB,MAC1D,MAAM,IAAI,MAAM;iBAEhB,OAAO;QAEX;QACA,IAAI,YAAY,QAAQ,YAAY,CAAC;QACrC,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,c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F","sources":["packages/@react-aria/test-utils/src/select.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 {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let triggerButton = within(root).queryByRole('button');\n if (triggerButton == null) {\n triggerButton = root;\n }\n this._trigger = triggerButton;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.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 * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox || !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAmBM,MAAM;IAsBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,KAAK,OAAuB,CAAC,CAAC,EAAiB;QACnD,IAAI,mBACF,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,aAAa,QAAQ,YAAY,CAAC;QAEtC,IAAI,oBAAoB,SACtB,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ;aAC9B,IAAI,oBAAoB,YAAY;YACzC,CAAA,GAAA,UAAE,EAAE,IAAM,QAAQ,KAAK;YACvB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,OAAO,IAAI,oBAAoB,SAC7B,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;YAAC,QAAQ,IAAI,CAAC,QAAQ;YAAE,MAAM;QAAU;QAGlE,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,cAAc,QAAQ,YAAY,CAAC,oBAAoB,MAC1D,MAAM,IAAI,MAAM;iBAEhB,OAAO;QAEX;QACA,IAAI,YAAY,QAAQ,YAAY,CAAC;QACrC,MAAM,CAAA,GAAA,cAAM,EAAE;YACZ,IAAI,CAAC,cAAe,CAAA,CAAC,aAAa,SAAS,cAAc,CAAC,cAAc,IAAG,GACzE,MAAM,IAAI,MAAM,CAAC,mBAAmB,EAAE,UAAU,uBAAuB,CAAC;iBAExE,OAAO;QAEX;IACF;IAEA;;GAEC,GACD,MAAM,QAAuB;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F","sources":["packages/@react-aria/test-utils/src/select.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 {SelectTesterOpts, UserOpts} from './types';\n\ninterface SelectOpenOpts {\n /**\n * What interaction type to use when opening the select. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\n\ninterface SelectTriggerOptionOpts extends SelectOpenOpts {\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 SelectTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _trigger: HTMLElement;\n\n constructor(opts: SelectTesterOpts) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n // Handle case where the wrapper element is provided rather than the Select's button (aka RAC)\n let buttons = within(root).queryAllByRole('button');\n let triggerButton;\n if (buttons.length === 0) {\n triggerButton = root;\n } else if (buttons.length === 1) {\n triggerButton = buttons[0];\n } else {\n triggerButton = buttons.find(button => button.hasAttribute('aria-haspopup'));\n }\n\n this._trigger = triggerButton ?? root;\n }\n /**\n * Set the interaction type used by the select tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Opens the select. Defaults to using the interaction type set on the select tester.\n */\n async open(opts: SelectOpenOpts = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let trigger = this.trigger;\n let isDisabled = trigger.hasAttribute('disabled');\n\n if (interactionType === 'mouse') {\n await this.user.click(this._trigger);\n } else if (interactionType === 'keyboard') {\n act(() => trigger.focus());\n await this.user.keyboard('[Enter]');\n } else if (interactionType === 'touch') {\n await this.user.pointer({target: this._trigger, keys: '[TouchA]'});\n }\n\n await waitFor(() => {\n if (!isDisabled && trigger.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on select element trigger.');\n } else {\n return true;\n }\n });\n let listBoxId = trigger.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 * Closes the select.\n */\n async close(): Promise<void> {\n let listbox = this.listbox;\n if (listbox) {\n act(() => listbox.focus());\n await this.user.keyboard('[Escape]');\n }\n\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after closing the select dropdown to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (listbox && document.contains(listbox)) {\n throw new Error('Expected the select element listbox to not be in the document after closing the dropdown.');\n }\n }\n\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n let 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 private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n if (document.activeElement === this.listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Selects the desired select option. Defaults to using the interaction type set on the select tester. If necessary, will open the select 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: SelectTriggerOptionOpts): Promise<void> {\n let {\n option,\n interactionType = this._interactionType\n } = opts || {};\n let trigger = this.trigger;\n if (!trigger.getAttribute('aria-controls')) {\n await this.open();\n }\n let listbox = this.listbox;\n if (!listbox) {\n throw new Error('Select\\'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 if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== listbox && !listbox.contains(document.activeElement)) {\n act(() => listbox.focus());\n }\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n // TODO: what if the user needs to scroll the list to find the option? What if there are multiple matches for text (hopefully the picker options are pretty unique)\n if (interactionType === 'mouse') {\n await this.user.click(option);\n } else {\n await this.user.pointer({target: option, keys: '[TouchA]'});\n }\n }\n\n if (option?.getAttribute('href') == null) {\n await waitFor(() => {\n if (document.activeElement !== this._trigger) {\n throw new Error(`Expected the document.activeElement after selecting an option to be the select component trigger but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n\n if (document.contains(listbox)) {\n throw new Error('Expected select element listbox to not be in the document after selecting an option');\n }\n }\n }\n }\n\n /**\n * Returns the select'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 select's trigger.\n */\n get trigger(): HTMLElement {\n return this._trigger;\n }\n\n /**\n * Returns the select's listbox if present.\n */\n get listbox(): HTMLElement | null {\n let listBoxId = this.trigger.getAttribute('aria-controls');\n return listBoxId ? document.getElementById(listBoxId) : null;\n }\n\n /**\n * Returns the select's sections if present.\n */\n get sections(): HTMLElement[] {\n let listbox = this.listbox;\n return listbox ? within(listbox).queryAllByRole('group') : [];\n }\n}\n"],"names":[],"version":3,"file":"select.module.js.map"}
|
package/dist/table.main.js
CHANGED
|
@@ -25,21 +25,48 @@ class $80a9def682ac1297$export$4c6a9d6ae3b0086 {
|
|
|
25
25
|
*/ setInteractionType(type) {
|
|
26
26
|
this._interactionType = type;
|
|
27
27
|
}
|
|
28
|
+
// TODO: RTL
|
|
29
|
+
async keyboardNavigateToRow(opts) {
|
|
30
|
+
let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
|
|
31
|
+
let altKey = (0, $5a8bfe1663b8366d$exports.getAltKey)();
|
|
32
|
+
let rows = this.rows;
|
|
33
|
+
let targetIndex = rows.indexOf(row);
|
|
34
|
+
if (targetIndex === -1) throw new Error('Row provided is not in the table');
|
|
35
|
+
// Move focus into the table
|
|
36
|
+
if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) (0, $2auAU$testinglibraryreact.act)(()=>this._table.focus());
|
|
37
|
+
if (document.activeElement === this._table) await this.user.keyboard('[ArrowDown]');
|
|
38
|
+
// If focus is currently somewhere in the first row group (aka on a column), we want to keyboard navigate downwards till we reach the rows
|
|
39
|
+
if (this.rowGroups[0].contains(document.activeElement)) do await this.user.keyboard('[ArrowDown]');
|
|
40
|
+
while (!this.rowGroups[1].contains(document.activeElement));
|
|
41
|
+
// Move focus onto the row itself
|
|
42
|
+
if (this.rowGroups[1].contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
43
|
+
while (document.activeElement.getAttribute('role') !== 'row');
|
|
44
|
+
let currIndex = rows.indexOf(document.activeElement);
|
|
45
|
+
if (currIndex === -1) throw new Error('Current active element is not on any of the table rows');
|
|
46
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
47
|
+
if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
|
|
48
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
49
|
+
if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
|
|
50
|
+
}
|
|
28
51
|
/**
|
|
29
52
|
* Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
|
|
30
53
|
*/ async toggleRowSelection(opts) {
|
|
31
|
-
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
54
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
|
|
55
|
+
let altKey = (0, $5a8bfe1663b8366d$exports.getMetaKey)();
|
|
56
|
+
let metaKey = (0, $5a8bfe1663b8366d$exports.getMetaKey)();
|
|
32
57
|
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
33
58
|
rowIndexOrText: row
|
|
34
59
|
});
|
|
35
60
|
if (!row) throw new Error('Target row not found in the table.');
|
|
36
61
|
let rowCheckbox = (0, $2auAU$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
37
|
-
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
62
|
+
if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
|
|
63
|
+
await this.keyboardNavigateToRow({
|
|
64
|
+
row: row,
|
|
65
|
+
selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
|
|
41
66
|
});
|
|
42
|
-
await this.user.keyboard(
|
|
67
|
+
if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
|
|
68
|
+
await this.user.keyboard('[Space]');
|
|
69
|
+
if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
|
|
43
70
|
return;
|
|
44
71
|
}
|
|
45
72
|
if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
@@ -55,7 +82,11 @@ class $80a9def682ac1297$export$4c6a9d6ae3b0086 {
|
|
|
55
82
|
pointerType: 'touch'
|
|
56
83
|
}
|
|
57
84
|
});
|
|
58
|
-
} else
|
|
85
|
+
} else {
|
|
86
|
+
if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
|
|
87
|
+
await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
88
|
+
if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
}
|
|
61
92
|
/**
|
|
@@ -166,8 +197,10 @@ class $80a9def682ac1297$export$4c6a9d6ae3b0086 {
|
|
|
166
197
|
if (!row) throw new Error('Target row not found in the table.');
|
|
167
198
|
if (needsDoubleClick) await this.user.dblClick(row);
|
|
168
199
|
else if (interactionType === 'keyboard') {
|
|
169
|
-
|
|
170
|
-
|
|
200
|
+
await this.keyboardNavigateToRow({
|
|
201
|
+
row: row,
|
|
202
|
+
selectionOnNav: 'none'
|
|
203
|
+
});
|
|
171
204
|
await this.user.keyboard('[Enter]');
|
|
172
205
|
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
173
206
|
}
|