@pingux/astro 2.24.0-alpha.1 → 2.24.1-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 +15 -6
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +44 -1
- package/lib/components/MultivaluesField/MultivaluesField.js +15 -6
- package/lib/components/MultivaluesField/MultivaluesField.test.js +44 -1
- package/package.json +1 -1
@@ -237,7 +237,7 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
237
237
|
// there actually is a test for this, but coverage is not picking it up.
|
238
238
|
/* istanbul ignore next */
|
239
239
|
var onBlurTextField = function onBlurTextField() {
|
240
|
-
if (
|
240
|
+
if (hasCustomValue && filteredItems.length === 1) {
|
241
241
|
selectTheOnlyFilteredItem();
|
242
242
|
} else if (hasCustomValue) {
|
243
243
|
addNewBadgeFromInput(filterString);
|
@@ -256,8 +256,11 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
256
256
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
257
257
|
setFilterString('');
|
258
258
|
}
|
259
|
-
} else if (
|
259
|
+
} else if (hasCustomValue && filteredItems.length === 1) {
|
260
260
|
selectTheOnlyFilteredItem();
|
261
|
+
} else if (!hasCustomValue) {
|
262
|
+
setFilterString('');
|
263
|
+
close();
|
261
264
|
} else if (hasCustomValue) {
|
262
265
|
var _key = e.target.value;
|
263
266
|
if (_key === '') {
|
@@ -279,6 +282,12 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
279
282
|
if (prevKey) selectionManager.setFocusedKey(prevKey);
|
280
283
|
break;
|
281
284
|
}
|
285
|
+
case 'Escape':
|
286
|
+
{
|
287
|
+
setFilterString('');
|
288
|
+
close();
|
289
|
+
break;
|
290
|
+
}
|
282
291
|
default:
|
283
292
|
break;
|
284
293
|
}
|
@@ -442,18 +451,19 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
442
451
|
border: 'none'
|
443
452
|
}
|
444
453
|
},
|
445
|
-
status: status
|
446
|
-
isRestrictiveMultivalues: !hasCustomValue
|
454
|
+
status: status
|
447
455
|
});
|
448
456
|
return (0, _react2.jsx)(_MultivaluesContext.MultivaluesContext.Provider, {
|
449
457
|
value: setActiveDescendant
|
450
458
|
}, (0, _react2.jsx)(_.Box, containerProps, (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
451
459
|
onBlur: function onBlur(e) {
|
452
460
|
setIsOpen(false);
|
453
|
-
if (
|
461
|
+
if (filterString !== '') onBlurTextField();
|
454
462
|
if (_onBlur) _onBlur(e.nativeEvent);
|
463
|
+
if (!hasCustomValue) setFilterString('');
|
455
464
|
},
|
456
465
|
onChange: function onChange(e) {
|
466
|
+
if (!isOpen) setIsOpen(true);
|
457
467
|
setFilterString(e.target.value);
|
458
468
|
if (onInputChange) onInputChange(e.target.value);
|
459
469
|
},
|
@@ -599,7 +609,6 @@ MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
|
599
609
|
MultivaluesField.defaultProps = _objectSpread({
|
600
610
|
direction: 'bottom',
|
601
611
|
isReadOnly: false,
|
602
|
-
mode: 'restrictive',
|
603
612
|
scrollBoxProps: {
|
604
613
|
maxHeight: 300
|
605
614
|
}
|
@@ -600,8 +600,8 @@ test('form does not submit when adding custom value', function () {
|
|
600
600
|
expect(input).toHaveValue('');
|
601
601
|
var value = 'custom';
|
602
602
|
_userEvent["default"].type(input, value);
|
603
|
-
expect(input).toHaveValue('');
|
604
603
|
_userEvent["default"].type(input, '{enter}');
|
604
|
+
expect(input).toHaveValue('');
|
605
605
|
expect(onFormSubmit).not.toHaveBeenCalled();
|
606
606
|
});
|
607
607
|
test('in non-restrictive mode the value should be trimmed', function () {
|
@@ -677,4 +677,47 @@ test('deleting the last badge via keyboard moves focus to the previous badge', f
|
|
677
677
|
});
|
678
678
|
expect(badge2).not.toBeInTheDocument();
|
679
679
|
expect(deleteButton1).toHaveClass('is-focused');
|
680
|
+
});
|
681
|
+
test('pressing Esc should clear the input', function () {
|
682
|
+
getComponent();
|
683
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
684
|
+
expect(input).toHaveValue('');
|
685
|
+
var value = 'custom';
|
686
|
+
_userEvent["default"].type(input, value);
|
687
|
+
_userEvent["default"].type(input, '{esc}');
|
688
|
+
expect(_testWrapper.screen.queryByText(value)).not.toBeInTheDocument();
|
689
|
+
expect(input).toHaveValue('');
|
690
|
+
expect(input).toHaveFocus();
|
691
|
+
_userEvent["default"].type(input, 'Aardvark');
|
692
|
+
expect(_testWrapper.screen.queryByRole('listbox')).toBeInTheDocument();
|
693
|
+
});
|
694
|
+
test('should clear the input text onBlur', function () {
|
695
|
+
getComponent();
|
696
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
697
|
+
expect(input).toHaveValue('');
|
698
|
+
var value = 'custom';
|
699
|
+
_userEvent["default"].type(input, value);
|
700
|
+
_userEvent["default"].tab();
|
701
|
+
expect(_testWrapper.screen.queryByText(value)).not.toBeInTheDocument();
|
702
|
+
expect(input).toHaveValue('');
|
703
|
+
});
|
704
|
+
test('should clear the input text onBlur and enter when a single filter result is showing', function () {
|
705
|
+
getComponent();
|
706
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
707
|
+
expect(input).toHaveValue('');
|
708
|
+
var value = 'Snake';
|
709
|
+
_userEvent["default"].type(input, value);
|
710
|
+
var listbox = _testWrapper.screen.getByRole('listbox');
|
711
|
+
expect(listbox).toBeInTheDocument();
|
712
|
+
var options = (0, _testWrapper.within)(listbox).getAllByRole('option');
|
713
|
+
expect(options.length).toBe(1);
|
714
|
+
_userEvent["default"].tab();
|
715
|
+
expect(_testWrapper.screen.queryByText(value)).not.toBeInTheDocument();
|
716
|
+
expect(input).toHaveValue('');
|
717
|
+
_userEvent["default"].type(input, value);
|
718
|
+
expect(options.length).toBe(1);
|
719
|
+
_userEvent["default"].type(input, '{enter}', {
|
720
|
+
skipClick: true
|
721
|
+
});
|
722
|
+
expect(input).toHaveValue('');
|
680
723
|
});
|
@@ -225,7 +225,7 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
225
225
|
// there actually is a test for this, but coverage is not picking it up.
|
226
226
|
/* istanbul ignore next */
|
227
227
|
var onBlurTextField = function onBlurTextField() {
|
228
|
-
if (
|
228
|
+
if (hasCustomValue && filteredItems.length === 1) {
|
229
229
|
selectTheOnlyFilteredItem();
|
230
230
|
} else if (hasCustomValue) {
|
231
231
|
addNewBadgeFromInput(filterString);
|
@@ -244,8 +244,11 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
244
244
|
selectionManager.toggleSelection(selectionManager.focusedKey);
|
245
245
|
setFilterString('');
|
246
246
|
}
|
247
|
-
} else if (
|
247
|
+
} else if (hasCustomValue && filteredItems.length === 1) {
|
248
248
|
selectTheOnlyFilteredItem();
|
249
|
+
} else if (!hasCustomValue) {
|
250
|
+
setFilterString('');
|
251
|
+
close();
|
249
252
|
} else if (hasCustomValue) {
|
250
253
|
var _key = e.target.value;
|
251
254
|
if (_key === '') {
|
@@ -267,6 +270,12 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
267
270
|
if (prevKey) selectionManager.setFocusedKey(prevKey);
|
268
271
|
break;
|
269
272
|
}
|
273
|
+
case 'Escape':
|
274
|
+
{
|
275
|
+
setFilterString('');
|
276
|
+
close();
|
277
|
+
break;
|
278
|
+
}
|
270
279
|
default:
|
271
280
|
break;
|
272
281
|
}
|
@@ -430,18 +439,19 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
430
439
|
border: 'none'
|
431
440
|
}
|
432
441
|
},
|
433
|
-
status: status
|
434
|
-
isRestrictiveMultivalues: !hasCustomValue
|
442
|
+
status: status
|
435
443
|
});
|
436
444
|
return ___EmotionJSX(MultivaluesContext.Provider, {
|
437
445
|
value: setActiveDescendant
|
438
446
|
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
439
447
|
onBlur: function onBlur(e) {
|
440
448
|
setIsOpen(false);
|
441
|
-
if (
|
449
|
+
if (filterString !== '') onBlurTextField();
|
442
450
|
if (_onBlur) _onBlur(e.nativeEvent);
|
451
|
+
if (!hasCustomValue) setFilterString('');
|
443
452
|
},
|
444
453
|
onChange: function onChange(e) {
|
454
|
+
if (!isOpen) setIsOpen(true);
|
445
455
|
setFilterString(e.target.value);
|
446
456
|
if (onInputChange) onInputChange(e.target.value);
|
447
457
|
},
|
@@ -587,7 +597,6 @@ MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
|
587
597
|
MultivaluesField.defaultProps = _objectSpread({
|
588
598
|
direction: 'bottom',
|
589
599
|
isReadOnly: false,
|
590
|
-
mode: 'restrictive',
|
591
600
|
scrollBoxProps: {
|
592
601
|
maxHeight: 300
|
593
602
|
}
|
@@ -597,8 +597,8 @@ test('form does not submit when adding custom value', function () {
|
|
597
597
|
expect(input).toHaveValue('');
|
598
598
|
var value = 'custom';
|
599
599
|
userEvent.type(input, value);
|
600
|
-
expect(input).toHaveValue('');
|
601
600
|
userEvent.type(input, '{enter}');
|
601
|
+
expect(input).toHaveValue('');
|
602
602
|
expect(onFormSubmit).not.toHaveBeenCalled();
|
603
603
|
});
|
604
604
|
test('in non-restrictive mode the value should be trimmed', function () {
|
@@ -674,4 +674,47 @@ test('deleting the last badge via keyboard moves focus to the previous badge', f
|
|
674
674
|
});
|
675
675
|
expect(badge2).not.toBeInTheDocument();
|
676
676
|
expect(deleteButton1).toHaveClass('is-focused');
|
677
|
+
});
|
678
|
+
test('pressing Esc should clear the input', function () {
|
679
|
+
getComponent();
|
680
|
+
var input = screen.getByRole('combobox');
|
681
|
+
expect(input).toHaveValue('');
|
682
|
+
var value = 'custom';
|
683
|
+
userEvent.type(input, value);
|
684
|
+
userEvent.type(input, '{esc}');
|
685
|
+
expect(screen.queryByText(value)).not.toBeInTheDocument();
|
686
|
+
expect(input).toHaveValue('');
|
687
|
+
expect(input).toHaveFocus();
|
688
|
+
userEvent.type(input, 'Aardvark');
|
689
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
690
|
+
});
|
691
|
+
test('should clear the input text onBlur', function () {
|
692
|
+
getComponent();
|
693
|
+
var input = screen.getByRole('combobox');
|
694
|
+
expect(input).toHaveValue('');
|
695
|
+
var value = 'custom';
|
696
|
+
userEvent.type(input, value);
|
697
|
+
userEvent.tab();
|
698
|
+
expect(screen.queryByText(value)).not.toBeInTheDocument();
|
699
|
+
expect(input).toHaveValue('');
|
700
|
+
});
|
701
|
+
test('should clear the input text onBlur and enter when a single filter result is showing', function () {
|
702
|
+
getComponent();
|
703
|
+
var input = screen.getByRole('combobox');
|
704
|
+
expect(input).toHaveValue('');
|
705
|
+
var value = 'Snake';
|
706
|
+
userEvent.type(input, value);
|
707
|
+
var listbox = screen.getByRole('listbox');
|
708
|
+
expect(listbox).toBeInTheDocument();
|
709
|
+
var options = within(listbox).getAllByRole('option');
|
710
|
+
expect(options.length).toBe(1);
|
711
|
+
userEvent.tab();
|
712
|
+
expect(screen.queryByText(value)).not.toBeInTheDocument();
|
713
|
+
expect(input).toHaveValue('');
|
714
|
+
userEvent.type(input, value);
|
715
|
+
expect(options.length).toBe(1);
|
716
|
+
userEvent.type(input, '{enter}', {
|
717
|
+
skipClick: true
|
718
|
+
});
|
719
|
+
expect(input).toHaveValue('');
|
677
720
|
});
|