@pingux/astro 2.242.1-alpha.0 → 2.243.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/BadgeLabelTooltip.d.ts +3 -0
- package/lib/cjs/components/MultivaluesField/BadgeLabelTooltip.js +3 -3
- package/lib/cjs/components/MultivaluesField/CondensedMultivaluesField.d.ts +4 -0
- package/lib/cjs/components/MultivaluesField/CondensedMultivaluesField.js +24 -132
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.d.ts +4 -0
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.js +33 -139
- package/lib/cjs/components/MultivaluesField/MultivaluesField.d.ts +4 -0
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +6 -104
- package/lib/cjs/components/MultivaluesField/index.d.ts +1 -0
- package/lib/cjs/components/RadioGroupField/RadioGroupField.js +1 -1
- package/lib/cjs/types/MultivaluesField.d.ts +212 -0
- package/lib/cjs/types/MultivaluesField.js +5 -0
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.js +11 -0
- package/lib/components/MultivaluesField/BadgeLabelTooltip.js +3 -3
- package/lib/components/MultivaluesField/CondensedMultivaluesField.js +24 -132
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +33 -139
- package/lib/components/MultivaluesField/MultivaluesField.js +7 -105
- package/lib/components/RadioGroupField/RadioGroupField.js +1 -1
- package/lib/types/MultivaluesField.js +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +2 -2
|
@@ -21,13 +21,13 @@ const BadgeLabelTooltip = ({
|
|
|
21
21
|
deleteItem,
|
|
22
22
|
closeBadgeRefs
|
|
23
23
|
}) => {
|
|
24
|
-
const isLong = item.name.length > BADGE_TOOLTIP_CHAR_THRESHOLD;
|
|
24
|
+
const isLong = (item.name || '').length > BADGE_TOOLTIP_CHAR_THRESHOLD;
|
|
25
25
|
const {
|
|
26
26
|
hoverProps,
|
|
27
27
|
isHovered
|
|
28
28
|
} = (0, _interactions.useHover)({});
|
|
29
29
|
const textProps = (0, _reactAria.mergeProps)(item.badgeProps?.textProps || {}, hoverProps);
|
|
30
|
-
const badgeRef = (0, _react.useRef)();
|
|
30
|
+
const badgeRef = (0, _react.useRef)(null);
|
|
31
31
|
return (0, _react2.jsx)(_.Box, {
|
|
32
32
|
as: "li"
|
|
33
33
|
}, (0, _react2.jsx)(_TooltipTrigger.default, {
|
|
@@ -47,7 +47,7 @@ const BadgeLabelTooltip = ({
|
|
|
47
47
|
}), (0, _react2.jsx)(_.IconButton, (0, _extends2.default)({
|
|
48
48
|
"aria-label": `delete ${item.name}`,
|
|
49
49
|
"data-item": item.name,
|
|
50
|
-
onPress: e => deleteItem(item.key, e),
|
|
50
|
+
onPress: e => item.key !== undefined && deleteItem(item.key, e),
|
|
51
51
|
ref: el => closeBadgeRefs.current[index] = el // eslint-disable-line
|
|
52
52
|
,
|
|
53
53
|
variant: "badge.deleteButton",
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { CondensedMultivaluesFieldProps } from '../../types/MultivaluesField';
|
|
3
|
+
declare const CondensedMultivaluesField: React.ForwardRefExoticComponent<CondensedMultivaluesFieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
export default CondensedMultivaluesField;
|
|
@@ -13,16 +13,12 @@ var _interactions = require("@react-aria/interactions");
|
|
|
13
13
|
var _utils = require("@react-aria/utils");
|
|
14
14
|
var _visuallyHidden = require("@react-aria/visually-hidden");
|
|
15
15
|
var _list = require("@react-stately/list");
|
|
16
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
16
|
var _ = require("../..");
|
|
18
17
|
var _MultivaluesContext = require("../../context/MultivaluesContext");
|
|
19
18
|
var _hooks = require("../../hooks");
|
|
20
19
|
var _loadingStates = _interopRequireDefault(require("../../utils/devUtils/constants/loadingStates"));
|
|
21
20
|
var _pendoID = require("../../utils/devUtils/constants/pendoID");
|
|
22
|
-
var
|
|
23
|
-
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
|
24
|
-
var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
|
25
|
-
var _statusProp = require("../../utils/docUtils/statusProp");
|
|
21
|
+
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
|
26
22
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
|
27
23
|
var _Popover = _interopRequireDefault(require("../Popover/Popover"));
|
|
28
24
|
var _react2 = require("@emotion/react");
|
|
@@ -30,7 +26,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
30
26
|
const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
31
27
|
const {
|
|
32
28
|
defaultSelectedKeys,
|
|
33
|
-
direction,
|
|
29
|
+
direction = 'bottom',
|
|
34
30
|
disabledKeys = [],
|
|
35
31
|
containerProps,
|
|
36
32
|
filter,
|
|
@@ -42,7 +38,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
42
38
|
isDisabled,
|
|
43
39
|
isFilteringDisabled,
|
|
44
40
|
isNotFlippable,
|
|
45
|
-
isReadOnly,
|
|
41
|
+
isReadOnly = false,
|
|
46
42
|
isRequired,
|
|
47
43
|
items,
|
|
48
44
|
label,
|
|
@@ -60,8 +56,10 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
60
56
|
placeholder,
|
|
61
57
|
selectedKeys,
|
|
62
58
|
selectedOptionText: selectedOptionTextProp,
|
|
63
|
-
scrollBoxProps
|
|
64
|
-
|
|
59
|
+
scrollBoxProps = {
|
|
60
|
+
maxHeight: 300
|
|
61
|
+
},
|
|
62
|
+
status = _statuses.default.DEFAULT,
|
|
65
63
|
...others
|
|
66
64
|
} = props;
|
|
67
65
|
(0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
|
|
@@ -69,9 +67,9 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
69
67
|
const [isOpen, setIsOpen] = (0, _react.useState)(false);
|
|
70
68
|
const [hasFocusWithin, setFocusWithin] = (0, _react.useState)(false);
|
|
71
69
|
const [activeDescendant, setActiveDescendant] = (0, _react.useState)('');
|
|
72
|
-
const inputWrapperRef = (0, _react.useRef)();
|
|
73
|
-
const inputRef = (0, _react.useRef)();
|
|
74
|
-
const buttonRef = (0, _react.useRef)();
|
|
70
|
+
const inputWrapperRef = (0, _react.useRef)(null);
|
|
71
|
+
const inputRef = (0, _react.useRef)(null);
|
|
72
|
+
const buttonRef = (0, _react.useRef)(null);
|
|
75
73
|
const {
|
|
76
74
|
icons,
|
|
77
75
|
themeState: {
|
|
@@ -141,8 +139,8 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
141
139
|
(0, _react.useImperativeHandle)(ref, () => inputWrapperRef.current);
|
|
142
140
|
/* istanbul ignore next */
|
|
143
141
|
(0, _react.useImperativeHandle)(ref, () => inputRef.current);
|
|
144
|
-
const listBoxRef = (0, _react.useRef)();
|
|
145
|
-
const popoverRef = (0, _react.useRef)();
|
|
142
|
+
const listBoxRef = (0, _react.useRef)(null);
|
|
143
|
+
const popoverRef = (0, _react.useRef)(null);
|
|
146
144
|
|
|
147
145
|
// Measure the width of the input to inform the width of the menu (below).
|
|
148
146
|
const [menuWidth, setMenuWidth] = (0, _react.useState)(null);
|
|
@@ -222,11 +220,15 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
222
220
|
setIsOpen(false);
|
|
223
221
|
};
|
|
224
222
|
const [selectionState, setSelectionState] = (0, _react.useState)('Select All');
|
|
225
|
-
const arrayItems =
|
|
223
|
+
const arrayItems = items || [];
|
|
226
224
|
const itemCount = arrayItems.reduce((count, obj) => count + (obj.children ? obj.children.length : 1), 0);
|
|
227
225
|
const selectedKeysSize = selectionManager.selectedKeys.size;
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
|
|
227
|
+
// `selectionManager.state` is private in the react-stately typings but is
|
|
228
|
+
// read throughout this component; the access is kept via a cast.
|
|
229
|
+
const selectionManagerState = selectionManager.state;
|
|
230
|
+
const selectedOptionText = selectedOptionTextProp || `${itemCount === selectedKeysSize ? 'All' : selectionManagerState.selectedKeys?.size} Selected`;
|
|
231
|
+
const checkboxSelected = selectionManagerState.selectedKeys?.size !== 0 && (0, _react2.jsx)(_.Text, {
|
|
230
232
|
color: "text.secondary"
|
|
231
233
|
}, selectedOptionText);
|
|
232
234
|
(0, _react.useEffect)(() => {
|
|
@@ -236,7 +238,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
236
238
|
}, [itemCount, selectedKeysSize]);
|
|
237
239
|
const handleSelection = () => {
|
|
238
240
|
if (selectedKeysSize < itemCount) {
|
|
239
|
-
const allItemNames = arrayItems.flatMap(obj => obj.children ? obj.children.map(child => child.key) : obj.key);
|
|
241
|
+
const allItemNames = arrayItems.flatMap(obj => obj.children ? obj.children.map(child => child.key) : obj.key).filter(key => key !== undefined);
|
|
240
242
|
selectionManager.setSelectedKeys(allItemNames);
|
|
241
243
|
setSelectionState('Deselect All');
|
|
242
244
|
} else if (selectionState === 'Deselect All') {
|
|
@@ -282,7 +284,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
282
284
|
id: "emptyKeysState"
|
|
283
285
|
}, "Nothing Selected");
|
|
284
286
|
};
|
|
285
|
-
const placeholderText =
|
|
287
|
+
const placeholderText = selectionManagerState.selectedKeys?.size === 0 ? placeholder || 'Select' : '';
|
|
286
288
|
const inputProps = {
|
|
287
289
|
...customInputProps,
|
|
288
290
|
controlProps: {
|
|
@@ -300,7 +302,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
300
302
|
isDisabled,
|
|
301
303
|
isReadOnly,
|
|
302
304
|
isRequired,
|
|
303
|
-
label,
|
|
305
|
+
label: label,
|
|
304
306
|
placeholder: placeholderText,
|
|
305
307
|
wrapperProps: {
|
|
306
308
|
ref: inputWrapperRef,
|
|
@@ -315,7 +317,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
315
317
|
const handleButtonPress = () => {
|
|
316
318
|
if (!isOpen) {
|
|
317
319
|
setIsOpen(true);
|
|
318
|
-
inputRef.current
|
|
320
|
+
inputRef.current?.focus();
|
|
319
321
|
} else {
|
|
320
322
|
setIsOpen(false);
|
|
321
323
|
}
|
|
@@ -375,7 +377,7 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
375
377
|
beforeInput: (0, _react2.jsx)(_react.default.Fragment, null, checkboxSelected, selectionManager.selectedKeys.size > 0 && visuallyHidden)
|
|
376
378
|
},
|
|
377
379
|
value: filterString,
|
|
378
|
-
helperText
|
|
380
|
+
helperText,
|
|
379
381
|
"aria-invalid": status === 'error' && true
|
|
380
382
|
}, (0, _pendoID.getPendoID)('MultivaluesField'), others, inputProps)), (0, _react2.jsx)(_Popover.default, {
|
|
381
383
|
hasNoArrow: true,
|
|
@@ -390,114 +392,4 @@ const CondensedMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, re
|
|
|
390
392
|
onBlur: e => handleBlur(e)
|
|
391
393
|
}, listbox), (0, _react2.jsx)(EmptyVisuallyHidden, null)));
|
|
392
394
|
});
|
|
393
|
-
CondensedMultivaluesField.propTypes = {
|
|
394
|
-
/** The initial selected keys in the collection (uncontrolled). */
|
|
395
|
-
defaultSelectedKeys: _isIterable.isIterableProp,
|
|
396
|
-
/** Where the menu opens relative to its trigger. */
|
|
397
|
-
direction: _propTypes.default.oneOf(['top', 'right', 'bottom', 'left']),
|
|
398
|
-
/**
|
|
399
|
-
* The item keys that are disabled. These items cannot be selected.
|
|
400
|
-
*/
|
|
401
|
-
disabledKeys: _isIterable.isIterableProp,
|
|
402
|
-
/** Whether the element should receive focus on render. */
|
|
403
|
-
hasAutoFocus: _propTypes.default.bool,
|
|
404
|
-
/** Whether the field has the select all button. */
|
|
405
|
-
hasNoSelectAll: _propTypes.default.bool,
|
|
406
|
-
/** Whether the field has a status indicator. */
|
|
407
|
-
hasNoStatusIndicator: _propTypes.default.bool,
|
|
408
|
-
/** Text rendered below the input. */
|
|
409
|
-
helperText: _propTypes.default.node,
|
|
410
|
-
/**
|
|
411
|
-
* Props that get passed as-is to the underlying TextField element
|
|
412
|
-
*/
|
|
413
|
-
inputProps: _propTypes.default.shape({}),
|
|
414
|
-
/** Whether the input is disabled. */
|
|
415
|
-
isDisabled: _propTypes.default.bool,
|
|
416
|
-
/**
|
|
417
|
-
* Whether the menu is prevented from flipping directions when insufficient space is
|
|
418
|
-
* available for the given `direction` placement.
|
|
419
|
-
*/
|
|
420
|
-
isNotFlippable: _propTypes.default.bool,
|
|
421
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
422
|
-
isReadOnly: _propTypes.default.bool,
|
|
423
|
-
/** Whether user input is required on the input before form submission. */
|
|
424
|
-
isRequired: _propTypes.default.bool,
|
|
425
|
-
/** The list of items.
|
|
426
|
-
*
|
|
427
|
-
* **Note:** Every item needs to have key and name properties.
|
|
428
|
-
*
|
|
429
|
-
* `Array<{key: string, name: string}>`
|
|
430
|
-
*/
|
|
431
|
-
items: _isIterable.isIterableProp,
|
|
432
|
-
/** The rendered label for the field. */
|
|
433
|
-
label: _propTypes.default.string,
|
|
434
|
-
/** Whether the component allows to create new values or only choose from the selection list */
|
|
435
|
-
mode: _propTypes.default.oneOf(['restrictive', 'non-restrictive', 'condensed']),
|
|
436
|
-
/**
|
|
437
|
-
* Handler that is called when the element loses focus.
|
|
438
|
-
*
|
|
439
|
-
* `(e: FocusEvent) => void`
|
|
440
|
-
*/
|
|
441
|
-
onBlur: _propTypes.default.func,
|
|
442
|
-
/**
|
|
443
|
-
* Handler that is called when the element receives focus.
|
|
444
|
-
*
|
|
445
|
-
* `(e: FocusEvent) => void`
|
|
446
|
-
*/
|
|
447
|
-
onFocus: _propTypes.default.func,
|
|
448
|
-
/**
|
|
449
|
-
* Handler that is called when the input value changes.
|
|
450
|
-
*
|
|
451
|
-
* `(value: string) => void`
|
|
452
|
-
*/
|
|
453
|
-
onInputChange: _propTypes.default.func,
|
|
454
|
-
/**
|
|
455
|
-
* Handler that is called when a key is pressed.
|
|
456
|
-
*
|
|
457
|
-
* `(e: KeyboardEvent) => void`
|
|
458
|
-
*/
|
|
459
|
-
onKeyDown: _propTypes.default.func,
|
|
460
|
-
/**
|
|
461
|
-
* Handler that is called when a key is released.
|
|
462
|
-
*
|
|
463
|
-
* `(e: KeyboardEvent) => void`
|
|
464
|
-
*/
|
|
465
|
-
onKeyUp: _propTypes.default.func,
|
|
466
|
-
/**
|
|
467
|
-
* Method that is called when the open state of the menu changes.
|
|
468
|
-
*
|
|
469
|
-
* `(isOpen: boolean) => void`
|
|
470
|
-
*/
|
|
471
|
-
onOpenChange: _propTypes.default.func,
|
|
472
|
-
/**
|
|
473
|
-
* Handler that is called when the selection changes.
|
|
474
|
-
*
|
|
475
|
-
* `(keys: Iterable<Key>) => any`
|
|
476
|
-
*/
|
|
477
|
-
onSelectionChange: _propTypes.default.func,
|
|
478
|
-
/** Temporary text that occupies the text input when it is empty. */
|
|
479
|
-
placeholder: _propTypes.default.string,
|
|
480
|
-
/**
|
|
481
|
-
* The item keys that are readonly. These items cannot be changed or selected.
|
|
482
|
-
*/
|
|
483
|
-
readOnlyKeys: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
484
|
-
/** The currently selected keys in the collection (controlled). */
|
|
485
|
-
selectedKeys: _isIterable.isIterableProp,
|
|
486
|
-
// /** Props object that is spread directly into the ScrollBox element. */
|
|
487
|
-
/** @ignore */
|
|
488
|
-
scrollBoxProps: _propTypes.default.shape({
|
|
489
|
-
maxHeight: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object, _propTypes.default.number])
|
|
490
|
-
}),
|
|
491
|
-
..._statusProp.statusPropTypes,
|
|
492
|
-
..._ariaAttributes.ariaAttributesBasePropTypes,
|
|
493
|
-
..._fieldAttributes.inputFieldAttributesBasePropTypes
|
|
494
|
-
};
|
|
495
|
-
CondensedMultivaluesField.defaultProps = {
|
|
496
|
-
direction: 'bottom',
|
|
497
|
-
isReadOnly: false,
|
|
498
|
-
scrollBoxProps: {
|
|
499
|
-
maxHeight: 300
|
|
500
|
-
},
|
|
501
|
-
..._statusProp.statusDefaultProp
|
|
502
|
-
};
|
|
503
395
|
var _default = exports.default = CondensedMultivaluesField;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DefaultMultivaluesFieldProps } from '../../types/MultivaluesField';
|
|
3
|
+
declare const DefaultMultivaluesField: React.ForwardRefExoticComponent<DefaultMultivaluesFieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
|
+
export default DefaultMultivaluesField;
|
|
@@ -12,16 +12,12 @@ var _i18n = require("@react-aria/i18n");
|
|
|
12
12
|
var _utils = require("@react-aria/utils");
|
|
13
13
|
var _visuallyHidden = require("@react-aria/visually-hidden");
|
|
14
14
|
var _list = require("@react-stately/list");
|
|
15
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
15
|
var _ = require("../..");
|
|
17
16
|
var _MultivaluesContext = require("../../context/MultivaluesContext");
|
|
18
17
|
var _hooks = require("../../hooks");
|
|
19
18
|
var _loadingStates = _interopRequireDefault(require("../../utils/devUtils/constants/loadingStates"));
|
|
20
19
|
var _pendoID = require("../../utils/devUtils/constants/pendoID");
|
|
21
|
-
var
|
|
22
|
-
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
|
23
|
-
var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
|
24
|
-
var _statusProp = require("../../utils/docUtils/statusProp");
|
|
20
|
+
var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/statuses"));
|
|
25
21
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
|
26
22
|
var _Popover = _interopRequireDefault(require("../Popover/Popover"));
|
|
27
23
|
var _BadgeLabelTooltip = _interopRequireDefault(require("./BadgeLabelTooltip"));
|
|
@@ -34,7 +30,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
34
30
|
} = props;
|
|
35
31
|
const {
|
|
36
32
|
defaultSelectedKeys,
|
|
37
|
-
direction,
|
|
33
|
+
direction = 'bottom',
|
|
38
34
|
disabledKeys = [],
|
|
39
35
|
containerProps,
|
|
40
36
|
hasAutoFocus,
|
|
@@ -44,7 +40,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
44
40
|
isDisabled,
|
|
45
41
|
isFilteringDisabled,
|
|
46
42
|
isNotFlippable,
|
|
47
|
-
isReadOnly,
|
|
43
|
+
isReadOnly = false,
|
|
48
44
|
isRequired,
|
|
49
45
|
label,
|
|
50
46
|
loadingState,
|
|
@@ -62,8 +58,10 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
62
58
|
placeholder,
|
|
63
59
|
readOnlyKeys = [],
|
|
64
60
|
selectedKeys,
|
|
65
|
-
scrollBoxProps
|
|
66
|
-
|
|
61
|
+
scrollBoxProps = {
|
|
62
|
+
maxHeight: 300
|
|
63
|
+
},
|
|
64
|
+
status = _statuses.default.DEFAULT,
|
|
67
65
|
...others
|
|
68
66
|
} = otherProps;
|
|
69
67
|
const hasCustomValue = mode === 'non-restrictive';
|
|
@@ -85,7 +83,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
85
83
|
}
|
|
86
84
|
}, [initialItems, mode]);
|
|
87
85
|
const toggleItems = keys => {
|
|
88
|
-
setItems(initialItems.filter(item => !Array.from(keys).includes(item.key)));
|
|
86
|
+
setItems((initialItems || []).filter(item => !Array.from(keys).includes(item.key)));
|
|
89
87
|
if (onSelectionChange) onSelectionChange(keys);
|
|
90
88
|
// Selecting an option removes it from the list, unmounting its row while
|
|
91
89
|
// focusedKey still points at it — the virtualizer then holds DOM focus on
|
|
@@ -106,7 +104,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
106
104
|
};
|
|
107
105
|
const state = (0, _list.useListState)({
|
|
108
106
|
...otherProps,
|
|
109
|
-
items: items.filter(({
|
|
107
|
+
items: (items || []).filter(({
|
|
110
108
|
key
|
|
111
109
|
}) => !readOnlyKeys.includes(key)),
|
|
112
110
|
onSelectionChange: toggleItems,
|
|
@@ -118,6 +116,10 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
118
116
|
const {
|
|
119
117
|
selectionManager
|
|
120
118
|
} = state;
|
|
119
|
+
|
|
120
|
+
// `selectionManager.state` is private in the react-stately typings but is
|
|
121
|
+
// read throughout this component; the access is kept via a cast.
|
|
122
|
+
const selectionManagerState = selectionManager.state;
|
|
121
123
|
const filteredItems = (0, _react.useMemo)(() => Array.from(state.collection), [state.collection, filterString]);
|
|
122
124
|
const close = () => setIsOpen(false);
|
|
123
125
|
const {
|
|
@@ -127,13 +129,13 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
127
129
|
inputValue: filterString
|
|
128
130
|
});
|
|
129
131
|
const closeBadgeRefs = (0, _react.useRef)([]);
|
|
130
|
-
const inputWrapperRef = (0, _react.useRef)();
|
|
131
|
-
const inputRef = (0, _react.useRef)();
|
|
132
|
+
const inputWrapperRef = (0, _react.useRef)(null);
|
|
133
|
+
const inputRef = (0, _react.useRef)(null);
|
|
132
134
|
/* istanbul ignore next */
|
|
133
135
|
(0, _react.useImperativeHandle)(ref, () => inputWrapperRef.current);
|
|
134
136
|
(0, _react.useImperativeHandle)(ref, () => inputRef.current);
|
|
135
|
-
const listBoxRef = (0, _react.useRef)();
|
|
136
|
-
const popoverRef = (0, _react.useRef)();
|
|
137
|
+
const listBoxRef = (0, _react.useRef)(null);
|
|
138
|
+
const popoverRef = (0, _react.useRef)(null);
|
|
137
139
|
|
|
138
140
|
// Measure the width of the input to inform the width of the menu (below).
|
|
139
141
|
const [menuWidth, setMenuWidth] = (0, _react.useState)(null);
|
|
@@ -159,13 +161,13 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
159
161
|
(0, _react.useEffect)(() => {
|
|
160
162
|
if (defaultSelectedKeys) {
|
|
161
163
|
selectionManager.setSelectedKeys(defaultSelectedKeys);
|
|
162
|
-
setItems(prevItems => prevItems.filter(item => !Array.from(defaultSelectedKeys).includes(item.key)));
|
|
164
|
+
setItems(prevItems => (prevItems || []).filter(item => !Array.from(defaultSelectedKeys).includes(item.key)));
|
|
163
165
|
}
|
|
164
166
|
}, []);
|
|
165
167
|
(0, _react.useEffect)(() => {
|
|
166
168
|
if (selectedKeys) {
|
|
167
169
|
selectionManager.setSelectedKeys(selectedKeys);
|
|
168
|
-
setItems(prevItems => prevItems.filter(item => !Array.from(selectedKeys).includes(item.key)));
|
|
170
|
+
setItems(prevItems => (prevItems || []).filter(item => !Array.from(selectedKeys).includes(item.key)));
|
|
169
171
|
}
|
|
170
172
|
}, []);
|
|
171
173
|
(0, _react.useEffect)(() => {
|
|
@@ -180,7 +182,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
180
182
|
if (state.selectionManager.isSelected(key)) {
|
|
181
183
|
return;
|
|
182
184
|
}
|
|
183
|
-
selectionManager.setSelectedKeys([].concat(Array.from(
|
|
185
|
+
selectionManager.setSelectedKeys([].concat(Array.from(selectionManagerState.selectedKeys), [key]));
|
|
184
186
|
setCustomItems([].concat(customItems, [{
|
|
185
187
|
id: key,
|
|
186
188
|
key,
|
|
@@ -269,9 +271,9 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
269
271
|
if (activeBadgesKeys.length > 1) {
|
|
270
272
|
const badgeIndex = activeBadgesKeys.findIndex(item => item === key);
|
|
271
273
|
const nextFocusBadgeIndex = badgeIndex === activeBadgesKeys.length - 1 ? badgeIndex - 1 : badgeIndex;
|
|
272
|
-
closeBadgeRefs.current[nextFocusBadgeIndex]
|
|
274
|
+
closeBadgeRefs.current[nextFocusBadgeIndex]?.focus();
|
|
273
275
|
} else {
|
|
274
|
-
inputRef.current
|
|
276
|
+
inputRef.current?.focus();
|
|
275
277
|
}
|
|
276
278
|
};
|
|
277
279
|
const readOnlyFieldBadge = (key, name) => {
|
|
@@ -300,28 +302,28 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
300
302
|
}, name);
|
|
301
303
|
};
|
|
302
304
|
const readOnlyInputEntry = isReadOnly && (readOnlyKeys.length ? readOnlyKeys.map(key => {
|
|
303
|
-
const item = [].concat(initialItems, customItems).find(el => el.key === key);
|
|
305
|
+
const item = [].concat(initialItems || [], customItems).find(el => el.key === key);
|
|
304
306
|
if (item) {
|
|
305
|
-
return readOnlyTextItem(item.key, item.name);
|
|
307
|
+
return item.key !== undefined && readOnlyTextItem(item.key, item.name);
|
|
306
308
|
}
|
|
307
309
|
return null;
|
|
308
|
-
}) : initialItems.map(item => {
|
|
309
|
-
return readOnlyTextItem(item.key, item.name);
|
|
310
|
+
}) : (initialItems || []).map(item => {
|
|
311
|
+
return item.key !== undefined && readOnlyTextItem(item.key, item.name);
|
|
310
312
|
}));
|
|
311
313
|
const onyxReadOnlyInputEntry = isReadOnly && (0, _react2.jsx)(_.Box, {
|
|
312
314
|
isRow: true,
|
|
313
315
|
gap: "xs"
|
|
314
|
-
}, initialItems.map(item => {
|
|
315
|
-
return readOnlyFieldBadge(item.key, item.name);
|
|
316
|
+
}, (initialItems || []).map(item => {
|
|
317
|
+
return item.key !== undefined && readOnlyFieldBadge(item.key, item.name || '');
|
|
316
318
|
}));
|
|
317
319
|
const readOnlyItems = !isReadOnly && readOnlyKeys.map(key => {
|
|
318
|
-
const item = initialItems.find(el => el.key === key);
|
|
320
|
+
const item = (initialItems || []).find(el => el.key === key);
|
|
319
321
|
if (item) {
|
|
320
322
|
return (0, _react2.jsx)(_.Badge, {
|
|
321
323
|
key: item.key,
|
|
322
324
|
label: item.name,
|
|
323
325
|
variant: "readOnlyBadge",
|
|
324
|
-
as:
|
|
326
|
+
as: 'li',
|
|
325
327
|
tabIndex: 0
|
|
326
328
|
});
|
|
327
329
|
}
|
|
@@ -335,7 +337,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
335
337
|
closeBadgeRefs: closeBadgeRefs
|
|
336
338
|
});
|
|
337
339
|
const selectedItems = (0, _react2.jsx)(_react.default.Fragment, null, Array.from(selectionManager.selectedKeys).map((key, i) => {
|
|
338
|
-
const item = [].concat(initialItems, customItems).find(el => el.key === key);
|
|
340
|
+
const item = [].concat(initialItems || [], customItems).find(el => el.key === key);
|
|
339
341
|
if (item) {
|
|
340
342
|
return multivaluesFieldBadge(item, i);
|
|
341
343
|
}
|
|
@@ -399,7 +401,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
399
401
|
isDisabled,
|
|
400
402
|
isReadOnly,
|
|
401
403
|
isRequired,
|
|
402
|
-
label,
|
|
404
|
+
label: label,
|
|
403
405
|
placeholder,
|
|
404
406
|
wrapperProps: {
|
|
405
407
|
ref: inputWrapperRef,
|
|
@@ -456,7 +458,7 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
456
458
|
}, selectedItems), isOnyx ? onyxReadOnlyInputEntry : readOnlyInputEntry, selectionManager.selectedKeys.size > 0 && visuallyHidden)
|
|
457
459
|
},
|
|
458
460
|
value: filterString,
|
|
459
|
-
helperText
|
|
461
|
+
helperText,
|
|
460
462
|
"aria-invalid": status === 'error' && true
|
|
461
463
|
}, (0, _pendoID.getPendoID)('MultivaluesField'), others, inputProps)), (0, _react2.jsx)(_Popover.default, {
|
|
462
464
|
hasNoArrow: true,
|
|
@@ -470,112 +472,4 @@ const DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)((props, ref)
|
|
|
470
472
|
sx: menuWidthSx
|
|
471
473
|
}, listbox), (0, _react2.jsx)(EmptyVisuallyHidden, null)));
|
|
472
474
|
});
|
|
473
|
-
DefaultMultivaluesField.propTypes = {
|
|
474
|
-
/** The initial selected keys in the collection (uncontrolled). */
|
|
475
|
-
defaultSelectedKeys: _isIterable.isIterableProp,
|
|
476
|
-
/** Where the menu opens relative to its trigger. */
|
|
477
|
-
direction: _propTypes.default.oneOf(['top', 'right', 'bottom', 'left']),
|
|
478
|
-
/**
|
|
479
|
-
* The item keys that are disabled. These items cannot be selected.
|
|
480
|
-
*/
|
|
481
|
-
disabledKeys: _isIterable.isIterableProp,
|
|
482
|
-
/** Whether the element should receive focus on render. */
|
|
483
|
-
hasAutoFocus: _propTypes.default.bool,
|
|
484
|
-
/** Whether the field has a status indicator. */
|
|
485
|
-
hasNoStatusIndicator: _propTypes.default.bool,
|
|
486
|
-
/** Text rendered below the input. */
|
|
487
|
-
helperText: _propTypes.default.node,
|
|
488
|
-
/**
|
|
489
|
-
* Props that get passed as-is to the underlying TextField element
|
|
490
|
-
*/
|
|
491
|
-
inputProps: _propTypes.default.shape({}),
|
|
492
|
-
/** Whether the input is disabled. */
|
|
493
|
-
isDisabled: _propTypes.default.bool,
|
|
494
|
-
/**
|
|
495
|
-
* Whether the menu is prevented from flipping directions when insufficient space is
|
|
496
|
-
* available for the given `direction` placement.
|
|
497
|
-
*/
|
|
498
|
-
isNotFlippable: _propTypes.default.bool,
|
|
499
|
-
/** Whether the input can be selected but not changed by the user. */
|
|
500
|
-
isReadOnly: _propTypes.default.bool,
|
|
501
|
-
/** Whether user input is required on the input before form submission. */
|
|
502
|
-
isRequired: _propTypes.default.bool,
|
|
503
|
-
/** The list of items.
|
|
504
|
-
*
|
|
505
|
-
* **Note:** Every item needs to have key and name properties.
|
|
506
|
-
*
|
|
507
|
-
* `Array<{key: string, name: string}>`
|
|
508
|
-
*/
|
|
509
|
-
items: _isIterable.isIterableProp,
|
|
510
|
-
/** The rendered label for the field. */
|
|
511
|
-
label: _propTypes.default.string,
|
|
512
|
-
/** Whether the component allows to create new values or only choose from the selection list */
|
|
513
|
-
mode: _propTypes.default.oneOf(['restrictive', 'non-restrictive']),
|
|
514
|
-
/**
|
|
515
|
-
* Handler that is called when the element loses focus.
|
|
516
|
-
*
|
|
517
|
-
* `(e: FocusEvent) => void`
|
|
518
|
-
*/
|
|
519
|
-
onBlur: _propTypes.default.func,
|
|
520
|
-
/**
|
|
521
|
-
* Handler that is called when the element receives focus.
|
|
522
|
-
*
|
|
523
|
-
* `(e: FocusEvent) => void`
|
|
524
|
-
*/
|
|
525
|
-
onFocus: _propTypes.default.func,
|
|
526
|
-
/**
|
|
527
|
-
* Handler that is called when the input value changes.
|
|
528
|
-
*
|
|
529
|
-
* `(value: string) => void`
|
|
530
|
-
*/
|
|
531
|
-
onInputChange: _propTypes.default.func,
|
|
532
|
-
/**
|
|
533
|
-
* Handler that is called when a key is pressed.
|
|
534
|
-
*
|
|
535
|
-
* `(e: KeyboardEvent) => void`
|
|
536
|
-
*/
|
|
537
|
-
onKeyDown: _propTypes.default.func,
|
|
538
|
-
/**
|
|
539
|
-
* Handler that is called when a key is released.
|
|
540
|
-
*
|
|
541
|
-
* `(e: KeyboardEvent) => void`
|
|
542
|
-
*/
|
|
543
|
-
onKeyUp: _propTypes.default.func,
|
|
544
|
-
/**
|
|
545
|
-
* Method that is called when the open state of the menu changes.
|
|
546
|
-
*
|
|
547
|
-
* `(isOpen: boolean) => void`
|
|
548
|
-
*/
|
|
549
|
-
onOpenChange: _propTypes.default.func,
|
|
550
|
-
/**
|
|
551
|
-
* Handler that is called when the selection changes.
|
|
552
|
-
*
|
|
553
|
-
* `(keys: Iterable<Key>) => any`
|
|
554
|
-
*/
|
|
555
|
-
onSelectionChange: _propTypes.default.func,
|
|
556
|
-
/** Temporary text that occupies the text input when it is empty. */
|
|
557
|
-
placeholder: _propTypes.default.string,
|
|
558
|
-
/**
|
|
559
|
-
* The item keys that are readonly. These items cannot be changed or selected.
|
|
560
|
-
*/
|
|
561
|
-
readOnlyKeys: _propTypes.default.arrayOf(_propTypes.default.string),
|
|
562
|
-
/** The currently selected keys in the collection (controlled). */
|
|
563
|
-
selectedKeys: _isIterable.isIterableProp,
|
|
564
|
-
// /** Props object that is spread directly into the ScrollBox element. */
|
|
565
|
-
/** @ignore */
|
|
566
|
-
scrollBoxProps: _propTypes.default.shape({
|
|
567
|
-
maxHeight: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object, _propTypes.default.number])
|
|
568
|
-
}),
|
|
569
|
-
..._statusProp.statusPropTypes,
|
|
570
|
-
..._ariaAttributes.ariaAttributesBasePropTypes,
|
|
571
|
-
..._fieldAttributes.inputFieldAttributesBasePropTypes
|
|
572
|
-
};
|
|
573
|
-
DefaultMultivaluesField.defaultProps = {
|
|
574
|
-
direction: 'bottom',
|
|
575
|
-
isReadOnly: false,
|
|
576
|
-
scrollBoxProps: {
|
|
577
|
-
maxHeight: 300
|
|
578
|
-
},
|
|
579
|
-
..._statusProp.statusDefaultProp
|
|
580
|
-
};
|
|
581
475
|
var _default = exports.default = DefaultMultivaluesField;
|