@pingux/astro 2.5.3-alpha.0 → 2.5.3-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/ListBox/Option.js +7 -0
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +12 -3
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +14 -0
- package/lib/cjs/context/MultivaluesContext/index.js +14 -0
- package/lib/components/ListBox/Option.js +8 -1
- package/lib/components/MultivaluesField/MultivaluesField.js +12 -3
- package/lib/components/MultivaluesField/MultivaluesField.test.js +15 -1
- package/lib/context/MultivaluesContext/index.js +5 -0
- package/package.json +1 -1
@@ -22,6 +22,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
22
22
|
var _listbox = require("@react-aria/listbox");
|
23
23
|
var _CircleSmallIcon = _interopRequireDefault(require("mdi-react/CircleSmallIcon"));
|
24
24
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
25
|
+
var _MultivaluesContext = require("../../context/MultivaluesContext");
|
25
26
|
var _hooks = require("../../hooks");
|
26
27
|
var _isIterable = require("../../utils/devUtils/props/isIterable");
|
27
28
|
var _Box = _interopRequireDefault(require("../Box"));
|
@@ -74,6 +75,12 @@ var Option = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
74
75
|
isSelected: isSelected
|
75
76
|
}),
|
76
77
|
classNames = _useStatusClasses.classNames;
|
78
|
+
var updateActiveDescendant = (0, _MultivaluesContext.useMultivaluesContext)();
|
79
|
+
(0, _react.useEffect)(function () {
|
80
|
+
if (isFocused && updateActiveDescendant) {
|
81
|
+
updateActiveDescendant(optionProps.id);
|
82
|
+
}
|
83
|
+
}, [isFocused, updateActiveDescendant]);
|
77
84
|
|
78
85
|
/* Related to UIP-4992
|
79
86
|
* Need to remove these properties to avoid errors in the console on the external app.
|
@@ -34,6 +34,7 @@ var _list = require("@react-stately/list");
|
|
34
34
|
var _CloseIcon = _interopRequireDefault(require("mdi-react/CloseIcon"));
|
35
35
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
36
36
|
var _ = require("../..");
|
37
|
+
var _MultivaluesContext = require("../../context/MultivaluesContext");
|
37
38
|
var _hooks = require("../../hooks");
|
38
39
|
var _isIterable = require("../../utils/devUtils/props/isIterable");
|
39
40
|
var _ariaAttributes = require("../../utils/docUtils/ariaAttributes");
|
@@ -56,7 +57,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
56
57
|
* Stately.
|
57
58
|
*/
|
58
59
|
var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
59
|
-
var _context7;
|
60
|
+
var _context7, _listBoxRef$current;
|
60
61
|
var defaultSelectedKeys = props.defaultSelectedKeys,
|
61
62
|
direction = props.direction,
|
62
63
|
_props$disabledKeys = props.disabledKeys,
|
@@ -372,8 +373,14 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
372
373
|
})), (0, _react2.jsx)(_reactAria.DismissButton, {
|
373
374
|
onDismiss: close
|
374
375
|
}));
|
376
|
+
var _useState11 = (0, _react.useState)(null),
|
377
|
+
_useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
|
378
|
+
activeDescendant = _useState12[0],
|
379
|
+
setActiveDescendant = _useState12[1];
|
375
380
|
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
376
381
|
controlProps: {
|
382
|
+
'aria-activedescendant': activeDescendant,
|
383
|
+
'aria-controls': (_listBoxRef$current = listBoxRef.current) === null || _listBoxRef$current === void 0 ? void 0 : _listBoxRef$current.id,
|
377
384
|
'aria-expanded': isOpen,
|
378
385
|
role: 'combobox'
|
379
386
|
},
|
@@ -395,7 +402,9 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
395
402
|
status: status,
|
396
403
|
isRestrictiveMultivalues: !hasCustomValue
|
397
404
|
});
|
398
|
-
return (0, _react2.jsx)(
|
405
|
+
return (0, _react2.jsx)(_MultivaluesContext.MultivaluesContext.Provider, {
|
406
|
+
value: setActiveDescendant
|
407
|
+
}, (0, _react2.jsx)(_.Box, containerProps, (0, _react2.jsx)(_.TextField, (0, _extends2["default"])({
|
399
408
|
onBlur: function onBlur(e) {
|
400
409
|
setIsOpen(false);
|
401
410
|
if (mode === 'non-restrictive' && filterString !== '') onBlurTextField();
|
@@ -430,7 +439,7 @@ var MultivaluesField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
430
439
|
placement: placement,
|
431
440
|
ref: popoverRef,
|
432
441
|
style: style
|
433
|
-
}, listbox));
|
442
|
+
}, listbox)));
|
434
443
|
});
|
435
444
|
MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
436
445
|
/** The initial selected keys in the collection (uncontrolled). */
|
@@ -149,6 +149,20 @@ test('multiple selection is enabled, option disappears after selection', functio
|
|
149
149
|
secondOption.click();
|
150
150
|
expect(secondOption).not.toBeInTheDocument();
|
151
151
|
});
|
152
|
+
test('updates aria attributes on option focus', function () {
|
153
|
+
getComponent();
|
154
|
+
var input = _testWrapper.screen.getByRole('combobox');
|
155
|
+
_userEvent["default"].tab();
|
156
|
+
expect(input).toHaveFocus();
|
157
|
+
_testWrapper.fireEvent.keyDown(input, {
|
158
|
+
key: 'ArrowDown'
|
159
|
+
});
|
160
|
+
var options = _testWrapper.screen.getAllByRole('option');
|
161
|
+
var listbox = _testWrapper.screen.getByRole('listbox');
|
162
|
+
expect(input).toHaveAttribute('aria-activedescendant', options[0].id);
|
163
|
+
expect(input).toHaveAttribute('aria-expanded', 'true');
|
164
|
+
expect(input).toHaveAttribute('aria-controls', listbox.id);
|
165
|
+
});
|
152
166
|
test('clicking an option renders badge with option name', function () {
|
153
167
|
getComponent();
|
154
168
|
var input = _testWrapper.screen.getByRole('combobox');
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.useMultivaluesContext = exports.MultivaluesContext = void 0;
|
8
|
+
var _react = require("react");
|
9
|
+
var MultivaluesContext = /*#__PURE__*/(0, _react.createContext)(null);
|
10
|
+
exports.MultivaluesContext = MultivaluesContext;
|
11
|
+
var useMultivaluesContext = function useMultivaluesContext() {
|
12
|
+
return (0, _react.useContext)(MultivaluesContext);
|
13
|
+
};
|
14
|
+
exports.useMultivaluesContext = useMultivaluesContext;
|
@@ -12,10 +12,11 @@ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectW
|
|
12
12
|
var _excluded = ["item", "hasVirtualFocus"];
|
13
13
|
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
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
-
import React, { forwardRef, useContext, useImperativeHandle, useRef } from 'react';
|
15
|
+
import React, { forwardRef, useContext, useEffect, useImperativeHandle, useRef } from 'react';
|
16
16
|
import { useOption } from '@react-aria/listbox';
|
17
17
|
import CircleSmallIcon from 'mdi-react/CircleSmallIcon';
|
18
18
|
import PropTypes from 'prop-types';
|
19
|
+
import { useMultivaluesContext } from '../../context/MultivaluesContext';
|
19
20
|
import { useStatusClasses } from '../../hooks';
|
20
21
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
21
22
|
import Box from '../Box';
|
@@ -63,6 +64,12 @@ var Option = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
63
64
|
isSelected: isSelected
|
64
65
|
}),
|
65
66
|
classNames = _useStatusClasses.classNames;
|
67
|
+
var updateActiveDescendant = useMultivaluesContext();
|
68
|
+
useEffect(function () {
|
69
|
+
if (isFocused && updateActiveDescendant) {
|
70
|
+
updateActiveDescendant(optionProps.id);
|
71
|
+
}
|
72
|
+
}, [isFocused, updateActiveDescendant]);
|
66
73
|
|
67
74
|
/* Related to UIP-4992
|
68
75
|
* Need to remove these properties to avoid errors in the console on the external app.
|
@@ -27,6 +27,7 @@ import { useListState } from '@react-stately/list';
|
|
27
27
|
import Clear from 'mdi-react/CloseIcon';
|
28
28
|
import PropTypes from 'prop-types';
|
29
29
|
import { Badge, Box, Icon, IconButton, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
30
|
+
import { MultivaluesContext } from '../../context/MultivaluesContext';
|
30
31
|
import { usePropWarning } from '../../hooks';
|
31
32
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
32
33
|
import { ariaAttributesBasePropTypes, getAriaAttributeProps } from '../../utils/docUtils/ariaAttributes';
|
@@ -45,7 +46,7 @@ import ListBox from '../ListBox';
|
|
45
46
|
*/
|
46
47
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
47
48
|
var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
48
|
-
var _context7;
|
49
|
+
var _context7, _listBoxRef$current;
|
49
50
|
var defaultSelectedKeys = props.defaultSelectedKeys,
|
50
51
|
direction = props.direction,
|
51
52
|
_props$disabledKeys = props.disabledKeys,
|
@@ -361,8 +362,14 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
361
362
|
})), ___EmotionJSX(DismissButton, {
|
362
363
|
onDismiss: close
|
363
364
|
}));
|
365
|
+
var _useState11 = useState(null),
|
366
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
367
|
+
activeDescendant = _useState12[0],
|
368
|
+
setActiveDescendant = _useState12[1];
|
364
369
|
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
365
370
|
controlProps: {
|
371
|
+
'aria-activedescendant': activeDescendant,
|
372
|
+
'aria-controls': (_listBoxRef$current = listBoxRef.current) === null || _listBoxRef$current === void 0 ? void 0 : _listBoxRef$current.id,
|
366
373
|
'aria-expanded': isOpen,
|
367
374
|
role: 'combobox'
|
368
375
|
},
|
@@ -384,7 +391,9 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
384
391
|
status: status,
|
385
392
|
isRestrictiveMultivalues: !hasCustomValue
|
386
393
|
});
|
387
|
-
return ___EmotionJSX(
|
394
|
+
return ___EmotionJSX(MultivaluesContext.Provider, {
|
395
|
+
value: setActiveDescendant
|
396
|
+
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
388
397
|
onBlur: function onBlur(e) {
|
389
398
|
setIsOpen(false);
|
390
399
|
if (mode === 'non-restrictive' && filterString !== '') onBlurTextField();
|
@@ -419,7 +428,7 @@ var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
419
428
|
placement: placement,
|
420
429
|
ref: popoverRef,
|
421
430
|
style: style
|
422
|
-
}, listbox));
|
431
|
+
}, listbox)));
|
423
432
|
});
|
424
433
|
MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
425
434
|
/** The initial selected keys in the collection (uncontrolled). */
|
@@ -16,7 +16,7 @@ import userEvent from '@testing-library/user-event';
|
|
16
16
|
import { axe } from 'jest-axe';
|
17
17
|
import { Item, MultivaluesField, OverlayProvider } from '../../index';
|
18
18
|
import statuses from '../../utils/devUtils/constants/statuses';
|
19
|
-
import { getDefaultNormalizer, render, screen, within } from '../../utils/testUtils/testWrapper';
|
19
|
+
import { fireEvent, getDefaultNormalizer, render, screen, within } from '../../utils/testUtils/testWrapper';
|
20
20
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
21
21
|
var items = [{
|
22
22
|
id: 1,
|
@@ -146,6 +146,20 @@ test('multiple selection is enabled, option disappears after selection', functio
|
|
146
146
|
secondOption.click();
|
147
147
|
expect(secondOption).not.toBeInTheDocument();
|
148
148
|
});
|
149
|
+
test('updates aria attributes on option focus', function () {
|
150
|
+
getComponent();
|
151
|
+
var input = screen.getByRole('combobox');
|
152
|
+
userEvent.tab();
|
153
|
+
expect(input).toHaveFocus();
|
154
|
+
fireEvent.keyDown(input, {
|
155
|
+
key: 'ArrowDown'
|
156
|
+
});
|
157
|
+
var options = screen.getAllByRole('option');
|
158
|
+
var listbox = screen.getByRole('listbox');
|
159
|
+
expect(input).toHaveAttribute('aria-activedescendant', options[0].id);
|
160
|
+
expect(input).toHaveAttribute('aria-expanded', 'true');
|
161
|
+
expect(input).toHaveAttribute('aria-controls', listbox.id);
|
162
|
+
});
|
149
163
|
test('clicking an option renders badge with option name', function () {
|
150
164
|
getComponent();
|
151
165
|
var input = screen.getByRole('combobox');
|