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
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
6
6
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
-
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
8
7
|
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
9
8
|
var PropTypes = require('prop-types');
|
|
10
9
|
var React = require('react');
|
|
@@ -16,7 +15,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
15
|
|
|
17
16
|
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
18
17
|
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
19
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
20
18
|
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
21
19
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
22
20
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
@@ -154,7 +152,7 @@ function resetIdCounter() {
|
|
|
154
152
|
* @param {Object} param the downshift state and other relevant properties
|
|
155
153
|
* @return {String} the a11y status message
|
|
156
154
|
*/
|
|
157
|
-
function getA11yStatusMessage
|
|
155
|
+
function getA11yStatusMessage(_ref2) {
|
|
158
156
|
var isOpen = _ref2.isOpen,
|
|
159
157
|
resultCount = _ref2.resultCount,
|
|
160
158
|
previousResultCount = _ref2.previousResultCount;
|
|
@@ -423,6 +421,17 @@ function setStatus(status, documentProp) {
|
|
|
423
421
|
cleanupStatus(documentProp);
|
|
424
422
|
}
|
|
425
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Removes the status element from the DOM
|
|
426
|
+
* @param {Document} documentProp
|
|
427
|
+
*/
|
|
428
|
+
function cleanupStatusDiv(documentProp) {
|
|
429
|
+
var statusDiv = documentProp == null ? void 0 : documentProp.getElementById('a11y-status-message');
|
|
430
|
+
if (statusDiv) {
|
|
431
|
+
statusDiv.remove();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
426
435
|
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
427
436
|
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
428
437
|
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
@@ -462,14 +471,13 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
462
471
|
touchEnd: touchEnd
|
|
463
472
|
});
|
|
464
473
|
|
|
465
|
-
var _excluded$
|
|
474
|
+
var _excluded$3 = ["refKey", "ref"],
|
|
466
475
|
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
467
476
|
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
468
477
|
_excluded4$2 = ["refKey", "ref"],
|
|
469
478
|
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
470
479
|
var Downshift = /*#__PURE__*/function () {
|
|
471
480
|
var Downshift = /*#__PURE__*/function (_Component) {
|
|
472
|
-
_inheritsLoose__default["default"](Downshift, _Component);
|
|
473
481
|
function Downshift(_props) {
|
|
474
482
|
var _this;
|
|
475
483
|
_this = _Component.call(this, _props) || this;
|
|
@@ -655,7 +663,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
655
663
|
_ref$refKey = _ref.refKey,
|
|
656
664
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
657
665
|
ref = _ref.ref,
|
|
658
|
-
rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$
|
|
666
|
+
rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$3);
|
|
659
667
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
660
668
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
661
669
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
@@ -834,7 +842,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
834
842
|
_this.buttonHandleKeyDown = function (event) {
|
|
835
843
|
var key = normalizeArrowKey(event);
|
|
836
844
|
if (_this.buttonKeyDownHandlers[key]) {
|
|
837
|
-
_this.buttonKeyDownHandlers[key].call(
|
|
845
|
+
_this.buttonKeyDownHandlers[key].call(_this, event);
|
|
838
846
|
}
|
|
839
847
|
};
|
|
840
848
|
_this.buttonHandleClick = function (event) {
|
|
@@ -934,7 +942,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
934
942
|
_this.inputHandleKeyDown = function (event) {
|
|
935
943
|
var key = normalizeArrowKey(event);
|
|
936
944
|
if (key && _this.inputKeyDownHandlers[key]) {
|
|
937
|
-
_this.inputKeyDownHandlers[key].call(
|
|
945
|
+
_this.inputKeyDownHandlers[key].call(_this, event);
|
|
938
946
|
}
|
|
939
947
|
};
|
|
940
948
|
_this.inputHandleChange = function (event) {
|
|
@@ -1138,6 +1146,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1138
1146
|
_this.state = _state;
|
|
1139
1147
|
return _this;
|
|
1140
1148
|
}
|
|
1149
|
+
_inheritsLoose__default["default"](Downshift, _Component);
|
|
1141
1150
|
var _proto = Downshift.prototype;
|
|
1142
1151
|
/**
|
|
1143
1152
|
* Clear all running timeouts
|
|
@@ -1345,7 +1354,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1345
1354
|
Downshift.defaultProps = {
|
|
1346
1355
|
defaultHighlightedIndex: null,
|
|
1347
1356
|
defaultIsOpen: false,
|
|
1348
|
-
getA11yStatusMessage: getA11yStatusMessage
|
|
1357
|
+
getA11yStatusMessage: getA11yStatusMessage,
|
|
1349
1358
|
itemToString: function itemToString(i) {
|
|
1350
1359
|
if (i == null) {
|
|
1351
1360
|
return '';
|
|
@@ -1447,7 +1456,6 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
|
|
|
1447
1456
|
}
|
|
1448
1457
|
}
|
|
1449
1458
|
|
|
1450
|
-
var _excluded$3 = ["highlightedIndex", "items", "environment"];
|
|
1451
1459
|
var dropdownDefaultStateValues = {
|
|
1452
1460
|
highlightedIndex: -1,
|
|
1453
1461
|
isOpen: false,
|
|
@@ -1492,23 +1500,11 @@ function stateReducer(s, a) {
|
|
|
1492
1500
|
return a.changes;
|
|
1493
1501
|
}
|
|
1494
1502
|
|
|
1495
|
-
/**
|
|
1496
|
-
* Returns a message to be added to aria-live region when item is selected.
|
|
1497
|
-
*
|
|
1498
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
1499
|
-
* @returns {string} The a11y message.
|
|
1500
|
-
*/
|
|
1501
|
-
function getA11ySelectionMessage(selectionParameters) {
|
|
1502
|
-
var selectedItem = selectionParameters.selectedItem,
|
|
1503
|
-
itemToString = selectionParameters.itemToString;
|
|
1504
|
-
return selectedItem ? itemToString(selectedItem) + " has been selected." : '';
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
1503
|
/**
|
|
1508
1504
|
* Debounced call for updating the a11y message.
|
|
1509
1505
|
*/
|
|
1510
|
-
var updateA11yStatus = debounce(function (
|
|
1511
|
-
setStatus(
|
|
1506
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
1507
|
+
setStatus(status, document);
|
|
1512
1508
|
}, 200);
|
|
1513
1509
|
|
|
1514
1510
|
// istanbul ignore next
|
|
@@ -1653,7 +1649,6 @@ var defaultProps$3 = {
|
|
|
1653
1649
|
return item;
|
|
1654
1650
|
},
|
|
1655
1651
|
stateReducer: stateReducer,
|
|
1656
|
-
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
1657
1652
|
scrollIntoView: scrollIntoView,
|
|
1658
1653
|
environment: /* istanbul ignore next (ssr) */
|
|
1659
1654
|
typeof window === 'undefined' || true ? undefined : window
|
|
@@ -1799,34 +1794,47 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1799
1794
|
return setGetterPropCallInfo;
|
|
1800
1795
|
};
|
|
1801
1796
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1800
|
+
* @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
|
|
1801
|
+
* @param {Object} options The options to be passed to getA11yStatusMessage if called.
|
|
1802
|
+
* @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
|
|
1803
|
+
* @param {{document: Document}} environment The environment object containing the document.
|
|
1804
|
+
*/
|
|
1805
|
+
function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
|
|
1806
|
+
if (environment === void 0) {
|
|
1807
|
+
environment = {};
|
|
1808
|
+
}
|
|
1809
|
+
var document = environment.document;
|
|
1807
1810
|
var isInitialMount = useIsInitialMount();
|
|
1808
|
-
|
|
1811
|
+
|
|
1812
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
1809
1813
|
React.useEffect(function () {
|
|
1810
|
-
if (isInitialMount || true || !
|
|
1814
|
+
if (!getA11yStatusMessage || isInitialMount || true || !document) {
|
|
1811
1815
|
return;
|
|
1812
1816
|
}
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
highlightedItem: items[highlightedIndex],
|
|
1817
|
-
resultCount: items.length
|
|
1818
|
-
}, rest));
|
|
1819
|
-
}, environment.document);
|
|
1817
|
+
var status = getA11yStatusMessage(options);
|
|
1818
|
+
updateA11yStatus(status, document);
|
|
1819
|
+
|
|
1820
1820
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1821
|
-
}, dependencyArray);
|
|
1821
|
+
}, [dependencyArray]);
|
|
1822
|
+
|
|
1823
|
+
// Cleanup the status message container.
|
|
1824
|
+
React.useEffect(function () {
|
|
1825
|
+
return function () {
|
|
1826
|
+
updateA11yStatus.cancel();
|
|
1827
|
+
cleanupStatusDiv(document);
|
|
1828
|
+
};
|
|
1829
|
+
}, [document]);
|
|
1822
1830
|
}
|
|
1823
|
-
function useScrollIntoView(
|
|
1824
|
-
var highlightedIndex =
|
|
1825
|
-
isOpen =
|
|
1826
|
-
itemRefs =
|
|
1827
|
-
getItemNodeFromIndex =
|
|
1828
|
-
menuElement =
|
|
1829
|
-
scrollIntoViewProp =
|
|
1831
|
+
function useScrollIntoView(_ref3) {
|
|
1832
|
+
var highlightedIndex = _ref3.highlightedIndex,
|
|
1833
|
+
isOpen = _ref3.isOpen,
|
|
1834
|
+
itemRefs = _ref3.itemRefs,
|
|
1835
|
+
getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
|
|
1836
|
+
menuElement = _ref3.menuElement,
|
|
1837
|
+
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
1830
1838
|
// used not to scroll on highlight by mouse.
|
|
1831
1839
|
var shouldScrollRef = React.useRef(true);
|
|
1832
1840
|
// Scroll on highlighted item if change comes from keyboard.
|
|
@@ -1848,9 +1856,9 @@ function useScrollIntoView(_ref4) {
|
|
|
1848
1856
|
var useControlPropsValidator = noop;
|
|
1849
1857
|
/* istanbul ignore next */
|
|
1850
1858
|
if (process.env.NODE_ENV !== 'production') {
|
|
1851
|
-
useControlPropsValidator = function useControlPropsValidator(
|
|
1852
|
-
var props =
|
|
1853
|
-
state =
|
|
1859
|
+
useControlPropsValidator = function useControlPropsValidator(_ref4) {
|
|
1860
|
+
var props = _ref4.props,
|
|
1861
|
+
state = _ref4.state;
|
|
1854
1862
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
1855
1863
|
var prevPropsRef = React.useRef(props);
|
|
1856
1864
|
var isInitialMount = useIsInitialMount();
|
|
@@ -2031,29 +2039,8 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2031
2039
|
}
|
|
2032
2040
|
return highlightedIndex;
|
|
2033
2041
|
}
|
|
2034
|
-
var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes__default["default"].array.isRequired, isItemDisabled: PropTypes__default["default"].func
|
|
2035
|
-
|
|
2036
|
-
* Default implementation for status message. Only added when menu is open.
|
|
2037
|
-
* Will specift if there are results in the list, and if so, how many,
|
|
2038
|
-
* and what keys are relevant.
|
|
2039
|
-
*
|
|
2040
|
-
* @param {Object} param the downshift state and other relevant properties
|
|
2041
|
-
* @return {String} the a11y status message
|
|
2042
|
-
*/
|
|
2043
|
-
function getA11yStatusMessage(_a) {
|
|
2044
|
-
var isOpen = _a.isOpen, resultCount = _a.resultCount, previousResultCount = _a.previousResultCount;
|
|
2045
|
-
if (!isOpen) {
|
|
2046
|
-
return '';
|
|
2047
|
-
}
|
|
2048
|
-
if (!resultCount) {
|
|
2049
|
-
return 'No results are available.';
|
|
2050
|
-
}
|
|
2051
|
-
if (resultCount !== previousResultCount) {
|
|
2052
|
-
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.");
|
|
2053
|
-
}
|
|
2054
|
-
return '';
|
|
2055
|
-
}
|
|
2056
|
-
var defaultProps$2 = tslib.__assign(tslib.__assign({}, defaultProps$3), { getA11yStatusMessage: getA11yStatusMessage, isItemDisabled: function () {
|
|
2042
|
+
var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes__default["default"].array.isRequired, isItemDisabled: PropTypes__default["default"].func });
|
|
2043
|
+
var defaultProps$2 = tslib.__assign(tslib.__assign({}, defaultProps$3), { isItemDisabled: function () {
|
|
2057
2044
|
return false;
|
|
2058
2045
|
} });
|
|
2059
2046
|
// eslint-disable-next-line import/no-mutable-exports
|
|
@@ -2235,11 +2222,8 @@ function useSelect(userProps) {
|
|
|
2235
2222
|
validatePropTypes$2(userProps, useSelect);
|
|
2236
2223
|
// Props defaults and destructuring.
|
|
2237
2224
|
var props = _extends__default["default"]({}, defaultProps$2, userProps);
|
|
2238
|
-
var
|
|
2239
|
-
scrollIntoView = props.scrollIntoView,
|
|
2225
|
+
var scrollIntoView = props.scrollIntoView,
|
|
2240
2226
|
environment = props.environment,
|
|
2241
|
-
itemToString = props.itemToString,
|
|
2242
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
2243
2227
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2244
2228
|
// Initial state depending on controlled props.
|
|
2245
2229
|
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2, isDropdownsStateEqual),
|
|
@@ -2257,9 +2241,6 @@ function useSelect(userProps) {
|
|
|
2257
2241
|
var clearTimeoutRef = React.useRef(null);
|
|
2258
2242
|
// prevent id re-generation between renders.
|
|
2259
2243
|
var elementIds = useElementIds(props);
|
|
2260
|
-
// used to keep track of how many items we had on previous cycle.
|
|
2261
|
-
var previousResultCountRef = React.useRef();
|
|
2262
|
-
var isInitialMount = useIsInitialMount();
|
|
2263
2244
|
// utility callback to get item element.
|
|
2264
2245
|
var latest = useLatestRef({
|
|
2265
2246
|
state: state,
|
|
@@ -2272,20 +2253,8 @@ function useSelect(userProps) {
|
|
|
2272
2253
|
}, [elementIds]);
|
|
2273
2254
|
|
|
2274
2255
|
// Effects.
|
|
2275
|
-
//
|
|
2276
|
-
|
|
2277
|
-
previousResultCount: previousResultCountRef.current,
|
|
2278
|
-
items: items,
|
|
2279
|
-
environment: environment,
|
|
2280
|
-
itemToString: itemToString
|
|
2281
|
-
}, state));
|
|
2282
|
-
// Sets a11y status message on changes in selectedItem.
|
|
2283
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
|
|
2284
|
-
previousResultCount: previousResultCountRef.current,
|
|
2285
|
-
items: items,
|
|
2286
|
-
environment: environment,
|
|
2287
|
-
itemToString: itemToString
|
|
2288
|
-
}, state));
|
|
2256
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2257
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2289
2258
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2290
2259
|
var shouldScrollRef = useScrollIntoView({
|
|
2291
2260
|
menuElement: menuRef.current,
|
|
@@ -2295,7 +2264,6 @@ function useSelect(userProps) {
|
|
|
2295
2264
|
scrollIntoView: scrollIntoView,
|
|
2296
2265
|
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2297
2266
|
});
|
|
2298
|
-
|
|
2299
2267
|
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2300
2268
|
React.useEffect(function () {
|
|
2301
2269
|
// init the clean function here as we need access to dispatch.
|
|
@@ -2311,7 +2279,6 @@ function useSelect(userProps) {
|
|
|
2311
2279
|
clearTimeoutRef.current.cancel();
|
|
2312
2280
|
};
|
|
2313
2281
|
}, []);
|
|
2314
|
-
|
|
2315
2282
|
// Invokes the keysSoFar callback set up above.
|
|
2316
2283
|
React.useEffect(function () {
|
|
2317
2284
|
if (!inputValue) {
|
|
@@ -2323,12 +2290,6 @@ function useSelect(userProps) {
|
|
|
2323
2290
|
props: props,
|
|
2324
2291
|
state: state
|
|
2325
2292
|
});
|
|
2326
|
-
React.useEffect(function () {
|
|
2327
|
-
if (isInitialMount) {
|
|
2328
|
-
return;
|
|
2329
|
-
}
|
|
2330
|
-
previousResultCountRef.current = items.length;
|
|
2331
|
-
});
|
|
2332
2293
|
// Focus the toggle button on first render if required.
|
|
2333
2294
|
React.useEffect(function () {
|
|
2334
2295
|
var focusOnOpen = getInitialValue$1(props, 'isOpen');
|
|
@@ -2694,8 +2655,6 @@ function getInitialState$1(props) {
|
|
|
2694
2655
|
var propTypes$1 = _extends__default["default"]({}, commonDropdownPropTypes, {
|
|
2695
2656
|
items: PropTypes__default["default"].array.isRequired,
|
|
2696
2657
|
isItemDisabled: PropTypes__default["default"].func,
|
|
2697
|
-
selectedItemChanged: PropTypes__default["default"].func,
|
|
2698
|
-
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
2699
2658
|
inputValue: PropTypes__default["default"].string,
|
|
2700
2659
|
defaultInputValue: PropTypes__default["default"].string,
|
|
2701
2660
|
initialInputValue: PropTypes__default["default"].string,
|
|
@@ -2728,13 +2687,7 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2728
2687
|
}
|
|
2729
2688
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
2730
2689
|
) {
|
|
2731
|
-
var shouldCallDispatch;
|
|
2732
|
-
if (props.selectedItemChanged === undefined) {
|
|
2733
|
-
shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
2734
|
-
} else {
|
|
2735
|
-
console.warn("The \"selectedItemChanged\" is deprecated. Please use \"itemToKey instead\". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged");
|
|
2736
|
-
shouldCallDispatch = props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem);
|
|
2737
|
-
}
|
|
2690
|
+
var shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
|
|
2738
2691
|
if (shouldCallDispatch) {
|
|
2739
2692
|
dispatch({
|
|
2740
2693
|
type: ControlledPropUpdatedSelectedItem,
|
|
@@ -2757,7 +2710,6 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2757
2710
|
};
|
|
2758
2711
|
}
|
|
2759
2712
|
var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
2760
|
-
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
2761
2713
|
isItemDisabled: function isItemDisabled() {
|
|
2762
2714
|
return false;
|
|
2763
2715
|
}
|
|
@@ -2894,9 +2846,7 @@ function useCombobox(userProps) {
|
|
|
2894
2846
|
var items = props.items,
|
|
2895
2847
|
scrollIntoView = props.scrollIntoView,
|
|
2896
2848
|
environment = props.environment,
|
|
2897
|
-
getA11yStatusMessage = props.getA11yStatusMessage
|
|
2898
|
-
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
2899
|
-
itemToString = props.itemToString;
|
|
2849
|
+
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2900
2850
|
// Initial state depending on controlled props.
|
|
2901
2851
|
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1, isDropdownsStateEqual),
|
|
2902
2852
|
state = _useControlledReducer[0],
|
|
@@ -2927,20 +2877,8 @@ function useCombobox(userProps) {
|
|
|
2927
2877
|
}, [elementIds]);
|
|
2928
2878
|
|
|
2929
2879
|
// Effects.
|
|
2930
|
-
//
|
|
2931
|
-
|
|
2932
|
-
previousResultCount: previousResultCountRef.current,
|
|
2933
|
-
items: items,
|
|
2934
|
-
environment: environment,
|
|
2935
|
-
itemToString: itemToString
|
|
2936
|
-
}, state));
|
|
2937
|
-
// Sets a11y status message on changes in selectedItem.
|
|
2938
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
|
|
2939
|
-
previousResultCount: previousResultCountRef.current,
|
|
2940
|
-
items: items,
|
|
2941
|
-
environment: environment,
|
|
2942
|
-
itemToString: itemToString
|
|
2943
|
-
}, state));
|
|
2880
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2881
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2944
2882
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2945
2883
|
var shouldScrollRef = useScrollIntoView({
|
|
2946
2884
|
menuElement: menuRef.current,
|
|
@@ -3375,18 +3313,6 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3375
3313
|
return true;
|
|
3376
3314
|
}
|
|
3377
3315
|
|
|
3378
|
-
/**
|
|
3379
|
-
* Returns a message to be added to aria-live region when item is removed.
|
|
3380
|
-
*
|
|
3381
|
-
* @param {Object} selectionParameters Parameters required to build the message.
|
|
3382
|
-
* @returns {string} The a11y message.
|
|
3383
|
-
*/
|
|
3384
|
-
function getA11yRemovalMessage(selectionParameters) {
|
|
3385
|
-
var removedSelectedItem = selectionParameters.removedSelectedItem,
|
|
3386
|
-
itemToStringLocal = selectionParameters.itemToString;
|
|
3387
|
-
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3388
|
-
}
|
|
3389
|
-
|
|
3390
3316
|
/**
|
|
3391
3317
|
* Check if a state is equal for taglist, by comparing active index and selected items.
|
|
3392
3318
|
* Used by useSelect and useCombobox.
|
|
@@ -3398,11 +3324,14 @@ function getA11yRemovalMessage(selectionParameters) {
|
|
|
3398
3324
|
function isStateEqual(prevState, newState) {
|
|
3399
3325
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3400
3326
|
}
|
|
3401
|
-
var propTypes =
|
|
3327
|
+
var propTypes = {
|
|
3328
|
+
stateReducer: commonPropTypes.stateReducer,
|
|
3329
|
+
itemToKey: commonPropTypes.itemToKey,
|
|
3330
|
+
environment: commonPropTypes.environment,
|
|
3402
3331
|
selectedItems: PropTypes__default["default"].array,
|
|
3403
3332
|
initialSelectedItems: PropTypes__default["default"].array,
|
|
3404
3333
|
defaultSelectedItems: PropTypes__default["default"].array,
|
|
3405
|
-
|
|
3334
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
3406
3335
|
activeIndex: PropTypes__default["default"].number,
|
|
3407
3336
|
initialActiveIndex: PropTypes__default["default"].number,
|
|
3408
3337
|
defaultActiveIndex: PropTypes__default["default"].number,
|
|
@@ -3410,13 +3339,11 @@ var propTypes = _extends__default["default"]({}, commonPropTypes, {
|
|
|
3410
3339
|
onSelectedItemsChange: PropTypes__default["default"].func,
|
|
3411
3340
|
keyNavigationNext: PropTypes__default["default"].string,
|
|
3412
3341
|
keyNavigationPrevious: PropTypes__default["default"].string
|
|
3413
|
-
}
|
|
3342
|
+
};
|
|
3414
3343
|
var defaultProps = {
|
|
3415
|
-
itemToString: defaultProps$3.itemToString,
|
|
3416
3344
|
itemToKey: defaultProps$3.itemToKey,
|
|
3417
3345
|
stateReducer: defaultProps$3.stateReducer,
|
|
3418
3346
|
environment: defaultProps$3.environment,
|
|
3419
|
-
getA11yRemovalMessage: getA11yRemovalMessage,
|
|
3420
3347
|
keyNavigationNext: 'ArrowRight',
|
|
3421
3348
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3422
3349
|
};
|
|
@@ -3583,8 +3510,7 @@ function useMultipleSelection(userProps) {
|
|
|
3583
3510
|
validatePropTypes(userProps, useMultipleSelection);
|
|
3584
3511
|
// Props defaults and destructuring.
|
|
3585
3512
|
var props = _extends__default["default"]({}, defaultProps, userProps);
|
|
3586
|
-
var
|
|
3587
|
-
itemToString = props.itemToString,
|
|
3513
|
+
var getA11yStatusMessage = props.getA11yStatusMessage,
|
|
3588
3514
|
environment = props.environment,
|
|
3589
3515
|
keyNavigationNext = props.keyNavigationNext,
|
|
3590
3516
|
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
@@ -3599,7 +3525,6 @@ function useMultipleSelection(userProps) {
|
|
|
3599
3525
|
// Refs.
|
|
3600
3526
|
var isInitialMount = useIsInitialMount();
|
|
3601
3527
|
var dropdownRef = React.useRef(null);
|
|
3602
|
-
var previousSelectedItemsRef = React.useRef(selectedItems);
|
|
3603
3528
|
var selectedItemRefs = React.useRef();
|
|
3604
3529
|
selectedItemRefs.current = [];
|
|
3605
3530
|
var latest = useLatestRef({
|
|
@@ -3608,29 +3533,8 @@ function useMultipleSelection(userProps) {
|
|
|
3608
3533
|
});
|
|
3609
3534
|
|
|
3610
3535
|
// Effects.
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
if (isInitialMount || true || !(environment != null && environment.document)) {
|
|
3614
|
-
return;
|
|
3615
|
-
}
|
|
3616
|
-
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
3617
|
-
var removedSelectedItem = previousSelectedItemsRef.current.find(function (selectedItem) {
|
|
3618
|
-
return selectedItems.findIndex(function (item) {
|
|
3619
|
-
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
3620
|
-
}) < 0;
|
|
3621
|
-
});
|
|
3622
|
-
setStatus(getA11yRemovalMessage({
|
|
3623
|
-
itemToString: itemToString,
|
|
3624
|
-
resultCount: selectedItems.length,
|
|
3625
|
-
removedSelectedItem: removedSelectedItem,
|
|
3626
|
-
activeIndex: activeIndex,
|
|
3627
|
-
activeSelectedItem: selectedItems[activeIndex]
|
|
3628
|
-
}), environment.document);
|
|
3629
|
-
}
|
|
3630
|
-
previousSelectedItemsRef.current = selectedItems;
|
|
3631
|
-
|
|
3632
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3633
|
-
}, [selectedItems.length]);
|
|
3536
|
+
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3537
|
+
useA11yMessageStatus(getA11yStatusMessage, state, [activeIndex, selectedItems], environment);
|
|
3634
3538
|
// Sets focus on active item.
|
|
3635
3539
|
React.useEffect(function () {
|
|
3636
3540
|
if (isInitialMount) {
|