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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/combobox.main.js +5 -4
  2. package/dist/combobox.main.js.map +1 -1
  3. package/dist/combobox.mjs +5 -4
  4. package/dist/combobox.module.js +5 -4
  5. package/dist/combobox.module.js.map +1 -1
  6. package/dist/events.main.js +31 -1
  7. package/dist/events.main.js.map +1 -1
  8. package/dist/events.mjs +30 -2
  9. package/dist/events.module.js +30 -2
  10. package/dist/events.module.js.map +1 -1
  11. package/dist/gridlist.main.js +23 -9
  12. package/dist/gridlist.main.js.map +1 -1
  13. package/dist/gridlist.mjs +24 -10
  14. package/dist/gridlist.module.js +24 -10
  15. package/dist/gridlist.module.js.map +1 -1
  16. package/dist/listbox.main.js +22 -13
  17. package/dist/listbox.main.js.map +1 -1
  18. package/dist/listbox.mjs +23 -14
  19. package/dist/listbox.module.js +23 -14
  20. package/dist/listbox.module.js.map +1 -1
  21. package/dist/menu.main.js +1 -1
  22. package/dist/menu.main.js.map +1 -1
  23. package/dist/menu.mjs +1 -1
  24. package/dist/menu.module.js +1 -1
  25. package/dist/menu.module.js.map +1 -1
  26. package/dist/select.main.js +7 -4
  27. package/dist/select.main.js.map +1 -1
  28. package/dist/select.mjs +7 -4
  29. package/dist/select.module.js +7 -4
  30. package/dist/select.module.js.map +1 -1
  31. package/dist/table.main.js +42 -9
  32. package/dist/table.main.js.map +1 -1
  33. package/dist/table.mjs +44 -11
  34. package/dist/table.module.js +44 -11
  35. package/dist/table.module.js.map +1 -1
  36. package/dist/tabs.main.js +1 -1
  37. package/dist/tabs.main.js.map +1 -1
  38. package/dist/tabs.mjs +1 -1
  39. package/dist/tabs.module.js +1 -1
  40. package/dist/tabs.module.js.map +1 -1
  41. package/dist/tree.main.js +27 -8
  42. package/dist/tree.main.js.map +1 -1
  43. package/dist/tree.mjs +28 -9
  44. package/dist/tree.module.js +28 -9
  45. package/dist/tree.module.js.map +1 -1
  46. package/dist/types.d.ts +29 -9
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/user.main.js.map +1 -1
  49. package/dist/user.module.js.map +1 -1
  50. package/dist/userEventMaps.main.js.map +1 -1
  51. package/dist/userEventMaps.module.js.map +1 -1
  52. package/package.json +7 -3
  53. package/src/combobox.ts +10 -7
  54. package/src/events.ts +34 -2
  55. package/src/gridlist.ts +35 -12
  56. package/src/listbox.ts +47 -19
  57. package/src/menu.ts +1 -1
  58. package/src/select.ts +10 -4
  59. package/src/table.ts +71 -10
  60. package/src/tabs.ts +1 -1
  61. package/src/tree.ts +40 -10
  62. package/src/types.ts +11 -1
  63. package/src/user.ts +10 -1
  64. package/src/userEventMaps.ts +1 -1
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAyBM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,mBAAmB,IAAwB,EAAiB;QAChE,IAAI,OACF,GAAG,kBACH,cAAc,qBACd,oBAAoB,uBACpB,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QAEJ,IAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAC5C,MAAM,IAAI,CAAC,OAAO,CAAC;YAAC,gBAAgB;QAAG;QAGzC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;QAGlB,IAAI,cAAc,CAAA,GAAA,iCAAK,EAAE,KAAK,WAAW,CAAC;QAE1C,IAAI,oBAAoB,cAAc,CAAC,mBAAmB;YACxD,uEAAuE;YACvE,MAAM,CAAA,GAAA,8BAAE,EAAE;gBACR,IAAI,KAAK;YACX;YACA,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzB;QACF;QACA,IAAI,eAAe,mBACjB,MAAM,CAAA,GAAA,sCAAW,EAAE,IA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O,cAAc,CAAC,cAAc,EAAE;IAC9D;IAEA;;GAEC,GACD,IAAI,UAAyB;QAC3B,IAAI,iBAAiB,IAAI,CAAC,SAAS,CAAC,EAAE;QACtC,OAAO,iBAAiB,CAAA,GAAA,iCAAK,EAAE,gBAAgB,cAAc,CAAC,kBAAkB,EAAE;IACpF;IAEA;;GAEC,GACD,IAAI,OAAsB;QACxB,IAAI,eAAe,IAAI,CAAC,SAAS,CAAC,EAAE;QACpC,OAAO,eAAe,CAAA,GAAA,iCAAK,EAAE,cAAc,cAAc,CAAC,SAAS,EAAE;IACvE;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA/XA,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;AA0XF","sources":["packages/@react-aria/test-utils/src/table.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 {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && !checkboxSelection) {\n // TODO: for now focus the row directly until I add keyboard navigation\n await act(async () => {\n row.focus();\n });\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAyBM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GAAG,kBAAE,iBAAiB,WAAU,GAAG;QACxC,IAAI,SAAS,CAAA,GAAA,mCAAQ;QACrB,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,4BAA4B;QAC5B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,aAAa,GACxF,CAAA,GAAA,8BAAE,EAAE,IAAM,IAAI,CAAC,MAAM,CAAC,KAAK;QAG7B,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,MAAM,EACxC,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAG3B,0IAA0I;QAC1I,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,aAAa,GACnD,GACE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;eAClB,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;QAGhE,iCAAiC;QACjC,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,aAAa,KAAK,SAAS,aAAa,CAAE,YAAY,CAAC,YA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EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,iCAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA5bA,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;AAubF","sources":["packages/@react-aria/test-utils/src/table.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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // 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\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.main.js.map"}
package/dist/table.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
2
- import {within as $2KUjE$within, act as $2KUjE$act, waitFor as $2KUjE$waitFor} from "@testing-library/react";
1
+ import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
2
+ import {act as $2KUjE$act, within as $2KUjE$within, waitFor as $2KUjE$waitFor} from "@testing-library/react";
3
3
 
4
4
  /*
5
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -19,21 +19,48 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
19
19
  */ setInteractionType(type) {
20
20
  this._interactionType = type;
21
21
  }
22
+ // TODO: RTL
23
+ async keyboardNavigateToRow(opts) {
24
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
25
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
26
+ let rows = this.rows;
27
+ let targetIndex = rows.indexOf(row);
28
+ if (targetIndex === -1) throw new Error('Row provided is not in the table');
29
+ // Move focus into the table
30
+ if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) (0, $2KUjE$act)(()=>this._table.focus());
31
+ if (document.activeElement === this._table) await this.user.keyboard('[ArrowDown]');
32
+ // 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
33
+ if (this.rowGroups[0].contains(document.activeElement)) do await this.user.keyboard('[ArrowDown]');
34
+ while (!this.rowGroups[1].contains(document.activeElement));
35
+ // Move focus onto the row itself
36
+ if (this.rowGroups[1].contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
37
+ while (document.activeElement.getAttribute('role') !== 'row');
38
+ let currIndex = rows.indexOf(document.activeElement);
39
+ if (currIndex === -1) throw new Error('Current active element is not on any of the table rows');
40
+ let direction = targetIndex > currIndex ? 'down' : 'up';
41
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
42
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
43
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
44
+ }
22
45
  /**
23
46
  * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
24
47
  */ async toggleRowSelection(opts) {
25
- let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
48
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
49
+ let altKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
50
+ let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
26
51
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
27
52
  rowIndexOrText: row
28
53
  });
