@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/combobox.main.js +116 -82
- package/dist/combobox.main.js.map +1 -1
- package/dist/combobox.mjs +117 -83
- package/dist/combobox.module.js +117 -83
- package/dist/combobox.module.js.map +1 -1
- package/dist/events.main.js +42 -4
- package/dist/events.main.js.map +1 -1
- package/dist/events.mjs +42 -4
- package/dist/events.module.js +42 -4
- package/dist/events.module.js.map +1 -1
- package/dist/gridlist.main.js +102 -59
- package/dist/gridlist.main.js.map +1 -1
- package/dist/gridlist.mjs +103 -60
- package/dist/gridlist.module.js +103 -60
- package/dist/gridlist.module.js.map +1 -1
- package/dist/listbox.main.js +135 -0
- package/dist/listbox.main.js.map +1 -0
- package/dist/listbox.mjs +130 -0
- package/dist/listbox.module.js +130 -0
- package/dist/listbox.module.js.map +1 -0
- package/dist/main.js.map +1 -1
- package/dist/menu.main.js +195 -161
- package/dist/menu.main.js.map +1 -1
- package/dist/menu.mjs +196 -162
- package/dist/menu.module.js +196 -162
- package/dist/menu.module.js.map +1 -1
- package/dist/module.js.map +1 -1
- package/dist/select.main.js +116 -70
- package/dist/select.main.js.map +1 -1
- package/dist/select.mjs +117 -71
- package/dist/select.module.js +117 -71
- package/dist/select.module.js.map +1 -1
- package/dist/table.main.js +166 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +167 -140
- package/dist/table.module.js +167 -140
- package/dist/table.module.js.map +1 -1
- package/dist/tabs.main.js +133 -0
- package/dist/tabs.main.js.map +1 -0
- package/dist/tabs.mjs +128 -0
- package/dist/tabs.module.js +128 -0
- package/dist/tabs.module.js.map +1 -0
- package/dist/tree.main.js +165 -0
- package/dist/tree.main.js.map +1 -0
- package/dist/tree.mjs +160 -0
- package/dist/tree.module.js +160 -0
- package/dist/tree.module.js.map +1 -0
- package/dist/types.d.ts +607 -145
- package/dist/types.d.ts.map +1 -1
- package/dist/user.main.js +15 -4
- package/dist/user.main.js.map +1 -1
- package/dist/user.mjs +15 -4
- package/dist/user.module.js +15 -4
- package/dist/user.module.js.map +1 -1
- package/package.json +3 -4
- package/src/combobox.ts +105 -36
- package/src/events.ts +29 -4
- package/src/gridlist.ts +146 -59
- package/src/index.ts +1 -1
- package/src/listbox.ts +226 -0
- package/src/menu.ts +152 -62
- package/src/select.ts +137 -44
- package/src/table.ts +130 -69
- package/src/tabs.ts +198 -0
- package/src/tree.ts +248 -0
- package/src/types.ts +133 -0
- package/src/user.ts +62 -37
package/dist/gridlist.main.js
CHANGED
|
@@ -20,75 +20,118 @@ $parcel$export(module.exports, "GridListTester", () => $30ee8e379774bea4$export$
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
class $30ee8e379774bea4$export$93a85aaed9fabd83 {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the gridlist tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns a row matching the specified index or text content.
|
|
30
|
+
*/ findRow(opts) {
|
|
31
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
32
|
+
let row;
|
|
33
|
+
if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
|
|
34
|
+
else if (typeof rowIndexOrText === 'string') row = (0, $cgwRb$testinglibraryreact.within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
|
|
35
|
+
return row;
|
|
36
|
+
}
|
|
37
|
+
// TODO: RTL
|
|
38
|
+
async keyboardNavigateToRow(opts) {
|
|
39
|
+
let { row: row } = opts;
|
|
40
|
+
let rows = this.rows;
|
|
41
|
+
let targetIndex = rows.indexOf(row);
|
|
42
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
|
|
43
|
+
if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
|
|
44
|
+
else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
45
|
+
while (document.activeElement.getAttribute('role') !== 'row');
|
|
46
|
+
let currIndex = rows.indexOf(document.activeElement);
|
|
47
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
|
|
48
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
49
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
53
|
+
*/ async toggleRowSelection(opts) {
|
|
54
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
55
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
56
|
+
rowIndexOrText: row
|
|
57
|
+
});
|
|
58
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
59
|
+
let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
60
|
+
// TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
|
|
61
|
+
// but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
|
|
62
|
+
if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
|
|
63
|
+
// this would be better than the check to do nothing in events.ts
|
|
64
|
+
// also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
|
|
65
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
66
|
+
await this.keyboardNavigateToRow({
|
|
67
|
+
row: row
|
|
68
|
+
});
|
|
69
|
+
await this.user.keyboard('{Space}');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (rowCheckbox && checkboxSelection) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
73
|
+
else {
|
|
74
|
+
let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
75
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
76
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
77
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
78
|
+
await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
|
|
79
|
+
element: cell,
|
|
80
|
+
advanceTimer: this._advanceTimer,
|
|
81
|
+
pointerOpts: {
|
|
82
|
+
pointerType: 'touch'
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
89
|
+
// user specificlly tells us
|
|
90
|
+
/**
|
|
91
|
+
* Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
92
|
+
*/ async triggerRowAction(opts) {
|
|
93
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
94
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
95
|
+
rowIndexOrText: row
|
|
96
|
+
});
|
|
97
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
98
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
99
|
+
else if (interactionType === 'keyboard') {
|
|
100
|
+
if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
|
|
101
|
+
if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $cgwRb$testinglibraryreact.act)(()=>this._gridlist.focus());
|
|
102
|
+
await this.keyboardNavigateToRow({
|
|
103
|
+
row: row
|
|
104
|
+
});
|
|
105
|
+
await this.user.keyboard('[Enter]');
|
|
106
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns the gridlist.
|
|
110
|
+
*/ get gridlist() {
|
|
25
111
|
return this._gridlist;
|
|
26
112
|
}
|
|
27
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Returns the gridlist's rows if any.
|
|
115
|
+
*/ get rows() {
|
|
28
116
|
var _this;
|
|
29
117
|
return (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
|
|
30
118
|
}
|
|
31
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Returns the gridlist's selected rows if any.
|
|
121
|
+
*/ get selectedRows() {
|
|
32
122
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
33
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
|
|
126
|
+
*/ cells(opts = {}) {
|
|
127
|
+
let { element: element = this.gridlist } = opts;
|
|
128
|
+
return (0, $cgwRb$testinglibraryreact.within)(element).queryAllByRole('gridcell');
|
|
129
|
+
}
|
|
34
130
|
constructor(opts){
|
|
35
|
-
|
|
36
|
-
this._interactionType = type;
|
|
37
|
-
};
|
|
38
|
-
// TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
|
|
39
|
-
// For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
|
|
40
|
-
// If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
|
|
41
|
-
// Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
|
|
42
|
-
// the user can test a specific type of interaction?
|
|
43
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
44
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
45
|
-
let row = this.findRow({
|
|
46
|
-
index: index,
|
|
47
|
-
text: text
|
|
48
|
-
});
|
|
49
|
-
let rowCheckbox = (0, $cgwRb$testinglibraryreact.within)(row).queryByRole('checkbox');
|
|
50
|
-
if (rowCheckbox) await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, rowCheckbox, interactionType);
|
|
51
|
-
else {
|
|
52
|
-
let cell = (0, $cgwRb$testinglibraryreact.within)(row).getAllByRole('gridcell')[0];
|
|
53
|
-
await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, cell, interactionType);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
// TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
|
|
57
|
-
// an element?
|
|
58
|
-
this.findRow = (opts)=>{
|
|
59
|
-
let { index: index, text: text } = opts;
|
|
60
|
-
let row;
|
|
61
|
-
if (index != null) row = this.rows[index];
|
|
62
|
-
else if (text != null) {
|
|
63
|
-
var _this;
|
|
64
|
-
row = (0, $cgwRb$testinglibraryreact.within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
|
|
65
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
66
|
-
}
|
|
67
|
-
return row;
|
|
68
|
-
};
|
|
69
|
-
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
70
|
-
// user specificlly tells us
|
|
71
|
-
this.triggerRowAction = async (opts)=>{
|
|
72
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
73
|
-
let row = this.findRow({
|
|
74
|
-
index: index,
|
|
75
|
-
text: text
|
|
76
|
-
});
|
|
77
|
-
if (row) {
|
|
78
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
79
|
-
else if (interactionType === 'keyboard') {
|
|
80
|
-
(0, $cgwRb$testinglibraryreact.act)(()=>row.focus());
|
|
81
|
-
await this.user.keyboard('[Enter]');
|
|
82
|
-
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, row, interactionType);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
this.cells = (opts = {})=>{
|
|
86
|
-
let { element: element } = opts;
|
|
87
|
-
return (0, $cgwRb$testinglibraryreact.within)(element || this.gridlist).queryAllByRole('gridcell');
|
|
88
|
-
};
|
|
89
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
131
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
90
132
|
this.user = user;
|
|
91
133
|
this._interactionType = interactionType || 'mouse';
|
|
134
|
+
this._advanceTimer = advanceTimer;
|
|
92
135
|
this._gridlist = root;
|
|
93
136
|
}
|
|
94
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IA+EX,wGAAwG;IACxG,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,OAAO;YACK;QAAd,OAAO,CAAA,GAAA,iCAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IApFA,YAAY,IAAqB,CAAE;aAOnC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;QAEA,+GAA+G;QAC/G,6IAA6I;QAC7I,kHAAkH;QAClH,0HAA0H;QAC1H,oDAAoD;aACpD,qBAAqB,OAAO,OAAuF,CAAC,CAAC;YACnH,IAAI,SAAC,KAAK,QAAE,IAAI,mBAAE,kBAAkB,IAAI,CAAC,gBAAgB,EAAC,GAAG;YAE7D,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC;uBAAC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gC,CAAC,CAAC;YACzC,IAAI,WAAC,OAAO,EAAC,GAAG;YAChB,OAAO,CAAA,GAAA,iCAAK,EAAE,WAAW,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;QACzD;QAxFE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,SAAS,GAAG;IACnB;AAqFF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement} from './events';\n\nexport interface GridListOptions extends UserOpts, BaseTesterOpts {\n user?: any\n}\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _gridlist: HTMLElement;\n\n\n constructor(opts: GridListOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._gridlist = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share\n // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common\n // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press\n // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way\n // the user can test a specific type of interaction?\n toggleRowSelection = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {index, text, interactionType = this._interactionType} = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n await pressElement(this.user, cell, interactionType);\n }\n };\n\n // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for\n // an element?\n findRow = (opts: {index?: number, text?: string}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n if (index != null) {\n row = this.rows[index];\n } else if (text != null) {\n row = within(this?.gridlist).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist\n get gridlist() {\n return this._gridlist;\n }\n\n get rows() {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n cells = (opts: {element?: HTMLElement} = {}) => {\n let {element} = opts;\n return within(element || this.gridlist).queryAllByRole('gridcell');\n };\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GAC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YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;AA2KF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement}) {\n let {row} = opts;\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard('[ArrowDown]');\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts) {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && !checkboxSelection) {\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts) {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.main.js.map"}
|
package/dist/gridlist.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.mjs";
|
|
1
|
+
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.mjs";
|
|
2
2
|
import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -14,75 +14,118 @@ import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the gridlist tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a row matching the specified index or text content.
|
|
24
|
+
*/ findRow(opts) {
|
|
25
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
26
|
+
let row;
|
|
27
|
+
if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
|
|
28
|
+
else if (typeof rowIndexOrText === 'string') row = (0, $haOzD$within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
|
|
29
|
+
return row;
|
|
30
|
+
}
|
|
31
|
+
// TODO: RTL
|
|
32
|
+
async keyboardNavigateToRow(opts) {
|
|
33
|
+
let { row: row } = opts;
|
|
34
|
+
let rows = this.rows;
|
|
35
|
+
let targetIndex = rows.indexOf(row);
|
|
36
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
|
|
37
|
+
if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
|
|
38
|
+
else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
39
|
+
while (document.activeElement.getAttribute('role') !== 'row');
|
|
40
|
+
let currIndex = rows.indexOf(document.activeElement);
|
|
41
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
|
|
42
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
43
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
47
|
+
*/ async toggleRowSelection(opts) {
|
|
48
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
49
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
50
|
+
rowIndexOrText: row
|
|
51
|
+
});
|
|
52
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
53
|
+
let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
|
|
54
|
+
// TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
|
|
55
|
+
// but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
|
|
56
|
+
if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
|
|
57
|
+
// this would be better than the check to do nothing in events.ts
|
|
58
|
+
// also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
|
|
59
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
60
|
+
await this.keyboardNavigateToRow({
|
|
61
|
+
row: row
|
|
62
|
+
});
|
|
63
|
+
await this.user.keyboard('{Space}');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
67
|
+
else {
|
|
68
|
+
let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
|
|
69
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
70
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
71
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
72
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
73
|
+
element: cell,
|
|
74
|
+
advanceTimer: this._advanceTimer,
|
|
75
|
+
pointerOpts: {
|
|
76
|
+
pointerType: 'touch'
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
83
|
+
// user specificlly tells us
|
|
84
|
+
/**
|
|
85
|
+
* Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
86
|
+
*/ async triggerRowAction(opts) {
|
|
87
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
88
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
89
|
+
rowIndexOrText: row
|
|
90
|
+
});
|
|
91
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
92
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
93
|
+
else if (interactionType === 'keyboard') {
|
|
94
|
+
if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
|
|
95
|
+
if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
|
|
96
|
+
await this.keyboardNavigateToRow({
|
|
97
|
+
row: row
|
|
98
|
+
});
|
|
99
|
+
await this.user.keyboard('[Enter]');
|
|
100
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the gridlist.
|
|
104
|
+
*/ get gridlist() {
|
|
19
105
|
return this._gridlist;
|
|
20
106
|
}
|
|
21
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Returns the gridlist's rows if any.
|
|
109
|
+
*/ get rows() {
|
|
22
110
|
var _this;
|
|
23
111
|
return (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
|
|
24
112
|
}
|
|
25
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Returns the gridlist's selected rows if any.
|
|
115
|
+
*/ get selectedRows() {
|
|
26
116
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
27
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
|
|
120
|
+
*/ cells(opts = {}) {
|
|
121
|
+
let { element: element = this.gridlist } = opts;
|
|
122
|
+
return (0, $haOzD$within)(element).queryAllByRole('gridcell');
|
|
123
|
+
}
|
|
28
124
|
constructor(opts){
|
|
29
|
-
|
|
30
|
-
this._interactionType = type;
|
|
31
|
-
};
|
|
32
|
-
// TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
|
|
33
|
-
// For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
|
|
34
|
-
// If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
|
|
35
|
-
// Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
|
|
36
|
-
// the user can test a specific type of interaction?
|
|
37
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
38
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
39
|
-
let row = this.findRow({
|
|
40
|
-
index: index,
|
|
41
|
-
text: text
|
|
42
|
-
});
|
|
43
|
-
let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
|
|
44
|
-
if (rowCheckbox) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
45
|
-
else {
|
|
46
|
-
let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
|
|
47
|
-
await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
// TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
|
|
51
|
-
// an element?
|
|
52
|
-
this.findRow = (opts)=>{
|
|
53
|
-
let { index: index, text: text } = opts;
|
|
54
|
-
let row;
|
|
55
|
-
if (index != null) row = this.rows[index];
|
|
56
|
-
else if (text != null) {
|
|
57
|
-
var _this;
|
|
58
|
-
row = (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
|
|
59
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
60
|
-
}
|
|
61
|
-
return row;
|
|
62
|
-
};
|
|
63
|
-
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
64
|
-
// user specificlly tells us
|
|
65
|
-
this.triggerRowAction = async (opts)=>{
|
|
66
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
67
|
-
let row = this.findRow({
|
|
68
|
-
index: index,
|
|
69
|
-
text: text
|
|
70
|
-
});
|
|
71
|
-
if (row) {
|
|
72
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
73
|
-
else if (interactionType === 'keyboard') {
|
|
74
|
-
(0, $haOzD$act)(()=>row.focus());
|
|
75
|
-
await this.user.keyboard('[Enter]');
|
|
76
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
this.cells = (opts = {})=>{
|
|
80
|
-
let { element: element } = opts;
|
|
81
|
-
return (0, $haOzD$within)(element || this.gridlist).queryAllByRole('gridcell');
|
|
82
|
-
};
|
|
83
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
125
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
84
126
|
this.user = user;
|
|
85
127
|
this._interactionType = interactionType || 'mouse';
|
|
128
|
+
this._advanceTimer = advanceTimer;
|
|
86
129
|
this._gridlist = root;
|
|
87
130
|
}
|
|
88
131
|
}
|
package/dist/gridlist.module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb} from "./events.module.js";
|
|
1
|
+
import {pressElement as $5d1eca18f92ad0e6$export$6ffa3eb717517feb, triggerLongPress as $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b} from "./events.module.js";
|
|
2
2
|
import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react";
|
|
3
3
|
|
|
4
4
|
/*
|
|
@@ -14,75 +14,118 @@ import {within as $haOzD$within, act as $haOzD$act} from "@testing-library/react
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
class $5ca9e9228f508f75$export$93a85aaed9fabd83 {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Set the interaction type used by the gridlist tester.
|
|
19
|
+
*/ setInteractionType(type) {
|
|
20
|
+
this._interactionType = type;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a row matching the specified index or text content.
|
|
24
|
+
*/ findRow(opts) {
|
|
25
|
+
let { rowIndexOrText: rowIndexOrText } = opts;
|
|
26
|
+
let row;
|
|
27
|
+
if (typeof rowIndexOrText === 'number') row = this.rows[rowIndexOrText];
|
|
28
|
+
else if (typeof rowIndexOrText === 'string') row = (0, $haOzD$within)(this.gridlist).getByText(rowIndexOrText).closest('[role=row]');
|
|
29
|
+
return row;
|
|
30
|
+
}
|
|
31
|
+
// TODO: RTL
|
|
32
|
+
async keyboardNavigateToRow(opts) {
|
|
33
|
+
let { row: row } = opts;
|
|
34
|
+
let rows = this.rows;
|
|
35
|
+
let targetIndex = rows.indexOf(row);
|
|
36
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the gridlist');
|
|
37
|
+
if (document.activeElement === this._gridlist) await this.user.keyboard('[ArrowDown]');
|
|
38
|
+
else if (this._gridlist.contains(document.activeElement) && document.activeElement.getAttribute('role') !== 'row') do await this.user.keyboard('[ArrowLeft]');
|
|
39
|
+
while (document.activeElement.getAttribute('role') !== 'row');
|
|
40
|
+
let currIndex = rows.indexOf(document.activeElement);
|
|
41
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the gridlist');
|
|
42
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
43
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
47
|
+
*/ async toggleRowSelection(opts) {
|
|
48
|
+
let { row: row, needsLongPress: needsLongPress, checkboxSelection: checkboxSelection = true, interactionType: interactionType = this._interactionType } = opts;
|
|
49
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
50
|
+
rowIndexOrText: row
|
|
51
|
+
});
|
|
52
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
53
|
+
let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
|
|
54
|
+
// TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually
|
|
55
|
+
// but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)
|
|
56
|
+
if (interactionType === 'keyboard' && ((rowCheckbox === null || rowCheckbox === void 0 ? void 0 : rowCheckbox.getAttribute('disabled')) === '' || (row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true')) return;
|
|
57
|
+
// this would be better than the check to do nothing in events.ts
|
|
58
|
+
// also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly
|
|
59
|
+
if (interactionType === 'keyboard' && !checkboxSelection) {
|
|
60
|
+
await this.keyboardNavigateToRow({
|
|
61
|
+
row: row
|
|
62
|
+
});
|
|
63
|
+
await this.user.keyboard('{Space}');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (rowCheckbox && checkboxSelection) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
67
|
+
else {
|
|
68
|
+
let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
|
|
69
|
+
if (needsLongPress && interactionType === 'touch') {
|
|
70
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
71
|
+
// Note that long press interactions with rows is strictly touch only for grid rows
|
|
72
|
+
await (0, $5d1eca18f92ad0e6$export$3a22a5a9bc0fd3b)({
|
|
73
|
+
element: cell,
|
|
74
|
+
advanceTimer: this._advanceTimer,
|
|
75
|
+
pointerOpts: {
|
|
76
|
+
pointerType: 'touch'
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
83
|
+
// user specificlly tells us
|
|
84
|
+
/**
|
|
85
|
+
* Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.
|
|
86
|
+
*/ async triggerRowAction(opts) {
|
|
87
|
+
let { row: row, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
88
|
+
if (typeof row === 'string' || typeof row === 'number') row = this.findRow({
|
|
89
|
+
rowIndexOrText: row
|
|
90
|
+
});
|
|
91
|
+
if (!row) throw new Error('Target row not found in the gridlist.');
|
|
92
|
+
if (needsDoubleClick) await this.user.dblClick(row);
|
|
93
|
+
else if (interactionType === 'keyboard') {
|
|
94
|
+
if ((row === null || row === void 0 ? void 0 : row.getAttribute('aria-disabled')) === 'true') return;
|
|
95
|
+
if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) (0, $haOzD$act)(()=>this._gridlist.focus());
|
|
96
|
+
await this.keyboardNavigateToRow({
|
|
97
|
+
row: row
|
|
98
|
+
});
|
|
99
|
+
await this.user.keyboard('[Enter]');
|
|
100
|
+
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the gridlist.
|
|
104
|
+
*/ get gridlist() {
|
|
19
105
|
return this._gridlist;
|
|
20
106
|
}
|
|
21
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Returns the gridlist's rows if any.
|
|
109
|
+
*/ get rows() {
|
|
22
110
|
var _this;
|
|
23
111
|
return (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).queryAllByRole('row');
|
|
24
112
|
}
|
|
25
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Returns the gridlist's selected rows if any.
|
|
115
|
+
*/ get selectedRows() {
|
|
26
116
|
return this.rows.filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
27
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.
|
|
120
|
+
*/ cells(opts = {}) {
|
|
121
|
+
let { element: element = this.gridlist } = opts;
|
|
122
|
+
return (0, $haOzD$within)(element).queryAllByRole('gridcell');
|
|
123
|
+
}
|
|
28
124
|
constructor(opts){
|
|
29
|
-
|
|
30
|
-
this._interactionType = type;
|
|
31
|
-
};
|
|
32
|
-
// TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share
|
|
33
|
-
// For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common
|
|
34
|
-
// If the current way of passing in the user specified advance timers is ok, then I'd be find including long press
|
|
35
|
-
// Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way
|
|
36
|
-
// the user can test a specific type of interaction?
|
|
37
|
-
this.toggleRowSelection = async (opts = {})=>{
|
|
38
|
-
let { index: index, text: text, interactionType: interactionType = this._interactionType } = opts;
|
|
39
|
-
let row = this.findRow({
|
|
40
|
-
index: index,
|
|
41
|
-
text: text
|
|
42
|
-
});
|
|
43
|
-
let rowCheckbox = (0, $haOzD$within)(row).queryByRole('checkbox');
|
|
44
|
-
if (rowCheckbox) await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, rowCheckbox, interactionType);
|
|
45
|
-
else {
|
|
46
|
-
let cell = (0, $haOzD$within)(row).getAllByRole('gridcell')[0];
|
|
47
|
-
await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, cell, interactionType);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
// TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for
|
|
51
|
-
// an element?
|
|
52
|
-
this.findRow = (opts)=>{
|
|
53
|
-
let { index: index, text: text } = opts;
|
|
54
|
-
let row;
|
|
55
|
-
if (index != null) row = this.rows[index];
|
|
56
|
-
else if (text != null) {
|
|
57
|
-
var _this;
|
|
58
|
-
row = (0, $haOzD$within)((_this = this) === null || _this === void 0 ? void 0 : _this.gridlist).getByText(text);
|
|
59
|
-
while(row && row.getAttribute('role') !== 'row')row = row.parentElement;
|
|
60
|
-
}
|
|
61
|
-
return row;
|
|
62
|
-
};
|
|
63
|
-
// TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the
|
|
64
|
-
// user specificlly tells us
|
|
65
|
-
this.triggerRowAction = async (opts)=>{
|
|
66
|
-
let { index: index, text: text, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
67
|
-
let row = this.findRow({
|
|
68
|
-
index: index,
|
|
69
|
-
text: text
|
|
70
|
-
});
|
|
71
|
-
if (row) {
|
|
72
|
-
if (needsDoubleClick) await this.user.dblClick(row);
|
|
73
|
-
else if (interactionType === 'keyboard') {
|
|
74
|
-
(0, $haOzD$act)(()=>row.focus());
|
|
75
|
-
await this.user.keyboard('[Enter]');
|
|
76
|
-
} else await (0, $5d1eca18f92ad0e6$export$6ffa3eb717517feb)(this.user, row, interactionType);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
this.cells = (opts = {})=>{
|
|
80
|
-
let { element: element } = opts;
|
|
81
|
-
return (0, $haOzD$within)(element || this.gridlist).queryAllByRole('gridcell');
|
|
82
|
-
};
|
|
83
|
-
let { root: root, user: user, interactionType: interactionType } = opts;
|
|
125
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
84
126
|
this.user = user;
|
|
85
127
|
this._interactionType = interactionType || 'mouse';
|
|
128
|
+
this._advanceTimer = advanceTimer;
|
|
86
129
|
this._gridlist = root;
|
|
87
130
|
}
|
|
88
131
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IA+EX,wGAAwG;IACxG,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,SAAS;IACvB;IAEA,IAAI,OAAO;YACK;QAAd,OAAO,CAAA,GAAA,aAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IApFA,YAAY,IAAqB,CAAE;aAOnC,qBAAqB,CAAC;YACpB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;QAEA,+GAA+G;QAC/G,6IAA6I;QAC7I,kHAAkH;QAClH,0HAA0H;QAC1H,oD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M,IAAI,KAAK;oBACnB,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3B,OACE,MAAM,CAAA,GAAA,yCAAW,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK;YAEvC;QACF;aAeA,QAAQ,CAAC,OAAgC,CAAC,CAAC;YACzC,IAAI,WAAC,OAAO,EAAC,GAAG;YAChB,OAAO,CAAA,GAAA,aAAK,EAAE,WAAW,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;QACzD;QAxFE,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,EAAC,GAAG;QACpC,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,SAAS,GAAG;IACnB;AAqFF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {BaseTesterOpts, UserOpts} from './user';\nimport {pressElement} from './events';\n\nexport interface GridListOptions extends UserOpts, BaseTesterOpts {\n user?: any\n}\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _gridlist: HTMLElement;\n\n\n constructor(opts: GridListOptions) {\n let {root, user, interactionType} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._gridlist = root;\n }\n\n setInteractionType = (type: UserOpts['interactionType']) => {\n this._interactionType = type;\n };\n\n // TODO: support long press? This is also pretty much the same as table's toggleRowSelection so maybe can share\n // For now, don't include long press, see if people need it or if we should just expose long press as a separate util if it isn't very common\n // If the current way of passing in the user specified advance timers is ok, then I'd be find including long press\n // Maybe also support an option to force the click to happen on a specific part of the element (checkbox or row). That way\n // the user can test a specific type of interaction?\n toggleRowSelection = async (opts: {index?: number, text?: string, interactionType?: UserOpts['interactionType']} = {}) => {\n let {index, text, interactionType = this._interactionType} = opts;\n\n let row = this.findRow({index, text});\n let rowCheckbox = within(row).queryByRole('checkbox');\n if (rowCheckbox) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n await pressElement(this.user, cell, interactionType);\n }\n };\n\n // TODO: pretty much the same as table except it uses this.gridlist. Make common between the two by accepting an option for\n // an element?\n findRow = (opts: {index?: number, text?: string}) => {\n let {\n index,\n text\n } = opts;\n\n let row;\n if (index != null) {\n row = this.rows[index];\n } else if (text != null) {\n row = within(this?.gridlist).getByText(text);\n while (row && row.getAttribute('role') !== 'row') {\n row = row.parentElement;\n }\n }\n\n return row;\n };\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n triggerRowAction = async (opts: {index?: number, text?: string, needsDoubleClick?: boolean, interactionType?: UserOpts['interactionType']}) => {\n let {\n index,\n text,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n let row = this.findRow({index, text});\n if (row) {\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n act(() => row.focus());\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n };\n\n // TODO: do we really need this getter? Theoretically the user already has the reference to the gridlist\n get gridlist() {\n return this._gridlist;\n }\n\n get rows() {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n get selectedRows() {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n cells = (opts: {element?: HTMLElement} = {}) => {\n let {element} = opts;\n return within(element || this.gridlist).queryAllByRole('gridcell');\n };\n}\n"],"names":[],"version":3,"file":"grid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Q,EAAC,GAAG;QAChC,OAAO,CAAA,GAAA,aAAK,EAAE,SAAS,cAAc,CAAC;IACxC;IAhLA,YAAY,IAAwB,CAAE;QACpC,IAAI,QAAC,IAAI,QAAE,IAAI,mBAAE,eAAe,gBAAE,YAAY,EAAC,GAAG;QAClD,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,gBAAgB,GAAG,mBAAmB;QAC3C,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,SAAS,GAAG;IACnB;AA2KF","sources":["packages/@react-aria/test-utils/src/gridlist.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {act, within} from '@testing-library/react';\nimport {GridListTesterOpts, GridRowActionOpts, ToggleGridRowOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface GridListToggleRowOpts extends ToggleGridRowOpts {}\ninterface GridListRowActionOpts extends GridRowActionOpts {}\n\nexport class GridListTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _gridlist: HTMLElement;\n\n constructor(opts: GridListTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._advanceTimer = advanceTimer;\n this._gridlist = root;\n }\n\n /**\n * Set the interaction type used by the gridlist tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\n this._interactionType = type;\n }\n\n /**\n * Returns a row matching the specified index or text content.\n */\n findRow(opts: {rowIndexOrText: number | string}): HTMLElement {\n let {\n rowIndexOrText\n } = opts;\n\n let row;\n if (typeof rowIndexOrText === 'number') {\n row = this.rows[rowIndexOrText];\n } else if (typeof rowIndexOrText === 'string') {\n row = (within(this.gridlist!).getByText(rowIndexOrText).closest('[role=row]'))! as HTMLElement;\n }\n\n return row;\n }\n\n // TODO: RTL\n private async keyboardNavigateToRow(opts: {row: HTMLElement}) {\n let {row} = opts;\n let rows = this.rows;\n let targetIndex = rows.indexOf(row);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the gridlist');\n }\n if (document.activeElement === this._gridlist) {\n await this.user.keyboard('[ArrowDown]');\n } else if (this._gridlist.contains(document.activeElement) && document.activeElement!.getAttribute('role') !== 'row') {\n do {\n await this.user.keyboard('[ArrowLeft]');\n } while (document.activeElement!.getAttribute('role') !== 'row');\n }\n let currIndex = rows.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the gridlist');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async toggleRowSelection(opts: GridListToggleRowOpts) {\n let {\n row,\n needsLongPress,\n checkboxSelection = true,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n let rowCheckbox = within(row).queryByRole('checkbox');\n\n // TODO: we early return here because the checkbox/row can't be keyboard navigated to if the row is disabled usually\n // but we may to check for disabledBehavior (aka if the disable row gets skipped when keyboard navigating or not)\n if (interactionType === 'keyboard' && (rowCheckbox?.getAttribute('disabled') === '' || row?.getAttribute('aria-disabled') === 'true')) {\n return;\n }\n\n // this would be better than the check to do nothing in events.ts\n // also, it'd be good to be able to trigger selection on the row instead of having to go to the checkbox directly\n if (interactionType === 'keyboard' && !checkboxSelection) {\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('{Space}');\n return;\n }\n if (rowCheckbox && checkboxSelection) {\n await pressElement(this.user, rowCheckbox, interactionType);\n } else {\n let cell = within(row).getAllByRole('gridcell')[0];\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n // Note that long press interactions with rows is strictly touch only for grid rows\n await triggerLongPress({element: cell, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n\n } else {\n await pressElement(this.user, cell, interactionType);\n }\n }\n }\n\n // TODO: There is a more difficult use case where the row has/behaves as link, don't think we have a good way to determine that unless the\n // user specificlly tells us\n /**\n * Triggers the action for the specified gridlist row. Defaults to using the interaction type set on the gridlist tester.\n */\n async triggerRowAction(opts: GridListRowActionOpts) {\n let {\n row,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof row === 'string' || typeof row === 'number') {\n row = this.findRow({rowIndexOrText: row});\n }\n\n if (!row) {\n throw new Error('Target row not found in the gridlist.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(row);\n } else if (interactionType === 'keyboard') {\n if (row?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== this._gridlist || !this._gridlist.contains(document.activeElement)) {\n act(() => this._gridlist.focus());\n }\n\n await this.keyboardNavigateToRow({row});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, row, interactionType);\n }\n }\n\n /**\n * Returns the gridlist.\n */\n get gridlist(): HTMLElement {\n return this._gridlist;\n }\n\n /**\n * Returns the gridlist's rows if any.\n */\n get rows(): HTMLElement[] {\n return within(this?.gridlist).queryAllByRole('row');\n }\n\n /**\n * Returns the gridlist's selected rows if any.\n */\n get selectedRows(): HTMLElement[] {\n return this.rows.filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the gridlist's cells if any. Can be filtered against a specific row if provided via `element`.\n */\n cells(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this.gridlist} = opts;\n return within(element).queryAllByRole('gridcell');\n }\n}\n"],"names":[],"version":3,"file":"gridlist.module.js.map"}
|