@pingux/astro 1.3.1 → 1.3.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +10 -8
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +74 -0
- package/lib/components/MultivaluesField/MultivaluesField.js +10 -7
- package/lib/components/MultivaluesField/MultivaluesField.test.js +52 -0
- package/package.json +1 -1
@@ -60,8 +60,6 @@ var _overlays = require("@react-aria/overlays");
|
|
60
60
|
|
61
61
|
var _utils = require("@react-aria/utils");
|
62
62
|
|
63
|
-
var _uuid = require("uuid");
|
64
|
-
|
65
63
|
var _ = require("../..");
|
66
64
|
|
67
65
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
@@ -262,13 +260,17 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
262
260
|
} else if (hasCustomValue) {
|
263
261
|
var _context3;
|
264
262
|
|
265
|
-
var
|
266
|
-
|
267
|
-
selectionManager.
|
263
|
+
var _key2 = e.target.value;
|
264
|
+
|
265
|
+
if (state.selectionManager.isSelected(_key2)) {
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
|
269
|
+
selectionManager.toggleSelection(_key2);
|
268
270
|
setCustomItems((0, _concat["default"])(_context3 = []).call(_context3, customItems, [{
|
269
|
-
id:
|
270
|
-
key:
|
271
|
-
name:
|
271
|
+
id: _key2,
|
272
|
+
key: _key2,
|
273
|
+
name: _key2
|
272
274
|
}]));
|
273
275
|
setFilterString('');
|
274
276
|
}
|
@@ -276,6 +276,80 @@ test('changing the input value and hitting enter creates new value in non-restri
|
|
276
276
|
var chipContainer = chip.parentElement;
|
277
277
|
expect(chipContainer).toHaveAttribute('role', 'presentation');
|
278
278
|
});
|
279
|
+
test('in non-restrictive mode "onSelectionChange" returns entered keys', function () {
|
280
|
+
var onSelectionChange = jest.fn();
|
281
|
+
getComponent({
|
282
|
+
mode: 'non-restrictive',
|
283
|
+
onSelectionChange: onSelectionChange
|
284
|
+
});
|
285
|
+
|
286
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
287
|
+
|
288
|
+
var value = 'custom';
|
289
|
+
|
290
|
+
_userEvent["default"].type(input, value);
|
291
|
+
|
292
|
+
_userEvent["default"].type(input, '{enter}');
|
293
|
+
|
294
|
+
var chip = _testWrapper.screen.queryByText(value);
|
295
|
+
|
296
|
+
expect(chip).toBeInTheDocument();
|
297
|
+
expect(onSelectionChange).toBeCalledTimes(1);
|
298
|
+
expect(onSelectionChange.mock.calls[0][0].has(value)).toBeTruthy();
|
299
|
+
});
|
300
|
+
test('in non-restrictive mode the same value cannot be applied twice', function () {
|
301
|
+
var onSelectionChange = jest.fn();
|
302
|
+
getComponent({
|
303
|
+
mode: 'non-restrictive',
|
304
|
+
onSelectionChange: onSelectionChange
|
305
|
+
});
|
306
|
+
|
307
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
308
|
+
|
309
|
+
var value = 'custom';
|
310
|
+
|
311
|
+
_userEvent["default"].type(input, value);
|
312
|
+
|
313
|
+
_userEvent["default"].type(input, '{enter}');
|
314
|
+
|
315
|
+
var chip = _testWrapper.screen.queryByText(value);
|
316
|
+
|
317
|
+
expect(chip).toBeInTheDocument();
|
318
|
+
expect(input).toHaveValue('');
|
319
|
+
|
320
|
+
_userEvent["default"].type(input, value);
|
321
|
+
|
322
|
+
_userEvent["default"].type(input, '{enter}');
|
323
|
+
|
324
|
+
expect(input).toHaveValue(value);
|
325
|
+
expect(onSelectionChange).toBeCalledTimes(1);
|
326
|
+
});
|
327
|
+
test('in non-restrictive mode the value that was already selected using the list cannot be applied', function () {
|
328
|
+
var onSelectionChange = jest.fn();
|
329
|
+
getComponent({
|
330
|
+
mode: 'non-restrictive',
|
331
|
+
onSelectionChange: onSelectionChange
|
332
|
+
});
|
333
|
+
|
334
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
335
|
+
|
336
|
+
input.focus();
|
337
|
+
|
338
|
+
var listbox = _testWrapper.screen.getByRole('listbox');
|
339
|
+
|
340
|
+
var options = (0, _testWrapper.within)(listbox).getAllByRole('option');
|
341
|
+
var firstOption = options[0];
|
342
|
+
firstOption.click();
|
343
|
+
expect(onSelectionChange.mock.calls[0][0].has(items[0].name)).toBeTruthy();
|
344
|
+
onSelectionChange.mockClear();
|
345
|
+
|
346
|
+
_userEvent["default"].type(input, items[0].name);
|
347
|
+
|
348
|
+
_userEvent["default"].type(input, '{enter}');
|
349
|
+
|
350
|
+
expect(input).toHaveValue(items[0].name);
|
351
|
+
expect(onSelectionChange).not.toBeCalled();
|
352
|
+
});
|
279
353
|
test('options can be focused via keyboard', function () {
|
280
354
|
getComponent();
|
281
355
|
|
@@ -27,7 +27,6 @@ import { FocusScope } from '@react-aria/focus';
|
|
27
27
|
import { useListState } from '@react-stately/list';
|
28
28
|
import { DismissButton, useOverlayPosition } from '@react-aria/overlays';
|
29
29
|
import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
|
30
|
-
import { v4 as uuid } from 'uuid';
|
31
30
|
import { Chip, Icon, IconButton, PopoverContainer, ScrollBox, TextField } from '../..';
|
32
31
|
import ListBox from '../ListBox';
|
33
32
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
@@ -220,13 +219,17 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
220
219
|
} else if (hasCustomValue) {
|
221
220
|
var _context3;
|
222
221
|
|
223
|
-
var
|
224
|
-
|
225
|
-
selectionManager.
|
222
|
+
var _key2 = e.target.value;
|
223
|
+
|
224
|
+
if (state.selectionManager.isSelected(_key2)) {
|
225
|
+
return;
|
226
|
+
}
|
227
|
+
|
228
|
+
selectionManager.toggleSelection(_key2);
|
226
229
|
setCustomItems(_concatInstanceProperty(_context3 = []).call(_context3, customItems, [{
|
227
|
-
id:
|
228
|
-
key:
|
229
|
-
name:
|
230
|
+
id: _key2,
|
231
|
+
key: _key2,
|
232
|
+
name: _key2
|
230
233
|
}]));
|
231
234
|
setFilterString('');
|
232
235
|
}
|
@@ -212,6 +212,58 @@ test('changing the input value and hitting enter creates new value in non-restri
|
|
212
212
|
var chipContainer = chip.parentElement;
|
213
213
|
expect(chipContainer).toHaveAttribute('role', 'presentation');
|
214
214
|
});
|
215
|
+
test('in non-restrictive mode "onSelectionChange" returns entered keys', function () {
|
216
|
+
var onSelectionChange = jest.fn();
|
217
|
+
getComponent({
|
218
|
+
mode: 'non-restrictive',
|
219
|
+
onSelectionChange: onSelectionChange
|
220
|
+
});
|
221
|
+
var input = screen.getByRole('combobox');
|
222
|
+
var value = 'custom';
|
223
|
+
userEvent.type(input, value);
|
224
|
+
userEvent.type(input, '{enter}');
|
225
|
+
var chip = screen.queryByText(value);
|
226
|
+
expect(chip).toBeInTheDocument();
|
227
|
+
expect(onSelectionChange).toBeCalledTimes(1);
|
228
|
+
expect(onSelectionChange.mock.calls[0][0].has(value)).toBeTruthy();
|
229
|
+
});
|
230
|
+
test('in non-restrictive mode the same value cannot be applied twice', function () {
|
231
|
+
var onSelectionChange = jest.fn();
|
232
|
+
getComponent({
|
233
|
+
mode: 'non-restrictive',
|
234
|
+
onSelectionChange: onSelectionChange
|
235
|
+
});
|
236
|
+
var input = screen.getByRole('combobox');
|
237
|
+
var value = 'custom';
|
238
|
+
userEvent.type(input, value);
|
239
|
+
userEvent.type(input, '{enter}');
|
240
|
+
var chip = screen.queryByText(value);
|
241
|
+
expect(chip).toBeInTheDocument();
|
242
|
+
expect(input).toHaveValue('');
|
243
|
+
userEvent.type(input, value);
|
244
|
+
userEvent.type(input, '{enter}');
|
245
|
+
expect(input).toHaveValue(value);
|
246
|
+
expect(onSelectionChange).toBeCalledTimes(1);
|
247
|
+
});
|
248
|
+
test('in non-restrictive mode the value that was already selected using the list cannot be applied', function () {
|
249
|
+
var onSelectionChange = jest.fn();
|
250
|
+
getComponent({
|
251
|
+
mode: 'non-restrictive',
|
252
|
+
onSelectionChange: onSelectionChange
|
253
|
+
});
|
254
|
+
var input = screen.getByRole('combobox');
|
255
|
+
input.focus();
|
256
|
+
var listbox = screen.getByRole('listbox');
|
257
|
+
var options = within(listbox).getAllByRole('option');
|
258
|
+
var firstOption = options[0];
|
259
|
+
firstOption.click();
|
260
|
+
expect(onSelectionChange.mock.calls[0][0].has(items[0].name)).toBeTruthy();
|
261
|
+
onSelectionChange.mockClear();
|
262
|
+
userEvent.type(input, items[0].name);
|
263
|
+
userEvent.type(input, '{enter}');
|
264
|
+
expect(input).toHaveValue(items[0].name);
|
265
|
+
expect(onSelectionChange).not.toBeCalled();
|
266
|
+
});
|
215
267
|
test('options can be focused via keyboard', function () {
|
216
268
|
getComponent();
|
217
269
|
var input = screen.getByRole('combobox');
|