29
54
  if (!row) throw new Error('Target row not found in the table.');
30
55
  let rowCheckbox = (0, $2KUjE$within)(row).queryByRole('checkbox');
31
- if (interactionType === 'keyboard' && !checkboxSelection) {
32
- // TODO: for now focus the row directly until I add keyboard navigation
33
- await (0, $2KUjE$act)(async ()=>{
34
- row.focus();
56
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
57
+ await this.keyboardNavigateToRow({
58
+ row: row,
59
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
35
60
  });
36
- await this.user.keyboard('{Space}');
61
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
62
+ await this.user.keyboard('[Space]');
63
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
37
64
  return;
38
65
  }
39
66
  if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
@@ -49,7 +76,11 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
49
76
  pointerType: 'touch'
50
77
  }
51
78
  });
52
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
79
+ } else {
80
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
81
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
82
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
83
+ }
53
84
  }
54
85
  }
55
86
  /**
@@ -160,8 +191,10 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
160
191
  if (!row) throw new Error('Target row not found in the table.');
161
192
  if (needsDoubleClick) await this.user.dblClick(row);
162
193
  else if (interactionType === 'keyboard') {
163
- // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns
164
- (0, $2KUjE$act)(()=>row.focus());
194
+ await this.keyboardNavigateToRow({
195
+ row: row,
196
+ selectionOnNav: 'none'
197
+ });
165
198
  await this.user.keyboard('[Enter]');
166
199
  } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
167
200
  }
@@ -1,5 +1,5 @@
1
- import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
2
- import {within as $2KUjE$within, act as $2KUjE$act, waitFor as $2KUjE$waitFor} from "@testing-library/react";
1
+ import {getAltKey as $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d, getMetaKey as $5d1eca18f92ad0e6$export$7943c508934e27ce, pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
2
+ import {act as $2KUjE$act, within as $2KUjE$within, waitFor as $2KUjE$waitFor} from "@testing-library/react";
3
3
 
4
4
  /*
5
5
  * Copyright 2024 Adobe. All rights reserved.
@@ -19,21 +19,48 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
19
19
  */ setInteractionType(type) {
20
20
  this._interactionType = type;
21
21
  }
