@decisiv/ui-components 2.0.1-alpha.212 → 2.0.1-alpha.214
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/components/Combobox/index.d.ts.map +1 -1
- package/lib/components/Combobox/index.js +62 -28
- package/lib/components/Combobox/index.test.js +35 -9
- package/lib/components/Combobox/schema.d.ts.map +1 -1
- package/lib/components/Combobox/schema.js +3 -0
- package/lib/components/Combobox/types.d.ts +2 -1
- package/lib/components/Combobox/types.d.ts.map +1 -1
- package/lib/components/DropdownList/index.d.ts.map +1 -1
- package/lib/components/DropdownList/index.js +10 -3
- package/lib/components/DropdownList/index.test.js +8 -27
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAGZ,sBAAsB,EAQvB,MAAM,OAAO,CAAC;AA2Bf,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAQ,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/index.tsx"],"names":[],"mappings":"AASA,OAAc,EAGZ,sBAAsB,EAQvB,MAAM,OAAO,CAAC;AA2Bf,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAQ,MAAM,SAAS,CAAC;AA4mBhE,QAAA,MAAM,eAAe,EAAE,sBAAsB,CAC3C,gBAAgB,EAChB,aAAa,CACS,CAAC;AAOzB,eAAe,eAAe,CAAC"}
|
|
@@ -125,7 +125,8 @@ function Combobox(props, ref) {
|
|
|
125
125
|
zIndex = props.zIndex,
|
|
126
126
|
containerSelector = props.containerSelector,
|
|
127
127
|
pointerEvents = props.pointerEvents,
|
|
128
|
-
externalIsPopoverVisible = props.isPopoverVisible
|
|
128
|
+
externalIsPopoverVisible = props.isPopoverVisible,
|
|
129
|
+
externalListRef = props.listRef;
|
|
129
130
|
|
|
130
131
|
var _useCombobox = (0, _useCombobox2.default)(props),
|
|
131
132
|
getInputFieldProps = _useCombobox.getInputFieldProps,
|
|
@@ -136,7 +137,8 @@ function Combobox(props, ref) {
|
|
|
136
137
|
var fallbackComboboxRef = (0, _react.useRef)(null);
|
|
137
138
|
var finalComboboxRef = ref || fallbackComboboxRef;
|
|
138
139
|
var inputId = (0, _useUniqueId.default)(id, 'combobox-');
|
|
139
|
-
var
|
|
140
|
+
var fallbackListRef = (0, _react.useRef)(null);
|
|
141
|
+
var listRef = externalListRef || fallbackListRef;
|
|
140
142
|
|
|
141
143
|
var _useBreakpointObserve = (0, _breakpointObserver.useBreakpointObserver)(),
|
|
142
144
|
_useBreakpointObserve2 = _slicedToArray(_useBreakpointObserve, 2),
|
|
@@ -241,13 +243,49 @@ function Combobox(props, ref) {
|
|
|
241
243
|
*/
|
|
242
244
|
|
|
243
245
|
|
|
244
|
-
var updateSelected = (0, _react.useCallback)(function (
|
|
246
|
+
var updateSelected = (0, _react.useCallback)(function (selectedIds) {
|
|
247
|
+
// When using a controlled multiple variation, we want to also have access to the
|
|
248
|
+
// removed id values.
|
|
249
|
+
if (multiple && onChangeValue && Array.isArray(selectedIds) && selectedValues) {
|
|
250
|
+
var isRemoving = selectedIds.length < selectedValues.length;
|
|
251
|
+
|
|
252
|
+
if (isRemoving && selectedValues.length > 0) {
|
|
253
|
+
var removedValue = selectedValues.find(function (_ref2) {
|
|
254
|
+
var optionId = _ref2.id;
|
|
255
|
+
return !selectedIds.includes(optionId);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
if (removedValue && removedValue.id !== undefined) {
|
|
259
|
+
var filteredValues = selectedValues.filter(function (_ref3) {
|
|
260
|
+
var optionId = _ref3.id;
|
|
261
|
+
return optionId !== removedValue.id;
|
|
262
|
+
});
|
|
263
|
+
setSelectedValues(filteredValues);
|
|
264
|
+
onChangeValue(removedValue.id, {
|
|
265
|
+
removed: true
|
|
266
|
+
});
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
var getSelectedId = function getSelectedId(ids) {
|
|
273
|
+
var isMultiple = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
274
|
+
|
|
275
|
+
if (Array.isArray(ids)) {
|
|
276
|
+
return isMultiple ? (0, _last.default)(ids) : ids[0];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return ids;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
var selectedId = getSelectedId(selectedIds, multiple);
|
|
245
283
|
setSelectedValue(selectedId);
|
|
246
284
|
var newSelected = (0, _utils.getOptionFromOptions)(options, selectedId) || null;
|
|
247
285
|
|
|
248
286
|
if (multiple) {
|
|
249
|
-
var index = selectedValues && selectedValues.findIndex(function (
|
|
250
|
-
var itemId =
|
|
287
|
+
var index = selectedValues && selectedValues.findIndex(function (_ref4) {
|
|
288
|
+
var itemId = _ref4.id;
|
|
251
289
|
return itemId === selectedId;
|
|
252
290
|
});
|
|
253
291
|
|
|
@@ -274,8 +312,8 @@ function Combobox(props, ref) {
|
|
|
274
312
|
}
|
|
275
313
|
}, [multiple, onChangeValue, options, selectedValues, setInternalInputValue, setSelectedValue, setSelectedValues, setActiveId]);
|
|
276
314
|
var removeSelected = (0, _react.useCallback)(function (selectedId) {
|
|
277
|
-
var newSelectedValues = selectedValues && selectedValues.filter(function (
|
|
278
|
-
var optionId =
|
|
315
|
+
var newSelectedValues = selectedValues && selectedValues.filter(function (_ref5) {
|
|
316
|
+
var optionId = _ref5.id;
|
|
279
317
|
return selectedId !== optionId;
|
|
280
318
|
});
|
|
281
319
|
setSelectedValues(newSelectedValues);
|
|
@@ -314,16 +352,12 @@ function Combobox(props, ref) {
|
|
|
314
352
|
/**
|
|
315
353
|
* This handler is called by the dropdown's "onChange" event. That handler is called with
|
|
316
354
|
* an array of values, but we only allow single select in the Combobox.
|
|
355
|
+
* This is being managed in the `updatedSelected` function.
|
|
317
356
|
*/
|
|
318
357
|
|
|
319
358
|
var handleChangeDropdownListValue = (0, _react.useCallback)(function (selectedIds) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
updateSelected(selectedIds[0]);
|
|
326
|
-
}, [updateSelected, multiple]);
|
|
359
|
+
updateSelected(selectedIds);
|
|
360
|
+
}, [updateSelected]);
|
|
327
361
|
/**
|
|
328
362
|
* Clicking anywhere within the Combobox component (except the clear button) should open
|
|
329
363
|
* the dropdown list. There is some complex logic here because of the <input> rendered inside
|
|
@@ -392,8 +426,8 @@ function Combobox(props, ref) {
|
|
|
392
426
|
if (!isPopoverVisible) {
|
|
393
427
|
updateIsPopoverVisible(true);
|
|
394
428
|
} else {
|
|
395
|
-
var currentIndex = (0, _findIndex.default)(flatOptions, function (
|
|
396
|
-
var optionId =
|
|
429
|
+
var currentIndex = (0, _findIndex.default)(flatOptions, function (_ref6) {
|
|
430
|
+
var optionId = _ref6.id;
|
|
397
431
|
return optionId === activeId;
|
|
398
432
|
});
|
|
399
433
|
|
|
@@ -505,18 +539,18 @@ function Combobox(props, ref) {
|
|
|
505
539
|
onClick: handleContainerClick,
|
|
506
540
|
onKeyDown: handleContainerKeyDown,
|
|
507
541
|
ref: finalComboboxRef
|
|
508
|
-
}), function (
|
|
509
|
-
var ariaLabelledBy =
|
|
510
|
-
disabled =
|
|
511
|
-
targetId =
|
|
512
|
-
onBlurTarget =
|
|
513
|
-
onChangeTargetValue =
|
|
514
|
-
onFocusTarget =
|
|
515
|
-
readOnly =
|
|
516
|
-
targetRef =
|
|
517
|
-
value =
|
|
518
|
-
autoComplete =
|
|
519
|
-
type =
|
|
542
|
+
}), function (_ref7) {
|
|
543
|
+
var ariaLabelledBy = _ref7['aria-labelledby'],
|
|
544
|
+
disabled = _ref7.disabled,
|
|
545
|
+
targetId = _ref7.id,
|
|
546
|
+
onBlurTarget = _ref7.onBlur,
|
|
547
|
+
onChangeTargetValue = _ref7.onChange,
|
|
548
|
+
onFocusTarget = _ref7.onFocus,
|
|
549
|
+
readOnly = _ref7.readOnly,
|
|
550
|
+
targetRef = _ref7.ref,
|
|
551
|
+
value = _ref7.value,
|
|
552
|
+
autoComplete = _ref7.autoComplete,
|
|
553
|
+
type = _ref7.type;
|
|
520
554
|
var dropdownListId = "".concat(targetId, "-dropdown-list");
|
|
521
555
|
return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_Target.default, {
|
|
522
556
|
"aria-haspopup": "listbox",
|
|
@@ -1031,12 +1031,12 @@ describe('Combobox', function () {
|
|
|
1031
1031
|
})));
|
|
1032
1032
|
describe('when in multiple select mode', function () {
|
|
1033
1033
|
describe('when a value is selected', function () {
|
|
1034
|
-
describe('
|
|
1035
|
-
it('calls the onChangeValue prop with
|
|
1034
|
+
describe('clicking the same value again', function () {
|
|
1035
|
+
it('calls the onChangeValue prop with the expected values', function () {
|
|
1036
1036
|
var onChangeValue = jest.fn();
|
|
1037
1037
|
|
|
1038
1038
|
var _render33 = render(_react.default.createElement(_.default, {
|
|
1039
|
-
label: "test",
|
|
1039
|
+
label: "test label",
|
|
1040
1040
|
options: defaultOptions,
|
|
1041
1041
|
inputValue: "",
|
|
1042
1042
|
value: [defaultOptions[1]],
|
|
@@ -1048,6 +1048,32 @@ describe('Combobox', function () {
|
|
|
1048
1048
|
|
|
1049
1049
|
expect(queryByText(defaultOptions[1].label)).toBeInTheDocument();
|
|
1050
1050
|
|
|
1051
|
+
_react2.fireEvent.click(queryByText('test label'));
|
|
1052
|
+
|
|
1053
|
+
_react2.fireEvent.click(queryByLabelText(defaultOptions[1].label));
|
|
1054
|
+
|
|
1055
|
+
expect(onChangeValue).toHaveBeenCalledWith(defaultOptions[1].id, expect.objectContaining({
|
|
1056
|
+
removed: true
|
|
1057
|
+
}));
|
|
1058
|
+
});
|
|
1059
|
+
});
|
|
1060
|
+
describe('when the "X" button is clicked to deselect a value', function () {
|
|
1061
|
+
it('calls the onChangeValue prop with removed: true', function () {
|
|
1062
|
+
var onChangeValue = jest.fn();
|
|
1063
|
+
|
|
1064
|
+
var _render34 = render(_react.default.createElement(_.default, {
|
|
1065
|
+
label: "test",
|
|
1066
|
+
options: defaultOptions,
|
|
1067
|
+
inputValue: "",
|
|
1068
|
+
value: [defaultOptions[1]],
|
|
1069
|
+
onChangeValue: onChangeValue,
|
|
1070
|
+
multiple: true
|
|
1071
|
+
})),
|
|
1072
|
+
queryByText = _render34.queryByText,
|
|
1073
|
+
queryByLabelText = _render34.queryByLabelText;
|
|
1074
|
+
|
|
1075
|
+
expect(queryByText(defaultOptions[1].label)).toBeInTheDocument();
|
|
1076
|
+
|
|
1051
1077
|
_react2.fireEvent.click(queryByLabelText('Delete'));
|
|
1052
1078
|
|
|
1053
1079
|
expect(onChangeValue).toHaveBeenCalledWith(defaultOptions[1].id, expect.objectContaining({
|
|
@@ -1060,18 +1086,18 @@ describe('Combobox', function () {
|
|
|
1060
1086
|
});
|
|
1061
1087
|
describe('when the isPopoverVisible is true', function () {
|
|
1062
1088
|
it('opens the popover', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
1063
|
-
var
|
|
1089
|
+
var _render35, baseElement;
|
|
1064
1090
|
|
|
1065
1091
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
1066
1092
|
while (1) {
|
|
1067
1093
|
switch (_context2.prev = _context2.next) {
|
|
1068
1094
|
case 0:
|
|
1069
|
-
|
|
1095
|
+
_render35 = render(_react.default.createElement(_.default, {
|
|
1070
1096
|
label: "test",
|
|
1071
1097
|
options: defaultOptions,
|
|
1072
1098
|
hideLabel: true,
|
|
1073
1099
|
isPopoverVisible: true
|
|
1074
|
-
})), baseElement =
|
|
1100
|
+
})), baseElement = _render35.baseElement;
|
|
1075
1101
|
defaultOptions.forEach(function (_ref6) {
|
|
1076
1102
|
var label = _ref6.label;
|
|
1077
1103
|
expect((0, _react2.queryByText)(baseElement, label)).toBeInTheDocument();
|
|
@@ -1085,18 +1111,18 @@ describe('Combobox', function () {
|
|
|
1085
1111
|
}, _callee2);
|
|
1086
1112
|
})));
|
|
1087
1113
|
it('does not automatically close the popover', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
1088
|
-
var
|
|
1114
|
+
var _render36, baseElement, queryByLabelText;
|
|
1089
1115
|
|
|
1090
1116
|
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
1091
1117
|
while (1) {
|
|
1092
1118
|
switch (_context3.prev = _context3.next) {
|
|
1093
1119
|
case 0:
|
|
1094
|
-
|
|
1120
|
+
_render36 = render(_react.default.createElement(_.default, {
|
|
1095
1121
|
label: "test",
|
|
1096
1122
|
options: defaultOptions,
|
|
1097
1123
|
hideLabel: true,
|
|
1098
1124
|
isPopoverVisible: true
|
|
1099
|
-
})), baseElement =
|
|
1125
|
+
})), baseElement = _render36.baseElement, queryByLabelText = _render36.queryByLabelText;
|
|
1100
1126
|
|
|
1101
1127
|
_react2.fireEvent.click(queryByLabelText(defaultOptions[0].label));
|
|
1102
1128
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/schema.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,KAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/schema.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,MAAM,KAAwC,CAAC;AAsGrD,eAAe,MAAM,CAAC"}
|
|
@@ -49,6 +49,9 @@ schema.propTypes = _objectSpread({}, (0, _omit.default)(_InputField.schema.makeP
|
|
|
49
49
|
label: _reactDesc.PropTypes.string,
|
|
50
50
|
value: _reactDesc.PropTypes.string
|
|
51
51
|
}))]).description('The ID of the option that is selected. If provided, controlling the Select must be handled externally. Overrides `defaultValue`.'),
|
|
52
|
+
listRef: _reactDesc.PropTypes.oneOfType([_reactDesc.PropTypes.func, _reactDesc.PropTypes.shape({
|
|
53
|
+
current: _reactDesc.PropTypes.any
|
|
54
|
+
})]).description('A ref for the list container.'),
|
|
52
55
|
multiple: _reactDesc.PropTypes.bool.description('Used when multiple selections can be made in the Combobox').defaultValue(false),
|
|
53
56
|
variant: _reactDesc.PropTypes.oneOf(['async', 'sync']).description('Enables different logic for rendering the dropdown list.').defaultValue('sync'),
|
|
54
57
|
renderOptionLabel: _reactDesc.PropTypes.func.description('Function to customize render of option labels, called with the item value'),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputHTMLAttributes, Ref } from 'react';
|
|
1
|
+
import { InputHTMLAttributes, Ref, RefObject } from 'react';
|
|
2
2
|
import { BaseInputFieldProps } from '../../atoms/InputField';
|
|
3
3
|
import { ActionHandler } from '../Tag/types';
|
|
4
4
|
import { PopoverProps } from '../Popover/types';
|
|
@@ -16,6 +16,7 @@ export interface ComboboxProps extends Omit<React.InputHTMLAttributes<ComboboxIn
|
|
|
16
16
|
isPopoverVisible?: boolean;
|
|
17
17
|
multiple?: boolean;
|
|
18
18
|
maxWidth?: string;
|
|
19
|
+
listRef?: RefObject<HTMLUListElement>;
|
|
19
20
|
loading?: boolean;
|
|
20
21
|
onBlur?: React.FocusEventHandler;
|
|
21
22
|
onChangeInputValue?: (event?: React.ChangeEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/Combobox/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,E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MAAM,IAAI,CAAC;CACpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DropdownList/index.tsx"],"names":[],"mappings":";AAgBA,OAAO,EACL,QAAQ,IAAI,YAAY,EACxB,MAAM,IAAI,UAAU,EAErB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EACL,YAAY,IAAI,oBAAoB,EACpC,gBAAgB,EAChB,MAAM,IAAI,kBAAkB,EAC5B,KAAK,IAAI,iBAAiB,GAC3B,CAAC;AAEF,oBAAY,KAAK,GAAG,gBAAgB,EAAE,CAAC;AACvC,oBAAY,QAAQ,GAAG,YAAY,CAAC;AACpC,oBAAY,MAAM,GAAG,UAAU,CAAC;AAEhC,iBAAS,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DropdownList/index.tsx"],"names":[],"mappings":";AAgBA,OAAO,EACL,QAAQ,IAAI,YAAY,EACxB,MAAM,IAAI,UAAU,EAErB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIlD,OAAO,EACL,YAAY,IAAI,oBAAoB,EACpC,gBAAgB,EAChB,MAAM,IAAI,kBAAkB,EAC5B,KAAK,IAAI,iBAAiB,GAC3B,CAAC;AAEF,oBAAY,KAAK,GAAG,gBAAgB,EAAE,CAAC;AACvC,oBAAY,QAAQ,GAAG,YAAY,CAAC;AACpC,oBAAY,MAAM,GAAG,UAAU,CAAC;AAEhC,iBAAS,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA0M/C;kBA1MQ,YAAY;;;;;;;;AAkOrB,eAAe,YAAY,CAAC"}
|
|
@@ -95,7 +95,8 @@ function DropdownList(props) {
|
|
|
95
95
|
maxHeight = props.maxHeight,
|
|
96
96
|
maxWidth = props.maxWidth,
|
|
97
97
|
minWidth = props.minWidth,
|
|
98
|
-
|
|
98
|
+
multiple = props.multiple,
|
|
99
|
+
rest = _objectWithoutProperties(props, ["actions", "borderRadius", "containerSelector", "defaultSelectedIds", "defaultVisible", "defaultFooter", "focusOnShowing", "listRef", "onChange", "onHide", "onShow", "placement", "selectedIds", "showArrow", "target", "visible", "zIndex", "PanelComponent", "maxHeight", "maxWidth", "minWidth", "multiple"]); // Use a ref callback to get more control over re-rendering when a ref is stored.
|
|
99
100
|
// Specifically, the scroll to selected item on first render of dropdown requires this.
|
|
100
101
|
|
|
101
102
|
|
|
@@ -159,7 +160,12 @@ function DropdownList(props) {
|
|
|
159
160
|
var handleOnChange = (0, _react.useCallback)(function (selection) {
|
|
160
161
|
onChange && onChange(Array.isArray(selection) ? selection : [selection]);
|
|
161
162
|
defaultFooter && setSelected(selection) && setSaved(selection);
|
|
162
|
-
|
|
163
|
+
|
|
164
|
+
if (!multiple) {
|
|
165
|
+
setShowing(false);
|
|
166
|
+
popRef && popRef.current && popRef.current.hide() && popRef.current.targetNode && popRef.current.targetNode.focus();
|
|
167
|
+
}
|
|
168
|
+
}, [onChange, setSelected, setSaved, defaultFooter, setShowing]);
|
|
163
169
|
var handleOnApply = (0, _react.useCallback)(function () {
|
|
164
170
|
setSaved(selected);
|
|
165
171
|
popRef && popRef.current && popRef.current.hide();
|
|
@@ -227,7 +233,8 @@ function DropdownList(props) {
|
|
|
227
233
|
onKeyDown: onKeyDown,
|
|
228
234
|
maxHeight: maxHeight,
|
|
229
235
|
maxWidth: maxWidth,
|
|
230
|
-
minWidth: minWidth
|
|
236
|
+
minWidth: minWidth,
|
|
237
|
+
multiple: multiple
|
|
231
238
|
}, rest)))));
|
|
232
239
|
}
|
|
233
240
|
|
|
@@ -199,7 +199,7 @@ describe('DropdownList', function () {
|
|
|
199
199
|
expect(onChange).toHaveBeenCalledWith([item0Id]);
|
|
200
200
|
expect(baseElement).toMatchSnapshot();
|
|
201
201
|
});
|
|
202
|
-
it('
|
|
202
|
+
it('automatically hide the options', function () {
|
|
203
203
|
var _render7 = render(_react.default.createElement(_.default, defaultProps)),
|
|
204
204
|
baseElement = _render7.baseElement,
|
|
205
205
|
getByText = _render7.getByText;
|
|
@@ -208,38 +208,19 @@ describe('DropdownList', function () {
|
|
|
208
208
|
|
|
209
209
|
_react2.fireEvent.click((0, _react2.getByText)(baseElement, item0Label));
|
|
210
210
|
|
|
211
|
-
expect((0, _react2.queryByText)(baseElement, item0Label)).
|
|
212
|
-
});
|
|
213
|
-
it('does not allow multiple selections', function () {
|
|
214
|
-
var onChange = jest.fn();
|
|
215
|
-
|
|
216
|
-
var _render8 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
217
|
-
onChange: onChange
|
|
218
|
-
}))),
|
|
219
|
-
baseElement = _render8.baseElement,
|
|
220
|
-
getByText = _render8.getByText;
|
|
221
|
-
|
|
222
|
-
_react2.fireEvent.click(getByText(targetButtonText));
|
|
223
|
-
|
|
224
|
-
_react2.fireEvent.click((0, _react2.getByText)(baseElement, item0Label));
|
|
225
|
-
|
|
226
|
-
expect(onChange).toHaveBeenCalledWith([item0Id]);
|
|
227
|
-
|
|
228
|
-
_react2.fireEvent.click((0, _react2.getByText)(baseElement, item2Label));
|
|
229
|
-
|
|
230
|
-
expect(onChange).toHaveBeenCalledWith([item2Id]);
|
|
211
|
+
expect((0, _react2.queryByText)(baseElement, item0Label)).toBeFalsy();
|
|
231
212
|
});
|
|
232
213
|
});
|
|
233
214
|
describe('multiple options', function () {
|
|
234
215
|
it('calls the onChange prop with the selection ids', function () {
|
|
235
216
|
var onChange = jest.fn();
|
|
236
217
|
|
|
237
|
-
var
|
|
218
|
+
var _render8 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
238
219
|
onChange: onChange,
|
|
239
220
|
multiple: true
|
|
240
221
|
}))),
|
|
241
|
-
baseElement =
|
|
242
|
-
getByText =
|
|
222
|
+
baseElement = _render8.baseElement,
|
|
223
|
+
getByText = _render8.getByText;
|
|
243
224
|
|
|
244
225
|
_react2.fireEvent.click(getByText(targetButtonText));
|
|
245
226
|
|
|
@@ -251,11 +232,11 @@ describe('DropdownList', function () {
|
|
|
251
232
|
expect(baseElement).toMatchSnapshot();
|
|
252
233
|
});
|
|
253
234
|
it('does not automatically hide the options', function () {
|
|
254
|
-
var
|
|
235
|
+
var _render9 = render(_react.default.createElement(_.default, _extends({}, defaultProps, {
|
|
255
236
|
multiple: true
|
|
256
237
|
}))),
|
|
257
|
-
baseElement =
|
|
258
|
-
getByText =
|
|
238
|
+
baseElement = _render9.baseElement,
|
|
239
|
+
getByText = _render9.getByText;
|
|
259
240
|
|
|
260
241
|
_react2.fireEvent.click(getByText(targetButtonText));
|
|
261
242
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decisiv/ui-components",
|
|
3
|
-
"version": "2.0.1-alpha.
|
|
3
|
+
"version": "2.0.1-alpha.214+896898c",
|
|
4
4
|
"description": "Decisiv's design system React components",
|
|
5
5
|
"author": "Decisiv UI Development Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"access": "public"
|
|
72
72
|
},
|
|
73
73
|
"private": false,
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "896898ccffaece0ac325ee1b11376d0f011b5f93"
|
|
75
75
|
}
|