@pingux/astro 1.16.1-alpha.0 → 1.17.0-alpha.2
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/ComboBoxField/ComboBoxField.js +40 -7
- package/lib/cjs/components/ComboBoxField/ComboBoxField.stories.js +58 -2
- package/lib/cjs/components/ComboBoxField/ComboBoxField.test.js +123 -25
- package/lib/cjs/components/Image/Image.js +14 -3
- package/lib/cjs/components/Image/Image.stories.js +17 -8
- package/lib/cjs/components/Image/Image.test.js +9 -0
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +142 -21
- package/lib/components/ComboBoxField/ComboBoxField.js +40 -8
- package/lib/components/ComboBoxField/ComboBoxField.stories.js +51 -0
- package/lib/components/ComboBoxField/ComboBoxField.test.js +106 -25
- package/lib/components/Image/Image.js +15 -4
- package/lib/components/Image/Image.stories.js +17 -8
- package/lib/components/Image/Image.test.js +9 -0
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +142 -20
- package/package.json +1 -1
@@ -16,10 +16,10 @@ _Object$defineProperty(exports, "__esModule", {
|
|
16
16
|
|
17
17
|
exports["default"] = exports.WithReadOnlyValues = exports.WithDisabledKeys = exports.WithCustomValues = exports.WithCustomSize = exports.Uncontrolled = exports.Default = exports.Controlled = void 0;
|
18
18
|
|
19
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
20
|
-
|
21
19
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
22
20
|
|
21
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
22
|
+
|
23
23
|
var _react = _interopRequireWildcard(require("react"));
|
24
24
|
|
25
25
|
var _ = require("../..");
|
@@ -34,7 +34,9 @@ var _default = {
|
|
34
34
|
title: 'Form/MultivaluesField',
|
35
35
|
component: _.MultivaluesField,
|
36
36
|
argTypes: {
|
37
|
-
direction: {
|
37
|
+
direction: {
|
38
|
+
defaultValue: 'bottom'
|
39
|
+
},
|
38
40
|
hasAutoFocus: {},
|
39
41
|
hasNoStatusIndicator: {},
|
40
42
|
isDisabled: {},
|
@@ -118,7 +120,26 @@ var items = [{
|
|
118
120
|
key: 'Shark'
|
119
121
|
}];
|
120
122
|
|
123
|
+
var setOverlayStyle = function setOverlayStyle(direction, isOpen, mr, ml, mt) {
|
124
|
+
return {
|
125
|
+
marginRight: direction === 'right' && isOpen ? mr : 0,
|
126
|
+
marginLeft: direction === 'left' && isOpen ? ml : 0,
|
127
|
+
marginTop: direction === 'top' && isOpen ? mt : 0
|
128
|
+
};
|
129
|
+
};
|
130
|
+
|
121
131
|
var Default = function Default(args) {
|
132
|
+
var _useState = (0, _react.useState)(false),
|
133
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
134
|
+
isOpen = _useState2[0],
|
135
|
+
setIsOpen = _useState2[1];
|
136
|
+
|
137
|
+
var direction = args.direction;
|
138
|
+
|
139
|
+
var onOpenChange = function onOpenChange() {
|
140
|
+
setIsOpen(true);
|
141
|
+
};
|
142
|
+
|
122
143
|
return (// const items = [
|
123
144
|
// { id: 1, name: 'Aardvark', key: 'Aardvark' },
|
124
145
|
// { id: 2, name: 'Kangaroo', key: 'Kangaroo' },
|
@@ -128,9 +149,14 @@ var Default = function Default(args) {
|
|
128
149
|
// { id: 6, name: 'Orangutan', key: 'Orangutan' },
|
129
150
|
// { id: 7, name: 'Shark', key: 'Shark' },
|
130
151
|
// ];
|
131
|
-
(0, _react2.jsx)(_.OverlayProvider
|
152
|
+
(0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
153
|
+
, {
|
154
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
155
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
132
156
|
items: items
|
133
|
-
}, args
|
157
|
+
}, args, {
|
158
|
+
onOpenChange: onOpenChange
|
159
|
+
}), function (item) {
|
134
160
|
return (0, _react2.jsx)(_.Item, {
|
135
161
|
key: item.key,
|
136
162
|
"data-id": item.name
|
@@ -142,10 +168,26 @@ var Default = function Default(args) {
|
|
142
168
|
exports.Default = Default;
|
143
169
|
|
144
170
|
var WithCustomValues = function WithCustomValues(args) {
|
145
|
-
|
171
|
+
var _useState3 = (0, _react.useState)(false),
|
172
|
+
_useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
|
173
|
+
isOpen = _useState4[0],
|
174
|
+
setIsOpen = _useState4[1];
|
175
|
+
|
176
|
+
var direction = args.direction;
|
177
|
+
|
178
|
+
var onOpenChange = function onOpenChange() {
|
179
|
+
setIsOpen(true);
|
180
|
+
};
|
181
|
+
|
182
|
+
return (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
183
|
+
, {
|
184
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
185
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
146
186
|
items: items,
|
147
187
|
mode: "non-restrictive"
|
148
|
-
}, args
|
188
|
+
}, args, {
|
189
|
+
onOpenChange: onOpenChange
|
190
|
+
}), function (item) {
|
149
191
|
return (0, _react2.jsx)(_.Item, {
|
150
192
|
key: item.key,
|
151
193
|
"data-id": item.name
|
@@ -161,10 +203,26 @@ WithCustomValues.argTypes = {
|
|
161
203
|
};
|
162
204
|
|
163
205
|
var WithDisabledKeys = function WithDisabledKeys(args) {
|
164
|
-
|
206
|
+
var _useState5 = (0, _react.useState)(false),
|
207
|
+
_useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
|
208
|
+
isOpen = _useState6[0],
|
209
|
+
setIsOpen = _useState6[1];
|
210
|
+
|
211
|
+
var direction = args.direction;
|
212
|
+
|
213
|
+
var onOpenChange = function onOpenChange() {
|
214
|
+
setIsOpen(true);
|
215
|
+
};
|
216
|
+
|
217
|
+
return (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
218
|
+
, {
|
219
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
220
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
165
221
|
disabledKeys: ['Aardvark'],
|
166
222
|
items: items
|
167
|
-
}, args
|
223
|
+
}, args, {
|
224
|
+
onOpenChange: onOpenChange
|
225
|
+
}), function (item) {
|
168
226
|
return (0, _react2.jsx)(_.Item, {
|
169
227
|
key: item.key,
|
170
228
|
"data-id": item.name
|
@@ -175,10 +233,26 @@ var WithDisabledKeys = function WithDisabledKeys(args) {
|
|
175
233
|
exports.WithDisabledKeys = WithDisabledKeys;
|
176
234
|
|
177
235
|
var Uncontrolled = function Uncontrolled(args) {
|
178
|
-
|
236
|
+
var _useState7 = (0, _react.useState)(false),
|
237
|
+
_useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
|
238
|
+
isOpen = _useState8[0],
|
239
|
+
setIsOpen = _useState8[1];
|
240
|
+
|
241
|
+
var direction = args.direction;
|
242
|
+
|
243
|
+
var onOpenChange = function onOpenChange() {
|
244
|
+
setIsOpen(true);
|
245
|
+
};
|
246
|
+
|
247
|
+
return (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
248
|
+
, {
|
249
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
250
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
179
251
|
defaultSelectedKeys: ['Aardvark', 'Snake'],
|
180
252
|
items: items
|
181
|
-
}, args
|
253
|
+
}, args, {
|
254
|
+
onOpenChange: onOpenChange
|
255
|
+
}), function (item) {
|
182
256
|
return (0, _react2.jsx)(_.Item, {
|
183
257
|
key: item.key,
|
184
258
|
"data-id": item.name
|
@@ -189,17 +263,32 @@ var Uncontrolled = function Uncontrolled(args) {
|
|
189
263
|
exports.Uncontrolled = Uncontrolled;
|
190
264
|
|
191
265
|
var Controlled = function Controlled(args) {
|
192
|
-
var
|
193
|
-
|
194
|
-
selectedKeys =
|
195
|
-
setSelectedKeys =
|
266
|
+
var _useState9 = (0, _react.useState)(['Aardvark', 'Snake']),
|
267
|
+
_useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
|
268
|
+
selectedKeys = _useState10[0],
|
269
|
+
setSelectedKeys = _useState10[1];
|
270
|
+
|
271
|
+
var _useState11 = (0, _react.useState)(false),
|
272
|
+
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
273
|
+
isOpen = _useState12[0],
|
274
|
+
setIsOpen = _useState12[1];
|
275
|
+
|
276
|
+
var direction = args.direction;
|
277
|
+
|
278
|
+
var onOpenChange = function onOpenChange() {
|
279
|
+
setIsOpen(true);
|
280
|
+
};
|
196
281
|
|
197
|
-
return (0, _react2.jsx)(_.OverlayProvider
|
282
|
+
return (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
283
|
+
, {
|
284
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
285
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
198
286
|
label: "Field Label"
|
199
287
|
}, args, {
|
200
288
|
items: items,
|
201
289
|
onSelectionChange: setSelectedKeys,
|
202
|
-
selectedKeys: selectedKeys
|
290
|
+
selectedKeys: selectedKeys,
|
291
|
+
onOpenChange: onOpenChange
|
203
292
|
}), function (item) {
|
204
293
|
return (0, _react2.jsx)(_.Item, {
|
205
294
|
key: item.key,
|
@@ -211,6 +300,17 @@ var Controlled = function Controlled(args) {
|
|
211
300
|
exports.Controlled = Controlled;
|
212
301
|
|
213
302
|
var WithCustomSize = function WithCustomSize(args) {
|
303
|
+
var _useState13 = (0, _react.useState)(false),
|
304
|
+
_useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
|
305
|
+
isOpen = _useState14[0],
|
306
|
+
setIsOpen = _useState14[1];
|
307
|
+
|
308
|
+
var direction = args.direction;
|
309
|
+
|
310
|
+
var onOpenChange = function onOpenChange() {
|
311
|
+
setIsOpen(true);
|
312
|
+
};
|
313
|
+
|
214
314
|
return (0, _react2.jsx)(_.Box, {
|
215
315
|
sx: {
|
216
316
|
width: '100%',
|
@@ -219,9 +319,14 @@ var WithCustomSize = function WithCustomSize(args) {
|
|
219
319
|
}
|
220
320
|
}, (0, _react2.jsx)(_.Box, {
|
221
321
|
width: 300
|
222
|
-
}, (0, _react2.jsx)(_.OverlayProvider
|
322
|
+
}, (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
323
|
+
, {
|
324
|
+
style: setOverlayStyle(direction, isOpen, '25%', '25%', '75%')
|
325
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
223
326
|
items: items
|
224
|
-
}, args
|
327
|
+
}, args, {
|
328
|
+
onOpenChange: onOpenChange
|
329
|
+
}), function (item) {
|
225
330
|
return (0, _react2.jsx)(_.Item, {
|
226
331
|
key: item.key,
|
227
332
|
"data-id": item.name
|
@@ -232,10 +337,26 @@ var WithCustomSize = function WithCustomSize(args) {
|
|
232
337
|
exports.WithCustomSize = WithCustomSize;
|
233
338
|
|
234
339
|
var WithReadOnlyValues = function WithReadOnlyValues(args) {
|
235
|
-
|
340
|
+
var _useState15 = (0, _react.useState)(false),
|
341
|
+
_useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
|
342
|
+
isOpen = _useState16[0],
|
343
|
+
setIsOpen = _useState16[1];
|
344
|
+
|
345
|
+
var direction = args.direction;
|
346
|
+
|
347
|
+
var onOpenChange = function onOpenChange() {
|
348
|
+
setIsOpen(true);
|
349
|
+
};
|
350
|
+
|
351
|
+
return (0, _react2.jsx)(_.OverlayProvider // note: spacing for demo purpose only so that the select list renders in the correct place
|
352
|
+
, {
|
353
|
+
style: setOverlayStyle(direction, isOpen, '50%', '50%', '20%')
|
354
|
+
}, (0, _react2.jsx)(_.MultivaluesField, (0, _extends2["default"])({
|
236
355
|
readOnlyKeys: ['Aardvark', 'Snake'],
|
237
356
|
items: items
|
238
|
-
}, args
|
357
|
+
}, args, {
|
358
|
+
onOpenChange: onOpenChange
|
359
|
+
}), function (item) {
|
239
360
|
return (0, _react2.jsx)(_.Item, {
|
240
361
|
key: item.key,
|
241
362
|
"data-id": item.name
|
@@ -11,13 +11,14 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
11
11
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
12
12
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
13
13
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
14
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
14
15
|
var _excluded = ["shouldFocusOnHover", "shouldSelectOnPressUp"];
|
15
16
|
|
16
17
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
17
18
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
19
20
|
|
20
|
-
import React, { useCallback, useRef, useState, forwardRef, useImperativeHandle } from 'react';
|
21
|
+
import React, { useCallback, useRef, useState, forwardRef, useImperativeHandle, useEffect } from 'react';
|
21
22
|
import PropTypes from 'prop-types';
|
22
23
|
import { DismissButton, useOverlayPosition } from '@react-aria/overlays';
|
23
24
|
import { useComboBox } from '@react-aria/combobox';
|
@@ -57,13 +58,14 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
57
58
|
onFocusChange = props.onFocusChange,
|
58
59
|
onKeyDown = props.onKeyDown,
|
59
60
|
onKeyUp = props.onKeyUp,
|
61
|
+
hasAddOption = props.hasAddOption,
|
60
62
|
hasCustomValue = props.hasCustomValue,
|
61
63
|
hasNoEmptySelection = props.hasNoEmptySelection,
|
62
64
|
defaultSelectedKey = props.defaultSelectedKey,
|
63
65
|
selectedKey = props.selectedKey,
|
64
66
|
onSelectionChange = props.onSelectionChange,
|
65
|
-
|
66
|
-
|
67
|
+
initialDefaultItems = props.defaultItems,
|
68
|
+
initialItems = props.items,
|
67
69
|
onOpenChange = props.onOpenChange,
|
68
70
|
loadingState = props.loadingState,
|
69
71
|
onLoadMore = props.onLoadMore,
|
@@ -91,13 +93,11 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
91
93
|
onFocusChange: onFocusChange,
|
92
94
|
onKeyDown: onKeyDown,
|
93
95
|
onKeyUp: onKeyUp,
|
94
|
-
allowsCustomValue: hasCustomValue,
|
96
|
+
allowsCustomValue: hasAddOption || hasCustomValue,
|
95
97
|
disallowEmptySelection: hasNoEmptySelection,
|
96
98
|
defaultSelectedKey: defaultSelectedKey,
|
97
99
|
selectedKey: selectedKey,
|
98
100
|
onSelectionChange: onSelectionChange,
|
99
|
-
defaultItems: defaultItems,
|
100
|
-
items: items,
|
101
101
|
onOpenChange: onOpenChange,
|
102
102
|
loadingState: loadingState,
|
103
103
|
onLoadMore: onLoadMore,
|
@@ -123,18 +123,47 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
123
123
|
|
124
124
|
var onSelectionChangeHandler = function onSelectionChangeHandler(key) {
|
125
125
|
var newVal = key || selectedKey || '';
|
126
|
+
|
127
|
+
if (hasAddOption && selectedKey !== inputValue) {
|
128
|
+
newVal = inputValue;
|
129
|
+
}
|
130
|
+
|
126
131
|
if (onSelectionChange) onSelectionChange(newVal);
|
127
132
|
};
|
128
133
|
|
134
|
+
var shouldShowAddOption = hasAddOption && inputValue && selectedKey !== inputValue;
|
135
|
+
var addOption = "ADD: ".concat(inputValue);
|
136
|
+
|
137
|
+
var getItemsArr = function getItemsArr(initialArr) {
|
138
|
+
if (initialArr && shouldShowAddOption) {
|
139
|
+
var _context;
|
140
|
+
|
141
|
+
return _concatInstanceProperty(_context = []).call(_context, initialArr, [{
|
142
|
+
name: addOption,
|
143
|
+
key: addOption
|
144
|
+
}]);
|
145
|
+
}
|
146
|
+
|
147
|
+
return initialArr;
|
148
|
+
};
|
149
|
+
|
150
|
+
var defaultItems = getItemsArr(initialDefaultItems);
|
151
|
+
var items = getItemsArr(initialItems);
|
152
|
+
|
129
153
|
var _useFilter = useFilter({
|
130
154
|
sensitivity: 'base'
|
131
155
|
}),
|
132
156
|
contains = _useFilter.contains;
|
133
157
|
|
134
158
|
var state = useComboBoxState(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
|
135
|
-
|
159
|
+
defaultItems: defaultItems,
|
160
|
+
items: items,
|
161
|
+
onSelectionChange: hasAddOption || hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
|
136
162
|
defaultFilter: typeof defaultFilter !== 'undefined' ? defaultFilter : contains
|
137
163
|
}));
|
164
|
+
useEffect(function () {
|
165
|
+
if (shouldShowAddOption) state.selectionManager.setFocusedKey(addOption);
|
166
|
+
}, [shouldShowAddOption, state, addOption]);
|
138
167
|
|
139
168
|
var _useComboBox = useComboBox(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
|
140
169
|
buttonRef: buttonRef,
|
@@ -241,6 +270,9 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
241
270
|
}, listbox));
|
242
271
|
});
|
243
272
|
ComboBoxField.propTypes = {
|
273
|
+
/* Whether or not adding new options to the list is enabled. */
|
274
|
+
hasAddOption: PropTypes.bool,
|
275
|
+
|
244
276
|
/** Whether the ComboBox allows a non-item matching input value to be set. */
|
245
277
|
hasCustomValue: PropTypes.bool,
|
246
278
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
2
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
1
3
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
2
4
|
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
3
5
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
@@ -469,4 +471,53 @@ export var CustomDefaultFilter = function CustomDefaultFilter() {
|
|
469
471
|
key: item.name
|
470
472
|
}, item.name);
|
471
473
|
}));
|
474
|
+
};
|
475
|
+
export var ControlledWithAddOption = function ControlledWithAddOption() {
|
476
|
+
var _useState11 = useState(items),
|
477
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
478
|
+
options = _useState12[0],
|
479
|
+
setOptions = _useState12[1];
|
480
|
+
|
481
|
+
var _useState13 = useState(''),
|
482
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
483
|
+
inputValue = _useState14[0],
|
484
|
+
setInputValue = _useState14[1];
|
485
|
+
|
486
|
+
var _useState15 = useState(''),
|
487
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
488
|
+
selectedKey = _useState16[0],
|
489
|
+
setSelectedKey = _useState16[1];
|
490
|
+
|
491
|
+
var onSelectionChange = function onSelectionChange(key) {
|
492
|
+
// Add new option to options array
|
493
|
+
if (key && !_findInstanceProperty(options).call(options, function (_ref2) {
|
494
|
+
var name = _ref2.name;
|
495
|
+
return name === key;
|
496
|
+
})) {
|
497
|
+
var _context2;
|
498
|
+
|
499
|
+
setOptions(_concatInstanceProperty(_context2 = []).call(_context2, options, [{
|
500
|
+
key: key,
|
501
|
+
name: key
|
502
|
+
}]));
|
503
|
+
}
|
504
|
+
|
505
|
+
setInputValue(key);
|
506
|
+
setSelectedKey(key);
|
507
|
+
};
|
508
|
+
|
509
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
|
510
|
+
label: "Example label",
|
511
|
+
defaultItems: options
|
512
|
+
}, actions, {
|
513
|
+
inputValue: inputValue,
|
514
|
+
selectedKey: selectedKey,
|
515
|
+
onInputChange: setInputValue,
|
516
|
+
onSelectionChange: onSelectionChange,
|
517
|
+
hasAddOption: true
|
518
|
+
}), function (item) {
|
519
|
+
return ___EmotionJSX(Item, {
|
520
|
+
key: item.name
|
521
|
+
}, item.name);
|
522
|
+
}));
|
472
523
|
};
|
@@ -9,6 +9,8 @@ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance
|
|
9
9
|
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
10
10
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
11
11
|
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
12
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
13
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
12
14
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
13
15
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
14
16
|
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
@@ -16,7 +18,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
16
18
|
|
17
19
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
18
20
|
|
19
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context6, _context7; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context6 = ownKeys(Object(source), !0)).call(_context6, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context7 = ownKeys(Object(source))).call(_context7, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
20
22
|
|
21
23
|
import React, { useState, useMemo } from 'react';
|
22
24
|
import { axe } from 'jest-axe';
|
@@ -83,6 +85,54 @@ var ComboBoxWithCustomFilter = function ComboBoxWithCustomFilter() {
|
|
83
85
|
});
|
84
86
|
};
|
85
87
|
|
88
|
+
var ComboBoxWithAddOption = function ComboBoxWithAddOption() {
|
89
|
+
var _useState3 = useState(items),
|
90
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
91
|
+
options = _useState4[0],
|
92
|
+
setOptions = _useState4[1];
|
93
|
+
|
94
|
+
var _useState5 = useState(''),
|
95
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
96
|
+
inputValue = _useState6[0],
|
97
|
+
setInputValue = _useState6[1];
|
98
|
+
|
99
|
+
var _useState7 = useState(''),
|
100
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
101
|
+
selectedKey = _useState8[0],
|
102
|
+
setSelectedKey = _useState8[1];
|
103
|
+
|
104
|
+
var onSelectionChange = function onSelectionChange(key) {
|
105
|
+
if (key && !_findInstanceProperty(options).call(options, function (_ref2) {
|
106
|
+
var name = _ref2.name;
|
107
|
+
return name === key;
|
108
|
+
})) {
|
109
|
+
var _context;
|
110
|
+
|
111
|
+
setOptions(_concatInstanceProperty(_context = []).call(_context, options, [{
|
112
|
+
key: key,
|
113
|
+
name: key
|
114
|
+
}]));
|
115
|
+
}
|
116
|
+
|
117
|
+
setInputValue(key);
|
118
|
+
setSelectedKey(key);
|
119
|
+
};
|
120
|
+
|
121
|
+
return ___EmotionJSX(ComboBoxField, {
|
122
|
+
label: "Example label",
|
123
|
+
defaultItems: options,
|
124
|
+
inputValue: inputValue,
|
125
|
+
selectedKey: selectedKey,
|
126
|
+
onInputChange: setInputValue,
|
127
|
+
onSelectionChange: onSelectionChange,
|
128
|
+
hasAddOption: true
|
129
|
+
}, function (item) {
|
130
|
+
return ___EmotionJSX(Item, {
|
131
|
+
key: item.name
|
132
|
+
}, item.name);
|
133
|
+
});
|
134
|
+
};
|
135
|
+
|
86
136
|
beforeAll(function () {
|
87
137
|
jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function () {
|
88
138
|
return 1000;
|
@@ -357,41 +407,41 @@ test('should use default contains filtering', function () {
|
|
357
407
|
});
|
358
408
|
test('should be able to use controlled filtering', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
359
409
|
var options, input;
|
360
|
-
return _regeneratorRuntime.wrap(function _callee$(
|
410
|
+
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
361
411
|
while (1) {
|
362
|
-
switch (
|
412
|
+
switch (_context2.prev = _context2.next) {
|
363
413
|
case 0:
|
364
414
|
render(___EmotionJSX(ComboBoxWithCustomFilter, null));
|
365
415
|
input = screen.queryByRole('combobox'); // Should list all without filterable input
|
366
416
|
|
367
417
|
userEvent.type(input, '{arrowdown}');
|
368
|
-
|
418
|
+
_context2.next = 5;
|
369
419
|
return screen.findAllByRole('option');
|
370
420
|
|
371
421
|
case 5:
|
372
|
-
options =
|
422
|
+
options = _context2.sent;
|
373
423
|
expect(options).toHaveLength(items.length); // Should only list the second option
|
374
424
|
|
375
425
|
userEvent.type(input, 'k');
|
376
|
-
|
426
|
+
_context2.next = 10;
|
377
427
|
return screen.findAllByRole('option');
|
378
428
|
|
379
429
|
case 10:
|
380
|
-
options =
|
430
|
+
options = _context2.sent;
|
381
431
|
expect(options[0]).toHaveTextContent(items[1].name);
|
382
432
|
|
383
433
|
case 12:
|
384
434
|
case "end":
|
385
|
-
return
|
435
|
+
return _context2.stop();
|
386
436
|
}
|
387
437
|
}
|
388
438
|
}, _callee);
|
389
439
|
})));
|
390
440
|
test('should be able to use custom default filtering', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
391
441
|
var options, defaultFilter, input;
|
392
|
-
return _regeneratorRuntime.wrap(function _callee2$(
|
442
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
393
443
|
while (1) {
|
394
|
-
switch (
|
444
|
+
switch (_context3.prev = _context3.next) {
|
395
445
|
case 0:
|
396
446
|
defaultFilter = function defaultFilter(option, inputValue) {
|
397
447
|
return _startsWithInstanceProperty(option).call(option, inputValue);
|
@@ -403,33 +453,33 @@ test('should be able to use custom default filtering', /*#__PURE__*/_asyncToGene
|
|
403
453
|
input = screen.queryByRole('combobox'); // Should list all without filterable input
|
404
454
|
|
405
455
|
userEvent.type(input, '{arrowdown}');
|
406
|
-
|
456
|
+
_context3.next = 6;
|
407
457
|
return screen.findAllByRole('option');
|
408
458
|
|
409
459
|
case 6:
|
410
|
-
options =
|
460
|
+
options = _context3.sent;
|
411
461
|
expect(options).toHaveLength(items.length); // Should only list the second option
|
412
462
|
|
413
463
|
userEvent.type(input, 'K');
|
414
|
-
|
464
|
+
_context3.next = 11;
|
415
465
|
return screen.findAllByRole('option');
|
416
466
|
|
417
467
|
case 11:
|
418
|
-
options =
|
468
|
+
options = _context3.sent;
|
419
469
|
expect(options[0]).toHaveTextContent(items[1].name);
|
420
470
|
|
421
471
|
case 13:
|
422
472
|
case "end":
|
423
|
-
return
|
473
|
+
return _context3.stop();
|
424
474
|
}
|
425
475
|
}
|
426
476
|
}, _callee2);
|
427
477
|
})));
|
428
478
|
test('should show in input "textValue" if provided', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
429
479
|
var newItems, input, options;
|
430
|
-
return _regeneratorRuntime.wrap(function _callee3$(
|
480
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
431
481
|
while (1) {
|
432
|
-
switch (
|
482
|
+
switch (_context4.prev = _context4.next) {
|
433
483
|
case 0:
|
434
484
|
newItems = _mapInstanceProperty(items).call(items, function (item) {
|
435
485
|
return _objectSpread(_objectSpread({}, item), {}, {
|
@@ -441,11 +491,11 @@ test('should show in input "textValue" if provided', /*#__PURE__*/_asyncToGenera
|
|
441
491
|
});
|
442
492
|
input = screen.queryByRole('combobox');
|
443
493
|
userEvent.click(input);
|
444
|
-
|
494
|
+
_context4.next = 6;
|
445
495
|
return screen.findAllByRole('option');
|
446
496
|
|
447
497
|
case 6:
|
448
|
-
options =
|
498
|
+
options = _context4.sent;
|
449
499
|
userEvent.click(options[0]);
|
450
500
|
expect(input).toHaveValue(newItems[0].textValue); // Check that on clicking again "textValue" still returning
|
451
501
|
|
@@ -454,7 +504,7 @@ test('should show in input "textValue" if provided', /*#__PURE__*/_asyncToGenera
|
|
454
504
|
|
455
505
|
case 11:
|
456
506
|
case "end":
|
457
|
-
return
|
507
|
+
return _context4.stop();
|
458
508
|
}
|
459
509
|
}
|
460
510
|
}, _callee3);
|
@@ -777,25 +827,56 @@ test('onSelectionChange works properly with custom value', function () {
|
|
777
827
|
userEvent.type(input, '{selectall}{backspace}{enter}');
|
778
828
|
expect(onSelectionChange).toHaveBeenCalledWith('');
|
779
829
|
});
|
830
|
+
test('add option shows when "hasAddOption" is provided', function () {
|
831
|
+
render(___EmotionJSX(ComboBoxWithAddOption, null));
|
832
|
+
var input = screen.queryByRole('combobox');
|
833
|
+
expect(input).toHaveValue('');
|
834
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
835
|
+
expect(screen.queryByRole('option')).not.toBeInTheDocument();
|
836
|
+
var inputValue = 'New value';
|
837
|
+
userEvent.type(input, inputValue);
|
838
|
+
expect(input).toHaveValue(inputValue);
|
839
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
840
|
+
var option = screen.queryByRole('option');
|
841
|
+
expect(option).toBeInTheDocument();
|
842
|
+
expect(option).toHaveClass('is-focused');
|
843
|
+
expect(option).toHaveTextContent("ADD: ".concat(inputValue));
|
844
|
+
});
|
845
|
+
test('if "hasAddOption" is provided, then custom value is added to listbox on blur', function () {
|
846
|
+
render(___EmotionJSX(ComboBoxWithAddOption, null));
|
847
|
+
var input = screen.queryByRole('combobox');
|
848
|
+
var inputValue = 'New value';
|
849
|
+
userEvent.type(input, inputValue);
|
850
|
+
expect(input).toHaveValue(inputValue); // blur input
|
851
|
+
|
852
|
+
userEvent.tab();
|
853
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
854
|
+
expect(screen.queryByRole('option')).not.toBeInTheDocument();
|
855
|
+
userEvent.click(input);
|
856
|
+
expect(input).toHaveValue(inputValue);
|
857
|
+
expect(screen.queryByRole('listbox')).toBeInTheDocument();
|
858
|
+
var options = screen.queryAllByRole('option');
|
859
|
+
expect(options[options.length - 1]).toHaveTextContent(inputValue);
|
860
|
+
});
|
780
861
|
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
781
862
|
var _getComponent6, container, results;
|
782
863
|
|
783
|
-
return _regeneratorRuntime.wrap(function _callee4$(
|
864
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context5) {
|
784
865
|
while (1) {
|
785
|
-
switch (
|
866
|
+
switch (_context5.prev = _context5.next) {
|
786
867
|
case 0:
|
787
868
|
jest.useRealTimers();
|
788
869
|
_getComponent6 = getComponent(), container = _getComponent6.container;
|
789
|
-
|
870
|
+
_context5.next = 4;
|
790
871
|
return axe(container);
|
791
872
|
|
792
873
|
case 4:
|
793
|
-
results =
|
874
|
+
results = _context5.sent;
|
794
875
|
expect(results).toHaveNoViolations();
|
795
876
|
|
796
877
|
case 6:
|
797
878
|
case "end":
|
798
|
-
return
|
879
|
+
return _context5.stop();
|
799
880
|
}
|
800
881
|
}
|
801
882
|
}, _callee4);
|