22
+ // TODO: RTL
23
+ async keyboardNavigateToRow(opts) {
24
+ let { row: row, selectionOnNav: selectionOnNav = 'default' } = opts;
25
+ let altKey = (0, $5d1eca18f92ad0e6$export$6fc0ccaebd758b9d)();
26
+ let rows = this.rows;
27
+ let targetIndex = rows.indexOf(row);
28
+ if (targetIndex === -1) throw new Error('Row provided is not in the table');
29
+ // Move focus into the table
30
+ if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) (0, $2KUjE$act)(()=>this._table.focus());
31
+ if (document.activeElement === this._table) await this.user.keyboard('[ArrowDown]');
32
+ // 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
33
+ if (this.rowGroups[0].contains(document.activeElement)) do await this.user.keyboard('[ArrowDown]');
34
+ while (!this.rowGroups[1].contains(document.activeElement));
35
+ // Move focus onto the row itself
36
+ if (this.rowGroups[1].contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
37
+ while (document.activeElement.getAttribute('role') !== 'row');
38
+ let currIndex = rows.indexOf(document.activeElement);
39
+ if (currIndex === -1) throw new Error('Current active element is not on any of the table rows');
40
+ let direction = targetIndex > currIndex ? 'down' : 'up';
41
+ if (selectionOnNav === 'none') await this.user.keyboard(`[${altKey}>]`);
42
+ for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
43
+ if (selectionOnNav === 'none') await this.user.keyboard(`[/${altKey}]`);
44
+ }
22
45
  /**
23
46
  * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.
24
47
  */ async toggleRowSelection(opts) {
25
- let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
48
+ let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType, selectionBehavior: selectionBehavior = 'toggle' } = opts;
49
+ let altKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
50
+ let metaKey = (0, $5d1eca18f92ad0e6$export$7943c508934e27ce)();
26
51
  if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
27
52
  rowIndexOrText: row
28
53
  });
29
54
  if (!row) throw new Error('Target row not found in the table.');
30
55
  let rowCheckbox = (0, $2KUjE$within)(row).queryByRole('checkbox');
31
- if (interactionType === 'keyboard' && !checkboxSelection) {
32
- // TODO: for now focus the row directly until I add keyboard navigation
33
- await (0, $2KUjE$act)(async ()=>{
34
- row.focus();
56
+ if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {
57
+ await this.keyboardNavigateToRow({
58
+ row: row,
59
+ selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'
35
60
  });
36
- await this.user.keyboard('{Space}');
61
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[${altKey}>]`);
62
+ await this.user.keyboard('[Space]');
63
+ if (selectionBehavior === 'replace') await this.user.keyboard(`[/${altKey}]`);
37
64
  return;
38
65
  }
39
66
  if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
@@ -49,7 +76,11 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
49
76
  pointerType: 'touch'
50
77
  }
51
78
  });
52
- } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
79
+ } else {
80
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[${metaKey}>]`);
81
+ await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
82
+ if (selectionBehavior === 'replace' && interactionType !== 'touch') await this.user.keyboard(`[/${metaKey}]`);
83
+ }
53
84
  }
54
85
  }
