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.
@@ -1,24 +1,11 @@
1
- import { A11yStatusMessageOptions } from '../../types';
2
1
  import { GetItemIndexByCharacterKeyOptions } from './types';
3
2
  export declare function getItemIndexByCharacterKey<Item>({ keysSoFar, highlightedIndex, items, itemToString, isItemDisabled, }: GetItemIndexByCharacterKeyOptions<Item>): number;
4
- /**
5
- * Default implementation for status message. Only added when menu is open.
6
- * Will specift if there are results in the list, and if so, how many,
7
- * and what keys are relevant.
8
- *
9
- * @param {Object} param the downshift state and other relevant properties
10
- * @return {String} the a11y status message
11
- */
12
- declare function getA11yStatusMessage<Item>({ isOpen, resultCount, previousResultCount, }: A11yStatusMessageOptions<Item>): string;
13
3
  export declare const defaultProps: {
14
- getA11yStatusMessage: typeof getA11yStatusMessage;
15
4
  isItemDisabled(): boolean;
16
5
  itemToString(item: any): string;
17
6
  itemToKey(item: any): any;
18
7
  stateReducer: (s: Object, a: Object) => Object;
19
- getA11ySelectionMessage: (selectionParameters: Object) => string;
20
8
  scrollIntoView: typeof import("../../utils").scrollIntoView;
21
9
  environment: (Window & typeof globalThis) | undefined;
22
10
  };
23
11
  export declare let validatePropTypes: (options: unknown, caller: Function) => void;
24
- export {};
@@ -7,12 +7,10 @@ export function useScrollIntoView({ highlightedIndex, isOpen, itemRefs, getItemN
7
7
  menuElement: any;
8
8
  scrollIntoView: any;
9
9
  }): React.MutableRefObject<boolean>;
10
- export function useA11yMessageSetter(getA11yMessage: any, dependencyArray: any, { highlightedIndex, items, environment, ...rest }: {
11
- [x: string]: any;
12
- highlightedIndex: any;
13
- items: any;
14
- environment: any;
15
- }): void;
10
+ /**
11
+ * Debounced call for updating the a11y message.
12
+ */
13
+ export const updateA11yStatus: Function;
16
14
  export function useGetterPropsCalledChecker(): typeof noop;
17
15
  /**
18
16
  * Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
@@ -46,7 +44,6 @@ export namespace defaultProps {
46
44
  export function itemToString(item: any): string;
47
45
  export function itemToKey(item: any): any;
48
46
  export { stateReducer };
49
- export { getA11ySelectionMessage };
50
47
  export { scrollIntoView };
51
48
  export const environment: (Window & typeof globalThis) | undefined;
52
49
  }
@@ -166,6 +163,16 @@ export namespace commonPropTypes { }
166
163
  * Tracks if it's the first render.
167
164
  */
168
165
  export function useIsInitialMount(): boolean;
166
+ /**
167
+ * Adds an a11y aria live status message if getA11yStatusMessage is passed.
168
+ * @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
169
+ * @param {Object} options The options to be passed to getA11yStatusMessage if called.
170
+ * @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
171
+ * @param {{document: Document}} environment The environment object containing the document.
172
+ */
173
+ export function useA11yMessageStatus(getA11yStatusMessage: (options: Object) => string, options: Object, dependencyArray: Array<unknown>, environment?: {
174
+ document: Document;
175
+ }): void;
169
176
  import { noop } from "../utils";
170
177
  import React from "react";
171
178
  /**
@@ -176,13 +183,6 @@ import React from "react";
176
183
  * @returns {Object} changes.
177
184
  */
178
185
  declare function stateReducer(s: Object, a: Object): Object;
179
- /**
180
- * Returns a message to be added to aria-live region when item is selected.
181
- *
182
- * @param {Object} selectionParameters Parameters required to build the message.
183
- * @returns {string} The a11y message.
184
- */
185
- declare function getA11ySelectionMessage(selectionParameters: Object): string;
186
186
  import { scrollIntoView } from "../utils";
187
187
  import PropTypes from "prop-types";
188
188
  export {};
@@ -2,4 +2,9 @@
2
2
  * @param {String} status the status message
