@instructure/ui-select 10.16.1-snapshot-0 → 10.16.1-snapshot-1
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/CHANGELOG.md +1 -1
- package/es/Select/__new-tests__/Select.test.js +279 -221
- package/es/Select/index.js +110 -88
- package/lib/Select/__new-tests__/Select.test.js +278 -221
- package/lib/Select/index.js +109 -87
- package/package.json +23 -23
- package/src/Select/__new-tests__/Select.test.tsx +5 -4
- package/src/Select/index.tsx +4 -5
- package/src/Select/props.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Select/__new-tests__/Select.test.d.ts.map +1 -1
- package/types/Select/index.d.ts +13 -15
- package/types/Select/index.d.ts.map +1 -1
- package/types/Select/props.d.ts +1 -1
- package/types/Select/props.d.ts.map +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
-
var _react =
|
|
5
|
+
var _react = require("react");
|
|
6
6
|
var _react2 = require("@testing-library/react");
|
|
7
7
|
var _vitest = require("vitest");
|
|
8
8
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
@@ -16,6 +16,8 @@ var _IconAddLine = require("@instructure/ui-icons/lib/IconAddLine.js");
|
|
|
16
16
|
var _IconCheckSolid = require("@instructure/ui-icons/lib/IconCheckSolid.js");
|
|
17
17
|
var _IconDownloadSolid = require("@instructure/ui-icons/lib/IconDownloadSolid.js");
|
|
18
18
|
var _IconEyeSolid = require("@instructure/ui-icons/lib/IconEyeSolid.js");
|
|
19
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
20
|
+
var _react3 = require("@emotion/react");
|
|
19
21
|
var _Select, _Select2, _Select3, _Select4, _Select5, _Select6, _Select7;
|
|
20
22
|
/*
|
|
21
23
|
* The MIT License (MIT)
|
|
@@ -42,13 +44,13 @@ var _Select, _Select2, _Select3, _Select4, _Select5, _Select6, _Select7;
|
|
|
42
44
|
*/
|
|
43
45
|
// eslint-disable-next-line no-restricted-imports
|
|
44
46
|
const defaultOptions = ['foo', 'bar', 'baz'];
|
|
45
|
-
const getOptions = (highlighted, selected, disabled) => defaultOptions.map(opt =>
|
|
47
|
+
const getOptions = (highlighted, selected, disabled) => defaultOptions.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
46
48
|
id: opt,
|
|
47
|
-
key: opt,
|
|
48
49
|
value: opt,
|
|
49
50
|
isHighlighted: opt === highlighted,
|
|
50
51
|
isSelected: opt === selected,
|
|
51
|
-
isDisabled: opt === disabled
|
|
52
|
+
isDisabled: opt === disabled,
|
|
53
|
+
children: opt
|
|
52
54
|
}, opt));
|
|
53
55
|
const optionsWithBeforeContent = [{
|
|
54
56
|
id: 'opt1',
|
|
@@ -57,11 +59,11 @@ const optionsWithBeforeContent = [{
|
|
|
57
59
|
}, {
|
|
58
60
|
id: 'opt2',
|
|
59
61
|
label: 'Icon',
|
|
60
|
-
renderBeforeLabel:
|
|
62
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
|
|
61
63
|
}, {
|
|
62
64
|
id: 'opt3',
|
|
63
65
|
label: 'Colored Icon',
|
|
64
|
-
renderBeforeLabel:
|
|
66
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
|
|
65
67
|
}];
|
|
66
68
|
const groupOptionsWithBeforeContent = {
|
|
67
69
|
Options1: [{
|
|
@@ -71,11 +73,11 @@ const groupOptionsWithBeforeContent = {
|
|
|
71
73
|
}, {
|
|
72
74
|
id: 'opt2',
|
|
73
75
|
label: 'Icon1',
|
|
74
|
-
renderBeforeLabel:
|
|
76
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
|
|
75
77
|
}, {
|
|
76
78
|
id: 'opt3',
|
|
77
79
|
label: 'Colored Icon1',
|
|
78
|
-
renderBeforeLabel:
|
|
80
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
|
|
79
81
|
}],
|
|
80
82
|
Options2: [{
|
|
81
83
|
id: 'opt4',
|
|
@@ -84,11 +86,11 @@ const groupOptionsWithBeforeContent = {
|
|
|
84
86
|
}, {
|
|
85
87
|
id: 'opt5',
|
|
86
88
|
label: 'Icon2',
|
|
87
|
-
renderBeforeLabel:
|
|
89
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconAddLine.IconAddLine, {})
|
|
88
90
|
}, {
|
|
89
91
|
id: 'opt6',
|
|
90
92
|
label: 'Colored Icon2',
|
|
91
|
-
renderBeforeLabel:
|
|
93
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconDownloadSolid.IconDownloadSolid, {})
|
|
92
94
|
}]
|
|
93
95
|
};
|
|
94
96
|
const optionsWithAfterContent = [{
|
|
@@ -98,11 +100,11 @@ const optionsWithAfterContent = [{
|
|
|
98
100
|
}, {
|
|
99
101
|
id: 'opt2',
|
|
100
102
|
label: 'Icon',
|
|
101
|
-
renderAfterLabel:
|
|
103
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
|
|
102
104
|
}, {
|
|
103
105
|
id: 'opt3',
|
|
104
106
|
label: 'Colored Icon',
|
|
105
|
-
renderAfterLabel:
|
|
107
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
|
|
106
108
|
}];
|
|
107
109
|
const groupOptionsWithAfterContent = {
|
|
108
110
|
Options1: [{
|
|
@@ -112,11 +114,11 @@ const groupOptionsWithAfterContent = {
|
|
|
112
114
|
}, {
|
|
113
115
|
id: 'opt2',
|
|
114
116
|
label: 'Icon1',
|
|
115
|
-
renderAfterLabel:
|
|
117
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
|
|
116
118
|
}, {
|
|
117
119
|
id: 'opt3',
|
|
118
120
|
label: 'Colored Icon1',
|
|
119
|
-
renderAfterLabel:
|
|
121
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
|
|
120
122
|
}],
|
|
121
123
|
Options2: [{
|
|
122
124
|
id: 'opt4',
|
|
@@ -125,11 +127,11 @@ const groupOptionsWithAfterContent = {
|
|
|
125
127
|
}, {
|
|
126
128
|
id: 'opt5',
|
|
127
129
|
label: 'Icon2',
|
|
128
|
-
renderAfterLabel:
|
|
130
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconAddLine.IconAddLine, {})
|
|
129
131
|
}, {
|
|
130
132
|
id: 'opt6',
|
|
131
133
|
label: 'Colored Icon2',
|
|
132
|
-
renderAfterLabel:
|
|
134
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconDownloadSolid.IconDownloadSolid, {})
|
|
133
135
|
}]
|
|
134
136
|
};
|
|
135
137
|
const optionsWithBeforeAndAfterContent = [{
|
|
@@ -140,61 +142,58 @@ const optionsWithBeforeAndAfterContent = [{
|
|
|
140
142
|
}, {
|
|
141
143
|
id: 'opt2',
|
|
142
144
|
label: 'Icon',
|
|
143
|
-
renderAfterLabel:
|
|
144
|
-
renderBeforeLabel:
|
|
145
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {}),
|
|
146
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {})
|
|
145
147
|
}, {
|
|
146
148
|
id: 'opt3',
|
|
147
149
|
label: 'Colored Icon',
|
|
148
|
-
renderBeforeLabel:
|
|
149
|
-
renderAfterLabel:
|
|
150
|
+
renderBeforeLabel: (0, _jsxRuntime.jsx)(_IconEyeSolid.IconEyeSolid, {}),
|
|
151
|
+
renderAfterLabel: (0, _jsxRuntime.jsx)(_IconCheckSolid.IconCheckSolid, {})
|
|
150
152
|
}];
|
|
151
|
-
const getOptionsWithBeforeContent = selected => optionsWithBeforeContent.map(opt =>
|
|
153
|
+
const getOptionsWithBeforeContent = selected => optionsWithBeforeContent.map(opt => (0, _react3.createElement)(_index.default.Option, {
|
|
154
|
+
...opt,
|
|
152
155
|
key: opt.id,
|
|
153
156
|
isSelected: opt.id === selected
|
|
154
|
-
}))
|
|
157
|
+
}));
|
|
155
158
|
const getGroupOptionsWithBeforeContent = selected => {
|
|
156
159
|
return Object.keys(groupOptionsWithBeforeContent).map((key, index) => {
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
})));
|
|
160
|
+
return (0, _jsxRuntime.jsx)(_index.default.Group, {
|
|
161
|
+
renderLabel: key,
|
|
162
|
+
children: groupOptionsWithBeforeContent[key].map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
163
|
+
id: opt.id,
|
|
164
|
+
value: opt.label,
|
|
165
|
+
renderBeforeLabel: opt.renderBeforeLabel,
|
|
166
|
+
isSelected: opt.id === selected
|
|
167
|
+
}, opt.id))
|
|
168
|
+
}, index);
|
|
167
169
|
});
|
|
168
170
|
};
|
|
169
|
-
const getOptionsWithAfterContent = selected => optionsWithAfterContent.map(opt =>
|
|
171
|
+
const getOptionsWithAfterContent = selected => optionsWithAfterContent.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
170
172
|
id: opt.id,
|
|
171
|
-
key: opt.id,
|
|
172
173
|
value: opt.label,
|
|
173
174
|
renderAfterLabel: opt.renderAfterLabel,
|
|
174
175
|
isSelected: opt.id === selected
|
|
175
|
-
}));
|
|
176
|
+
}, opt.id));
|
|
176
177
|
const getGroupOptionsWithAfterContent = selected => {
|
|
177
178
|
return Object.keys(groupOptionsWithAfterContent).map((key, index) => {
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
})));
|
|
179
|
+
return (0, _jsxRuntime.jsx)(_index.default.Group, {
|
|
180
|
+
renderLabel: key,
|
|
181
|
+
children: groupOptionsWithAfterContent[key].map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
182
|
+
id: opt.id,
|
|
183
|
+
value: opt.label,
|
|
184
|
+
renderAfterLabel: opt.renderAfterLabel,
|
|
185
|
+
isSelected: opt.id === selected
|
|
186
|
+
}, opt.id))
|
|
187
|
+
}, index);
|
|
188
188
|
});
|
|
189
189
|
};
|
|
190
|
-
const getOptionsWithBeforeAndAfterContent = selected => optionsWithBeforeAndAfterContent.map(opt =>
|
|
190
|
+
const getOptionsWithBeforeAndAfterContent = selected => optionsWithBeforeAndAfterContent.map(opt => (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
191
191
|
id: opt.id,
|
|
192
|
-
key: opt.id,
|
|
193
192
|
value: opt.label,
|
|
194
193
|
renderBeforeLabel: opt.renderBeforeLabel,
|
|
195
194
|
renderAfterLabel: opt.renderAfterLabel,
|
|
196
195
|
isSelected: opt.id === selected
|
|
197
|
-
}));
|
|
196
|
+
}, opt.id));
|
|
198
197
|
_vitest.vi.mock('@instructure/ui-utils', async importOriginal => {
|
|
199
198
|
const originalModule = await importOriginal();
|
|
200
199
|
return {
|
|
@@ -214,37 +213,41 @@ describe('<Select />', () => {
|
|
|
214
213
|
consoleErrorMock.mockRestore();
|
|
215
214
|
});
|
|
216
215
|
it('should have role button in Safari without onInputChange', async () => {
|
|
217
|
-
const _render = (0, _react2.render)(
|
|
218
|
-
renderLabel: "Choose an option"
|
|
219
|
-
|
|
216
|
+
const _render = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
217
|
+
renderLabel: "Choose an option",
|
|
218
|
+
children: getOptions()
|
|
219
|
+
})),
|
|
220
220
|
container = _render.container;
|
|
221
221
|
const input = container.querySelector('input');
|
|
222
222
|
expect(input).toHaveAttribute('role', 'button');
|
|
223
223
|
});
|
|
224
224
|
it('should have role combobox in different browsers than Safari without onInputChange', async () => {
|
|
225
225
|
mockUtils.isSafari = _vitest.vi.fn(() => false);
|
|
226
|
-
const _render2 = (0, _react2.render)(
|
|
227
|
-
renderLabel: "Choose an option"
|
|
228
|
-
|
|
226
|
+
const _render2 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
227
|
+
renderLabel: "Choose an option",
|
|
228
|
+
children: getOptions()
|
|
229
|
+
})),
|
|
229
230
|
container = _render2.container;
|
|
230
231
|
const input = container.querySelector('input');
|
|
231
232
|
expect(input).toHaveAttribute('role', 'combobox');
|
|
232
233
|
});
|
|
233
234
|
it('should have role combobox with onInputChange', async () => {
|
|
234
|
-
const _render3 = (0, _react2.render)(
|
|
235
|
+
const _render3 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
235
236
|
renderLabel: "Choose an option",
|
|
236
|
-
onInputChange: () => {}
|
|
237
|
-
|
|
237
|
+
onInputChange: () => {},
|
|
238
|
+
children: getOptions()
|
|
239
|
+
})),
|
|
238
240
|
container = _render3.container;
|
|
239
241
|
const input = container.querySelector('input');
|
|
240
242
|
expect(input).toHaveAttribute('role', 'combobox');
|
|
241
243
|
});
|
|
242
244
|
it('should render an input and a list', async () => {
|
|
243
|
-
const _render4 = (0, _react2.render)(
|
|
245
|
+
const _render4 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
244
246
|
renderLabel: "Choose an option",
|
|
245
247
|
isShowingOptions: true,
|
|
246
|
-
"data-testid": "subidubi"
|
|
247
|
-
|
|
248
|
+
"data-testid": "subidubi",
|
|
249
|
+
children: getOptions()
|
|
250
|
+
})),
|
|
248
251
|
container = _render4.container;
|
|
249
252
|
const select = container.querySelector('span[class$="-select"]');
|
|
250
253
|
const label = _react2.screen.getByLabelText('Choose an option');
|
|
@@ -262,22 +265,29 @@ describe('<Select />', () => {
|
|
|
262
265
|
expect(options[2]).toHaveTextContent(defaultOptions[2]);
|
|
263
266
|
});
|
|
264
267
|
it('should render groups', async () => {
|
|
265
|
-
(0, _react2.render)(_Select || (_Select =
|
|
268
|
+
(0, _react2.render)(_Select || (_Select = (0, _jsxRuntime.jsxs)(_index.default, {
|
|
266
269
|
renderLabel: "Choose an option",
|
|
267
|
-
isShowingOptions: true
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
270
|
+
isShowingOptions: true,
|
|
271
|
+
children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
272
|
+
id: "0",
|
|
273
|
+
children: "ungrouped option one"
|
|
274
|
+
}), (0, _jsxRuntime.jsx)(_index.default.Group, {
|
|
275
|
+
renderLabel: "Group one",
|
|
276
|
+
children: (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
277
|
+
id: "1",
|
|
278
|
+
children: "grouped option one"
|
|
279
|
+
})
|
|
280
|
+
}), (0, _jsxRuntime.jsx)(_index.default.Group, {
|
|
281
|
+
renderLabel: "Group two",
|
|
282
|
+
children: (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
283
|
+
id: "2",
|
|
284
|
+
children: "grouped option two"
|
|
285
|
+
})
|
|
286
|
+
}), (0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
287
|
+
id: "3",
|
|
288
|
+
children: "ungrouped option two"
|
|
289
|
+
})]
|
|
290
|
+
})));
|
|
281
291
|
const groups = _react2.screen.getAllByRole('group');
|
|
282
292
|
const groupLabel = _react2.screen.getByText('Group one');
|
|
283
293
|
expect(groupLabel).toHaveAttribute('role', 'presentation');
|
|
@@ -285,12 +295,16 @@ describe('<Select />', () => {
|
|
|
285
295
|
expect(groups.length).toBe(2);
|
|
286
296
|
});
|
|
287
297
|
it('should ignore invalid children', async () => {
|
|
288
|
-
(0, _react2.render)(_Select2 || (_Select2 =
|
|
298
|
+
(0, _react2.render)(_Select2 || (_Select2 = (0, _jsxRuntime.jsxs)(_index.default, {
|
|
289
299
|
renderLabel: "Choose an option",
|
|
290
|
-
isShowingOptions: true
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
300
|
+
isShowingOptions: true,
|
|
301
|
+
children: [(0, _jsxRuntime.jsx)(_index.default.Option, {
|
|
302
|
+
id: "0",
|
|
303
|
+
children: "valid"
|
|
304
|
+
}), (0, _jsxRuntime.jsx)("div", {
|
|
305
|
+
children: "invalid"
|
|
306
|
+
})]
|
|
307
|
+
})));
|
|
294
308
|
const invalidChild = _react2.screen.queryByText('invalid');
|
|
295
309
|
expect(invalidChild).not.toBeInTheDocument();
|
|
296
310
|
const expectedErrorMessage = 'Expected one of Group, Option';
|
|
@@ -298,11 +312,12 @@ describe('<Select />', () => {
|
|
|
298
312
|
});
|
|
299
313
|
it('should provide a focus method', async () => {
|
|
300
314
|
var _ref$current;
|
|
301
|
-
const ref = /*#__PURE__*/_react.
|
|
302
|
-
(0, _react2.render)(
|
|
315
|
+
const ref = /*#__PURE__*/(0, _react.createRef)();
|
|
316
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
303
317
|
renderLabel: "Choose an option",
|
|
304
|
-
ref: ref
|
|
305
|
-
|
|
318
|
+
ref: ref,
|
|
319
|
+
children: getOptions()
|
|
320
|
+
}));
|
|
306
321
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
307
322
|
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
|
308
323
|
await (0, _react2.waitFor)(() => {
|
|
@@ -311,11 +326,12 @@ describe('<Select />', () => {
|
|
|
311
326
|
});
|
|
312
327
|
it('should provide a focused getter', async () => {
|
|
313
328
|
var _ref$current2, _ref$current3;
|
|
314
|
-
const ref = /*#__PURE__*/_react.
|
|
315
|
-
(0, _react2.render)(
|
|
329
|
+
const ref = /*#__PURE__*/(0, _react.createRef)();
|
|
330
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
316
331
|
renderLabel: "Choose an option",
|
|
317
|
-
ref: ref
|
|
318
|
-
|
|
332
|
+
ref: ref,
|
|
333
|
+
children: getOptions()
|
|
334
|
+
}));
|
|
319
335
|
expect((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.focused).toBe(false);
|
|
320
336
|
(_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.focus();
|
|
321
337
|
await (0, _react2.waitFor)(() => {
|
|
@@ -325,7 +341,7 @@ describe('<Select />', () => {
|
|
|
325
341
|
});
|
|
326
342
|
describe('input', () => {
|
|
327
343
|
it('should render with a generated id by default', () => {
|
|
328
|
-
const _render5 = (0, _react2.render)(_Select3 || (_Select3 =
|
|
344
|
+
const _render5 = (0, _react2.render)(_Select3 || (_Select3 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
329
345
|
renderLabel: "Choose an option"
|
|
330
346
|
}))),
|
|
331
347
|
container = _render5.container;
|
|
@@ -334,7 +350,7 @@ describe('<Select />', () => {
|
|
|
334
350
|
expect(input).toHaveAttribute('id', expect.stringContaining('Select_'));
|
|
335
351
|
});
|
|
336
352
|
it('should render with a custom id if given', () => {
|
|
337
|
-
const _render6 = (0, _react2.render)(_Select4 || (_Select4 =
|
|
353
|
+
const _render6 = (0, _react2.render)(_Select4 || (_Select4 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
338
354
|
renderLabel: "Choose an option",
|
|
339
355
|
id: "customSelect"
|
|
340
356
|
}))),
|
|
@@ -344,7 +360,7 @@ describe('<Select />', () => {
|
|
|
344
360
|
expect(input.getAttribute('id')).toEqual('customSelect');
|
|
345
361
|
});
|
|
346
362
|
it('should render readonly when interaction="enabled" with no onInputChange', () => {
|
|
347
|
-
(0, _react2.render)(_Select5 || (_Select5 =
|
|
363
|
+
(0, _react2.render)(_Select5 || (_Select5 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
348
364
|
renderLabel: "Choose an option"
|
|
349
365
|
})));
|
|
350
366
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
@@ -352,7 +368,7 @@ describe('<Select />', () => {
|
|
|
352
368
|
expect(input).not.toHaveAttribute('disabled');
|
|
353
369
|
});
|
|
354
370
|
it('should not render readonly when interaction="enabled" with onInputChange', () => {
|
|
355
|
-
(0, _react2.render)(
|
|
371
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
356
372
|
renderLabel: "Choose an option",
|
|
357
373
|
onInputChange: () => {}
|
|
358
374
|
}));
|
|
@@ -361,7 +377,7 @@ describe('<Select />', () => {
|
|
|
361
377
|
expect(input).not.toHaveAttribute('disabled');
|
|
362
378
|
});
|
|
363
379
|
it('should render readonly when interaction="readonly"', () => {
|
|
364
|
-
(0, _react2.render)(
|
|
380
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
365
381
|
renderLabel: "Choose an option",
|
|
366
382
|
interaction: "readonly",
|
|
367
383
|
onInputChange: () => {}
|
|
@@ -371,7 +387,7 @@ describe('<Select />', () => {
|
|
|
371
387
|
expect(input).not.toHaveAttribute('disabled');
|
|
372
388
|
});
|
|
373
389
|
it('should render disabled when interaction="disabled"', () => {
|
|
374
|
-
(0, _react2.render)(
|
|
390
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
375
391
|
renderLabel: "Choose an option",
|
|
376
392
|
interaction: "disabled",
|
|
377
393
|
onInputChange: () => {}
|
|
@@ -381,7 +397,7 @@ describe('<Select />', () => {
|
|
|
381
397
|
expect(input).not.toHaveAttribute('readonly');
|
|
382
398
|
});
|
|
383
399
|
it('should not render readonly when disabled', () => {
|
|
384
|
-
(0, _react2.render)(_Select6 || (_Select6 =
|
|
400
|
+
(0, _react2.render)(_Select6 || (_Select6 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
385
401
|
renderLabel: "Choose an option",
|
|
386
402
|
interaction: "disabled"
|
|
387
403
|
})));
|
|
@@ -390,7 +406,7 @@ describe('<Select />', () => {
|
|
|
390
406
|
expect(input).not.toHaveAttribute('readonly');
|
|
391
407
|
});
|
|
392
408
|
it('should render required when isRequired={true}', () => {
|
|
393
|
-
(0, _react2.render)(_Select7 || (_Select7 =
|
|
409
|
+
(0, _react2.render)(_Select7 || (_Select7 = (0, _jsxRuntime.jsx)(_index.default, {
|
|
394
410
|
renderLabel: "Choose an option",
|
|
395
411
|
isRequired: true
|
|
396
412
|
})));
|
|
@@ -399,7 +415,7 @@ describe('<Select />', () => {
|
|
|
399
415
|
});
|
|
400
416
|
it('should render with inputValue', () => {
|
|
401
417
|
const val = 'hello world';
|
|
402
|
-
(0, _react2.render)(
|
|
418
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
403
419
|
renderLabel: "Choose an option",
|
|
404
420
|
inputValue: val
|
|
405
421
|
}));
|
|
@@ -407,211 +423,233 @@ describe('<Select />', () => {
|
|
|
407
423
|
expect(input).toHaveAttribute('value', val);
|
|
408
424
|
});
|
|
409
425
|
it('should set aria-activedescendant based on the highlighted option', () => {
|
|
410
|
-
(0, _react2.render)(
|
|
426
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
411
427
|
renderLabel: "Choose an option",
|
|
412
|
-
isShowingOptions: true
|
|
413
|
-
|
|
428
|
+
isShowingOptions: true,
|
|
429
|
+
children: getOptions(defaultOptions[1])
|
|
430
|
+
}));
|
|
414
431
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
415
432
|
expect(input).toHaveAttribute('aria-activedescendant', defaultOptions[1]);
|
|
416
433
|
});
|
|
417
434
|
it('should not set aria-activedescendant when not showing options', () => {
|
|
418
|
-
(0, _react2.render)(
|
|
419
|
-
renderLabel: "Choose an option"
|
|
420
|
-
|
|
435
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
436
|
+
renderLabel: "Choose an option",
|
|
437
|
+
children: getOptions(defaultOptions[1])
|
|
438
|
+
}));
|
|
421
439
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
422
440
|
expect(input).not.toHaveAttribute('aria-activedescendant');
|
|
423
441
|
});
|
|
424
442
|
it('should allow assistive text', () => {
|
|
425
|
-
(0, _react2.render)(
|
|
443
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
426
444
|
renderLabel: "Choose an option",
|
|
427
|
-
assistiveText: "hello world"
|
|
428
|
-
|
|
445
|
+
assistiveText: "hello world",
|
|
446
|
+
children: getOptions()
|
|
447
|
+
}));
|
|
429
448
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
430
449
|
const assistiveText = _react2.screen.getByText('hello world');
|
|
431
450
|
const assistiveTextId = assistiveText.getAttribute('id');
|
|
432
451
|
expect(input).toHaveAttribute('aria-describedby', assistiveTextId);
|
|
433
452
|
});
|
|
434
453
|
it('should allow custom props to pass through', () => {
|
|
435
|
-
(0, _react2.render)(
|
|
454
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
436
455
|
renderLabel: "Choose an option",
|
|
437
|
-
"data-custom-attr": "true"
|
|
438
|
-
|
|
456
|
+
"data-custom-attr": "true",
|
|
457
|
+
children: getOptions()
|
|
458
|
+
}));
|
|
439
459
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
440
460
|
expect(input).toHaveAttribute('data-custom-attr', 'true');
|
|
441
461
|
});
|
|
442
462
|
it('should allow override of autoComplete prop', () => {
|
|
443
|
-
const _render7 = (0, _react2.render)(
|
|
444
|
-
renderLabel: "Choose an option"
|
|
445
|
-
|
|
463
|
+
const _render7 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
464
|
+
renderLabel: "Choose an option",
|
|
465
|
+
children: getOptions()
|
|
466
|
+
})),
|
|
446
467
|
rerender = _render7.rerender;
|
|
447
468
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
448
469
|
expect(input).toHaveAttribute('autocomplete', 'off');
|
|
449
|
-
rerender(
|
|
470
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
450
471
|
renderLabel: "Choose an option",
|
|
451
|
-
autoComplete: "false"
|
|
452
|
-
|
|
472
|
+
autoComplete: "false",
|
|
473
|
+
children: getOptions()
|
|
474
|
+
}));
|
|
453
475
|
expect(input).toHaveAttribute('autocomplete', 'false');
|
|
454
476
|
});
|
|
455
477
|
it('should provide a ref to the input element', async () => {
|
|
456
478
|
const inputRef = _vitest.vi.fn();
|
|
457
|
-
(0, _react2.render)(
|
|
479
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
458
480
|
renderLabel: "Choose an option",
|
|
459
|
-
inputRef: inputRef
|
|
460
|
-
|
|
481
|
+
inputRef: inputRef,
|
|
482
|
+
children: getOptions()
|
|
483
|
+
}));
|
|
461
484
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
462
485
|
await (0, _react2.waitFor)(() => {
|
|
463
486
|
expect(inputRef).toHaveBeenCalledWith(input);
|
|
464
487
|
});
|
|
465
488
|
});
|
|
466
|
-
it("should not render option's before content in input field when isOptionContentAppliedToInput is set to false
|
|
467
|
-
const _render8 = (0, _react2.render)(
|
|
489
|
+
it("should not render option's before content in input field when isOptionContentAppliedToInput is set to false", async () => {
|
|
490
|
+
const _render8 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
468
491
|
renderLabel: "Choose an option",
|
|
469
492
|
isOptionContentAppliedToInput: false,
|
|
470
|
-
inputValue: optionsWithBeforeContent[0].label
|
|
471
|
-
|
|
493
|
+
inputValue: optionsWithBeforeContent[0].label,
|
|
494
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
495
|
+
})),
|
|
472
496
|
container = _render8.container;
|
|
473
497
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
474
498
|
expect(beforeContent).not.toHaveTextContent('XY');
|
|
475
499
|
});
|
|
476
500
|
it('should render arrow in input field when isOptionContentAppliedToInput is set to false', async () => {
|
|
477
|
-
const _render9 = (0, _react2.render)(
|
|
501
|
+
const _render9 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
478
502
|
renderLabel: "Choose an option",
|
|
479
503
|
isOptionContentAppliedToInput: false,
|
|
480
|
-
inputValue: optionsWithBeforeContent[0].label
|
|
481
|
-
|
|
504
|
+
inputValue: optionsWithBeforeContent[0].label,
|
|
505
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
506
|
+
})),
|
|
482
507
|
container = _render9.container;
|
|
483
508
|
const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
484
509
|
const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
|
|
485
510
|
expect(svgElement).toBeInTheDocument();
|
|
486
511
|
});
|
|
487
512
|
it("should render option's before content in input field when isOptionContentAppliedToInput is set to true", async () => {
|
|
488
|
-
const _render10 = (0, _react2.render)(
|
|
513
|
+
const _render10 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
489
514
|
renderLabel: "Choose an option",
|
|
490
515
|
isOptionContentAppliedToInput: true,
|
|
491
|
-
inputValue: optionsWithBeforeContent[0].label
|
|
492
|
-
|
|
516
|
+
inputValue: optionsWithBeforeContent[0].label,
|
|
517
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
518
|
+
})),
|
|
493
519
|
container = _render10.container;
|
|
494
520
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
495
521
|
expect(beforeContent).toHaveTextContent('XY');
|
|
496
522
|
});
|
|
497
523
|
it('should render arrow icon when isOptionContentAppliedToInput is set to true with before content', async () => {
|
|
498
|
-
const _render11 = (0, _react2.render)(
|
|
524
|
+
const _render11 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
499
525
|
renderLabel: "Choose an option",
|
|
500
526
|
isOptionContentAppliedToInput: true,
|
|
501
|
-
inputValue: optionsWithBeforeContent[0].label
|
|
502
|
-
|
|
527
|
+
inputValue: optionsWithBeforeContent[0].label,
|
|
528
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
529
|
+
})),
|
|
503
530
|
container = _render11.container;
|
|
504
531
|
const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
505
532
|
const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
|
|
506
533
|
expect(svgElement).toBeInTheDocument();
|
|
507
534
|
});
|
|
508
535
|
it("should render option's after content in input field when isOptionContentAppliedToInput is set to true", async () => {
|
|
509
|
-
const _render12 = (0, _react2.render)(
|
|
536
|
+
const _render12 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
510
537
|
renderLabel: "Choose an option",
|
|
511
538
|
isOptionContentAppliedToInput: true,
|
|
512
|
-
inputValue: optionsWithAfterContent[0].label
|
|
513
|
-
|
|
539
|
+
inputValue: optionsWithAfterContent[0].label,
|
|
540
|
+
children: getOptionsWithAfterContent('opt1')
|
|
541
|
+
})),
|
|
514
542
|
container = _render12.container;
|
|
515
543
|
const beforeContent = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
516
544
|
expect(beforeContent).toHaveTextContent('XY');
|
|
517
545
|
});
|
|
518
546
|
it("should render option's before content in input field when isOptionContentAppliedToInput is set to true but renderBeforeInput is also set", async () => {
|
|
519
|
-
const _render13 = (0, _react2.render)(
|
|
547
|
+
const _render13 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
520
548
|
renderLabel: "Choose an option",
|
|
521
549
|
isOptionContentAppliedToInput: true,
|
|
522
550
|
inputValue: optionsWithBeforeContent[0].label,
|
|
523
|
-
renderBeforeInput: "ZZ"
|
|
524
|
-
|
|
551
|
+
renderBeforeInput: "ZZ",
|
|
552
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
553
|
+
})),
|
|
525
554
|
container = _render13.container;
|
|
526
555
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
527
556
|
expect(beforeContent).toHaveTextContent('XY');
|
|
528
557
|
});
|
|
529
558
|
it("should render option's after content in input field when isOptionContentAppliedToInput is set to true but renderAfterInput is also set", async () => {
|
|
530
|
-
const _render14 = (0, _react2.render)(
|
|
559
|
+
const _render14 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
531
560
|
renderLabel: "Choose an option",
|
|
532
561
|
isOptionContentAppliedToInput: true,
|
|
533
562
|
inputValue: optionsWithAfterContent[0].label,
|
|
534
|
-
renderAfterInput: "ZZ"
|
|
535
|
-
|
|
563
|
+
renderAfterInput: "ZZ",
|
|
564
|
+
children: getOptionsWithAfterContent('opt1')
|
|
565
|
+
})),
|
|
536
566
|
container = _render14.container;
|
|
537
567
|
const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
538
568
|
expect(afterContent).toHaveTextContent('XY');
|
|
539
569
|
});
|
|
540
570
|
it("should not render option's before content in input field when isOptionContentAppliedToInput is set to true but inputValue is not set", async () => {
|
|
541
|
-
const _render15 = (0, _react2.render)(
|
|
571
|
+
const _render15 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
542
572
|
renderLabel: "Choose an option",
|
|
543
|
-
isOptionContentAppliedToInput: true
|
|
544
|
-
|
|
573
|
+
isOptionContentAppliedToInput: true,
|
|
574
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
575
|
+
})),
|
|
545
576
|
container = _render15.container;
|
|
546
577
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
547
578
|
expect(beforeContent).not.toHaveTextContent('XY');
|
|
548
579
|
});
|
|
549
580
|
it("should render option's before content in input field when isOptionContentAppliedToInput is set to true and both optionBeforeContent and optionAfterContent are provided", async () => {
|
|
550
|
-
const _render16 = (0, _react2.render)(
|
|
581
|
+
const _render16 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
551
582
|
renderLabel: "Choose an option",
|
|
552
583
|
isOptionContentAppliedToInput: true,
|
|
553
|
-
inputValue: optionsWithBeforeAndAfterContent[0].label
|
|
554
|
-
|
|
584
|
+
inputValue: optionsWithBeforeAndAfterContent[0].label,
|
|
585
|
+
children: getOptionsWithBeforeAndAfterContent('opt1')
|
|
586
|
+
})),
|
|
555
587
|
container = _render16.container;
|
|
556
588
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
557
589
|
expect(beforeContent).toHaveTextContent('XY');
|
|
558
590
|
});
|
|
559
591
|
it("should render option's after content in input field when isOptionContentAppliedToInput is set to true and both optionBeforeContent and optionAfterContent are provided", async () => {
|
|
560
|
-
const _render17 = (0, _react2.render)(
|
|
592
|
+
const _render17 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
561
593
|
renderLabel: "Choose an option",
|
|
562
594
|
isOptionContentAppliedToInput: true,
|
|
563
|
-
inputValue: optionsWithBeforeAndAfterContent[0].label
|
|
564
|
-
|
|
595
|
+
inputValue: optionsWithBeforeAndAfterContent[0].label,
|
|
596
|
+
children: getOptionsWithBeforeAndAfterContent('opt1')
|
|
597
|
+
})),
|
|
565
598
|
container = _render17.container;
|
|
566
599
|
const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
567
600
|
expect(afterContent).toHaveTextContent('ZZ');
|
|
568
601
|
});
|
|
569
602
|
it('should render arrow in input field when isOptionContentAppliedToInput is set to true but inputValue is not set', async () => {
|
|
570
|
-
const _render18 = (0, _react2.render)(
|
|
603
|
+
const _render18 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
571
604
|
renderLabel: "Choose an option",
|
|
572
|
-
isOptionContentAppliedToInput: true
|
|
573
|
-
|
|
605
|
+
isOptionContentAppliedToInput: true,
|
|
606
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
607
|
+
})),
|
|
574
608
|
container = _render18.container;
|
|
575
609
|
const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
576
610
|
const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
|
|
577
611
|
expect(svgElement).toBeInTheDocument();
|
|
578
612
|
});
|
|
579
613
|
it("should not render option's after content in input field when isOptionContentAppliedToInput is set to true but inputValue is not set", async () => {
|
|
580
|
-
const _render19 = (0, _react2.render)(
|
|
614
|
+
const _render19 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
581
615
|
renderLabel: "Choose an option",
|
|
582
|
-
isOptionContentAppliedToInput: true
|
|
583
|
-
|
|
616
|
+
isOptionContentAppliedToInput: true,
|
|
617
|
+
children: getOptionsWithBeforeContent('opt1')
|
|
618
|
+
})),
|
|
584
619
|
container = _render19.container;
|
|
585
620
|
const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
586
621
|
expect(afterContent).not.toHaveTextContent('XY');
|
|
587
622
|
});
|
|
588
623
|
it("should render option's before content input field when isOptionContentAppliedToInput is set to true with group options", async () => {
|
|
589
|
-
const _render20 = (0, _react2.render)(
|
|
624
|
+
const _render20 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
590
625
|
renderLabel: "Choose an option",
|
|
591
626
|
isOptionContentAppliedToInput: true,
|
|
592
|
-
inputValue: groupOptionsWithBeforeContent.Options1[0].label
|
|
593
|
-
|
|
627
|
+
inputValue: groupOptionsWithBeforeContent.Options1[0].label,
|
|
628
|
+
children: getGroupOptionsWithBeforeContent('opt1')
|
|
629
|
+
})),
|
|
594
630
|
container = _render20.container;
|
|
595
631
|
const beforeContent = container.querySelector('span[class$="-textInput__layout"]');
|
|
596
632
|
expect(beforeContent).toHaveTextContent('XY');
|
|
597
633
|
});
|
|
598
634
|
it('should render arrow icon when isOptionContentAppliedToInput is set to true with before content and group options', async () => {
|
|
599
|
-
const _render21 = (0, _react2.render)(
|
|
635
|
+
const _render21 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
600
636
|
renderLabel: "Choose an option",
|
|
601
637
|
isOptionContentAppliedToInput: true,
|
|
602
|
-
inputValue: groupOptionsWithBeforeContent.Options1[0].label
|
|
603
|
-
|
|
638
|
+
inputValue: groupOptionsWithBeforeContent.Options1[0].label,
|
|
639
|
+
children: getGroupOptionsWithBeforeContent('opt1')
|
|
640
|
+
})),
|
|
604
641
|
container = _render21.container;
|
|
605
642
|
const spanElement = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
606
643
|
const svgElement = spanElement.querySelector('svg[name="IconArrowOpenDown"]');
|
|
607
644
|
expect(svgElement).toBeInTheDocument();
|
|
608
645
|
});
|
|
609
646
|
it("should render option's after content input field when isOptionContentAppliedToInput is set to true with group options", async () => {
|
|
610
|
-
const _render22 = (0, _react2.render)(
|
|
647
|
+
const _render22 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
611
648
|
renderLabel: "Choose an option",
|
|
612
649
|
isOptionContentAppliedToInput: true,
|
|
613
|
-
inputValue: groupOptionsWithAfterContent.Options2[0].label
|
|
614
|
-
|
|
650
|
+
inputValue: groupOptionsWithAfterContent.Options2[0].label,
|
|
651
|
+
children: getGroupOptionsWithAfterContent('opt4')
|
|
652
|
+
})),
|
|
615
653
|
container = _render22.container;
|
|
616
654
|
const afterContent = container.querySelector('span[class$="-textInput__afterElement"]');
|
|
617
655
|
expect(afterContent).toHaveTextContent('AB');
|
|
@@ -619,38 +657,42 @@ describe('<Select />', () => {
|
|
|
619
657
|
});
|
|
620
658
|
describe('list', () => {
|
|
621
659
|
it('should set aria-selected on options with isSelected={true}', () => {
|
|
622
|
-
(0, _react2.render)(
|
|
660
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
623
661
|
renderLabel: "Choose an option",
|
|
624
|
-
isShowingOptions: true
|
|
625
|
-
|
|
662
|
+
isShowingOptions: true,
|
|
663
|
+
children: getOptions(void 0, defaultOptions[1])
|
|
664
|
+
}));
|
|
626
665
|
const options = _react2.screen.getAllByRole('option');
|
|
627
666
|
expect(options[1].getAttribute('aria-selected')).toEqual('true');
|
|
628
667
|
});
|
|
629
668
|
it('should set aria-disabled on options when isDisabled={true}', () => {
|
|
630
|
-
(0, _react2.render)(
|
|
669
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
631
670
|
renderLabel: "Choose an option",
|
|
632
|
-
isShowingOptions: true
|
|
633
|
-
|
|
671
|
+
isShowingOptions: true,
|
|
672
|
+
children: getOptions(void 0, void 0, defaultOptions[2])
|
|
673
|
+
}));
|
|
634
674
|
const options = _react2.screen.getAllByRole('option');
|
|
635
675
|
expect(options[0]).not.toHaveAttribute('aria-disabled');
|
|
636
676
|
expect(options[2]).toHaveAttribute('aria-disabled', 'true');
|
|
637
677
|
});
|
|
638
678
|
it('should set list element role to "listbox"', async () => {
|
|
639
|
-
(0, _react2.render)(
|
|
679
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
640
680
|
renderLabel: "Choose an option",
|
|
641
|
-
isShowingOptions: true
|
|
642
|
-
|
|
681
|
+
isShowingOptions: true,
|
|
682
|
+
children: getOptions()
|
|
683
|
+
}));
|
|
643
684
|
const listbox = _react2.screen.getByRole('listbox');
|
|
644
685
|
expect(listbox).toBeInTheDocument();
|
|
645
686
|
expect(listbox.tagName).toBe('UL');
|
|
646
687
|
});
|
|
647
688
|
it('should provide a ref to the list element', async () => {
|
|
648
689
|
const listRef = _vitest.vi.fn();
|
|
649
|
-
(0, _react2.render)(
|
|
690
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
650
691
|
renderLabel: "Choose an option",
|
|
651
692
|
isShowingOptions: true,
|
|
652
|
-
listRef: listRef
|
|
653
|
-
|
|
693
|
+
listRef: listRef,
|
|
694
|
+
children: getOptions()
|
|
695
|
+
}));
|
|
654
696
|
const listbox = _react2.screen.getByRole('listbox');
|
|
655
697
|
await (0, _react2.waitFor)(() => {
|
|
656
698
|
expect(listRef).toHaveBeenCalledWith(listbox);
|
|
@@ -661,10 +703,11 @@ describe('<Select />', () => {
|
|
|
661
703
|
describe('should fire onRequestShowOptions', () => {
|
|
662
704
|
it('when root is clicked', async () => {
|
|
663
705
|
const onRequestShowOptions = _vitest.vi.fn();
|
|
664
|
-
const _render23 = (0, _react2.render)(
|
|
706
|
+
const _render23 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
665
707
|
renderLabel: "Choose an option",
|
|
666
|
-
onRequestShowOptions: onRequestShowOptions
|
|
667
|
-
|
|
708
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
709
|
+
children: getOptions()
|
|
710
|
+
})),
|
|
668
711
|
container = _render23.container,
|
|
669
712
|
rerender = _render23.rerender;
|
|
670
713
|
const icon = container.querySelector('svg[name="IconArrowOpenDown"]');
|
|
@@ -679,11 +722,12 @@ describe('<Select />', () => {
|
|
|
679
722
|
await (0, _react2.waitFor)(() => {
|
|
680
723
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
|
|
681
724
|
});
|
|
682
|
-
rerender(
|
|
725
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
683
726
|
renderLabel: "Choose an option",
|
|
684
727
|
onRequestShowOptions: onRequestShowOptions,
|
|
685
|
-
isShowingOptions: true
|
|
686
|
-
|
|
728
|
+
isShowingOptions: true,
|
|
729
|
+
children: getOptions()
|
|
730
|
+
}));
|
|
687
731
|
await _userEvent.default.click(label);
|
|
688
732
|
await (0, _react2.waitFor)(() => {
|
|
689
733
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(2);
|
|
@@ -691,21 +735,23 @@ describe('<Select />', () => {
|
|
|
691
735
|
});
|
|
692
736
|
it('when input is clicked', async () => {
|
|
693
737
|
const onRequestShowOptions = _vitest.vi.fn();
|
|
694
|
-
const _render24 = (0, _react2.render)(
|
|
738
|
+
const _render24 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
695
739
|
renderLabel: "Choose an option",
|
|
696
|
-
onRequestShowOptions: onRequestShowOptions
|
|
697
|
-
|
|
740
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
741
|
+
children: getOptions()
|
|
742
|
+
})),
|
|
698
743
|
rerender = _render24.rerender;
|
|
699
744
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
700
745
|
await _userEvent.default.click(input);
|
|
701
746
|
await (0, _react2.waitFor)(() => {
|
|
702
747
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
703
748
|
});
|
|
704
|
-
rerender(
|
|
749
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
705
750
|
renderLabel: "Choose an option",
|
|
706
751
|
onRequestShowOptions: onRequestShowOptions,
|
|
707
|
-
isShowingOptions: true
|
|
708
|
-
|
|
752
|
+
isShowingOptions: true,
|
|
753
|
+
children: getOptions()
|
|
754
|
+
}));
|
|
709
755
|
await _userEvent.default.click(input);
|
|
710
756
|
await (0, _react2.waitFor)(() => {
|
|
711
757
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
@@ -713,10 +759,11 @@ describe('<Select />', () => {
|
|
|
713
759
|
});
|
|
714
760
|
it('when up/down arrows are pressed', async () => {
|
|
715
761
|
const onRequestShowOptions = _vitest.vi.fn();
|
|
716
|
-
(0, _react2.render)(
|
|
762
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
717
763
|
renderLabel: "Choose an option",
|
|
718
|
-
onRequestShowOptions: onRequestShowOptions
|
|
719
|
-
|
|
764
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
765
|
+
children: getOptions()
|
|
766
|
+
}));
|
|
720
767
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
721
768
|
await _userEvent.default.type(input, '{arrowdown}');
|
|
722
769
|
await (0, _react2.waitFor)(() => {
|
|
@@ -729,21 +776,23 @@ describe('<Select />', () => {
|
|
|
729
776
|
});
|
|
730
777
|
it('when space is pressed', async () => {
|
|
731
778
|
const onRequestShowOptions = _vitest.vi.fn();
|
|
732
|
-
const _render25 = (0, _react2.render)(
|
|
779
|
+
const _render25 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
733
780
|
renderLabel: "Choose an option",
|
|
734
|
-
onRequestShowOptions: onRequestShowOptions
|
|
735
|
-
|
|
781
|
+
onRequestShowOptions: onRequestShowOptions,
|
|
782
|
+
children: getOptions()
|
|
783
|
+
})),
|
|
736
784
|
rerender = _render25.rerender;
|
|
737
785
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
738
786
|
await _userEvent.default.type(input, '{space}');
|
|
739
787
|
await (0, _react2.waitFor)(() => {
|
|
740
788
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
741
789
|
});
|
|
742
|
-
rerender(
|
|
790
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
743
791
|
renderLabel: "Choose an option",
|
|
744
792
|
onRequestShowOptions: onRequestShowOptions,
|
|
745
|
-
isShowingOptions: true
|
|
746
|
-
|
|
793
|
+
isShowingOptions: true,
|
|
794
|
+
children: getOptions()
|
|
795
|
+
}));
|
|
747
796
|
await _userEvent.default.type(input, '{space}');
|
|
748
797
|
await (0, _react2.waitFor)(() => {
|
|
749
798
|
expect(onRequestShowOptions).toHaveBeenCalledTimes(1);
|
|
@@ -753,11 +802,12 @@ describe('<Select />', () => {
|
|
|
753
802
|
describe('should fire onRequestHideOptions', () => {
|
|
754
803
|
it('when root is clicked and isShowingOptions is true', async () => {
|
|
755
804
|
const onRequestHideOptions = _vitest.vi.fn();
|
|
756
|
-
const _render26 = (0, _react2.render)(
|
|
805
|
+
const _render26 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
757
806
|
renderLabel: "Choose an option",
|
|
758
807
|
isShowingOptions: true,
|
|
759
|
-
onRequestHideOptions: onRequestHideOptions
|
|
760
|
-
|
|
808
|
+
onRequestHideOptions: onRequestHideOptions,
|
|
809
|
+
children: getOptions()
|
|
810
|
+
})),
|
|
761
811
|
container = _render26.container;
|
|
762
812
|
const icon = container.querySelector('svg[name="IconArrowOpenUp"]');
|
|
763
813
|
const label = _react2.screen.getByText('Choose an option');
|
|
@@ -774,11 +824,12 @@ describe('<Select />', () => {
|
|
|
774
824
|
});
|
|
775
825
|
it('when root is clicked and isShowingOptions is false should NOT fire onRequestHideOptions', async () => {
|
|
776
826
|
const onRequestHideOptions = _vitest.vi.fn();
|
|
777
|
-
(0, _react2.render)(
|
|
827
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
778
828
|
renderLabel: "Choose an option",
|
|
779
829
|
isShowingOptions: false,
|
|
780
|
-
onRequestHideOptions: onRequestHideOptions
|
|
781
|
-
|
|
830
|
+
onRequestHideOptions: onRequestHideOptions,
|
|
831
|
+
children: getOptions()
|
|
832
|
+
}));
|
|
782
833
|
const label = _react2.screen.getByText('Choose an option');
|
|
783
834
|
expect(label).toBeInTheDocument();
|
|
784
835
|
await _userEvent.default.click(label);
|
|
@@ -788,22 +839,24 @@ describe('<Select />', () => {
|
|
|
788
839
|
});
|
|
789
840
|
it('when input is clicked', async () => {
|
|
790
841
|
const onRequestHideOptions = _vitest.vi.fn();
|
|
791
|
-
const _render27 = (0, _react2.render)(
|
|
842
|
+
const _render27 = (0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
792
843
|
renderLabel: "Choose an option",
|
|
793
844
|
isShowingOptions: true,
|
|
794
|
-
onRequestHideOptions: onRequestHideOptions
|
|
795
|
-
|
|
845
|
+
onRequestHideOptions: onRequestHideOptions,
|
|
846
|
+
children: getOptions()
|
|
847
|
+
})),
|
|
796
848
|
rerender = _render27.rerender;
|
|
797
849
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
798
850
|
await _userEvent.default.click(input);
|
|
799
851
|
await (0, _react2.waitFor)(() => {
|
|
800
852
|
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
801
853
|
});
|
|
802
|
-
rerender(
|
|
854
|
+
rerender((0, _jsxRuntime.jsx)(_index.default, {
|
|
803
855
|
renderLabel: "Choose an option",
|
|
804
856
|
isShowingOptions: false,
|
|
805
|
-
onRequestHideOptions: onRequestHideOptions
|
|
806
|
-
|
|
857
|
+
onRequestHideOptions: onRequestHideOptions,
|
|
858
|
+
children: getOptions()
|
|
859
|
+
}));
|
|
807
860
|
await _userEvent.default.click(input);
|
|
808
861
|
await (0, _react2.waitFor)(() => {
|
|
809
862
|
expect(onRequestHideOptions).toHaveBeenCalledTimes(1);
|
|
@@ -811,11 +864,12 @@ describe('<Select />', () => {
|
|
|
811
864
|
});
|
|
812
865
|
it('when escape is pressed', async () => {
|
|
813
866
|
const onRequestHideOptions = _vitest.vi.fn();
|
|
814
|
-
(0, _react2.render)(
|
|
867
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
815
868
|
renderLabel: "Choose an option",
|
|
816
869
|
isShowingOptions: true,
|
|
817
|
-
onRequestHideOptions: onRequestHideOptions
|
|
818
|
-
|
|
870
|
+
onRequestHideOptions: onRequestHideOptions,
|
|
871
|
+
children: getOptions()
|
|
872
|
+
}));
|
|
819
873
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
820
874
|
await _userEvent.default.type(input, '{esc}');
|
|
821
875
|
await (0, _react2.waitFor)(() => {
|
|
@@ -826,11 +880,12 @@ describe('<Select />', () => {
|
|
|
826
880
|
describe('should fire onRequestHighlightOption', () => {
|
|
827
881
|
it('when options are hovered', async () => {
|
|
828
882
|
const onRequestHighlightOption = _vitest.vi.fn();
|
|
829
|
-
(0, _react2.render)(
|
|
883
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
830
884
|
renderLabel: "Choose an option",
|
|
831
885
|
isShowingOptions: true,
|
|
832
|
-
onRequestHighlightOption: onRequestHighlightOption
|
|
833
|
-
|
|
886
|
+
onRequestHighlightOption: onRequestHighlightOption,
|
|
887
|
+
children: getOptions()
|
|
888
|
+
}));
|
|
834
889
|
const options = _react2.screen.getAllByRole('option');
|
|
835
890
|
await _userEvent.default.hover(options[0]);
|
|
836
891
|
await (0, _react2.waitFor)(() => {
|
|
@@ -849,10 +904,11 @@ describe('<Select />', () => {
|
|
|
849
904
|
describe('input callbacks', () => {
|
|
850
905
|
it('should fire onInputChange when input is typed in', async () => {
|
|
851
906
|
const onInputChange = _vitest.vi.fn();
|
|
852
|
-
(0, _react2.render)(
|
|
907
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
853
908
|
renderLabel: "Choose an option",
|
|
854
|
-
onInputChange: onInputChange
|
|
855
|
-
|
|
909
|
+
onInputChange: onInputChange,
|
|
910
|
+
children: getOptions()
|
|
911
|
+
}));
|
|
856
912
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
857
913
|
await _userEvent.default.type(input, 'h');
|
|
858
914
|
await (0, _react2.waitFor)(() => {
|
|
@@ -861,10 +917,11 @@ describe('<Select />', () => {
|
|
|
861
917
|
});
|
|
862
918
|
it('should fire onFocus when input gains focus', async () => {
|
|
863
919
|
const onFocus = _vitest.vi.fn();
|
|
864
|
-
(0, _react2.render)(
|
|
920
|
+
(0, _react2.render)((0, _jsxRuntime.jsx)(_index.default, {
|
|
865
921
|
renderLabel: "Choose an option",
|
|
866
|
-
onFocus: onFocus
|
|
867
|
-
|
|
922
|
+
onFocus: onFocus,
|
|
923
|
+
children: getOptions()
|
|
924
|
+
}));
|
|
868
925
|
const input = _react2.screen.getByLabelText('Choose an option');
|
|
869
926
|
input.focus();
|
|
870
927
|
await (0, _react2.waitFor)(() => {
|