@pingux/astro 1.1.0-alpha.2 → 1.1.0-alpha.3
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/lib/cjs/components/ComboBoxField/ComboBoxField.js +7 -0
- package/lib/cjs/components/ComboBoxField/ComboBoxField.stories.js +25 -1
- package/lib/cjs/components/ComboBoxField/ComboBoxField.test.js +44 -0
- package/lib/components/ComboBoxField/ComboBoxField.js +7 -0
- package/lib/components/ComboBoxField/ComboBoxField.stories.js +21 -0
- package/lib/components/ComboBoxField/ComboBoxField.test.js +35 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
# [1.1.0-alpha.3](https://gitlab.corp.pingidentity.com/ux/pingux/compare/@pingux/astro@1.1.0-alpha.2...@pingux/astro@1.1.0-alpha.3) (2022-01-20)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* [UIP-5007] ComboBoxField controlled custom input throws an exception ([9651c98](https://gitlab.corp.pingidentity.com/ux/pingux/commit/9651c98da3b3ac158c84f378303a2d331db78cce))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
6
17
|
# [1.1.0-alpha.2](https://gitlab.corp.pingidentity.com/ux/pingux/compare/@pingux/astro@1.1.0-alpha.1...@pingux/astro@1.1.0-alpha.2) (2022-01-19)
|
7
18
|
|
8
19
|
|
@@ -157,6 +157,12 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
157
157
|
(0, _react.useImperativeHandle)(ref, function () {
|
158
158
|
return inputRef.current;
|
159
159
|
});
|
160
|
+
/* istanbul ignore next */
|
161
|
+
|
162
|
+
var onSelectionChangeHandler = function onSelectionChangeHandler(key) {
|
163
|
+
var newVal = key || selectedKey || '';
|
164
|
+
if (onSelectionChange) onSelectionChange(newVal);
|
165
|
+
};
|
160
166
|
|
161
167
|
var _useFilter = (0, _i18n.useFilter)({
|
162
168
|
sensitivity: 'base'
|
@@ -164,6 +170,7 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
164
170
|
contains = _useFilter.contains;
|
165
171
|
|
166
172
|
var state = (0, _combobox2.useComboBoxState)(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
|
173
|
+
onSelectionChange: hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
|
167
174
|
defaultFilter: contains
|
168
175
|
}));
|
169
176
|
|
@@ -10,7 +10,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
10
10
|
value: true
|
11
11
|
});
|
12
12
|
|
13
|
-
exports.WithCustomHeight = exports.WithoutStatusIndicator = exports.Required = exports.HelperText = exports.Disabled = exports.FocusMenuTrigger = exports.DisabledKeys = exports.AllowCustomValue = exports.ControlledFiltering = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.AsyncLoading = exports.WithSections = exports.Default = exports["default"] = void 0;
|
13
|
+
exports.WithCustomHeight = exports.WithoutStatusIndicator = exports.Required = exports.HelperText = exports.Disabled = exports.FocusMenuTrigger = exports.DisabledKeys = exports.AllowCustomValue = exports.ControlledWithCustomValue = exports.ControlledFiltering = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.AsyncLoading = exports.WithSections = exports.Default = exports["default"] = void 0;
|
14
14
|
|
15
15
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
16
16
|
|
@@ -383,6 +383,30 @@ var ControlledFiltering = function ControlledFiltering() {
|
|
383
383
|
|
384
384
|
exports.ControlledFiltering = ControlledFiltering;
|
385
385
|
|
386
|
+
var ControlledWithCustomValue = function ControlledWithCustomValue() {
|
387
|
+
var _useState9 = (0, _react.useState)(''),
|
388
|
+
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
389
|
+
inputValue = _useState10[0],
|
390
|
+
setInputValue = _useState10[1];
|
391
|
+
|
392
|
+
return (0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], (0, _extends2["default"])({
|
393
|
+
label: "Example label",
|
394
|
+
defaultItems: items
|
395
|
+
}, actions, {
|
396
|
+
inputValue: inputValue,
|
397
|
+
selectedKey: inputValue,
|
398
|
+
onInputChange: setInputValue,
|
399
|
+
onSelectionChange: setInputValue,
|
400
|
+
hasCustomValue: true
|
401
|
+
}), function (item) {
|
402
|
+
return (0, _react2.jsx)(_index.Item, {
|
403
|
+
key: item.name
|
404
|
+
}, item.name);
|
405
|
+
}));
|
406
|
+
};
|
407
|
+
|
408
|
+
exports.ControlledWithCustomValue = ControlledWithCustomValue;
|
409
|
+
|
386
410
|
var AllowCustomValue = function AllowCustomValue() {
|
387
411
|
return (0, _react2.jsx)(_index.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], (0, _extends2["default"])({
|
388
412
|
label: "Example label",
|
@@ -772,6 +772,50 @@ test('two listbox can not be open at the same time', function () {
|
|
772
772
|
name: 'Tango'
|
773
773
|
})).toBeInTheDocument();
|
774
774
|
});
|
775
|
+
test('should handle selecting custom option', function () {
|
776
|
+
getComponent({
|
777
|
+
hasCustomValue: true
|
778
|
+
});
|
779
|
+
|
780
|
+
var input = _testWrapper.screen.queryByRole('combobox');
|
781
|
+
|
782
|
+
expect(input).toHaveValue(''); // type something
|
783
|
+
|
784
|
+
_userEvent["default"].type(input, 'custom'); // set input value as selected
|
785
|
+
|
786
|
+
|
787
|
+
_userEvent["default"].type(input, '{enter}', {
|
788
|
+
skipClick: true
|
789
|
+
});
|
790
|
+
|
791
|
+
expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
|
792
|
+
expect(_testWrapper.screen.queryByRole('combobox')).toHaveValue('custom'); // blur input
|
793
|
+
|
794
|
+
_userEvent["default"].tab();
|
795
|
+
|
796
|
+
expect(input).toHaveValue('custom');
|
797
|
+
});
|
798
|
+
test('onSelectionChange works properly with custom value', function () {
|
799
|
+
var onSelectionChange = jest.fn();
|
800
|
+
getComponent({
|
801
|
+
hasCustomValue: true,
|
802
|
+
onSelectionChange: onSelectionChange,
|
803
|
+
onInputChange: onSelectionChange
|
804
|
+
});
|
805
|
+
|
806
|
+
var input = _testWrapper.screen.queryByRole('combobox');
|
807
|
+
|
808
|
+
expect(input).toHaveValue('');
|
809
|
+
expect(onSelectionChange).not.toHaveBeenCalled(); // Should fire when input value was typed, and enter was pressed
|
810
|
+
|
811
|
+
_userEvent["default"].type(input, 'custom{enter}');
|
812
|
+
|
813
|
+
expect(onSelectionChange).toHaveBeenCalledWith('custom'); // Should fire when input is cleared
|
814
|
+
|
815
|
+
_userEvent["default"].type(input, '{selectall}{backspace}{enter}');
|
816
|
+
|
817
|
+
expect(onSelectionChange).toHaveBeenCalledWith('');
|
818
|
+
});
|
775
819
|
test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
776
820
|
var _getComponent6, container, results;
|
777
821
|
|
@@ -116,6 +116,12 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
116
116
|
useImperativeHandle(ref, function () {
|
117
117
|
return inputRef.current;
|
118
118
|
});
|
119
|
+
/* istanbul ignore next */
|
120
|
+
|
121
|
+
var onSelectionChangeHandler = function onSelectionChangeHandler(key) {
|
122
|
+
var newVal = key || selectedKey || '';
|
123
|
+
if (onSelectionChange) onSelectionChange(newVal);
|
124
|
+
};
|
119
125
|
|
120
126
|
var _useFilter = useFilter({
|
121
127
|
sensitivity: 'base'
|
@@ -123,6 +129,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
123
129
|
contains = _useFilter.contains;
|
124
130
|
|
125
131
|
var state = useComboBoxState(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
|
132
|
+
onSelectionChange: hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
|
126
133
|
defaultFilter: contains
|
127
134
|
}));
|
128
135
|
|
@@ -330,6 +330,27 @@ export var ControlledFiltering = function ControlledFiltering() {
|
|
330
330
|
}, item.name);
|
331
331
|
}));
|
332
332
|
};
|
333
|
+
export var ControlledWithCustomValue = function ControlledWithCustomValue() {
|
334
|
+
var _useState9 = useState(''),
|
335
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
336
|
+
inputValue = _useState10[0],
|
337
|
+
setInputValue = _useState10[1];
|
338
|
+
|
339
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
|
340
|
+
label: "Example label",
|
341
|
+
defaultItems: items
|
342
|
+
}, actions, {
|
343
|
+
inputValue: inputValue,
|
344
|
+
selectedKey: inputValue,
|
345
|
+
onInputChange: setInputValue,
|
346
|
+
onSelectionChange: setInputValue,
|
347
|
+
hasCustomValue: true
|
348
|
+
}), function (item) {
|
349
|
+
return ___EmotionJSX(Item, {
|
350
|
+
key: item.name
|
351
|
+
}, item.name);
|
352
|
+
}));
|
353
|
+
};
|
333
354
|
export var AllowCustomValue = function AllowCustomValue() {
|
334
355
|
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
|
335
356
|
label: "Example label",
|
@@ -639,6 +639,41 @@ test('two listbox can not be open at the same time', function () {
|
|
639
639
|
name: 'Tango'
|
640
640
|
})).toBeInTheDocument();
|
641
641
|
});
|
642
|
+
test('should handle selecting custom option', function () {
|
643
|
+
getComponent({
|
644
|
+
hasCustomValue: true
|
645
|
+
});
|
646
|
+
var input = screen.queryByRole('combobox');
|
647
|
+
expect(input).toHaveValue(''); // type something
|
648
|
+
|
649
|
+
userEvent.type(input, 'custom'); // set input value as selected
|
650
|
+
|
651
|
+
userEvent.type(input, '{enter}', {
|
652
|
+
skipClick: true
|
653
|
+
});
|
654
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
655
|
+
expect(screen.queryByRole('combobox')).toHaveValue('custom'); // blur input
|
656
|
+
|
657
|
+
userEvent.tab();
|
658
|
+
expect(input).toHaveValue('custom');
|
659
|
+
});
|
660
|
+
test('onSelectionChange works properly with custom value', function () {
|
661
|
+
var onSelectionChange = jest.fn();
|
662
|
+
getComponent({
|
663
|
+
hasCustomValue: true,
|
664
|
+
onSelectionChange: onSelectionChange,
|
665
|
+
onInputChange: onSelectionChange
|
666
|
+
});
|
667
|
+
var input = screen.queryByRole('combobox');
|
668
|
+
expect(input).toHaveValue('');
|
669
|
+
expect(onSelectionChange).not.toHaveBeenCalled(); // Should fire when input value was typed, and enter was pressed
|
670
|
+
|
671
|
+
userEvent.type(input, 'custom{enter}');
|
672
|
+
expect(onSelectionChange).toHaveBeenCalledWith('custom'); // Should fire when input is cleared
|
673
|
+
|
674
|
+
userEvent.type(input, '{selectall}{backspace}{enter}');
|
675
|
+
expect(onSelectionChange).toHaveBeenCalledWith('');
|
676
|
+
});
|
642
677
|
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
643
678
|
var _getComponent6, container, results;
|
644
679
|
|