3
3
  * @param {Object} documentProp document passed by the user.
4
4
  */
5
- export default function setStatus(status: string, documentProp: Object): void;
5
+ export function setStatus(status: string, documentProp: Object): void;
6
+ /**
7
+ * Removes the status element from the DOM
8
+ * @param {Document} documentProp
9
+ */
10
+ export function cleanupStatusDiv(documentProp: Document): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "8.5.0",
3
+ "version": "9.0.0",
4
4
  "description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
5
5
  "main": "dist/downshift.cjs.js",
6
6
  "react-native": "dist/downshift.native.cjs.js",
@@ -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 React = require('preact/compat');
10
9
  var reactIs = require('react-is');
@@ -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 React__default = /*#__PURE__*/_interopDefaultLegacy(React);
22
20
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
@@ -165,7 +163,7 @@ function resetIdCounter() {
165
163
  * @param {Object} param the downshift state and other relevant properties
166
164
  * @return {String} the a11y status message
167
165
  */
168
- function getA11yStatusMessage$1(_ref2) {
166
+ function getA11yStatusMessage(_ref2) {
169
167
  var isOpen = _ref2.isOpen,
170
168
  resultCount = _ref2.resultCount,
171
169
  previousResultCount = _ref2.previousResultCount;
@@ -460,6 +458,17 @@ function setStatus(status, documentProp) {
460
458
  cleanupStatus(documentProp);
461
459
  }
462
460
 
461
+ /**
462
+ * Removes the status element from the DOM
463
+ * @param {Document} documentProp
464
+ */
465
+ function cleanupStatusDiv(documentProp) {
466
+ var statusDiv = documentProp == null ? void 0 : documentProp.getElementById('a11y-status-message');
467
+ if (statusDiv) {
468
+ statusDiv.remove();
469
+ }
470
+ }
471
+
463
472
  var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
464
473
  var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
465
474
  var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
@@ -499,14 +508,13 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
499
508
  touchEnd: touchEnd
500
509
  });
501
510
 
502
- var _excluded$4 = ["refKey", "ref"],
511
+ var _excluded$3 = ["refKey", "ref"],
503
512
  _excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
504
513
  _excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
505
514
  _excluded4$2 = ["refKey", "ref"],
506
515
  _excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
507
516
  var Downshift = /*#__PURE__*/function () {
508
517
  var Downshift = /*#__PURE__*/function (_Component) {
509
- _inheritsLoose__default["default"](Downshift, _Component);
510
518
  function Downshift(_props) {
511
519
  var _this;
512
520
  _this = _Component.call(this, _props) || this;
@@ -692,7 +700,7 @@ var Downshift = /*#__PURE__*/function () {
692
700
  _ref$refKey = _ref.refKey,
693
701
  refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
694
702
  ref = _ref.ref,
695
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
703
+ rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$3);
696
704
  var _ref2 = _temp2 === void 0 ? {} : _temp2,
697
705
  _ref2$suppressRefErro = _ref2.suppressRefError,
698
706
  suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
@@ -873,7 +881,7 @@ var Downshift = /*#__PURE__*/function () {
873
881
  _this.buttonHandleKeyDown = function (event) {
874
882
  var key = normalizeArrowKey(event);
875
883
  if (_this.buttonKeyDownHandlers[key]) {
876
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
884
+ _this.buttonKeyDownHandlers[key].call(_this, event);
877
885
  }
878
886
  };
879
887
  _this.buttonHandleClick = function (event) {
@@ -969,7 +977,7 @@ var Downshift = /*#__PURE__*/function () {
969
977
  _this.inputHandleKeyDown = function (event) {
970
978
  var key = normalizeArrowKey(event);
971
979
  if (key && _this.inputKeyDownHandlers[key]) {
972
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
980
+ _this.inputKeyDownHandlers[key].call(_this, event);
973
981
  }
974
982
  };
975
983
  _this.inputHandleChange = function (event) {
@@ -1173,6 +1181,7 @@ var Downshift = /*#__PURE__*/function () {
1173
1181
  _this.state = _state;
1174
1182
  return _this;
1175
1183
  }
1184
+ _inheritsLoose__default["default"](Downshift, _Component);
1176
1185
  var _proto = Downshift.prototype;
1177
1186
  /**
1178
1187
  * Clear all running timeouts
@@ -1453,7 +1462,7 @@ var Downshift = /*#__PURE__*/function () {
1453
1462
  Downshift.defaultProps = {
1454
1463
  defaultHighlightedIndex: null,
1455
1464
  defaultIsOpen: false,
1456
- getA11yStatusMessage: getA11yStatusMessage$1,
1465
+ getA11yStatusMessage: getA11yStatusMessage,
1457
1466
  itemToString: function itemToString(i) {
1458
1467
  if (i == null) {
1459
1468
  return '';
@@ -1509,7 +1518,6 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
1509
1518
  }
1510
1519
  }
1511
1520
 
1512
- var _excluded$3 = ["highlightedIndex", "items", "environment"];
1513
1521
  var dropdownDefaultStateValues = {
1514
1522
  highlightedIndex: -1,
1515
1523
  isOpen: false,
@@ -1554,23 +1562,11 @@ function stateReducer(s, a) {
1554
1562
  return a.changes;
1555
1563
  }
1556
1564
 
1557
- /**
1558
- * Returns a message to be added to aria-live region when item is selected.
1559
- *
1560
- * @param {Object} selectionParameters Parameters required to build the message.
1561
- * @returns {string} The a11y message.
1562
- */
1563
- function getA11ySelectionMessage(selectionParameters) {
1564
- var selectedItem = selectionParameters.selectedItem,
1565
- itemToString = selectionParameters.itemToString;
1566
- return selectedItem ? itemToString(selectedItem) + " has been selected." : '';
1567
- }
1568
-
1569
1565
  /**
1570
1566
  * Debounced call for updating the a11y message.
1571
1567
  */
1572
- var updateA11yStatus = debounce(function (getA11yMessage, document) {
1573
- setStatus(getA11yMessage(), document);
1568
+ var updateA11yStatus = debounce(function (status, document) {
1569
+ setStatus(status, document);
1574
1570
  }, 200);
1575
1571
 
1576
1572
  // istanbul ignore next
@@ -1718,7 +1714,6 @@ var defaultProps$3 = {
1718
1714
  return item;
1719
1715
  },
1720
1716
  stateReducer: stateReducer,
1721
- getA11ySelectionMessage: getA11ySelectionMessage,
1722
1717
  scrollIntoView: scrollIntoView,
1723
1718
  environment: /* istanbul ignore next (ssr) */
1724
1719
  typeof window === 'undefined' || false ? undefined : window
@@ -1902,34 +1897,47 @@ if (process.env.NODE_ENV !== 'production') {
1902
1897
  return setGetterPropCallInfo;
1903
1898
  };
1904
1899
  }
1905
- function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref3) {
1906
- var highlightedIndex = _ref3.highlightedIndex,
1907
- items = _ref3.items,
1908
- environment = _ref3.environment,
1909
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded$3);
1900
+
1901
+ /**
1902
+ * Adds an a11y aria live status message if getA11yStatusMessage is passed.
1903
+ * @param {(options: Object) => string} getA11yStatusMessage The function that builds the status message.
1904
+ * @param {Object} options The options to be passed to getA11yStatusMessage if called.
1905
+ * @param {Array<unknown>} dependencyArray The dependency array that triggers the status message setter via useEffect.
1906
+ * @param {{document: Document}} environment The environment object containing the document.
1907
+ */
1908
+ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, environment) {
1909
+ if (environment === void 0) {
1910
+ environment = {};
1911
+ }
1912
+ var document = environment.document;
1910
1913
  var isInitialMount = useIsInitialMount();
1911
- // Sets a11y status message on changes in state.
1914
+
1915
+ // Adds an a11y aria live status message if getA11yStatusMessage is passed.
1912
1916
  React.useEffect(function () {
1913
- if (isInitialMount || false || !(environment != null && environment.document)) {
1917
+ if (!getA11yStatusMessage || isInitialMount || false || !document) {
1914
1918
  return;
1915
1919
  }
1916
- updateA11yStatus(function () {
1917
- return getA11yMessage(_extends__default["default"]({
1918
- highlightedIndex: highlightedIndex,
1919
- highlightedItem: items[highlightedIndex],
1920
- resultCount: items.length
1921
- }, rest));
1922
- }, environment.document);
1920
+ var status = getA11yStatusMessage(options);
1921
+ updateA11yStatus(status, document);
1922
+
1923
1923
  // eslint-disable-next-line react-hooks/exhaustive-deps
1924
- }, dependencyArray);
1925
- }
1926
- function useScrollIntoView(_ref4) {
1927
- var highlightedIndex = _ref4.highlightedIndex,
1928
- isOpen = _ref4.isOpen,
1929
- itemRefs = _ref4.itemRefs,
1930
- getItemNodeFromIndex = _ref4.getItemNodeFromIndex,
1931
- menuElement = _ref4.menuElement,
1932
- scrollIntoViewProp = _ref4.scrollIntoView;
1924
+ }, [dependencyArray]);
1925
+
1926
+ // Cleanup the status message container.
1927
+ React.useEffect(function () {
1928
+ return function () {
1929
+ updateA11yStatus.cancel();
1930
+ cleanupStatusDiv(document);
1931
+ };
1932
+ }, [document]);
1933
+ }
1934
+ function useScrollIntoView(_ref3) {
1935
+ var highlightedIndex = _ref3.highlightedIndex,
1936
+ isOpen = _ref3.isOpen,
1937
+ itemRefs = _ref3.itemRefs,
1938
+ getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
1939
+ menuElement = _ref3.menuElement,
1940
+ scrollIntoViewProp = _ref3.scrollIntoView;
1933
1941
  // used not to scroll on highlight by mouse.
1934
1942
  var shouldScrollRef = React.useRef(true);
1935
1943
  // Scroll on highlighted item if change comes from keyboard.
@@ -1951,9 +1959,9 @@ function useScrollIntoView(_ref4) {
1951
1959
  var useControlPropsValidator = noop;
1952
1960
  /* istanbul ignore next */
1953
1961
  if (process.env.NODE_ENV !== 'production') {
1954
- useControlPropsValidator = function useControlPropsValidator(_ref5) {
1955
- var props = _ref5.props,
1956
- state = _ref5.state;
1962
+ useControlPropsValidator = function useControlPropsValidator(_ref4) {
1963
+ var props = _ref4.props,
1964
+ state = _ref4.state;
1957
1965
  // used for checking when props are moving from controlled to uncontrolled.
1958
1966
  var prevPropsRef = React.useRef(props);
1959
1967
  var isInitialMount = useIsInitialMount();
@@ -2134,29 +2142,8 @@ function getItemIndexByCharacterKey(_a) {
2134
2142
  }
2135
2143
  return highlightedIndex;
2136
2144
  }
2137
- var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes__default["default"].array.isRequired, isItemDisabled: PropTypes__default["default"].func, getA11ySelectionMessage: PropTypes__default["default"].func });
2138
- /**
2139
- * Default implementation for status message. Only added when menu is open.
2140
- * Will specift if there are results in the list, and if so, how many,
2141
- * and what keys are relevant.
2142
- *
2143
- * @param {Object} param the downshift state and other relevant properties
2144
- * @return {String} the a11y status message
2145
- */
2146
- function getA11yStatusMessage(_a) {
2147
- var isOpen = _a.isOpen, resultCount = _a.resultCount, previousResultCount = _a.previousResultCount;
2148
- if (!isOpen) {
2149
- return '';
2150
- }
2151
- if (!resultCount) {
2152
- return 'No results are available.';
2153
- }
2154
- if (resultCount !== previousResultCount) {
2155
- 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.");
2156
- }
2157
- return '';
2158
- }
2159
- var defaultProps$2 = tslib.__assign(tslib.__assign({}, defaultProps$3), { getA11yStatusMessage: getA11yStatusMessage, isItemDisabled: function () {
2145
+ var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes__default["default"].array.isRequired, isItemDisabled: PropTypes__default["default"].func });
2146
+ var defaultProps$2 = tslib.__assign(tslib.__assign({}, defaultProps$3), { isItemDisabled: function () {
2160
2147
  return false;
2161
2148
  } });
2162
2149
  // eslint-disable-next-line import/no-mutable-exports
@@ -2338,11 +2325,8 @@ function useSelect(userProps) {
2338
2325
  validatePropTypes$2(userProps, useSelect);
2339
2326
  // Props defaults and destructuring.
2340
2327
  var props = _extends__default["default"]({}, defaultProps$2, userProps);
2341
- var items = props.items,
2342
- scrollIntoView = props.scrollIntoView,
2328
+ var scrollIntoView = props.scrollIntoView,
2343
2329
  environment = props.environment,
2344
- itemToString = props.itemToString,
2345
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2346
2330
  getA11yStatusMessage = props.getA11yStatusMessage;
2347
2331
  // Initial state depending on controlled props.
2348
2332
  var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$2, isDropdownsStateEqual),
@@ -2360,9 +2344,6 @@ function useSelect(userProps) {
2360
2344
  var clearTimeoutRef = React.useRef(null);
2361
2345
  // prevent id re-generation between renders.
2362
2346
  var elementIds = useElementIds(props);
2363
- // used to keep track of how many items we had on previous cycle.
2364
- var previousResultCountRef = React.useRef();
2365
- var isInitialMount = useIsInitialMount();
2366
2347
  // utility callback to get item element.
2367
2348
  var latest = useLatestRef({
2368
2349
  state: state,
@@ -2375,20 +2356,8 @@ function useSelect(userProps) {
2375
2356
  }, [elementIds]);
2376
2357
 
2377
2358
  // Effects.
2378
- // Sets a11y status message on changes in state.
2379
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2380
- previousResultCount: previousResultCountRef.current,
2381
- items: items,
2382
- environment: environment,
2383
- itemToString: itemToString
2384
- }, state));
2385
- // Sets a11y status message on changes in selectedItem.
2386
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2387
- previousResultCount: previousResultCountRef.current,
2388
- items: items,
2389
- environment: environment,
2390
- itemToString: itemToString
2391
- }, state));
2359
+ // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2360
+ useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
2392
2361
  // Scroll on highlighted item if change comes from keyboard.
2393
2362
  var shouldScrollRef = useScrollIntoView({
2394
2363
  menuElement: menuRef.current,
@@ -2398,7 +2367,6 @@ function useSelect(userProps) {
2398
2367
  scrollIntoView: scrollIntoView,
2399
2368
  getItemNodeFromIndex: getItemNodeFromIndex
2400
2369
  });
2401
-
2402
2370
  // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2403
2371
  React.useEffect(function () {
2404
2372
  // init the clean function here as we need access to dispatch.
@@ -2414,7 +2382,6 @@ function useSelect(userProps) {
2414
2382
  clearTimeoutRef.current.cancel();
2415
2383
  };
2416
2384
  }, []);
2417
-
2418
2385
  // Invokes the keysSoFar callback set up above.
2419
2386
  React.useEffect(function () {
2420
2387
  if (!inputValue) {
@@ -2426,12 +2393,6 @@ function useSelect(userProps) {
2426
2393
  props: props,
2427
2394
  state: state
2428
2395
  });
2429
- React.useEffect(function () {
2430
- if (isInitialMount) {
2431
- return;
2432
- }
2433
- previousResultCountRef.current = items.length;
2434
- });
2435
2396
  // Focus the toggle button on first render if required.
2436
2397
  React.useEffect(function () {
2437
2398
  var focusOnOpen = getInitialValue$1(props, 'isOpen');
@@ -2809,8 +2770,6 @@ function getInitialState$1(props) {
2809
2770
  var propTypes$1 = _extends__default["default"]({}, commonDropdownPropTypes, {
2810
2771
  items: PropTypes__default["default"].array.isRequired,
2811
2772
  isItemDisabled: PropTypes__default["default"].func,
2812
- selectedItemChanged: PropTypes__default["default"].func,
2813
- getA11ySelectionMessage: PropTypes__default["default"].func,
2814
2773
  inputValue: PropTypes__default["default"].string,
2815
2774
  defaultInputValue: PropTypes__default["default"].string,
2816
2775
  initialInputValue: PropTypes__default["default"].string,
@@ -2843,13 +2802,7 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
2843
2802
  }
2844
2803
  if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
2845
2804
  ) {
2846
- var shouldCallDispatch;
2847
- if (props.selectedItemChanged === undefined) {
2848
- shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
2849
- } else {
2850
- console.warn("The \"selectedItemChanged\" is deprecated. Please use \"itemToKey instead\". https://github.com/downshift-js/downshift/blob/master/src/hooks/useCombobox/README.md#selecteditemchanged");
2851
- shouldCallDispatch = props.selectedItemChanged(previousSelectedItemRef.current, props.selectedItem);
2852
- }
2805
+ var shouldCallDispatch = props.itemToKey(props.selectedItem) !== props.itemToKey(previousSelectedItemRef.current);
2853
2806
  if (shouldCallDispatch) {
2854
2807
  dispatch({
2855
2808
  type: ControlledPropUpdatedSelectedItem,
@@ -2872,7 +2825,6 @@ if (process.env.NODE_ENV !== 'production') {
2872
2825
  };
2873
2826
  }
2874
2827
  var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
2875
- getA11yStatusMessage: getA11yStatusMessage$1,
2876
2828
  isItemDisabled: function isItemDisabled() {
2877
2829
  return false;
2878
2830
  }
@@ -3009,9 +2961,7 @@ function useCombobox(userProps) {
3009
2961
  var items = props.items,
3010
2962
  scrollIntoView = props.scrollIntoView,
3011
2963
  environment = props.environment,
3012
- getA11yStatusMessage = props.getA11yStatusMessage,
3013
- getA11ySelectionMessage = props.getA11ySelectionMessage,
3014
- itemToString = props.itemToString;
2964
+ getA11yStatusMessage = props.getA11yStatusMessage;
3015
2965
  // Initial state depending on controlled props.
3016
2966
  var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$1, isDropdownsStateEqual),
3017
2967
  state = _useControlledReducer[0],
@@ -3042,20 +2992,8 @@ function useCombobox(userProps) {
3042
2992
  }, [elementIds]);
3043
2993
 
3044
2994
  // Effects.
3045
- // Sets a11y status message on changes in state.
3046
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
3047
- previousResultCount: previousResultCountRef.current,
3048
- items: items,
3049
- environment: environment,
3050
- itemToString: itemToString
3051
- }, state));
3052
- // Sets a11y status message on changes in selectedItem.
3053
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
3054
- previousResultCount: previousResultCountRef.current,
3055
- items: items,
3056
- environment: environment,
3057
- itemToString: itemToString
3058
- }, state));
2995
+ // Adds an a11y aria live status message if getA11yStatusMessage is passed.
2996
+ useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
3059
2997
  // Scroll on highlighted item if change comes from keyboard.
3060
2998
  var shouldScrollRef = useScrollIntoView({
3061
2999
  menuElement: menuRef.current,
@@ -3478,18 +3416,6 @@ function isKeyDownOperationPermitted(event) {
3478
3416
  return true;
3479
3417
  }
3480
3418
 
3481
- /**
3482
- * Returns a message to be added to aria-live region when item is removed.
3483
- *
3484
- * @param {Object} selectionParameters Parameters required to build the message.
3485
- * @returns {string} The a11y message.
3486
- */
3487
- function getA11yRemovalMessage(selectionParameters) {
3488
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3489
- itemToStringLocal = selectionParameters.itemToString;
3490
- return itemToStringLocal(removedSelectedItem) + " has been removed.";
3491
- }
3492
-
3493
3419
  /**
3494
3420
  * Check if a state is equal for taglist, by comparing active index and selected items.
3495
3421
  * Used by useSelect and useCombobox.
@@ -3501,11 +3427,14 @@ function getA11yRemovalMessage(selectionParameters) {
3501
3427
  function isStateEqual(prevState, newState) {
3502
3428
  return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
3503
3429
  }
3504
- var propTypes = _extends__default["default"]({}, commonPropTypes, {
3430
+ var propTypes = {
3431
+ stateReducer: commonPropTypes.stateReducer,
3432
+ itemToKey: commonPropTypes.itemToKey,
3433
+ environment: commonPropTypes.environment,
3505
3434
  selectedItems: PropTypes__default["default"].array,
3506
3435
  initialSelectedItems: PropTypes__default["default"].array,
3507
3436
  defaultSelectedItems: PropTypes__default["default"].array,
3508
- getA11yRemovalMessage: PropTypes__default["default"].func,
3437
+ getA11yStatusMessage: PropTypes__default["default"].func,
3509
3438
  activeIndex: PropTypes__default["default"].number,
3510
3439
  initialActiveIndex: PropTypes__default["default"].number,
3511
3440
  defaultActiveIndex: PropTypes__default["default"].number,
@@ -3513,13 +3442,11 @@ var propTypes = _extends__default["default"]({}, commonPropTypes, {
3513
3442
  onSelectedItemsChange: PropTypes__default["default"].func,
3514
3443
  keyNavigationNext: PropTypes__default["default"].string,
3515
3444
  keyNavigationPrevious: PropTypes__default["default"].string
3516
- });
3445
+ };
3517
3446
  var defaultProps = {
3518
- itemToString: defaultProps$3.itemToString,
3519
3447
  itemToKey: defaultProps$3.itemToKey,
3520
3448
  stateReducer: defaultProps$3.stateReducer,
3521
3449
  environment: defaultProps$3.environment,
3522
- getA11yRemovalMessage: getA11yRemovalMessage,
3523
3450
  keyNavigationNext: 'ArrowRight',
3524
3451
  keyNavigationPrevious: 'ArrowLeft'
3525
3452
  };
@@ -3686,8 +3613,7 @@ function useMultipleSelection(userProps) {
3686
3613
  validatePropTypes(userProps, useMultipleSelection);
3687
3614
  // Props defaults and destructuring.
3688
3615
  var props = _extends__default["default"]({}, defaultProps, userProps);
3689
- var getA11yRemovalMessage = props.getA11yRemovalMessage,
3690
- itemToString = props.itemToString,
3616
+ var getA11yStatusMessage = props.getA11yStatusMessage,
3691
3617
  environment = props.environment,
3692
3618
  keyNavigationNext = props.keyNavigationNext,
3693
3619
  keyNavigationPrevious = props.keyNavigationPrevious;
@@ -3702,7 +3628,6 @@ function useMultipleSelection(userProps) {
3702
3628
  // Refs.
3703
3629
  var isInitialMount = useIsInitialMount();
3704
3630
  var dropdownRef = React.useRef(null);
3705
- var previousSelectedItemsRef = React.useRef(selectedItems);
3706
3631
  var selectedItemRefs = React.useRef();
3707
3632
  selectedItemRefs.current = [];
3708
3633
  var latest = useLatestRef({
@@ -3711,29 +3636,8 @@ function useMultipleSelection(userProps) {
3711
3636
  });
3712
3637
 
3713
3638
  // Effects.
3714
- /* Sets a11y status message on changes in selectedItem. */
3715
- React.useEffect(function () {
3716
- if (isInitialMount || false || !(environment != null && environment.document)) {
3717
- return;
3718
- }
3719
- if (selectedItems.length < previousSelectedItemsRef.current.length) {
3720
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (selectedItem) {
3721
- return selectedItems.findIndex(function (item) {
3722
- return props.itemToKey(item) === props.itemToKey(selectedItem);
3723
- }) < 0;
3724
- });
3725
- setStatus(getA11yRemovalMessage({
3726
- itemToString: itemToString,
3727
- resultCount: selectedItems.length,
3728
- removedSelectedItem: removedSelectedItem,
3729
- activeIndex: activeIndex,
3730
- activeSelectedItem: selectedItems[activeIndex]
3731
- }), environment.document);
3732
- }
3733
- previousSelectedItemsRef.current = selectedItems;
3734
-
3735
- // eslint-disable-next-line react-hooks/exhaustive-deps
3736
- }, [selectedItems.length]);
3639
+ // Adds an a11y aria live status message if getA11yStatusMessage is passed.
3640
+ useA11yMessageStatus(getA11yStatusMessage, state, [activeIndex, selectedItems], environment);
3737
3641
  // Sets focus on active item.
3738
3642
  React.useEffect(function () {
3739
3643
  if (isInitialMount) {