@pingux/astro 2.118.0 → 2.118.1-alpha.1
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/DefaultMultivaluesField.js +54 -43
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +26 -0
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +54 -43
- package/lib/components/MultivaluesField/MultivaluesField.test.js +26 -0
- package/package.json +1 -1
@@ -47,46 +47,48 @@ var _fieldAttributes = require("../../utils/docUtils/fieldAttributes");
|
|
47
47
|
var _statusProp = require("../../utils/docUtils/statusProp");
|
48
48
|
var _ListBox = _interopRequireDefault(require("../ListBox"));
|
49
49
|
var _react2 = require("@emotion/react");
|
50
|
-
var _excluded = ["
|
50
|
+
var _excluded = ["items"],
|
51
|
+
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
51
52
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
52
53
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
53
54
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty2(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
54
55
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context11, _context12; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context11 = ownKeys(Object(source), !0)).call(_context11, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
55
56
|
var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
56
|
-
var _context8, _listBoxRef$
|
57
|
-
var
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
57
|
+
var _context8, _listBoxRef$current2;
|
58
|
+
var initialItems = props.items,
|
59
|
+
otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
60
|
+
var defaultSelectedKeys = otherProps.defaultSelectedKeys,
|
61
|
+
direction = otherProps.direction,
|
62
|
+
_otherProps$disabledK = otherProps.disabledKeys,
|
63
|
+
disabledKeys = _otherProps$disabledK === void 0 ? [] : _otherProps$disabledK,
|
64
|
+
containerProps = otherProps.containerProps,
|
65
|
+
hasAutoFocus = otherProps.hasAutoFocus,
|
66
|
+
hasNoStatusIndicator = otherProps.hasNoStatusIndicator,
|
67
|
+
helperText = otherProps.helperText,
|
68
|
+
customInputProps = otherProps.inputProps,
|
69
|
+
isDisabled = otherProps.isDisabled,
|
70
|
+
isNotFlippable = otherProps.isNotFlippable,
|
71
|
+
isReadOnly = otherProps.isReadOnly,
|
72
|
+
isRequired = otherProps.isRequired,
|
73
|
+
label = otherProps.label,
|
74
|
+
loadingState = otherProps.loadingState,
|
75
|
+
mode = otherProps.mode,
|
76
|
+
onBlur = otherProps.onBlur,
|
77
|
+
_onFocus = otherProps.onFocus,
|
78
|
+
onInputChange = otherProps.onInputChange,
|
79
|
+
onKeyDown = otherProps.onKeyDown,
|
80
|
+
_onKeyUp = otherProps.onKeyUp,
|
81
|
+
onLoadMore = otherProps.onLoadMore,
|
82
|
+
onLoadPrev = otherProps.onLoadPrev,
|
83
|
+
onOpenChange = otherProps.onOpenChange,
|
84
|
+
onSelectionChange = otherProps.onSelectionChange,
|
85
|
+
placeholder = otherProps.placeholder,
|
86
|
+
_otherProps$readOnlyK = otherProps.readOnlyKeys,
|
87
|
+
readOnlyKeys = _otherProps$readOnlyK === void 0 ? [] : _otherProps$readOnlyK,
|
88
|
+
selectedKeys = otherProps.selectedKeys,
|
89
|
+
scrollBoxProps = otherProps.scrollBoxProps,
|
90
|
+
status = otherProps.status,
|
91
|
+
others = (0, _objectWithoutProperties2["default"])(otherProps, _excluded2);
|
90
92
|
var hasCustomValue = mode === 'non-restrictive';
|
91
93
|
(0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
|
92
94
|
var _useState = (0, _react.useState)([]),
|
@@ -126,7 +128,7 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
126
128
|
sensitivity: 'base'
|
127
129
|
}),
|
128
130
|
contains = _useFilter.contains;
|
129
|
-
var state = (0, _list.useListState)(_objectSpread(_objectSpread({},
|
131
|
+
var state = (0, _list.useListState)(_objectSpread(_objectSpread({}, otherProps), {}, {
|
130
132
|
filter: function filter(nodes) {
|
131
133
|
var _context2;
|
132
134
|
return (0, _filter["default"])(_context2 = (0, _from["default"])(nodes)).call(_context2, function (item) {
|
@@ -440,10 +442,24 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
440
442
|
id: "emptyKeysState"
|
441
443
|
}, "Nothing Selected");
|
442
444
|
};
|
445
|
+
var handleBlur = function handleBlur(e) {
|
446
|
+
var _inputWrapperRef$curr, _listBoxRef$current;
|
447
|
+
var relatedTarget = e.relatedTarget || document.activeElement;
|
448
|
+
|
449
|
+
// Relates to [UIP-7515] to check if the
|
450
|
+
// focused element is inside the listbox or input wrapper
|
451
|
+
if ((_inputWrapperRef$curr = inputWrapperRef.current) !== null && _inputWrapperRef$curr !== void 0 && _inputWrapperRef$curr.contains(relatedTarget) || (_listBoxRef$current = listBoxRef.current) !== null && _listBoxRef$current !== void 0 && _listBoxRef$current.contains(relatedTarget)) {
|
452
|
+
return;
|
453
|
+
}
|
454
|
+
setIsOpen(false);
|
455
|
+
if (filterString !== '') onBlurTextField();
|
456
|
+
if (onBlur) onBlur(e.nativeEvent);
|
457
|
+
if (!hasCustomValue) setFilterString('');
|
458
|
+
};
|
443
459
|
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
444
460
|
controlProps: {
|
445
461
|
'aria-activedescendant': activeDescendant,
|
446
|
-
'aria-controls': (_listBoxRef$
|
462
|
+
'aria-controls': (_listBoxRef$current2 = listBoxRef.current) === null || _listBoxRef$current2 === void 0 ? void 0 : _listBoxRef$current2.id,
|
447
463
|
'aria-expanded': isOpen,
|
448
464
|
role: 'combobox',
|
449
465
|
ref: inputRef
|
@@ -468,12 +484,7 @@ var DefaultMultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (prop
|
|
468
484
|
return (0, _react2.jsx)(_MultivaluesContext.MultivaluesContext.Provider, {
|
469
485
|
value: setActiveDescendant
|
470
486
|
}, (0, _react2.jsx)(_.Box, containerProps, (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
471
|
-
onBlur:
|
472
|
-
setIsOpen(false);
|
473
|
-
if (filterString !== '') onBlurTextField();
|
474
|
-
if (_onBlur) _onBlur(e.nativeEvent);
|
475
|
-
if (!hasCustomValue) setFilterString('');
|
476
|
-
},
|
487
|
+
onBlur: handleBlur,
|
477
488
|
onChange: function onChange(e) {
|
478
489
|
if (!isOpen) setIsOpen(true);
|
479
490
|
setFilterString(e.target.value);
|
@@ -245,6 +245,32 @@ test('closes listbox on blur and fires "onBlur"', function () {
|
|
245
245
|
expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
|
246
246
|
expect(onBlur).toBeCalled();
|
247
247
|
});
|
248
|
+
it('should not close the dropdown if focus moves within the input wrapper or listbox', function () {
|
249
|
+
getComponent();
|
250
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
251
|
+
_testWrapper.fireEvent.focus(input);
|
252
|
+
var listbox = _testWrapper.screen.queryByRole('listbox');
|
253
|
+
expect(listbox).toBeInTheDocument();
|
254
|
+
_testWrapper.fireEvent.blur(input, {
|
255
|
+
relatedTarget: input
|
256
|
+
});
|
257
|
+
expect(listbox).toBeInTheDocument();
|
258
|
+
_testWrapper.fireEvent.blur(input, {
|
259
|
+
relatedTarget: listbox
|
260
|
+
});
|
261
|
+
expect(listbox).toBeInTheDocument();
|
262
|
+
});
|
263
|
+
it('should close the dropdown if focus moves outside the input wrapper and listbox', function () {
|
264
|
+
getComponent();
|
265
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
266
|
+
_testWrapper.fireEvent.focus(input);
|
267
|
+
var listbox = _testWrapper.screen.queryByRole('listbox');
|
268
|
+
expect(listbox).toBeInTheDocument();
|
269
|
+
_testWrapper.fireEvent.blur(input, {
|
270
|
+
relatedTarget: document.body
|
271
|
+
});
|
272
|
+
expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
|
273
|
+
});
|
248
274
|
test('opening and closing listbox fires "onOpenChange"', function () {
|
249
275
|
var onOpenChange = jest.fn();
|
250
276
|
getComponent({
|
@@ -9,7 +9,8 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["
|
12
|
+
var _excluded = ["items"],
|
13
|
+
_excluded2 = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "label", "loadingState", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onLoadMore", "onLoadPrev", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
13
14
|
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; }
|
14
15
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context11, _context12; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context11 = ownKeys(Object(source), !0)).call(_context11, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context12 = ownKeys(Object(source))).call(_context12, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
16
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
@@ -41,40 +42,41 @@ import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusP
|
|
41
42
|
import ListBox from '../ListBox';
|
42
43
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
43
44
|
var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
44
|
-
var _context8, _listBoxRef$
|
45
|
-
var
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
45
|
+
var _context8, _listBoxRef$current2;
|
46
|
+
var initialItems = props.items,
|
47
|
+
otherProps = _objectWithoutProperties(props, _excluded);
|
48
|
+
var defaultSelectedKeys = otherProps.defaultSelectedKeys,
|
49
|
+
direction = otherProps.direction,
|
50
|
+
_otherProps$disabledK = otherProps.disabledKeys,
|
51
|
+
disabledKeys = _otherProps$disabledK === void 0 ? [] : _otherProps$disabledK,
|
52
|
+
containerProps = otherProps.containerProps,
|
53
|
+
hasAutoFocus = otherProps.hasAutoFocus,
|
54
|
+
hasNoStatusIndicator = otherProps.hasNoStatusIndicator,
|
55
|
+
helperText = otherProps.helperText,
|
56
|
+
customInputProps = otherProps.inputProps,
|
57
|
+
isDisabled = otherProps.isDisabled,
|
58
|
+
isNotFlippable = otherProps.isNotFlippable,
|
59
|
+
isReadOnly = otherProps.isReadOnly,
|
60
|
+
isRequired = otherProps.isRequired,
|
61
|
+
label = otherProps.label,
|
62
|
+
loadingState = otherProps.loadingState,
|
63
|
+
mode = otherProps.mode,
|
64
|
+
onBlur = otherProps.onBlur,
|
65
|
+
_onFocus = otherProps.onFocus,
|
66
|
+
onInputChange = otherProps.onInputChange,
|
67
|
+
onKeyDown = otherProps.onKeyDown,
|
68
|
+
_onKeyUp = otherProps.onKeyUp,
|
69
|
+
onLoadMore = otherProps.onLoadMore,
|
70
|
+
onLoadPrev = otherProps.onLoadPrev,
|
71
|
+
onOpenChange = otherProps.onOpenChange,
|
72
|
+
onSelectionChange = otherProps.onSelectionChange,
|
73
|
+
placeholder = otherProps.placeholder,
|
74
|
+
_otherProps$readOnlyK = otherProps.readOnlyKeys,
|
75
|
+
readOnlyKeys = _otherProps$readOnlyK === void 0 ? [] : _otherProps$readOnlyK,
|
76
|
+
selectedKeys = otherProps.selectedKeys,
|
77
|
+
scrollBoxProps = otherProps.scrollBoxProps,
|
78
|
+
status = otherProps.status,
|
79
|
+
others = _objectWithoutProperties(otherProps, _excluded2);
|
78
80
|
var hasCustomValue = mode === 'non-restrictive';
|
79
81
|
usePropWarning(props, 'disabled', 'isDisabled');
|
80
82
|
var _useState = useState([]),
|
@@ -114,7 +116,7 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
114
116
|
sensitivity: 'base'
|
115
117
|
}),
|
116
118
|
contains = _useFilter.contains;
|
117
|
-
var state = useListState(_objectSpread(_objectSpread({},
|
119
|
+
var state = useListState(_objectSpread(_objectSpread({}, otherProps), {}, {
|
118
120
|
filter: function filter(nodes) {
|
119
121
|
var _context2;
|
120
122
|
return _filterInstanceProperty(_context2 = _Array$from(nodes)).call(_context2, function (item) {
|
@@ -428,10 +430,24 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
428
430
|
id: "emptyKeysState"
|
429
431
|
}, "Nothing Selected");
|
430
432
|
};
|
433
|
+
var handleBlur = function handleBlur(e) {
|
434
|
+
var _inputWrapperRef$curr, _listBoxRef$current;
|
435
|
+
var relatedTarget = e.relatedTarget || document.activeElement;
|
436
|
+
|
437
|
+
// Relates to [UIP-7515] to check if the
|
438
|
+
// focused element is inside the listbox or input wrapper
|
439
|
+
if ((_inputWrapperRef$curr = inputWrapperRef.current) !== null && _inputWrapperRef$curr !== void 0 && _inputWrapperRef$curr.contains(relatedTarget) || (_listBoxRef$current = listBoxRef.current) !== null && _listBoxRef$current !== void 0 && _listBoxRef$current.contains(relatedTarget)) {
|
440
|
+
return;
|
441
|
+
}
|
442
|
+
setIsOpen(false);
|
443
|
+
if (filterString !== '') onBlurTextField();
|
444
|
+
if (onBlur) onBlur(e.nativeEvent);
|
445
|
+
if (!hasCustomValue) setFilterString('');
|
446
|
+
};
|
431
447
|
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
432
448
|
controlProps: {
|
433
449
|
'aria-activedescendant': activeDescendant,
|
434
|
-
'aria-controls': (_listBoxRef$
|
450
|
+
'aria-controls': (_listBoxRef$current2 = listBoxRef.current) === null || _listBoxRef$current2 === void 0 ? void 0 : _listBoxRef$current2.id,
|
435
451
|
'aria-expanded': isOpen,
|
436
452
|
role: 'combobox',
|
437
453
|
ref: inputRef
|
@@ -456,12 +472,7 @@ var DefaultMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
456
472
|
return ___EmotionJSX(MultivaluesContext.Provider, {
|
457
473
|
value: setActiveDescendant
|
458
474
|
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
459
|
-
onBlur:
|
460
|
-
setIsOpen(false);
|
461
|
-
if (filterString !== '') onBlurTextField();
|
462
|
-
if (_onBlur) _onBlur(e.nativeEvent);
|
463
|
-
if (!hasCustomValue) setFilterString('');
|
464
|
-
},
|
475
|
+
onBlur: handleBlur,
|
465
476
|
onChange: function onChange(e) {
|
466
477
|
if (!isOpen) setIsOpen(true);
|
467
478
|
setFilterString(e.target.value);
|
@@ -237,6 +237,32 @@ test('closes listbox on blur and fires "onBlur"', function () {
|
|
237
237
|
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
238
238
|
expect(onBlur).toBeCalled();
|
239
239
|
});
|
240
|
+
it('should not close the dropdown if focus moves within the input wrapper or listbox', function () {
|
241
|
+
getComponent();
|
242
|
+
var input = screen.getByRole('combobox');
|
243
|
+
fireEvent.focus(input);
|
244
|
+
var listbox = screen.queryByRole('listbox');
|
245
|
+
expect(listbox).toBeInTheDocument();
|
246
|
+
fireEvent.blur(input, {
|
247
|
+
relatedTarget: input
|
248
|
+
});
|
249
|
+
expect(listbox).toBeInTheDocument();
|
250
|
+
fireEvent.blur(input, {
|
251
|
+
relatedTarget: listbox
|
252
|
+
});
|
253
|
+
expect(listbox).toBeInTheDocument();
|
254
|
+
});
|
255
|
+
it('should close the dropdown if focus moves outside the input wrapper and listbox', function () {
|
256
|
+
getComponent();
|
257
|
+
var input = screen.getByRole('combobox');
|
258
|
+
fireEvent.focus(input);
|
259
|
+
var listbox = screen.queryByRole('listbox');
|
260
|
+
expect(listbox).toBeInTheDocument();
|
261
|
+
fireEvent.blur(input, {
|
262
|
+
relatedTarget: document.body
|
263
|
+
});
|
264
|
+
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
|
265
|
+
});
|
240
266
|
test('opening and closing listbox fires "onOpenChange"', function () {
|
241
267
|
var onOpenChange = jest.fn();
|
242
268
|
getComponent({
|