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.esm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
|
|
2
2
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
|
-
import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
|
|
4
3
|
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
6
5
|
import React, { cloneElement, Component, useRef, useEffect, useCallback, useLayoutEffect, useReducer, useMemo } from 'react';
|
|
@@ -152,7 +151,7 @@ function resetIdCounter() {
|
|
|
152
151
|
* @param {Object} param the downshift state and other relevant properties
|
|
153
152
|
* @return {String} the a11y status message
|
|
154
153
|
*/
|
|
155
|
-
function getA11yStatusMessage
|
|
154
|
+
function getA11yStatusMessage(_ref2) {
|
|
156
155
|
var isOpen = _ref2.isOpen,
|
|
157
156
|
resultCount = _ref2.resultCount,
|
|
158
157
|
previousResultCount = _ref2.previousResultCount;
|
|
@@ -440,6 +439,17 @@ function setStatus(status, documentProp) {
|
|
|
440
439
|
cleanupStatus(documentProp);
|
|
441
440
|
}
|
|
442
441
|
|
|
442
|
+
/**
|
|
443
|
+
* Removes the status element from the DOM
|
|
444
|
+
* @param {Document} documentProp
|
|
445
|
+
*/
|
|
446
|
+
function cleanupStatusDiv(documentProp) {
|
|
447
|
+
var statusDiv = documentProp == null ? void 0 : documentProp.getElementById('a11y-status-message');
|
|
448
|
+
if (statusDiv) {
|
|
449
|
+
statusDiv.remove();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
443
453
|
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
444
454
|
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
445
455
|
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
@@ -479,14 +489,13 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
479
489
|
touchEnd: touchEnd
|
|
480
490
|
});
|
|
481
491
|
|
|
482
|
-
var _excluded$
|
|
492
|
+
var _excluded$3 = ["refKey", "ref"],
|
|
483
493
|
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
484
494
|
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
485
495
|
_excluded4$2 = ["refKey", "ref"],
|
|
486
496
|
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
487
497
|
var Downshift = /*#__PURE__*/function () {
|
|
488
498
|
var Downshift = /*#__PURE__*/function (_Component) {
|
|
489
|
-
_inheritsLoose(Downshift, _Component);
|
|
490
499
|
function Downshift(_props) {
|
|
491
500
|
var _this;
|
|
492
501
|
_this = _Component.call(this, _props) || this;
|
|
@@ -672,7 +681,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
672
681
|
_ref$refKey = _ref.refKey,
|
|
673
682
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
674
683
|
ref = _ref.ref,
|
|
675
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$
|
|
684
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
676
685
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
677
686
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
678
687
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
@@ -853,7 +862,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
853
862
|
_this.buttonHandleKeyDown = function (event) {
|
|
854
863
|
var key = normalizeArrowKey(event);
|
|
855
864
|
if (_this.buttonKeyDownHandlers[key]) {
|
|
856
|
-
_this.buttonKeyDownHandlers[key].call(
|
|
865
|
+
_this.buttonKeyDownHandlers[key].call(_this, event);
|
|
857
866
|
}
|
|
858
867
|
};
|
|
859
868
|
_this.buttonHandleClick = function (event) {
|
|
@@ -949,7 +958,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
949
958
|
_this.inputHandleKeyDown = function (event) {
|
|
950
959
|
var key = normalizeArrowKey(event);
|
|
951
960
|
if (key && _this.inputKeyDownHandlers[key]) {
|
|
952
|
-
_this.inputKeyDownHandlers[key].call(
|
|
961
|
+
_this.inputKeyDownHandlers[key].call(_this, event);
|
|
953
962
|
}
|
|
954
963
|
};
|
|
955
964
|
_this.inputHandleChange = function (event) {
|
|
@@ -1153,6 +1162,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1153
1162
|
_this.state = _state;
|
|
1154
1163
|
return _this;
|
|
1155
1164
|
}
|
|
1165
|
+
_inheritsLoose(Downshift, _Component);
|
|
1156
1166
|
var _proto = Downshift.prototype;
|
|
1157
1167
|
/**
|
|
1158
1168
|
* Clear all running timeouts
|
|
@@ -1433,7 +1443,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1433
1443
|
Downshift.defaultProps = {
|
|
1434
1444
|
defaultHighlightedIndex: null,
|
|
1435
1445
|
defaultIsOpen: false,
|
|
1436
|
-
getA11yStatusMessage: getA11yStatusMessage
|
|
1446
|
+
getA11yStatusMessage: getA11yStatusMessage,
|
|
1437
1447
|
itemToString: function itemToString(i) {
|
|
1438
1448
|
if (i == null) {
|
|
1439
1449
|
return '';
|
|
@@ -1535,7 +1545,6 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
|
|
|
1535
1545
|
}
|
|
1536
1546
|
}
|
|
1537
1547
|
|
|
1538
|
-
var _excluded$3 = ["highlightedIndex", "items", "environment"];
|
|
1539
1548
|
var dropdownDefaultStateValues = {
|
|
1540
1549
|
highlightedIndex: -1,
|
|
1541
1550
|
isOpen: false,
|
|
@@ -1580,23 +1589,11 @@ function stateReducer(s, a) {
|
|
|
1580
1589
|
return a.changes;
|
|
1581
1590
|
}
|
|
1582
1591
|
|
|
1583
|
-
/**
|
|
1584
|
-
* Returns a message to be added to aria-live region when item is selected.
|
|
1585
|
-
*
|
|
1586
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
1587
|
-
* @returns {string} The a11y message.
|
|
1588
|
-
*/
|
|
1589
|
-
function getA11ySelectionMessage(selectionParameters) {
|
|
1590
|
-
var selectedItem = selectionParameters.selectedItem,
|
|
1591
|
-
itemToString = selectionParameters.itemToString;
|
|
1592
|
-
return selectedItem ? itemToString(selectedItem) + " has been selected." : '';
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
1592
|
/**
|
|
1596
1593
|
* Debounced call for updating the a11y message.
|
|
1597
1594
|
*/
|
|
1598
|
-
var updateA11yStatus = debounce(function (
|
|
1599
|
-
setStatus(
|
|
1595
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
1596
|
+
setStatus(status, document);
|
|
1600
1597
|
}, 200);
|
|
1601
1598
|
|
|
1602
1599
|
// istanbul ignore next
|
|
@@ -1744,7 +1741,6 @@ var defaultProps$3 = {
|
|
|
1744
1741
|
return item;
|
|
1745
1742
|
},
|
|
1746
1743
|
stateReducer: stateReducer,
|
|
1747
|
-
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
1748
1744
|
scrollIntoView: scrollIntoView,
|
|
1749
1745
|
environment: /* istanbul ignore next (ssr) */
|
|
1750
1746
|
typeof window === 'undefined' || false ? undefined : window
|
|
@@ -1928,34 +1924,47 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1928
1924
|
return setGetterPropCallInfo;
|
|
1929
1925
|
};
|
|
1930
1926
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1927
|
+
|
|
1928
|
+
/**
|
|
1929
|
+
* Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1930
|
+
* @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
|
|
1931
|
+
* @param {Object} options The options to be passed to getA11yStatusMessage if called.
|
|
1932
|
+
* @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
|
|
1933
|
+
* @param {{document: Document}} environment The environment object containing the document.
|
|
1934
|
+
*/
|
|
1935
|
+
function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
|
|
1936
|
+
if (environment === void 0) {
|
|
1937
|
+
environment = {};
|
|
1938
|
+
}
|
|
1939
|
+
var document = environment.document;
|
|
1936
1940
|
var isInitialMount = useIsInitialMount();
|
|
1937
|
-
|
|
1941
|
+
|
|
1942
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1938
1943
|
useEffect(function () {
|
|
1939
|
-
if (isInitialMount || false || !
|
|
1944
|
+
if (!getA11yStatusMessage || isInitialMount || false || !document) {
|
|
1940
1945
|
return;
|
|
1941
1946
|
}
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
highlightedItem: items[highlightedIndex],
|
|
1946
|
-
resultCount: items.length
|
|
1947
|
-
}, rest));
|
|
1948
|
-
}, environment.document);
|
|
1947
|
+
var status = getA11yStatusMessage(options);
|
|
1948
|
+
updateA11yStatus(status, document);
|
|
1949
|
+
|
|
1949
1950
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1950
|
-
}, dependencyArray);
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1951
|
+
}, [dependencyArray]);
|
|
1952
|
+
|
|
1953
|
+
// Cleanup the status message container.
|
|
1954
|
+
useEffect(function () {
|
|
1955
|
+
return function () {
|
|
1956
|
+
updateA11yStatus.cancel();
|
|
1957
|
+
cleanupStatusDiv(document);
|
|
1958
|
+
};
|
|
1959
|
+
}, [document]);
|
|
1960
|
+
}
|
|
1961
|
+
function useScrollIntoView(_ref3) {
|
|
1962
|
+
var highlightedIndex = _ref3.highlightedIndex,
|
|
1963
|
+
isOpen = _ref3.isOpen,
|
|
1964
|
+
itemRefs = _ref3.itemRefs,
|
|
1965
|
+
getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
|
|
1966
|
+
menuElement = _ref3.menuElement,
|
|
1967
|
+
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
1959
1968
|
// used not to scroll on highlight by mouse.
|
|
1960
1969
|
var shouldScrollRef = useRef(true);
|
|
1961
1970
|
// Scroll on highlighted item if change comes from keyboard.
|
|
@@ -1977,9 +1986,9 @@ function useScrollIntoView(_ref4) {
|
|
|
1977
1986
|
var useControlPropsValidator = noop;
|
|
1978
1987
|
/* istanbul ignore next */
|
|
1979
1988
|
if (process.env.NODE_ENV !== 'production') {
|
|
1980
|
-
useControlPropsValidator = function useControlPropsValidator(
|
|
1981
|
-
var props =
|
|
1982
|
-
state =
|
|
1989
|
+
useControlPropsValidator = function useControlPropsValidator(_ref4) {
|
|
1990
|
+
var props = _ref4.props,
|
|
1991
|
+
state = _ref4.state;
|
|
1983
1992
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
1984
1993
|
var prevPropsRef = useRef(props);
|
|
1985
1994
|
var isInitialMount = useIsInitialMount();
|
|
@@ -2160,29 +2169,8 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2160
2169
|
}
|
|
2161
2170
|
return highlightedIndex;
|
|
2162
2171
|
}
|
|
2163
|
-
var propTypes$2 = __assign(__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func
|
|
2164
|
-
|
|
2165
|
-
* Default implementation for status message. Only added when menu is open.
|
|
2166
|
-
* Will specift if there are results in the list, and if so, how many,
|
|
2167
|
-
* and what keys are relevant.
|
|
2168
|
-
*
|
|
2169
|
-
* @param {Object} param the downshift state and other relevant properties
|
|
2170
|
-
* @return {String} the a11y status message
|
|
2171
|
-
*/
|
|
2172
|
-
function getA11yStatusMessage(_a) {
|
|
2173
|
-
var isOpen = _a.isOpen, resultCount = _a.resultCount, previousResultCount = _a.previousResultCount;
|
|
2174
|
-
if (!isOpen) {
|
|
2175
|
-
return '';
|
|
2176
|
-
}
|
|
2177
|
-
if (!resultCount) {
|
|
2178
|
-
return 'No results are available.';
|
|
2179
|
-
}
|
|
2180
|
-
if (resultCount !== previousResultCount) {
|
|
2181
|
-
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.");
|
|
2182
|
-
}
|
|
2183
|
-
return '';
|
|
2184
|
-
}
|
|
2185
|
-
var defaultProps$2 = __assign(__assign({}, defaultProps$3), { getA11yStatusMessage: getA11yStatusMessage, isItemDisabled: function () {
|
|
2172
|
+
var propTypes$2 = __assign(__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func });
|
|
2173
|
+
var defaultProps$2 = __assign(__assign({}, defaultProps$3), { isItemDisabled: function () {
|
|
2186
2174
|
return false;
|
|
2187
2175
|
} });
|
|
2188
2176
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -2364,11 +2352,8 @@ function useSelect(userProps) {
|
|
|
2364
2352
|
validatePropTypes$2(userProps, useSelect);
|
|
2365
2353
|
// Props defaults and destructuring.
|
|
2366
2354
|
var props = _extends({}, defaultProps$2, userProps);
|
|
2367
|
-
var
|
|
2368
|
-
scrollIntoView = props.scrollIntoView,
|
|
2355
|
+
var scrollIntoView = props.scrollIntoView,
|
|
2369
2356
|
environment = props.environment,
|
|
2370
|
-
itemToString = props.itemToString,
|
|
2371
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
2372
2357
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2373
2358
|
// Initial state depending on controlled props.
|
|
2374
2359
|
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2, isDropdownsStateEqual),
|
|
@@ -2386,9 +2371,6 @@ function useSelect(userProps) {
|
|
|
2386
2371
|
var clearTimeoutRef = useRef(null);
|
|
2387
2372
|
// prevent id re-generation between renders.
|
|
2388
2373
|
var elementIds = useElementIds(props);
|
|
2389
|
-
// used to keep track of how many items we had on previous cycle.
|
|
2390
|
-
var previousResultCountRef = useRef();
|
|
2391
|
-
var isInitialMount = useIsInitialMount();
|
|
2392
2374
|
// utility callback to get item element.
|
|
2393
2375
|
var latest = useLatestRef({
|
|
2394
2376
|
state: state,
|
|
@@ -2401,20 +2383,8 @@ function useSelect(userProps) {
|
|
|
2401
2383
|
}, [elementIds]);
|
|
2402
2384
|
|
|
2403
2385
|
// Effects.
|
|
2404
|
-
//
|
|
2405
|
-
|
|
2406
|
-
previousResultCount: previousResultCountRef.current,
|
|
2407
|
-
items: items,
|
|
2408
|
-
environment: environment,
|
|
2409
|
-
itemToString: itemToString
|
|
2410
|
-
}, state));
|
|
2411
|
-
// Sets a11y status message on changes in selectedItem.
|
|
2412
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
2413
|
-
previousResultCount: previousResultCountRef.current,
|
|
2414
|
-
items: items,
|
|
2415
|
-
environment: environment,
|
|
2416
|
-
itemToString: itemToString
|
|
2417
|
-
}, state));
|
|
2386
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2387
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2418
2388
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2419
2389
|
var shouldScrollRef = useScrollIntoView({
|
|
2420
2390
|
menuElement: menuRef.current,
|
|
@@ -2424,7 +2394,6 @@ function useSelect(userProps) {
|
|
|
2424
2394
|
scrollIntoView: scrollIntoView,
|
|
2425
2395
|
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2426
2396
|
});
|
|
2427
|
-
|
|
2428
2397
|
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2429
2398
|
useEffect(function () {
|
|
2430
2399
|
// init the clean function here as we need access to dispatch.
|
|
@@ -2440,7 +2409,6 @@ function useSelect(userProps) {
|
|
|
2440
2409
|
clearTimeoutRef.current.cancel();
|
|
2441
2410
|
};
|
|
2442
2411
|
}, []);
|
|
2443
|
-
|
|
2444
2412
|
// Invokes the keysSoFar callback set up above.
|
|
2445
2413
|
useEffect(function () {
|
|
2446
2414
|
if (!inputValue) {
|
|
@@ -2452,12 +2420,6 @@ function useSelect(userProps) {
|
|
|
2452
2420
|
props: props,
|
|
2453
2421
|
state: state
|
|
2454
2422
|
});
|
|
2455
|
-
useEffect(function () {
|
|
2456
|
-
if (isInitialMount) {
|
|
2457
|
-
return;
|
|
2458
|
-
}
|
|
2459
|
-
previousResultCountRef.current = items.length;
|
|
2460
|
-
});
|
|
2461
2423
|
// Focus the toggle button on first render if required.
|
|
2462
2424
|
useEffect(function () {
|
|
2463
2425
|
var focusOnOpen = getInitialValue$1(props, 'isOpen');
|
|
@@ -2835,8 +2797,6 @@ function getInitialState$1(props) {
|
|
|
2835
2797
|
var propTypes$1 = _extends({}, commonDropdownPropTypes, {
|
|
2836
2798
|
items: PropTypes.array.isRequired,
|
|
2837
2799
|
isItemDisabled: PropTypes.func,
|
|
2838
|
-
selectedItemChanged: PropTypes.func,
|
|
2839
|
-
getA11ySelectionMessage: PropTypes.func,
|
|
2840
2800
|
inputValue: PropTypes.string,
|
|
2841
2801
|
defaultInputValue: PropTypes.string,
|
|
2842
2802
|
initialInputValue: PropTypes.string,
|
|
@@ -2869,13 +2829,7 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2869
2829
|
}
|
|
2870
2830
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
2871
2831
|
) {
|
|
2872
|
-
var shouldCallDispatch;
|
|
2873
|
-
if (props.selectedItemChanged === undefined) {
|
|
2874
|
-
shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
2875
|
-
} else {
|
|
2876
|
-
console.warn("The \"selectedItemChanged\" is deprecated. Please use \"itemToKey instead\". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged");
|
|
2877
|
-
shouldCallDispatch = props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem);
|
|
2878
|
-
}
|
|
2832
|
+
var shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
2879
2833
|
if (shouldCallDispatch) {
|
|
2880
2834
|
dispatch({
|
|
2881
2835
|
type: ControlledPropUpdatedSelectedItem,
|
|
@@ -2898,7 +2852,6 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2898
2852
|
};
|
|
2899
2853
|
}
|
|
2900
2854
|
var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
2901
|
-
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
2902
2855
|
isItemDisabled: function isItemDisabled() {
|
|
2903
2856
|
return false;
|
|
2904
2857
|
}
|
|
@@ -3035,9 +2988,7 @@ function useCombobox(userProps) {
|
|
|
3035
2988
|
var items = props.items,
|
|
3036
2989
|
scrollIntoView = props.scrollIntoView,
|
|
3037
2990
|
environment = props.environment,
|
|
3038
|
-
getA11yStatusMessage = props.getA11yStatusMessage
|
|
3039
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
3040
|
-
itemToString = props.itemToString;
|
|
2991
|
+
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3041
2992
|
// Initial state depending on controlled props.
|
|
3042
2993
|
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1, isDropdownsStateEqual),
|
|
3043
2994
|
state = _useControlledReducer[0],
|
|
@@ -3068,20 +3019,8 @@ function useCombobox(userProps) {
|
|
|
3068
3019
|
}, [elementIds]);
|
|
3069
3020
|
|
|
3070
3021
|
// Effects.
|
|
3071
|
-
//
|
|
3072
|
-
|
|
3073
|
-
previousResultCount: previousResultCountRef.current,
|
|
3074
|
-
items: items,
|
|
3075
|
-
environment: environment,
|
|
3076
|
-
itemToString: itemToString
|
|
3077
|
-
}, state));
|
|
3078
|
-
// Sets a11y status message on changes in selectedItem.
|
|
3079
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
3080
|
-
previousResultCount: previousResultCountRef.current,
|
|
3081
|
-
items: items,
|
|
3082
|
-
environment: environment,
|
|
3083
|
-
itemToString: itemToString
|
|
3084
|
-
}, state));
|
|
3022
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3023
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
3085
3024
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3086
3025
|
var shouldScrollRef = useScrollIntoView({
|
|
3087
3026
|
menuElement: menuRef.current,
|
|
@@ -3504,18 +3443,6 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3504
3443
|
return true;
|
|
3505
3444
|
}
|
|
3506
3445
|
|
|
3507
|
-
/**
|
|
3508
|
-
* Returns a message to be added to aria-live region when item is removed.
|
|
3509
|
-
*
|
|
3510
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
3511
|
-
* @returns {string} The a11y message.
|
|
3512
|
-
*/
|
|
3513
|
-
function getA11yRemovalMessage(selectionParameters) {
|
|
3514
|
-
var removedSelectedItem = selectionParameters.removedSelectedItem,
|
|
3515
|
-
itemToStringLocal = selectionParameters.itemToString;
|
|
3516
|
-
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3517
|
-
}
|
|
3518
|
-
|
|
3519
3446
|
/**
|
|
3520
3447
|
* Check if a state is equal for taglist, by comparing active index and selected items.
|
|
3521
3448
|
* Used by useSelect and useCombobox.
|
|
@@ -3527,11 +3454,14 @@ function getA11yRemovalMessage(selectionParameters) {
|
|
|
3527
3454
|
function isStateEqual(prevState, newState) {
|
|
3528
3455
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3529
3456
|
}
|
|
3530
|
-
var propTypes =
|
|
3457
|
+
var propTypes = {
|
|
3458
|
+
stateReducer: commonPropTypes.stateReducer,
|
|
3459
|
+
itemToKey: commonPropTypes.itemToKey,
|
|
3460
|
+
environment: commonPropTypes.environment,
|
|
3531
3461
|
selectedItems: PropTypes.array,
|
|
3532
3462
|
initialSelectedItems: PropTypes.array,
|
|
3533
3463
|
defaultSelectedItems: PropTypes.array,
|
|
3534
|
-
|
|
3464
|
+
getA11yStatusMessage: PropTypes.func,
|
|
3535
3465
|
activeIndex: PropTypes.number,
|
|
3536
3466
|
initialActiveIndex: PropTypes.number,
|
|
3537
3467
|
defaultActiveIndex: PropTypes.number,
|
|
@@ -3539,13 +3469,11 @@ var propTypes = _extends({}, commonPropTypes, {
|
|
|
3539
3469
|
onSelectedItemsChange: PropTypes.func,
|
|
3540
3470
|
keyNavigationNext: PropTypes.string,
|
|
3541
3471
|
keyNavigationPrevious: PropTypes.string
|
|
3542
|
-
}
|
|
3472
|
+
};
|
|
3543
3473
|
var defaultProps = {
|
|
3544
|
-
itemToString: defaultProps$3.itemToString,
|
|
3545
3474
|
itemToKey: defaultProps$3.itemToKey,
|
|
3546
3475
|
stateReducer: defaultProps$3.stateReducer,
|
|
3547
3476
|
environment: defaultProps$3.environment,
|
|
3548
|
-
getA11yRemovalMessage: getA11yRemovalMessage,
|
|
3549
3477
|
keyNavigationNext: 'ArrowRight',
|
|
3550
3478
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3551
3479
|
};
|
|
@@ -3712,8 +3640,7 @@ function useMultipleSelection(userProps) {
|
|
|
3712
3640
|
validatePropTypes(userProps, useMultipleSelection);
|
|
3713
3641
|
// Props defaults and destructuring.
|
|
3714
3642
|
var props = _extends({}, defaultProps, userProps);
|
|
3715
|
-
var
|
|
3716
|
-
itemToString = props.itemToString,
|
|
3643
|
+
var getA11yStatusMessage = props.getA11yStatusMessage,
|
|
3717
3644
|
environment = props.environment,
|
|
3718
3645
|
keyNavigationNext = props.keyNavigationNext,
|
|
3719
3646
|
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
@@ -3728,7 +3655,6 @@ function useMultipleSelection(userProps) {
|
|
|
3728
3655
|
// Refs.
|
|
3729
3656
|
var isInitialMount = useIsInitialMount();
|
|
3730
3657
|
var dropdownRef = useRef(null);
|
|
3731
|
-
var previousSelectedItemsRef = useRef(selectedItems);
|
|
3732
3658
|
var selectedItemRefs = useRef();
|
|
3733
3659
|
selectedItemRefs.current = [];
|
|
3734
3660
|
var latest = useLatestRef({
|
|
@@ -3737,29 +3663,8 @@ function useMultipleSelection(userProps) {
|
|
|
3737
3663
|
});
|
|
3738
3664
|
|
|
3739
3665
|
// Effects.
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
if (isInitialMount || false || !(environment != null && environment.document)) {
|
|
3743
|
-
return;
|
|
3744
|
-
}
|
|
3745
|
-
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
3746
|
-
var removedSelectedItem = previousSelectedItemsRef.current.find(function (selectedItem) {
|
|
3747
|
-
return selectedItems.findIndex(function (item) {
|
|
3748
|
-
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
3749
|
-
}) < 0;
|
|
3750
|
-
});
|
|
3751
|
-
setStatus(getA11yRemovalMessage({
|
|
3752
|
-
itemToString: itemToString,
|
|
3753
|
-
resultCount: selectedItems.length,
|
|
3754
|
-
removedSelectedItem: removedSelectedItem,
|
|
3755
|
-
activeIndex: activeIndex,
|
|
3756
|
-
activeSelectedItem: selectedItems[activeIndex]
|
|
3757
|
-
}), environment.document);
|
|
3758
|
-
}
|
|
3759
|
-
previousSelectedItemsRef.current = selectedItems;
|
|
3760
|
-
|
|
3761
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3762
|
-
}, [selectedItems.length]);
|
|
3666
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3667
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [activeIndex, selectedItems], environment);
|
|
3763
3668
|
// Sets focus on active item.
|
|
3764
3669
|
useEffect(function () {
|
|
3765
3670
|
if (isInitialMount) {
|