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