55
86
  /**
@@ -160,8 +191,10 @@ class $6d1e4cf220920c37$export$4c6a9d6ae3b0086 {
160
191
  if (!row) throw new Error('Target row not found in the table.');
161
192
  if (needsDoubleClick) await this.user.dblClick(row);
162
193
  else if (interactionType === 'keyboard') {
163
- // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns
164
- (0, $2KUjE$act)(()=>row.focus());
194
+ await this.keyboardNavigateToRow({
195
+ row: row,
196
+ selectionOnNav: 'none'
197
+ });
165
198
  await this.user.keyboard('[Enter]');
166
199
  } else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
167
200
  }
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAyBM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,MAAM,mBAAmB,IAAwB,EAAiB;QAChE,IAAI,OACF,GAAG,kBACH,cAAc,qBACd,oBAAoB,uBACpB,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;QAEJ,IAAI,OAAO,QAAQ,YAAY,OAAO,QAAQ,UAC5C,MAAM,IAAI,CAAC,OAAO,CAAC;YAAC,gBAAgB;QAAG;QAGzC,IAAI,CAAC,KACH,MAAM,IAAI,MAAM;QAGlB,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE,KAAK,WAAW,CAAC;QAE1C,IAAI,oBAAoB,cAAc,CAAC,mBAAmB;YACxD,uEAAuE;YACvE,MAAM,CAAA,GAAA,UAAE,EAAE;gBACR,IAAI,KAAK;YACX;YACA,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;YACzB;QACF;QACA,IAAI,eAAe,mBACjB,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,aAAa;aACtC;YACL,IAAI,OAAO,CAAA,GAAA,aAAK,EAAE,KAAK,YAAY,CAAC,WAAW,CAAC,EAAE;YAClD,IAAI,kBAAkB,oBAAoB,SAAS;gBACjD,IAAI,IAAI,CAAC,aAAa,IAAI,MACxB,MAAM,IAAI,MAAM;gBAGlB,mFAAmF;gBACnF,MAAM,CAAA,GAAA,wCAAe,EAAE;oBAAC,SAAS;oBAAM,cAAc,IAAI,CAAC,aAAa;oBAAE,aAAa;wBAAC,aAAa;oBAAO;gBAAC;YAC9G,OACE,M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B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,IAAI,aAA4B;QAC9B,OAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;IAC3C;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,KAAK,EAAC,GAAG;QAC7B,OAAO,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IA/XA,YAAY,IAAqB,CAAE;QACjC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,MAAM,GAAG;IAChB;AA0XF","sources":["packages/@react-aria/test-utils/src/table.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 {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && !checkboxSelection) {\n // TODO: for now focus the row directly until I add keyboard navigation\n await act(async () => {\n row.focus();\n });\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n // TODO: add keyboard navigation instead of focusing the row directly. Will need to consider if the focus in in the columns\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAyBM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAA6D,EAAE;QACjG,IAAI,OAAC,GA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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 {getAltKey, getMetaKey, pressElement, triggerLongPress} from './events';\nimport {GridRowActionOpts, TableTesterOpts, ToggleGridRowOpts, UserOpts} from './types';\n\ninterface TableToggleRowOpts extends ToggleGridRowOpts {}\ninterface TableToggleSortOpts {\n /**\n * The index, text, or node of the column to toggle selection for.\n */\n column: number | string | HTMLElement,\n /**\n * What interaction type to use when sorting the column. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType']\n}\ninterface TableColumnHeaderActionOpts extends TableToggleSortOpts {\n /**\n * The index of the column header action to trigger.\n */\n action: number\n}\ninterface TableRowActionOpts extends GridRowActionOpts {}\n\nexport class TableTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _table: HTMLElement;\n\n constructor(opts: TableTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._table = root;\n }\n\n /**\n * Set the interaction type used by the table tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement, selectionOnNav?: 'default' | 'none'}) {\n let {row, selectionOnNav = 'default'} = opts;\n let altKey = getAltKey();\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Row provided is not in the table');\n }\n\n // Move focus into the table\n if (document.activeElement !== this._table && !this._table.contains(document.activeElement)) {\n act(() => this._table.focus());\n }\n\n if (document.activeElement === this._table) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // 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\n if (this.rowGroups[0].contains(document.activeElement)) {\n do {\n await this.user.keyboard('[ArrowDown]');\n } while (!this.rowGroups[1].contains(document.activeElement));\n }\n\n // Move focus onto the row itself\n if (this.rowGroups[1].contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('Current active element is not on any of the table rows');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n if (selectionOnNav === 'none') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async toggleRowSelection(opts: TableToggleRowOpts): Promise<void> {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType,\n selectionBehavior = 'toggle'\n } = opts;\n\n let altKey = getMetaKey();\n let metaKey = getMetaKey();\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n if (interactionType === 'keyboard' && (!checkboxSelection || !rowCheckbox)) {\n await this.keyboardNavigateToRow({row, selectionOnNav: selectionBehavior === 'replace' ? 'none' : 'default'});\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[${altKey}>]`);\n }\n await this.user.keyboard('[Space]');\n if (selectionBehavior === 'replace') {\n await this.user.keyboard(`[/${altKey}]`);\n }\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[${metaKey}>]`);\n }\n await pressElement(this.user, cell, interactionType);\n if (selectionBehavior === 'replace' && interactionType !== 'touch') {\n await this.user.keyboard(`[/${metaKey}]`);\n }\n }\n }\n };\n\n /**\n * Toggles the sort order for the specified table column. Defaults to using the interaction type set on the table tester.\n */\n async toggleSort(opts: TableToggleSortOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n let currentSort = columnheader.getAttribute('aria-sort');\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n if (currentSort === 'ascending') {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[1], interactionType);\n } else {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[0], interactionType);\n }\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n await pressElement(this.user, columnheader, interactionType);\n }\n }\n\n /**\n * Triggers an action for the specified table column menu. Defaults to using the interaction type set on the table tester.\n */\n async triggerColumnHeaderAction(opts: TableColumnHeaderActionOpts): Promise<void> {\n let {\n column,\n interactionType = this._interactionType,\n action\n } = opts;\n\n let columnheader;\n if (typeof column === 'number') {\n columnheader = this.columns[column];\n } else if (typeof column === 'string') {\n columnheader = within(this.rowGroups[0]).getByText(column);\n while (columnheader && !/columnheader/.test(columnheader.getAttribute('role'))) {\n columnheader = columnheader.parentElement;\n }\n } else {\n columnheader = column;\n }\n\n let menuButton = within(columnheader).queryByRole('button');\n if (menuButton) {\n // TODO: Focus management is all kinda of messed up if I just use .focus and Space to open the sort menu. Seems like\n // the focused key doesn't get properly set to the desired column header. Have to do this strange flow where I focus the\n // column header except if the active element is already the menu button within the column header\n if (interactionType === 'keyboard' && document.activeElement !== menuButton) {\n await pressElement(this.user, columnheader, interactionType);\n } else {\n await pressElement(this.user, menuButton, interactionType);\n }\n\n await waitFor(() => {\n if (menuButton.getAttribute('aria-controls') == null) {\n throw new Error('No aria-controls found on table column dropdown menu trigger element.');\n } else {\n return true;\n }\n });\n\n let menuId = menuButton.getAttribute('aria-controls');\n await waitFor(() => {\n if (!menuId || document.getElementById(menuId) == null) {\n throw new Error(`Table column header menu with id of ${menuId} not found in document.`);\n } else {\n return true;\n }\n });\n\n if (menuId) {\n let menu = document.getElementById(menuId);\n if (menu) {\n await pressElement(this.user, within(menu).getAllByRole('menuitem')[action], interactionType);\n\n await waitFor(() => {\n if (document.contains(menu)) {\n throw new Error('Expected table column menu listbox to not be in the document after selecting an option');\n } else {\n return true;\n }\n });\n }\n }\n\n // Handle cases where the table may transition in response to the row selection/deselection\n if (!this._advanceTimer) {\n throw new Error('No advanceTimers provided for table transition.');\n }\n\n await act(async () => {\n await this._advanceTimer?.(200);\n });\n\n await waitFor(() => {\n if (document.activeElement !== menuButton) {\n throw new Error(`Expected the document.activeElement to be the table column menu button but got ${document.activeElement}`);\n } else {\n return true;\n }\n });\n } else {\n throw new Error('No menu button found on table column header.');\n }\n }\n\n /**\n * Triggers the action for the specified table row. Defaults to using the interaction type set on the table tester.\n */\n async triggerRowAction(opts: TableRowActionOpts): Promise<void> {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the table.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n await this.keyboardNavigateToRow({row, selectionOnNav: 'none'});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n // TODO: should there be utils for drag and drop and column resizing? For column resizing, I'm not entirely convinced that users will be doing that in their tests.\n // For DnD, it might be tricky to do for keyboard DnD since we wouldn't know what valid drop zones there are... Similarly, for simulating mouse drag and drop the coordinates depend\n // on the mocks the user sets up for their row height/etc.\n // Additionally, should we also support keyboard navigation/typeahead? Those felt like they could be very easily replicated by the user via user.keyboard already and don't really\n // add much value if we provide that to them\n /**\n * Toggle selection for all rows in the table. Defaults to using the interaction type set on the table tester.\n */\n async toggleSelectAll(opts: {interactionType?: UserOpts['interactionType']} = {}): Promise<void> {\n let {\n interactionType = this._interactionType\n } = opts;\n let checkbox = within(this.table).getByLabelText('Select All');\n if (interactionType === 'keyboard') {\n // TODO: using the .focus -> trigger keyboard Enter approach doesn't work for some reason, for now just trigger select all with click.\n await this.user.click(checkbox);\n } else {\n await pressElement(this.user, checkbox, interactionType);\n }\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n let rows = this.rows;\n let bodyRowGroup = this.rowGroups[1];\n if (typeof rowIndexOrText === 'number') {\n row = rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = within(bodyRowGroup).getByText(rowIndexOrText);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n }\n\n /**\n * Returns a cell matching the specified text content.\n */\n findCell(opts: {text: string}): HTMLElement {\n let {\n text\n } = opts;\n\n let cell = within(this.table).getByText(text);\n if (cell) {\n while (cell && !/gridcell|rowheader|columnheader/.test(cell.getAttribute('role') || '')) {\n if (cell.parentElement) {\n cell = cell.parentElement;\n } else {\n break;\n }\n }\n }\n\n return cell;\n }\n\n /**\n * Returns the table.\n */\n get table(): HTMLElement {\n return this._table;\n }\n\n /**\n * Returns the row groups within the table.\n */\n get rowGroups(): HTMLElement[] {\n let table = this._table;\n return table ? within(table).queryAllByRole('rowgroup') : [];\n }\n\n /**\n * Returns the columns within the table.\n */\n get columns(): HTMLElement[] {\n let headerRowGroup = this.rowGroups[0];\n return headerRowGroup ? within(headerRowGroup).queryAllByRole('columnheader') : [];\n }\n\n /**\n * Returns the rows within the table if any.\n */\n get rows(): HTMLElement[] {\n let bodyRowGroup = this.rowGroups[1];\n return bodyRowGroup ? within(bodyRowGroup).queryAllByRole('row') : [];\n }\n\n /**\n * Returns the currently selected rows within the table if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the row headers within the table if any.\n */\n get rowHeaders(): HTMLElement[] {\n return within(this.table).queryAllByRole('rowheader');\n }\n\n /**\n * Returns the cells within the table if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.table} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"table.module.js.map"}
package/dist/tabs.main.js CHANGED
@@ -76,7 +76,7 @@ class $19633c03aff25ae5$export$f1539bff3fc7d485 {
76
76
  if (!tab) throw new Error('Target tab not found in the tablist.');
77
77
  else if (tab.hasAttribute('disabled')) throw new Error('Target tab is disabled.');
78
78
  if (interactionType === 'keyboard') {
79
- if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) (0, $1inx6$testinglibraryreact.act)(()=>this._tablist.focus());
79
+ if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) (0, $1inx6$testinglibraryreact.act)(()=>this._tablist.focus());
80
80
  let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
81
81
  await this.keyboardNavigateToTab({
82
82
  tab: tab,
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAA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AAC,IAAI,CAAC,IAAI,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB,WAAW;IAChF;IAEA;;GAEC,GACD,IAAI,iBAAqC;YAChB;QAAvB,IAAI,oBAAmB,oBAAA,IAAI,CAAC,WAAW,cAAhB,wCAAA,kBAAkB,YAAY,CAAC;QACtD,OAAO,mBAAmB,SAAS,cAAc,CAAC,oBAAoB;IACxE;IA/JA,YAAY,IAAoB,CAAE;QAChC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,iCAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AAqJF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGjE,OAAO;IACT;IAEA,+FAA+F;IAC/F,MAAc,sBAAsB,IAAmD,EAAE;QACvF,IAAI,OAAC,GAAG,eAAE,cAAc,YAAW,GAAG;QACtC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;YACnD,IAAI,cAAc,IAAI,CAAC,WAAW;YAClC,IAAI,eAAe,MACjB,CAAA,GAAA,8BAAE,EAAE,IAAM,YAAY,KAAK;iBAE3B,CAAA,GAAA,8BAAE,EAAE;oBAAM;wBAAA,aAAA,KAAK,IAAI,CAAC,CAAA,MAAO,CAAE,CAAA,IAAI,YAAY,CAAC,eAAe,IAAI,YAAY,CAAC,qBAAqB,MAAK,gBAA9F,iCAAA,WAAmG,KAAK;;QAEtH;QAE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/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.main.js.map"}
package/dist/tabs.mjs CHANGED
@@ -70,7 +70,7 @@ class $e615c34a00448a49$export$f1539bff3fc7d485 {
70
70
  if (!tab) throw new Error('Target tab not found in the tablist.');
71
71
  else if (tab.hasAttribute('disabled')) throw new Error('Target tab is disabled.');
72
72
  if (interactionType === 'keyboard') {
73
- if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) (0, $im2y9$act)(()=>this._tablist.focus());
73
+ if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) (0, $im2y9$act)(()=>this._tablist.focus());
74
74
  let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
75
75
  await this.keyboardNavigateToTab({
76
76
  tab: tab,
@@ -70,7 +70,7 @@ class $e615c34a00448a49$export$f1539bff3fc7d485 {
70
70
  if (!tab) throw new Error('Target tab not found in the tablist.');
71
71
  else if (tab.hasAttribute('disabled')) throw new Error('Target tab is disabled.');
72
72
  if (interactionType === 'keyboard') {
73
- if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) (0, $im2y9$act)(()=>this._tablist.focus());
73
+ if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) (0, $im2y9$act)(()=>this._tablist.focus());
74
74
  let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';
75
75
  await this.keyboardNavigateToTab({
76
76
  tab: tab,
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGjE,OAAO;IACT;IAEA,+FAA+F;IAC/F,MAAc,sBAAsB,IAAmD,EAAE;QACvF,IAAI,OAAC,GAAG,eAAE,cAAc,YAAW,GAAG;QACtC,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;YACnD,IAAI,cAAc,IAAI,CAAC,WAAW;YAClC,IAAI,eAAe,MACjB,CAAA,GAAA,UAAE,EAAE,IAAM,YAAY,KAAK;iBAE3B,CAAA,GAAA,UAAE,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AI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AAqJF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist || !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAqBM,MAAM;IAmBX;;GAEC,GACD,mBAAmB,IAAiC,EAAQ;QAC1D,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,mFAAmF;IACnF;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,eAAe;aACrB,I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EA;;GAEC,GACD,IAAI,cAAkC;QACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB,WAAW;IAChF;IAEA;;GAEC,GACD,IAAI,iBAAqC;YAChB;QAAvB,IAAI,oBAAmB,oBAAA,IAAI,CAAC,WAAW,cAAhB,wCAAA,kBAAkB,YAAY,CAAC;QACtD,OAAO,mBAAmB,SAAS,cAAc,CAAC,oBAAoB;IACxE;IA/JA,YAAY,IAAoB,CAAE;QAChC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,aAAE,SAAS,EAAC,GAAG;QAC/C,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,UAAU,GAAG,aAAa;QAE/B,IAAI,CAAC,QAAQ,GAAG;QAChB,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE,MAAM,cAAc,CAAC;QAC1C,IAAI,QAAQ,MAAM,GAAG,GACnB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,EAAE;IAE9B;AAqJF","sources":["packages/@react-aria/test-utils/src/tabs.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {Direction, Orientation, TabsTesterOpts, UserOpts} from './types';\nimport {pressElement} from './events';\n\ninterface TriggerTabOptions {\n /**\n * What interaction type to use when triggering a tab. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the tab to toggle selection for.\n */\n tab: number | string | HTMLElement,\n /**\n * Whether the tab needs to be activated manually rather than on focus.\n */\n manualActivation?: boolean\n}\n\nexport class TabsTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _tablist: HTMLElement;\n private _direction: Direction;\n\n constructor(opts: TabsTesterOpts) {\n let {root, user, interactionType, direction} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._direction = direction || 'ltr';\n\n this._tablist = root;\n let tablist = within(root).queryAllByRole('tablist');\n if (tablist.length > 0) {\n this._tablist = tablist[0];\n }\n }\n\n /**\n * Set the interaction type used by the tabs tester.\n */\n setInteractionType(type: UserOpts['interactionType']): void {\n this._interactionType = type;\n }\n\n // TODO: This is pretty similar across most the utils, refactor to make it generic?\n /**\n * Returns a tab matching the specified index or text content.\n */\n findTab(opts: {tabIndexOrText: number | string}): HTMLElement {\n let {\n tabIndexOrText\n } = opts;\n\n let tab;\n let tabs = this.tabs;\n if (typeof tabIndexOrText === 'number') {\n tab = tabs[tabIndexOrText];\n } else if (typeof tabIndexOrText === 'string') {\n tab = (within(this._tablist).getByText(tabIndexOrText).closest('[role=tab]'))! as HTMLElement;\n }\n\n return tab;\n }\n\n // TODO: also quite similar across more utils albeit with orientation, refactor to make generic\n private async keyboardNavigateToTab(opts: {tab: HTMLElement, orientation?: Orientation}) {\n let {tab, orientation = 'vertical'} = opts;\n let tabs = this.tabs;\n let targetIndex = tabs.indexOf(tab);\n if (targetIndex === -1) {\n throw new Error('Tab provided is not in the tablist');\n }\n\n if (!this._tablist.contains(document.activeElement)) {\n let selectedTab = this.selectedTab;\n if (selectedTab != null) {\n act(() => selectedTab.focus());\n } else {\n act(() => tabs.find(tab => !(tab.hasAttribute('disabled') || tab.getAttribute('aria-disabled') === 'true'))?.focus());\n }\n }\n\n let currIndex = this.tabs.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the tablist');\n }\n\n let arrowUp = 'ArrowUp';\n let arrowDown = 'ArrowDown';\n if (orientation === 'horizontal') {\n if (this._direction === 'ltr') {\n arrowUp = 'ArrowLeft';\n arrowDown = 'ArrowRight';\n } else {\n arrowUp = 'ArrowRight';\n arrowDown = 'ArrowLeft';\n }\n }\n\n let movementDirection = targetIndex > currIndex ? 'down' : 'up';\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${movementDirection === 'down' ? arrowDown : arrowUp}]`);\n }\n };\n\n /**\n * Triggers the specified tab. Defaults to using the interaction type set on the tabs tester.\n */\n async triggerTab(opts: TriggerTabOptions): Promise<void> {\n let {\n tab,\n interactionType = this._interactionType,\n manualActivation\n } = opts;\n\n if (typeof tab === 'string' || typeof tab === 'number') {\n tab = this.findTab({tabIndexOrText: tab});\n }\n\n if (!tab) {\n throw new Error('Target tab not found in the tablist.');\n } else if (tab.hasAttribute('disabled')) {\n throw new Error('Target tab is disabled.');\n }\n\n if (interactionType === 'keyboard') {\n if (document.activeElement !== this._tablist && !this._tablist.contains(document.activeElement)) {\n act(() => this._tablist.focus());\n }\n\n let tabsOrientation = this._tablist.getAttribute('aria-orientation') || 'horizontal';\n await this.keyboardNavigateToTab({tab, orientation: tabsOrientation as Orientation});\n if (manualActivation) {\n await this.user.keyboard('[Enter]');\n }\n } else {\n await pressElement(this.user, tab, interactionType);\n }\n }\n\n /**\n * Returns the tablist.\n */\n get tablist(): HTMLElement {\n return this._tablist;\n }\n\n /**\n * Returns the tabpanels.\n */\n get tabpanels(): HTMLElement[] {\n let tabpanels = [] as HTMLElement[];\n for (let tab of this.tabs) {\n let controlId = tab.getAttribute('aria-controls');\n let panel = controlId != null ? document.getElementById(controlId) : null;\n if (panel != null) {\n tabpanels.push(panel);\n }\n }\n\n return tabpanels;\n }\n\n /**\n * Returns the tabs in the tablist.\n */\n get tabs(): HTMLElement[] {\n return within(this.tablist).queryAllByRole('tab');\n }\n\n /**\n * Returns the currently selected tab in the tablist if any.\n */\n get selectedTab(): HTMLElement | null {\n return this.tabs.find(tab => tab.getAttribute('aria-selected') === 'true') || null;\n }\n\n /**\n * Returns the currently active tabpanel if any.\n */\n get activeTabpanel(): HTMLElement | null {\n let activeTabpanelId = this.selectedTab?.getAttribute('aria-controls');\n return activeTabpanelId ? document.getElementById(activeTabpanelId) : null;\n }\n}\n"],"names":[],"version":3,"file":"tabs.module.js.map"}