@react-aria/test-utils 1.0.0-alpha.3 → 1.0.0-alpha.4
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.map +1 -1
- 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 +170 -139
- package/dist/table.main.js.map +1 -1
- package/dist/table.mjs +171 -140
- package/dist/table.module.js +171 -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 +2 -3
- package/src/combobox.ts +105 -36
- package/src/events.ts +1 -1
- 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 +129 -64
- 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.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,c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,mBAAmB,OAAO;YACxB,IAAI,SACF,KAAK,QACL,IAAI,oBACJ,gBAAgB,mBAChB,kBAAkB,IAAI,CAAC,gBAAgB,EACxC,GAAG;YAEJ,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC;uBAAC;sBAAO;YAAI;YACnC,IAAI,KAAK;gBACP,IAAI,kBACF,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;qBACpB,IAAI,oBAAoB,YAAY;oBACzC,CAAA,GAAA,UAAE,EAAE,IAAM,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":"gridlist.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AASM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA;;GAEC,GACD,QAAQ,IAAuC,EAAe;QAC5D,IAAI,kBACF,cAAc,EACf,GAAG;QAEJ,IAAI;QACJ,IAAI,OAAO,mBAAmB,UAC5B,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe;aAC1B,IAAI,OAAO,mBAAmB,UACnC,MAAO,CAAA,GAAA,aAAK,EAAE,IAAI,CAAC,QAAQ,EAAG,SAAS,CAAC,gBAAgB,OAAO,CAAC;QAGlE,OAAO;IACT;IAEA,YAAY;IACZ,MAAc,sBAAsB,IAAwB,EAAE;QAC5D,IAAI,OAAC,GAAG,EAAC,GAAG;QACZ,IAAI,OAAO,IAAI,CAAC,IAAI;QACpB,IAAI,cAAc,KAAK,OAAO,CAAC;QAC/B,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAElB,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,SAAS,EAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;aACpB,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,SAAS,aAAa,KAAK,SAAS,aAAa,CAAE,YAAY,CAAC,YAAY,OAC7G,GACE,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;eAClB,S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ACV;QAAd,OAAO,CAAA,GAAA,aAAK,GAAE,QAAA,IAAI,cAAJ,4BAAA,MAAM,QAAQ,EAAE,cAAc,CAAC;IAC/C;IAEA;;GAEC,GACD,IAAI,eAA8B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,MAAO,IAAI,YAAY,CAAC,qBAAqB;IACvE;IAEA;;GAEC,GACD,MAAM,OAAgC,CAAC,CAAC,EAAiB;QACvD,IAAI,WAAC,UAAU,IAAI,CAAC,QAAQ,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"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var $5a8bfe1663b8366d$exports = require("./events.main.js");
|
|
2
|
+
var $bAxU9$testinglibraryreact = require("@testing-library/react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "ListBoxTester", () => $8ac94de7d2631d04$export$54c24f7ee8577f4f);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
class $8ac94de7d2631d04$export$54c24f7ee8577f4f {
|
|
23
|
+
/**
|
|
24
|
+
* Set the interaction type used by the listbox tester.
|
|
25
|
+
*/ setInteractionType(type) {
|
|
26
|
+
this._interactionType = type;
|
|
27
|
+
}
|
|
28
|
+
// TODO: now that we have listbox, perhaps select can make use of this tester internally
|
|
29
|
+
/**
|
|
30
|
+
* Returns a option matching the specified index or text content.
|
|
31
|
+
*/ findOption(opts) {
|
|
32
|
+
let { optionIndexOrText: optionIndexOrText } = opts;
|
|
33
|
+
let option;
|
|
34
|
+
let options = this.options();
|
|
35
|
+
if (typeof optionIndexOrText === 'number') option = options[optionIndexOrText];
|
|
36
|
+
else if (typeof optionIndexOrText === 'string') option = (0, $bAxU9$testinglibraryreact.within)(this.listbox).getByText(optionIndexOrText).closest('[role=option]');
|
|
37
|
+
return option;
|
|
38
|
+
}
|
|
39
|
+
// TODO: this is basically the same as menu except for the error message, refactor later so that they share
|
|
40
|
+
// TODO: this also doesn't support grid layout yet
|
|
41
|
+
async keyboardNavigateToOption(opts) {
|
|
42
|
+
var _document_activeElement;
|
|
43
|
+
let { option: option } = opts;
|
|
44
|
+
let options = this.options();
|
|
45
|
+
let targetIndex = options.indexOf(option);
|
|
46
|
+
if (targetIndex === -1) throw new Error('Option provided is not in the listbox');
|
|
47
|
+
if (document.activeElement === this._listbox) await this.user.keyboard('[ArrowDown]');
|
|
48
|
+
// TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,
|
|
49
|
+
// feels like it could break easily
|
|
50
|
+
if (((_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getAttribute('role')) !== 'option') await (0, $bAxU9$testinglibraryreact.act)(async ()=>{
|
|
51
|
+
option.focus();
|
|
52
|
+
});
|
|
53
|
+
let currIndex = options.indexOf(document.activeElement);
|
|
54
|
+
if (currIndex === -1) throw new Error('ActiveElement is not in the listbox');
|
|
55
|
+
let direction = targetIndex > currIndex ? 'down' : 'up';
|
|
56
|
+
for(let i = 0; i < Math.abs(targetIndex - currIndex); i++)await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
|
|
60
|
+
*/ async toggleOptionSelection(opts) {
|
|
61
|
+
let { option: option, needsLongPress: needsLongPress, keyboardActivation: keyboardActivation = 'Enter', interactionType: interactionType = this._interactionType } = opts;
|
|
62
|
+
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
63
|
+
optionIndexOrText: option
|
|
64
|
+
});
|
|
65
|
+
if (!option) throw new Error('Target option not found in the listbox.');
|
|
66
|
+
if (interactionType === 'keyboard') {
|
|
67
|
+
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
68
|
+
if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) (0, $bAxU9$testinglibraryreact.act)(()=>this._listbox.focus());
|
|
69
|
+
await this.keyboardNavigateToOption({
|
|
70
|
+
option: option
|
|
71
|
+
});
|
|
72
|
+
await this.user.keyboard(`[${keyboardActivation}]`);
|
|
73
|
+
} else if (needsLongPress && interactionType === 'touch') {
|
|
74
|
+
if (this._advanceTimer == null) throw new Error('No advanceTimers provided for long press.');
|
|
75
|
+
await (0, $5a8bfe1663b8366d$exports.triggerLongPress)({
|
|
76
|
+
element: option,
|
|
77
|
+
advanceTimer: this._advanceTimer,
|
|
78
|
+
pointerOpts: {
|
|
79
|
+
pointerType: 'touch'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.
|
|
86
|
+
*/ async triggerOptionAction(opts) {
|
|
87
|
+
let { option: option, needsDoubleClick: needsDoubleClick, interactionType: interactionType = this._interactionType } = opts;
|
|
88
|
+
if (typeof option === 'string' || typeof option === 'number') option = this.findOption({
|
|
89
|
+
optionIndexOrText: option
|
|
90
|
+
});
|
|
91
|
+
if (!option) throw new Error('Target option not found in the listbox.');
|
|
92
|
+
if (needsDoubleClick) await this.user.dblClick(option);
|
|
93
|
+
else if (interactionType === 'keyboard') {
|
|
94
|
+
if ((option === null || option === void 0 ? void 0 : option.getAttribute('aria-disabled')) === 'true') return;
|
|
95
|
+
if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) (0, $bAxU9$testinglibraryreact.act)(()=>this._listbox.focus());
|
|
96
|
+
await this.keyboardNavigateToOption({
|
|
97
|
+
option: option
|
|
98
|
+
});
|
|
99
|
+
await this.user.keyboard('[Enter]');
|
|
100
|
+
} else await (0, $5a8bfe1663b8366d$exports.pressElement)(this.user, option, interactionType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the listbox.
|
|
104
|
+
*/ get listbox() {
|
|
105
|
+
return this._listbox;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the listbox options. Can be filtered to a subsection of the listbox if provided via `element`.
|
|
109
|
+
*/ options(opts = {}) {
|
|
110
|
+
let { element: element = this._listbox } = opts;
|
|
111
|
+
let options = [];
|
|
112
|
+
if (element) options = (0, $bAxU9$testinglibraryreact.within)(element).queryAllByRole('option');
|
|
113
|
+
return options;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns the listbox's selected options if any.
|
|
117
|
+
*/ get selectedOptions() {
|
|
118
|
+
return this.options().filter((row)=>row.getAttribute('aria-selected') === 'true');
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Returns the listbox's sections if any.
|
|
122
|
+
*/ get sections() {
|
|
123
|
+
return (0, $bAxU9$testinglibraryreact.within)(this._listbox).queryAllByRole('group');
|
|
124
|
+
}
|
|
125
|
+
constructor(opts){
|
|
126
|
+
let { root: root, user: user, interactionType: interactionType, advanceTimer: advanceTimer } = opts;
|
|
127
|
+
this.user = user;
|
|
128
|
+
this._interactionType = interactionType || 'mouse';
|
|
129
|
+
this._listbox = root;
|
|
130
|
+
this._advanceTimer = advanceTimer;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=listbox.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAiCM,MAAM;IAcX;;GAEC,GACD,mBAAmB,IAAiC,EAAE;QACpD,IAAI,CAAC,gBAAgB,GAAG;IAC1B;IAEA,wFAAwF;IACxF;;GAEC,GACD,WAAW,IAA0C,EAAe;QAClE,IAAI,qBACF,iBAAiB,EAClB,GAAG;QAEJ,IAAI;QACJ,IAAI,UAAU,IAAI,CAAC,OAAO;QAE1B,IAAI,OAAO,sBAAsB,UAC/B,SAAS,OAAO,CAAC,kBAAkB;aAC9B,IAAI,OAAO,sBAAsB,UACtC,SAAU,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,OAAO,EAAG,SAAS,CAAC,mBAAmB,OAAO,CAAC;QAGvE,OAAO;IACT;IAEA,2GAA2G;IAC3G,kDAAkD;IAClD,MAAc,yBAAyB,IAA2B,EAAE;YAc9D;QAbJ,IAAI,UAAC,MAAM,EAAC,GAAG;QACf,IAAI,UAAU,IAAI,CAAC,OAAO;QAC1B,IAAI,cAAc,QAAQ,OAAO,CAAC;QAClC,IAAI,gBAAgB,IAClB,MAAM,IAAI,MAAM;QAGlB,IAAI,SAAS,aAAa,KAAK,IAAI,CAAC,QAAQ,EAC1C,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC;QAG3B,+GAA+G;QAC/G,mCAAmC;QACnC,IAAI,EAAA,0BAAA,SAAS,aAAa,cAAtB,8CAAA,wBAAwB,YAAY,CAAC,aAAY,UACnD,MAAM,CAAA,GAAA,8BAAE,EAAE;YACR,OAAO,KAAK;QACd;QAGF,IAAI,YAAY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A,MAAO,IAAI,YAAY,CAAC,qBAAqB;IAC5E;IAEA;;GAEC,GACD,IAAI,WAA0B;QAC5B,OAAO,CAAA,GAAA,iCAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC;IAC9C;IA/KA,YAAY,IAAuB,CAAE;QACnC,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,QAAQ,GAAG;QAChB,IAAI,CAAC,aAAa,GAAG;IACvB;AA0KF","sources":["packages/@react-aria/test-utils/src/listbox.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 {ListBoxTesterOpts, UserOpts} from './types';\nimport {pressElement, triggerLongPress} from './events';\n\ninterface ListBoxToggleOptionOpts {\n /**\n * What interaction type to use when toggling selection for an option. Defaults to the interaction type set on the tester.\n */\n interactionType?: UserOpts['interactionType'],\n /**\n * The index, text, or node of the option to toggle selection for.\n */\n option: number | string | HTMLElement,\n /**\n * Whether the option should be triggered by Space or Enter in keyboard modality.\n * @default 'Enter'\n */\n keyboardActivation?: 'Space' | 'Enter',\n /**\n * Whether the option needs to be long pressed to be selected. Depends on the listbox's implementation.\n */\n needsLongPress?: boolean\n}\n\ninterface ListBoxOptionActionOpts extends Omit<ListBoxToggleOptionOpts, 'keyboardActivation' | 'needsLongPress'> {\n /**\n * Whether or not the option needs a double click to trigger the option action. Depends on the listbox's implementation.\n */\n needsDoubleClick?: boolean\n}\n\nexport class ListBoxTester {\n private user;\n private _interactionType: UserOpts['interactionType'];\n private _advanceTimer: UserOpts['advanceTimer'];\n private _listbox: HTMLElement;\n\n constructor(opts: ListBoxTesterOpts) {\n let {root, user, interactionType, advanceTimer} = opts;\n this.user = user;\n this._interactionType = interactionType || 'mouse';\n this._listbox = root;\n this._advanceTimer = advanceTimer;\n }\n\n /**\n * Set the interaction type used by the listbox tester.\n */\n setInteractionType(type: UserOpts['interactionType']) {\n this._interactionType = type;\n }\n\n // TODO: now that we have listbox, perhaps select can make use of this tester internally\n /**\n * Returns a option matching the specified index or text content.\n */\n findOption(opts: {optionIndexOrText: number | string}): HTMLElement {\n let {\n optionIndexOrText\n } = opts;\n\n let option;\n let options = this.options();\n\n if (typeof optionIndexOrText === 'number') {\n option = options[optionIndexOrText];\n } else if (typeof optionIndexOrText === 'string') {\n option = (within(this.listbox!).getByText(optionIndexOrText).closest('[role=option]'))! as HTMLElement;\n }\n\n return option;\n }\n\n // TODO: this is basically the same as menu except for the error message, refactor later so that they share\n // TODO: this also doesn't support grid layout yet\n private async keyboardNavigateToOption(opts: {option: HTMLElement}) {\n let {option} = opts;\n let options = this.options();\n let targetIndex = options.indexOf(option);\n if (targetIndex === -1) {\n throw new Error('Option provided is not in the listbox');\n }\n\n if (document.activeElement === this._listbox) {\n await this.user.keyboard('[ArrowDown]');\n }\n\n // TODO: not sure about doing same while loop that exists in other implementations of keyboardNavigateToOption,\n // feels like it could break easily\n if (document.activeElement?.getAttribute('role') !== 'option') {\n await act(async () => {\n option.focus();\n });\n }\n\n let currIndex = options.indexOf(document.activeElement as HTMLElement);\n if (currIndex === -1) {\n throw new Error('ActiveElement is not in the listbox');\n }\n let direction = targetIndex > currIndex ? 'down' : 'up';\n\n for (let i = 0; i < Math.abs(targetIndex - currIndex); i++) {\n await this.user.keyboard(`[${direction === 'down' ? 'ArrowDown' : 'ArrowUp'}]`);\n }\n };\n\n /**\n * Toggles the selection for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async toggleOptionSelection(opts: ListBoxToggleOptionOpts) {\n let {option, needsLongPress, keyboardActivation = 'Enter', interactionType = this._interactionType} = opts;\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) {\n act(() => this._listbox.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard(`[${keyboardActivation}]`);\n } else {\n if (needsLongPress && interactionType === 'touch') {\n if (this._advanceTimer == null) {\n throw new Error('No advanceTimers provided for long press.');\n }\n\n await triggerLongPress({element: option, advanceTimer: this._advanceTimer, pointerOpts: {pointerType: 'touch'}});\n } else {\n await pressElement(this.user, option, interactionType);\n }\n }\n }\n\n /**\n * Triggers the action for the specified listbox option. Defaults to using the interaction type set on the listbox tester.\n */\n async triggerOptionAction(opts: ListBoxOptionActionOpts) {\n let {\n option,\n needsDoubleClick,\n interactionType = this._interactionType\n } = opts;\n\n if (typeof option === 'string' || typeof option === 'number') {\n option = this.findOption({optionIndexOrText: option});\n }\n\n if (!option) {\n throw new Error('Target option not found in the listbox.');\n }\n\n if (needsDoubleClick) {\n await this.user.dblClick(option);\n } else if (interactionType === 'keyboard') {\n if (option?.getAttribute('aria-disabled') === 'true') {\n return;\n }\n\n if (document.activeElement !== this._listbox || !this._listbox.contains(document.activeElement)) {\n act(() => this._listbox.focus());\n }\n\n await this.keyboardNavigateToOption({option});\n await this.user.keyboard('[Enter]');\n } else {\n await pressElement(this.user, option, interactionType);\n }\n }\n\n /**\n * Returns the listbox.\n */\n get listbox(): HTMLElement {\n return this._listbox;\n }\n\n /**\n * Returns the listbox options. Can be filtered to a subsection of the listbox if provided via `element`.\n */\n options(opts: {element?: HTMLElement} = {}): HTMLElement[] {\n let {element = this._listbox} = opts;\n let options = [];\n if (element) {\n options = within(element).queryAllByRole('option');\n }\n\n return options;\n }\n\n /**\n * Returns the listbox's selected options if any.\n */\n get selectedOptions(): HTMLElement[] {\n return this.options().filter(row => row.getAttribute('aria-selected') === 'true');\n }\n\n /**\n * Returns the listbox's sections if any.\n */\n get sections(): HTMLElement[] {\n return within(this._listbox).queryAllByRole('group');\n }\n}\n"],"names":[],"version":3,"file":"listbox.main.js.map"}
|