downshift 8.5.0 → 9.0.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/dist/downshift.cjs.js +77 -173
- package/dist/downshift.esm.js +77 -172
- package/dist/downshift.native.cjs.js +76 -172
- package/dist/downshift.nativeweb.cjs.js +77 -173
- package/dist/downshift.umd.js +76 -177
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/dist/src/hooks/useSelect/utils.d.ts +0 -13
- package/dist/src/hooks/utils.d.ts +14 -14
- package/dist/src/set-a11y-status.d.ts +6 -1
- package/package.json +1 -1
- package/preact/dist/downshift.cjs.js +77 -173
- package/preact/dist/downshift.esm.js +77 -172
- package/preact/dist/downshift.umd.js +76 -177
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +2 -2
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/typings/index.d.ts +62 -16
package/dist/downshift.umd.js
CHANGED
|
@@ -36,13 +36,6 @@
|
|
|
36
36
|
return _extends.apply(this, arguments);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function _assertThisInitialized(self) {
|
|
40
|
-
if (self === void 0) {
|
|
41
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
42
|
-
}
|
|
43
|
-
return self;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
39
|
function _setPrototypeOf(o, p) {
|
|
47
40
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
48
41
|
o.__proto__ = p;
|
|
@@ -1525,7 +1518,7 @@
|
|
|
1525
1518
|
* @param {Object} param the downshift state and other relevant properties
|
|
1526
1519
|
* @return {String} the a11y status message
|
|
1527
1520
|
*/
|
|
1528
|
-
function getA11yStatusMessage
|
|
1521
|
+
function getA11yStatusMessage(_ref2) {
|
|
1529
1522
|
var isOpen = _ref2.isOpen,
|
|
1530
1523
|
resultCount = _ref2.resultCount,
|
|
1531
1524
|
previousResultCount = _ref2.previousResultCount;
|
|
@@ -1813,6 +1806,17 @@
|
|
|
1813
1806
|
cleanupStatus(documentProp);
|
|
1814
1807
|
}
|
|
1815
1808
|
|
|
1809
|
+
/**
|
|
1810
|
+
* Removes the status element from the DOM
|
|
1811
|
+
* @param {Document} documentProp
|
|
1812
|
+
*/
|
|
1813
|
+
function cleanupStatusDiv(documentProp) {
|
|
1814
|
+
var statusDiv = documentProp == null ? void 0 : documentProp.getElementById('a11y-status-message');
|
|
1815
|
+
if (statusDiv) {
|
|
1816
|
+
statusDiv.remove();
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1816
1820
|
var unknown = '__autocomplete_unknown__' ;
|
|
1817
1821
|
var mouseUp = '__autocomplete_mouseup__' ;
|
|
1818
1822
|
var itemMouseEnter = '__autocomplete_item_mouseenter__' ;
|
|
@@ -1852,14 +1856,13 @@
|
|
|
1852
1856
|
touchEnd: touchEnd
|
|
1853
1857
|
});
|
|
1854
1858
|
|
|
1855
|
-
var _excluded$
|
|
1859
|
+
var _excluded$3 = ["refKey", "ref"],
|
|
1856
1860
|
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
1857
1861
|
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
1858
1862
|
_excluded4$2 = ["refKey", "ref"],
|
|
1859
1863
|
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
1860
1864
|
var Downshift = /*#__PURE__*/function () {
|
|
1861
1865
|
var Downshift = /*#__PURE__*/function (_Component) {
|
|
1862
|
-
_inheritsLoose(Downshift, _Component);
|
|
1863
1866
|
function Downshift(_props) {
|
|
1864
1867
|
var _this;
|
|
1865
1868
|
_this = _Component.call(this, _props) || this;
|
|
@@ -2045,7 +2048,7 @@
|
|
|
2045
2048
|
_ref$refKey = _ref.refKey,
|
|
2046
2049
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
2047
2050
|
ref = _ref.ref,
|
|
2048
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
2051
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2049
2052
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
2050
2053
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
2051
2054
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
@@ -2226,7 +2229,7 @@
|
|
|
2226
2229
|
_this.buttonHandleKeyDown = function (event) {
|
|
2227
2230
|
var key = normalizeArrowKey(event);
|
|
2228
2231
|
if (_this.buttonKeyDownHandlers[key]) {
|
|
2229
|
-
_this.buttonKeyDownHandlers[key].call(
|
|
2232
|
+
_this.buttonKeyDownHandlers[key].call(_this, event);
|
|
2230
2233
|
}
|
|
2231
2234
|
};
|
|
2232
2235
|
_this.buttonHandleClick = function (event) {
|
|
@@ -2318,7 +2321,7 @@
|
|
|
2318
2321
|
_this.inputHandleKeyDown = function (event) {
|
|
2319
2322
|
var key = normalizeArrowKey(event);
|
|
2320
2323
|
if (key && _this.inputKeyDownHandlers[key]) {
|
|
2321
|
-
_this.inputKeyDownHandlers[key].call(
|
|
2324
|
+
_this.inputKeyDownHandlers[key].call(_this, event);
|
|
2322
2325
|
}
|
|
2323
2326
|
};
|
|
2324
2327
|
_this.inputHandleChange = function (event) {
|
|
@@ -2522,6 +2525,7 @@
|
|
|
2522
2525
|
_this.state = _state;
|
|
2523
2526
|
return _this;
|
|
2524
2527
|
}
|
|
2528
|
+
_inheritsLoose(Downshift, _Component);
|
|
2525
2529
|
var _proto = Downshift.prototype;
|
|
2526
2530
|
/**
|
|
2527
2531
|
* Clear all running timeouts
|
|
@@ -2799,7 +2803,7 @@
|
|
|
2799
2803
|
Downshift.defaultProps = {
|
|
2800
2804
|
defaultHighlightedIndex: null,
|
|
2801
2805
|
defaultIsOpen: false,
|
|
2802
|
-
getA11yStatusMessage: getA11yStatusMessage
|
|
2806
|
+
getA11yStatusMessage: getA11yStatusMessage,
|
|
2803
2807
|
itemToString: function itemToString(i) {
|
|
2804
2808
|
if (i == null) {
|
|
2805
2809
|
return '';
|
|
@@ -2901,7 +2905,6 @@
|
|
|
2901
2905
|
}
|
|
2902
2906
|
}
|
|
2903
2907
|
|
|
2904
|
-
var _excluded$3 = ["highlightedIndex", "items", "environment"];
|
|
2905
2908
|
var dropdownDefaultStateValues = {
|
|
2906
2909
|
highlightedIndex: -1,
|
|
2907
2910
|
isOpen: false,
|
|
@@ -2946,23 +2949,11 @@
|
|
|
2946
2949
|
return a.changes;
|
|
2947
2950
|
}
|
|
2948
2951
|
|
|
2949
|
-
/**
|
|
2950
|
-
* Returns a message to be added to aria-live region when item is selected.
|
|
2951
|
-
*
|
|
2952
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
2953
|
-
* @returns {string} The a11y message.
|
|
2954
|
-
*/
|
|
2955
|
-
function getA11ySelectionMessage(selectionParameters) {
|
|
2956
|
-
var selectedItem = selectionParameters.selectedItem,
|
|
2957
|
-
itemToString = selectionParameters.itemToString;
|
|
2958
|
-
return selectedItem ? itemToString(selectedItem) + " has been selected." : '';
|
|
2959
|
-
}
|
|
2960
|
-
|
|
2961
2952
|
/**
|
|
2962
2953
|
* Debounced call for updating the a11y message.
|
|
2963
2954
|
*/
|
|
2964
|
-
var updateA11yStatus = debounce(function (
|
|
2965
|
-
setStatus(
|
|
2955
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
2956
|
+
setStatus(status, document);
|
|
2966
2957
|
}, 200);
|
|
2967
2958
|
|
|
2968
2959
|
// istanbul ignore next
|
|
@@ -3110,7 +3101,6 @@
|
|
|
3110
3101
|
return item;
|
|
3111
3102
|
},
|
|
3112
3103
|
stateReducer: stateReducer,
|
|
3113
|
-
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
3114
3104
|
scrollIntoView: scrollIntoView,
|
|
3115
3105
|
environment: /* istanbul ignore next (ssr) */
|
|
3116
3106
|
typeof window === 'undefined' || false ? undefined : window
|
|
@@ -3294,34 +3284,47 @@
|
|
|
3294
3284
|
return setGetterPropCallInfo;
|
|
3295
3285
|
};
|
|
3296
3286
|
}
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3287
|
+
|
|
3288
|
+
/**
|
|
3289
|
+
* Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3290
|
+
* @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
|
|
3291
|
+
* @param {Object} options The options to be passed to getA11yStatusMessage if called.
|
|
3292
|
+
* @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
|
|
3293
|
+
* @param {{document: Document}} environment The environment object containing the document.
|
|
3294
|
+
*/
|
|
3295
|
+
function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
|
|
3296
|
+
if (environment === void 0) {
|
|
3297
|
+
environment = {};
|
|
3298
|
+
}
|
|
3299
|
+
var document = environment.document;
|
|
3302
3300
|
var isInitialMount = useIsInitialMount();
|
|
3303
|
-
|
|
3301
|
+
|
|
3302
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3304
3303
|
React.useEffect(function () {
|
|
3305
|
-
if (isInitialMount || false || !
|
|
3304
|
+
if (!getA11yStatusMessage || isInitialMount || false || !document) {
|
|
3306
3305
|
return;
|
|
3307
3306
|
}
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
highlightedItem: items[highlightedIndex],
|
|
3312
|
-
resultCount: items.length
|
|
3313
|
-
}, rest));
|
|
3314
|
-
}, environment.document);
|
|
3307
|
+
var status = getA11yStatusMessage(options);
|
|
3308
|
+
updateA11yStatus(status, document);
|
|
3309
|
+
|
|
3315
3310
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3316
|
-
}, dependencyArray);
|
|
3311
|
+
}, [dependencyArray]);
|
|
3312
|
+
|
|
3313
|
+
// Cleanup the status message container.
|
|
3314
|
+
React.useEffect(function () {
|
|
3315
|
+
return function () {
|
|
3316
|
+
updateA11yStatus.cancel();
|
|
3317
|
+
cleanupStatusDiv(document);
|
|
3318
|
+
};
|
|
3319
|
+
}, [document]);
|
|
3317
3320
|
}
|
|
3318
|
-
function useScrollIntoView(
|
|
3319
|
-
var highlightedIndex =
|
|
3320
|
-
isOpen =
|
|
3321
|
-
itemRefs =
|
|
3322
|
-
getItemNodeFromIndex =
|
|
3323
|
-
menuElement =
|
|
3324
|
-
scrollIntoViewProp =
|
|
3321
|
+
function useScrollIntoView(_ref3) {
|
|
3322
|
+
var highlightedIndex = _ref3.highlightedIndex,
|
|
3323
|
+
isOpen = _ref3.isOpen,
|
|
3324
|
+
itemRefs = _ref3.itemRefs,
|
|
3325
|
+
getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
|
|
3326
|
+
menuElement = _ref3.menuElement,
|
|
3327
|
+
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
3325
3328
|
// used not to scroll on highlight by mouse.
|
|
3326
3329
|
var shouldScrollRef = React.useRef(true);
|
|
3327
3330
|
// Scroll on highlighted item if change comes from keyboard.
|
|
@@ -3343,9 +3346,9 @@
|
|
|
3343
3346
|
var useControlPropsValidator = noop;
|
|
3344
3347
|
/* istanbul ignore next */
|
|
3345
3348
|
{
|
|
3346
|
-
useControlPropsValidator = function useControlPropsValidator(
|
|
3347
|
-
var props =
|
|
3348
|
-
state =
|
|
3349
|
+
useControlPropsValidator = function useControlPropsValidator(_ref4) {
|
|
3350
|
+
var props = _ref4.props,
|
|
3351
|
+
state = _ref4.state;
|
|
3349
3352
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
3350
3353
|
var prevPropsRef = React.useRef(props);
|
|
3351
3354
|
var isInitialMount = useIsInitialMount();
|
|
@@ -3557,29 +3560,8 @@
|
|
|
3557
3560
|
}
|
|
3558
3561
|
return highlightedIndex;
|
|
3559
3562
|
}
|
|
3560
|
-
var propTypes$2 = __assign(__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func
|
|
3561
|
-
|
|
3562
|
-
* Default implementation for status message. Only added when menu is open.
|
|
3563
|
-
* Will specift if there are results in the list, and if so, how many,
|
|
3564
|
-
* and what keys are relevant.
|
|
3565
|
-
*
|
|
3566
|
-
* @param {Object} param the downshift state and other relevant properties
|
|
3567
|
-
* @return {String} the a11y status message
|
|
3568
|
-
*/
|
|
3569
|
-
function getA11yStatusMessage(_a) {
|
|
3570
|
-
var isOpen = _a.isOpen, resultCount = _a.resultCount, previousResultCount = _a.previousResultCount;
|
|
3571
|
-
if (!isOpen) {
|
|
3572
|
-
return '';
|
|
3573
|
-
}
|
|
3574
|
-
if (!resultCount) {
|
|
3575
|
-
return 'No results are available.';
|
|
3576
|
-
}
|
|
3577
|
-
if (resultCount !== previousResultCount) {
|
|
3578
|
-
return "".concat(resultCount, " result").concat(resultCount === 1 ? ' is' : 's are', " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.");
|
|
3579
|
-
}
|
|
3580
|
-
return '';
|
|
3581
|
-
}
|
|
3582
|
-
var defaultProps$2 = __assign(__assign({}, defaultProps$3), { getA11yStatusMessage: getA11yStatusMessage, isItemDisabled: function () {
|
|
3563
|
+
var propTypes$2 = __assign(__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func });
|
|
3564
|
+
var defaultProps$2 = __assign(__assign({}, defaultProps$3), { isItemDisabled: function () {
|
|
3583
3565
|
return false;
|
|
3584
3566
|
} });
|
|
3585
3567
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -3761,11 +3743,8 @@
|
|
|
3761
3743
|
validatePropTypes$2(userProps, useSelect);
|
|
3762
3744
|
// Props defaults and destructuring.
|
|
3763
3745
|
var props = _extends({}, defaultProps$2, userProps);
|
|
3764
|
-
var
|
|
3765
|
-
scrollIntoView = props.scrollIntoView,
|
|
3746
|
+
var scrollIntoView = props.scrollIntoView,
|
|
3766
3747
|
environment = props.environment,
|
|
3767
|
-
itemToString = props.itemToString,
|
|
3768
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
3769
3748
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3770
3749
|
// Initial state depending on controlled props.
|
|
3771
3750
|
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2, isDropdownsStateEqual),
|
|
@@ -3783,9 +3762,6 @@
|
|
|
3783
3762
|
var clearTimeoutRef = React.useRef(null);
|
|
3784
3763
|
// prevent id re-generation between renders.
|
|
3785
3764
|
var elementIds = useElementIds(props);
|
|
3786
|
-
// used to keep track of how many items we had on previous cycle.
|
|
3787
|
-
var previousResultCountRef = React.useRef();
|
|
3788
|
-
var isInitialMount = useIsInitialMount();
|
|
3789
3765
|
// utility callback to get item element.
|
|
3790
3766
|
var latest = useLatestRef({
|
|
3791
3767
|
state: state,
|
|
@@ -3798,20 +3774,8 @@
|
|
|
3798
3774
|
}, [elementIds]);
|
|
3799
3775
|
|
|
3800
3776
|
// Effects.
|
|
3801
|
-
//
|
|
3802
|
-
|
|
3803
|
-
previousResultCount: previousResultCountRef.current,
|
|
3804
|
-
items: items,
|
|
3805
|
-
environment: environment,
|
|
3806
|
-
itemToString: itemToString
|
|
3807
|
-
}, state));
|
|
3808
|
-
// Sets a11y status message on changes in selectedItem.
|
|
3809
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
3810
|
-
previousResultCount: previousResultCountRef.current,
|
|
3811
|
-
items: items,
|
|
3812
|
-
environment: environment,
|
|
3813
|
-
itemToString: itemToString
|
|
3814
|
-
}, state));
|
|
3777
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3778
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
3815
3779
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3816
3780
|
var shouldScrollRef = useScrollIntoView({
|
|
3817
3781
|
menuElement: menuRef.current,
|
|
@@ -3821,7 +3785,6 @@
|
|
|
3821
3785
|
scrollIntoView: scrollIntoView,
|
|
3822
3786
|
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3823
3787
|
});
|
|
3824
|
-
|
|
3825
3788
|
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
3826
3789
|
React.useEffect(function () {
|
|
3827
3790
|
// init the clean function here as we need access to dispatch.
|
|
@@ -3837,7 +3800,6 @@
|
|
|
3837
3800
|
clearTimeoutRef.current.cancel();
|
|
3838
3801
|
};
|
|
3839
3802
|
}, []);
|
|
3840
|
-
|
|
3841
3803
|
// Invokes the keysSoFar callback set up above.
|
|
3842
3804
|
React.useEffect(function () {
|
|
3843
3805
|
if (!inputValue) {
|
|
@@ -3849,12 +3811,6 @@
|
|
|
3849
3811
|
props: props,
|
|
3850
3812
|
state: state
|
|
3851
3813
|
});
|
|
3852
|
-
React.useEffect(function () {
|
|
3853
|
-
if (isInitialMount) {
|
|
3854
|
-
return;
|
|
3855
|
-
}
|
|
3856
|
-
previousResultCountRef.current = items.length;
|
|
3857
|
-
});
|
|
3858
3814
|
// Focus the toggle button on first render if required.
|
|
3859
3815
|
React.useEffect(function () {
|
|
3860
3816
|
var focusOnOpen = getInitialValue$1(props, 'isOpen');
|
|
@@ -4232,8 +4188,6 @@
|
|
|
4232
4188
|
var propTypes$1 = _extends({}, commonDropdownPropTypes, {
|
|
4233
4189
|
items: PropTypes.array.isRequired,
|
|
4234
4190
|
isItemDisabled: PropTypes.func,
|
|
4235
|
-
selectedItemChanged: PropTypes.func,
|
|
4236
|
-
getA11ySelectionMessage: PropTypes.func,
|
|
4237
4191
|
inputValue: PropTypes.string,
|
|
4238
4192
|
defaultInputValue: PropTypes.string,
|
|
4239
4193
|
initialInputValue: PropTypes.string,
|
|
@@ -4266,13 +4220,7 @@
|
|
|
4266
4220
|
}
|
|
4267
4221
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
4268
4222
|
) {
|
|
4269
|
-
var shouldCallDispatch;
|
|
4270
|
-
if (props.selectedItemChanged === undefined) {
|
|
4271
|
-
shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
4272
|
-
} else {
|
|
4273
|
-
console.warn("The \"selectedItemChanged\" is deprecated. Please use \"itemToKey instead\". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged");
|
|
4274
|
-
shouldCallDispatch = props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem);
|
|
4275
|
-
}
|
|
4223
|
+
var shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
4276
4224
|
if (shouldCallDispatch) {
|
|
4277
4225
|
dispatch({
|
|
4278
4226
|
type: ControlledPropUpdatedSelectedItem,
|
|
@@ -4295,7 +4243,6 @@
|
|
|
4295
4243
|
};
|
|
4296
4244
|
}
|
|
4297
4245
|
var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
4298
|
-
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
4299
4246
|
isItemDisabled: function isItemDisabled() {
|
|
4300
4247
|
return false;
|
|
4301
4248
|
}
|
|
@@ -4432,9 +4379,7 @@
|
|
|
4432
4379
|
var items = props.items,
|
|
4433
4380
|
scrollIntoView = props.scrollIntoView,
|
|
4434
4381
|
environment = props.environment,
|
|
4435
|
-
getA11yStatusMessage = props.getA11yStatusMessage
|
|
4436
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
4437
|
-
itemToString = props.itemToString;
|
|
4382
|
+
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
4438
4383
|
// Initial state depending on controlled props.
|
|
4439
4384
|
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1, isDropdownsStateEqual),
|
|
4440
4385
|
state = _useControlledReducer[0],
|
|
@@ -4465,20 +4410,8 @@
|
|
|
4465
4410
|
}, [elementIds]);
|
|
4466
4411
|
|
|
4467
4412
|
// Effects.
|
|
4468
|
-
//
|
|
4469
|
-
|
|
4470
|
-
previousResultCount: previousResultCountRef.current,
|
|
4471
|
-
items: items,
|
|
4472
|
-
environment: environment,
|
|
4473
|
-
itemToString: itemToString
|
|
4474
|
-
}, state));
|
|
4475
|
-
// Sets a11y status message on changes in selectedItem.
|
|
4476
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
4477
|
-
previousResultCount: previousResultCountRef.current,
|
|
4478
|
-
items: items,
|
|
4479
|
-
environment: environment,
|
|
4480
|
-
itemToString: itemToString
|
|
4481
|
-
}, state));
|
|
4413
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
4414
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
4482
4415
|
// Scroll on highlighted item if change comes from keyboard.
|
|
4483
4416
|
var shouldScrollRef = useScrollIntoView({
|
|
4484
4417
|
menuElement: menuRef.current,
|
|
@@ -4901,18 +4834,6 @@
|
|
|
4901
4834
|
return true;
|
|
4902
4835
|
}
|
|
4903
4836
|
|
|
4904
|
-
/**
|
|
4905
|
-
* Returns a message to be added to aria-live region when item is removed.
|
|
4906
|
-
*
|
|
4907
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
4908
|
-
* @returns {string} The a11y message.
|
|
4909
|
-
*/
|
|
4910
|
-
function getA11yRemovalMessage(selectionParameters) {
|
|
4911
|
-
var removedSelectedItem = selectionParameters.removedSelectedItem,
|
|
4912
|
-
itemToStringLocal = selectionParameters.itemToString;
|
|
4913
|
-
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
4914
|
-
}
|
|
4915
|
-
|
|
4916
4837
|
/**
|
|
4917
4838
|
* Check if a state is equal for taglist, by comparing active index and selected items.
|
|
4918
4839
|
* Used by useSelect and useCombobox.
|
|
@@ -4924,11 +4845,14 @@
|
|
|
4924
4845
|
function isStateEqual(prevState, newState) {
|
|
4925
4846
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
4926
4847
|
}
|
|
4927
|
-
var propTypes =
|
|
4848
|
+
var propTypes = {
|
|
4849
|
+
stateReducer: commonPropTypes.stateReducer,
|
|
4850
|
+
itemToKey: commonPropTypes.itemToKey,
|
|
4851
|
+
environment: commonPropTypes.environment,
|
|
4928
4852
|
selectedItems: PropTypes.array,
|
|
4929
4853
|
initialSelectedItems: PropTypes.array,
|
|
4930
4854
|
defaultSelectedItems: PropTypes.array,
|
|
4931
|
-
|
|
4855
|
+
getA11yStatusMessage: PropTypes.func,
|
|
4932
4856
|
activeIndex: PropTypes.number,
|
|
4933
4857
|
initialActiveIndex: PropTypes.number,
|
|
4934
4858
|
defaultActiveIndex: PropTypes.number,
|
|
@@ -4936,13 +4860,11 @@
|
|
|
4936
4860
|
onSelectedItemsChange: PropTypes.func,
|
|
4937
4861
|
keyNavigationNext: PropTypes.string,
|
|
4938
4862
|
keyNavigationPrevious: PropTypes.string
|
|
4939
|
-
}
|
|
4863
|
+
};
|
|
4940
4864
|
var defaultProps = {
|
|
4941
|
-
itemToString: defaultProps$3.itemToString,
|
|
4942
4865
|
itemToKey: defaultProps$3.itemToKey,
|
|
4943
4866
|
stateReducer: defaultProps$3.stateReducer,
|
|
4944
4867
|
environment: defaultProps$3.environment,
|
|
4945
|
-
getA11yRemovalMessage: getA11yRemovalMessage,
|
|
4946
4868
|
keyNavigationNext: 'ArrowRight',
|
|
4947
4869
|
keyNavigationPrevious: 'ArrowLeft'
|
|
4948
4870
|
};
|
|
@@ -5109,8 +5031,7 @@
|
|
|
5109
5031
|
validatePropTypes(userProps, useMultipleSelection);
|
|
5110
5032
|
// Props defaults and destructuring.
|
|
5111
5033
|
var props = _extends({}, defaultProps, userProps);
|
|
5112
|
-
var
|
|
5113
|
-
itemToString = props.itemToString,
|
|
5034
|
+
var getA11yStatusMessage = props.getA11yStatusMessage,
|
|
5114
5035
|
environment = props.environment,
|
|
5115
5036
|
keyNavigationNext = props.keyNavigationNext,
|
|
5116
5037
|
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
@@ -5125,7 +5046,6 @@
|
|
|
5125
5046
|
// Refs.
|
|
5126
5047
|
var isInitialMount = useIsInitialMount();
|
|
5127
5048
|
var dropdownRef = React.useRef(null);
|
|
5128
|
-
var previousSelectedItemsRef = React.useRef(selectedItems);
|
|
5129
5049
|
var selectedItemRefs = React.useRef();
|
|
5130
5050
|
selectedItemRefs.current = [];
|
|
5131
5051
|
var latest = useLatestRef({
|
|
@@ -5134,29 +5054,8 @@
|
|
|
5134
5054
|
});
|
|
5135
5055
|
|
|
5136
5056
|
// Effects.
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
if (isInitialMount || false || !(environment != null && environment.document)) {
|
|
5140
|
-
return;
|
|
5141
|
-
}
|
|
5142
|
-
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
5143
|
-
var removedSelectedItem = previousSelectedItemsRef.current.find(function (selectedItem) {
|
|
5144
|
-
return selectedItems.findIndex(function (item) {
|
|
5145
|
-
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
5146
|
-
}) < 0;
|
|
5147
|
-
});
|
|
5148
|
-
setStatus(getA11yRemovalMessage({
|
|
5149
|
-
itemToString: itemToString,
|
|
5150
|
-
resultCount: selectedItems.length,
|
|
5151
|
-
removedSelectedItem: removedSelectedItem,
|
|
5152
|
-
activeIndex: activeIndex,
|
|
5153
|
-
activeSelectedItem: selectedItems[activeIndex]
|
|
5154
|
-
}), environment.document);
|
|
5155
|
-
}
|
|
5156
|
-
previousSelectedItemsRef.current = selectedItems;
|
|
5157
|
-
|
|
5158
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5159
|
-
}, [selectedItems.length]);
|
|
5057
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
5058
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [activeIndex, selectedItems], environment);
|
|
5160
5059
|
// Sets focus on active item.
|
|
5161
5060
|
React.useEffect(function () {
|
|
5162
5061
|
if (isInitialMount) {
|