downshift 7.1.2 → 7.1.3-alpha.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.
@@ -2,26 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
6
- var _extends = require('@babel/runtime/helpers/extends');
7
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
8
- var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
9
5
  var PropTypes = require('prop-types');
10
6
  var react = require('react');
11
7
  var reactIs = require('react-is');
12
- var computeScrollIntoView = require('compute-scroll-into-view');
8
+ var compute = require('compute-scroll-into-view');
13
9
  var tslib = require('tslib');
14
10
 
15
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
12
 
17
- var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
18
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
19
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
20
- var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
21
13
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
22
- var computeScrollIntoView__default = /*#__PURE__*/_interopDefaultLegacy(computeScrollIntoView);
14
+ var compute__default = /*#__PURE__*/_interopDefaultLegacy(compute);
23
15
 
24
- var idCounter = 0;
16
+ let idCounter = 0;
25
17
 
26
18
  /**
27
19
  * Accepts a parameter and returns it if it's a function
@@ -45,15 +37,17 @@ function scrollIntoView(node, menuNode) {
45
37
  if (!node) {
46
38
  return;
47
39
  }
48
- var actions = computeScrollIntoView__default["default"](node, {
40
+ const actions = compute__default["default"](node, {
49
41
  boundary: menuNode,
50
42
  block: 'nearest',
51
43
  scrollMode: 'if-needed'
52
44
  });
53
- actions.forEach(function (_ref) {
54
- var el = _ref.el,
55
- top = _ref.top,
56
- left = _ref.left;
45
+ actions.forEach(_ref => {
46
+ let {
47
+ el,
48
+ top,
49
+ left
50
+ } = _ref;
57
51
  el.scrollTop = top;
58
52
  el.scrollLeft = left;
59
53
  });
@@ -66,7 +60,7 @@ function scrollIntoView(node, menuNode) {
66
60
  * @return {Boolean} whether the parent is the child or the child is in the parent
67
61
  */
68
62
  function isOrContainsNode(parent, child, environment) {
69
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
63
+ const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
70
64
  return result;
71
65
  }
72
66
 
@@ -79,7 +73,7 @@ function isOrContainsNode(parent, child, environment) {
79
73
  * @return {Function} the debounced function
80
74
  */
81
75
  function debounce(fn, time) {
82
- var timeoutId;
76
+ let timeoutId;
83
77
  function cancel() {
84
78
  if (timeoutId) {
85
79
  clearTimeout(timeoutId);
@@ -90,9 +84,9 @@ function debounce(fn, time) {
90
84
  args[_key] = arguments[_key];
91
85
  }
92
86
  cancel();
93
- timeoutId = setTimeout(function () {
87
+ timeoutId = setTimeout(() => {
94
88
  timeoutId = null;
95
- fn.apply(void 0, args);
89
+ fn(...args);
96
90
  }, time);
97
91
  }
98
92
  wrapper.cancel = cancel;
@@ -114,9 +108,9 @@ function callAllEventHandlers() {
114
108
  for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
115
109
  args[_key3 - 1] = arguments[_key3];
116
110
  }
117
- return fns.some(function (fn) {
111
+ return fns.some(fn => {
118
112
  if (fn) {
119
- fn.apply(void 0, [event].concat(args));
113
+ fn(event, ...args);
120
114
  }
121
115
  return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
122
116
  });
@@ -126,8 +120,8 @@ function handleRefs() {
126
120
  for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
127
121
  refs[_key4] = arguments[_key4];
128
122
  }
129
- return function (node) {
130
- refs.forEach(function (ref) {
123
+ return node => {
124
+ refs.forEach(ref => {
131
125
  if (typeof ref === 'function') {
132
126
  ref(node);
133
127
  } else if (ref) {
@@ -161,9 +155,11 @@ function resetIdCounter() {
161
155
  * @return {String} the a11y status message
162
156
  */
163
157
  function getA11yStatusMessage$1(_ref2) {
164
- var isOpen = _ref2.isOpen,
165
- resultCount = _ref2.resultCount,
166
- previousResultCount = _ref2.previousResultCount;
158
+ let {
159
+ isOpen,
160
+ resultCount,
161
+ previousResultCount
162
+ } = _ref2;
167
163
  if (!isOpen) {
168
164
  return '';
169
165
  }
@@ -171,7 +167,7 @@ function getA11yStatusMessage$1(_ref2) {
171
167
  return 'No results are available.';
172
168
  }
173
169
  if (resultCount !== previousResultCount) {
174
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
170
+ return `${resultCount} result${resultCount === 1 ? ' is' : 's are'} available, use up and down arrow keys to navigate. Press Enter key to select.`;
175
171
  }
176
172
  return '';
177
173
  }
@@ -218,9 +214,9 @@ function getElementProps(element) {
218
214
  */
219
215
  function requiredProp(fnName, propName) {
220
216
  // eslint-disable-next-line no-console
221
- console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
217
+ console.error(`The property "${propName}" is required in "${fnName}"`);
222
218
  }
223
- var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
219
+ const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
224
220
  /**
225
221
  * @param {Object} state the state object
226
222
  * @return {Object} state that is relevant to downshift
@@ -229,8 +225,8 @@ function pickState(state) {
229
225
  if (state === void 0) {
230
226
  state = {};
231
227
  }
232
- var result = {};
233
- stateKeys.forEach(function (k) {
228
+ const result = {};
229
+ stateKeys.forEach(k => {
234
230
  if (state.hasOwnProperty(k)) {
235
231
  result[k] = state[k];
236
232
  }
@@ -250,7 +246,7 @@ function pickState(state) {
250
246
  * @returns {Object} The merged controlled state.
251
247
  */
252
248
  function getState(state, props) {
253
- return Object.keys(state).reduce(function (prevState, key) {
249
+ return Object.keys(state).reduce((prevState, key) => {
254
250
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
255
251
  return prevState;
256
252
  }, {});
@@ -275,11 +271,13 @@ function isControlledProp(props, key) {
275
271
  * @return {String} keyboard key
276
272
  */
277
273
  function normalizeArrowKey(event) {
278
- var key = event.key,
279
- keyCode = event.keyCode;
274
+ const {
275
+ key,
276
+ keyCode
277
+ } = event;
280
278
  /* istanbul ignore next (ie) */
281
279
  if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
282
- return "Arrow" + key;
280
+ return `Arrow${key}`;
283
281
  }
284
282
  return key;
285
283
  }
@@ -311,17 +309,17 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
311
309
  if (itemCount === 0) {
312
310
  return -1;
313
311
  }
314
- var itemsLastIndex = itemCount - 1;
312
+ const itemsLastIndex = itemCount - 1;
315
313
  if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
316
314
  baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
317
315
  }
318
- var newIndex = baseIndex + moveAmount;
316
+ let newIndex = baseIndex + moveAmount;
319
317
  if (newIndex < 0) {
320
318
  newIndex = circular ? itemsLastIndex : 0;
321
319
  } else if (newIndex > itemsLastIndex) {
322
320
  newIndex = circular ? 0 : itemsLastIndex;
323
321
  }
324
- var nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
322
+ const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
325
323
  if (nonDisabledNewIndex === -1) {
326
324
  return baseIndex >= itemCount ? -1 : baseIndex;
327
325
  }
@@ -339,20 +337,20 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
339
337
  * @returns {number} The new index. Returns baseIndex if item is not disabled. Returns next non-disabled item otherwise. If no non-disabled found it will return -1.
340
338
  */
341
339
  function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
342
- var currentElementNode = getItemNodeFromIndex(baseIndex);
340
+ const currentElementNode = getItemNodeFromIndex(baseIndex);
343
341
  if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
344
342
  return baseIndex;
345
343
  }
346
344
  if (moveAmount > 0) {
347
- for (var index = baseIndex + 1; index < itemCount; index++) {
345
+ for (let index = baseIndex + 1; index < itemCount; index++) {
348
346
  if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
349
347
  return index;
350
348
  }
351
349
  }
352
350
  } else {
353
- for (var _index = baseIndex - 1; _index >= 0; _index--) {
354
- if (!getItemNodeFromIndex(_index).hasAttribute('disabled')) {
355
- return _index;
351
+ for (let index = baseIndex - 1; index >= 0; index--) {
352
+ if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
353
+ return index;
356
354
  }
357
355
  }
358
356
  }
@@ -376,30 +374,28 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
376
374
  if (checkActiveElement === void 0) {
377
375
  checkActiveElement = true;
378
376
  }
379
- return downshiftElements.some(function (contextNode) {
380
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
381
- });
377
+ return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
382
378
  }
383
379
 
384
380
  // eslint-disable-next-line import/no-mutable-exports
385
- var validateControlledUnchanged = noop;
381
+ let validateControlledUnchanged = noop;
386
382
  /* istanbul ignore next */
387
383
  if (process.env.NODE_ENV !== 'production') {
388
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
389
- var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
390
- Object.keys(state).forEach(function (propKey) {
384
+ validateControlledUnchanged = (state, prevProps, nextProps) => {
385
+ const warningDescription = `This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props`;
386
+ Object.keys(state).forEach(propKey => {
391
387
  if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
392
388
  // eslint-disable-next-line no-console
393
- console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
389
+ console.error(`downshift: A component has changed the controlled prop "${propKey}" to be uncontrolled. ${warningDescription}`);
394
390
  } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
395
391
  // eslint-disable-next-line no-console
396
- console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
392
+ console.error(`downshift: A component has changed the uncontrolled prop "${propKey}" to be controlled. ${warningDescription}`);
397
393
  }
398
394
  });
399
395
  };
400
396
  }
401
397
 
402
- var cleanupStatus = debounce(function (documentProp) {
398
+ const cleanupStatus = debounce(documentProp => {
403
399
  getStatusDiv(documentProp).textContent = '';
404
400
  }, 500);
405
401
 
@@ -408,7 +404,7 @@ var cleanupStatus = debounce(function (documentProp) {
408
404
  * @param {Object} documentProp document passed by the user.
409
405
  */
410
406
  function setStatus(status, documentProp) {
411
- var div = getStatusDiv(documentProp);
407
+ const div = getStatusDiv(documentProp);
412
408
  if (!status) {
413
409
  return;
414
410
  }
@@ -425,7 +421,7 @@ function getStatusDiv(documentProp) {
425
421
  if (documentProp === void 0) {
426
422
  documentProp = document;
427
423
  }
428
- var statusDiv = documentProp.getElementById('a11y-status-message');
424
+ let statusDiv = documentProp.getElementById('a11y-status-message');
429
425
  if (statusDiv) {
430
426
  return statusDiv;
431
427
  }
@@ -448,23 +444,23 @@ function getStatusDiv(documentProp) {
448
444
  return statusDiv;
449
445
  }
450
446
 
451
- var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
452
- var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
453
- var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
454
- var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
455
- var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
456
- var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
457
- var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
458
- var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
459
- var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
460
- var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
461
- var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
462
- var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
463
- var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
464
- var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
465
- var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
466
- var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
467
- var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
447
+ const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
448
+ const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
449
+ const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
450
+ const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
451
+ const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
452
+ const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
453
+ const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
454
+ const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
455
+ const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
456
+ const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
457
+ const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
458
+ const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
459
+ const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
460
+ const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
461
+ const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
462
+ const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
463
+ const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
468
464
 
469
465
  var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
470
466
  __proto__: null,
@@ -487,48 +483,37 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
487
483
  touchEnd: touchEnd
488
484
  });
489
485
 
490
- var _excluded$4 = ["refKey", "ref"],
491
- _excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
492
- _excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
493
- _excluded4$1 = ["refKey", "ref"],
494
- _excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
495
- var Downshift = /*#__PURE__*/function () {
496
- var Downshift = /*#__PURE__*/function (_Component) {
497
- _inheritsLoose__default["default"](Downshift, _Component);
498
- function Downshift(_props) {
486
+ /* eslint camelcase:0 */
487
+ const Downshift = /*#__PURE__*/(() => {
488
+ class Downshift extends react.Component {
489
+ constructor(_props) {
499
490
  var _this;
500
- _this = _Component.call(this, _props) || this;
501
- // fancy destructuring + defaults + aliases
502
- // this basically says each value of state should either be set to
503
- // the initial value or the default value if the initial value is not provided
504
- _this.id = _this.props.id || "downshift-" + generateId();
505
- _this.menuId = _this.props.menuId || _this.id + "-menu";
506
- _this.labelId = _this.props.labelId || _this.id + "-label";
507
- _this.inputId = _this.props.inputId || _this.id + "-input";
508
- _this.getItemId = _this.props.getItemId || function (index) {
509
- return _this.id + "-item-" + index;
510
- };
511
- _this.input = null;
512
- _this.items = [];
513
- _this.itemCount = null;
514
- _this.previousResultCount = 0;
515
- _this.timeoutIds = [];
516
- _this.internalSetTimeout = function (fn, time) {
517
- var id = setTimeout(function () {
518
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
519
- return i !== id;
520
- });
491
+ super(_props);
492
+ _this = this;
493
+ this.id = this.props.id || `downshift-${generateId()}`;
494
+ this.menuId = this.props.menuId || `${this.id}-menu`;
495
+ this.labelId = this.props.labelId || `${this.id}-label`;
496
+ this.inputId = this.props.inputId || `${this.id}-input`;
497
+ this.getItemId = this.props.getItemId || (index => `${this.id}-item-${index}`);
498
+ this.input = null;
499
+ this.items = [];
500
+ this.itemCount = null;
501
+ this.previousResultCount = 0;
502
+ this.timeoutIds = [];
503
+ this.internalSetTimeout = (fn, time) => {
504
+ const id = setTimeout(() => {
505
+ this.timeoutIds = this.timeoutIds.filter(i => i !== id);
521
506
  fn();
522
507
  }, time);
523
- _this.timeoutIds.push(id);
508
+ this.timeoutIds.push(id);
524
509
  };
525
- _this.setItemCount = function (count) {
526
- _this.itemCount = count;
510
+ this.setItemCount = count => {
511
+ this.itemCount = count;
527
512
  };
528
- _this.unsetItemCount = function () {
529
- _this.itemCount = null;
513
+ this.unsetItemCount = () => {
514
+ this.itemCount = null;
530
515
  };
531
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
516
+ this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
532
517
  if (highlightedIndex === void 0) {
533
518
  highlightedIndex = _this.props.defaultHighlightedIndex;
534
519
  }
@@ -536,41 +521,43 @@ var Downshift = /*#__PURE__*/function () {
536
521
  otherStateToSet = {};
537
522
  }
538
523
  otherStateToSet = pickState(otherStateToSet);
539
- _this.internalSetState(_extends__default["default"]({
540
- highlightedIndex: highlightedIndex
541
- }, otherStateToSet));
542
- };
543
- _this.clearSelection = function (cb) {
544
524
  _this.internalSetState({
525
+ highlightedIndex,
526
+ ...otherStateToSet
527
+ });
528
+ };
529
+ this.clearSelection = cb => {
530
+ this.internalSetState({
545
531
  selectedItem: null,
546
532
  inputValue: '',
547
- highlightedIndex: _this.props.defaultHighlightedIndex,
548
- isOpen: _this.props.defaultIsOpen
533
+ highlightedIndex: this.props.defaultHighlightedIndex,
534
+ isOpen: this.props.defaultIsOpen
549
535
  }, cb);
550
536
  };
551
- _this.selectItem = function (item, otherStateToSet, cb) {
537
+ this.selectItem = (item, otherStateToSet, cb) => {
552
538
  otherStateToSet = pickState(otherStateToSet);
553
- _this.internalSetState(_extends__default["default"]({
554
- isOpen: _this.props.defaultIsOpen,
555
- highlightedIndex: _this.props.defaultHighlightedIndex,
539
+ this.internalSetState({
540
+ isOpen: this.props.defaultIsOpen,
541
+ highlightedIndex: this.props.defaultHighlightedIndex,
556
542
  selectedItem: item,
557
- inputValue: _this.props.itemToString(item)
558
- }, otherStateToSet), cb);
543
+ inputValue: this.props.itemToString(item),
544
+ ...otherStateToSet
545
+ }, cb);
559
546
  };
560
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
561
- var item = _this.items[itemIndex];
547
+ this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
548
+ const item = this.items[itemIndex];
562
549
  if (item == null) {
563
550
  return;
564
551
  }
565
- _this.selectItem(item, otherStateToSet, cb);
552
+ this.selectItem(item, otherStateToSet, cb);
566
553
  };
567
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
568
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
554
+ this.selectHighlightedItem = (otherStateToSet, cb) => {
555
+ return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
569
556
  };
570
- _this.internalSetState = function (stateToSet, cb) {
571
- var isItemSelected, onChangeArg;
572
- var onStateChangeArg = {};
573
- var isStateToSetFunction = typeof stateToSet === 'function';
557
+ this.internalSetState = (stateToSet, cb) => {
558
+ let isItemSelected, onChangeArg;
559
+ const onStateChangeArg = {};
560
+ const isStateToSetFunction = typeof stateToSet === 'function';
574
561
 
575
562
  // we want to call `onInputValueChange` before the `setState` call
576
563
  // so someone controlling the `inputValue` state gets notified of
@@ -578,21 +565,24 @@ var Downshift = /*#__PURE__*/function () {
578
565
  // preserving the cursor position.
579
566
  // See https://github.com/downshift-js/downshift/issues/217 for more info.
580
567
  if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
581
- _this.props.onInputValueChange(stateToSet.inputValue, _extends__default["default"]({}, _this.getStateAndHelpers(), stateToSet));
568
+ this.props.onInputValueChange(stateToSet.inputValue, {
569
+ ...this.getStateAndHelpers(),
570
+ ...stateToSet
571
+ });
582
572
  }
583
- return _this.setState(function (state) {
584
- state = _this.getState(state);
585
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
573
+ return this.setState(state => {
574
+ state = this.getState(state);
575
+ let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
586
576
 
587
577
  // Your own function that could modify the state that will be set.
588
- newStateToSet = _this.props.stateReducer(state, newStateToSet);
578
+ newStateToSet = this.props.stateReducer(state, newStateToSet);
589
579
 
590
580
  // checks if an item is selected, regardless of if it's different from
591
581
  // what was selected before
592
582
  // used to determine if onSelect and onChange callbacks should be called
593
583
  isItemSelected = newStateToSet.hasOwnProperty('selectedItem');
594
584
  // this keeps track of the object we want to call with setState
595
- var nextState = {};
585
+ const nextState = {};
596
586
  // we need to call on change if the outside world is controlling any of our state
597
587
  // and we're trying to update that state. OR if the selection has changed and we're
598
588
  // trying to update the selection
@@ -600,7 +590,7 @@ var Downshift = /*#__PURE__*/function () {
600
590
  onChangeArg = newStateToSet.selectedItem;
601
591
  }
602
592
  newStateToSet.type = newStateToSet.type || unknown;
603
- Object.keys(newStateToSet).forEach(function (key) {
593
+ Object.keys(newStateToSet).forEach(key => {
604
594
  // onStateChangeArg should only have the state that is
605
595
  // actually changing
606
596
  if (state[key] !== newStateToSet[key]) {
@@ -617,7 +607,7 @@ var Downshift = /*#__PURE__*/function () {
617
607
  }
618
608
  newStateToSet[key];
619
609
  // if it's coming from props, then we don't care to set it internally
620
- if (!isControlledProp(_this.props, key)) {
610
+ if (!isControlledProp(this.props, key)) {
621
611
  nextState[key] = newStateToSet[key];
622
612
  }
623
613
  });
@@ -625,58 +615,66 @@ var Downshift = /*#__PURE__*/function () {
625
615
  // if stateToSet is a function, then we weren't able to call onInputValueChange
626
616
  // earlier, so we'll call it now that we know what the inputValue state will be.
627
617
  if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
628
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends__default["default"]({}, _this.getStateAndHelpers(), newStateToSet));
618
+ this.props.onInputValueChange(newStateToSet.inputValue, {
619
+ ...this.getStateAndHelpers(),
620
+ ...newStateToSet
621
+ });
629
622
  }
630
623
  return nextState;
631
- }, function () {
624
+ }, () => {
632
625
  // call the provided callback if it's a function
633
626
  cbToCb(cb)();
634
627
 
635
628
  // only call the onStateChange and onChange callbacks if
636
629
  // we have relevant information to pass them.
637
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
630
+ const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
638
631
  if (hasMoreStateThanType) {
639
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
632
+ this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
640
633
  }
641
634
  if (isItemSelected) {
642
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
635
+ this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
643
636
  }
644
637
  if (onChangeArg !== undefined) {
645
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
638
+ this.props.onChange(onChangeArg, this.getStateAndHelpers());
646
639
  }
647
640
  // this is currently undocumented and therefore subject to change
648
641
  // We'll try to not break it, but just be warned.
649
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
642
+ this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
650
643
  });
651
644
  };
652
- _this.rootRef = function (node) {
653
- return _this._rootNode = node;
654
- };
655
- _this.getRootProps = function (_temp, _temp2) {
656
- var _extends2;
657
- var _ref = _temp === void 0 ? {} : _temp,
658
- _ref$refKey = _ref.refKey,
659
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
660
- ref = _ref.ref,
661
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$4);
662
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
663
- _ref2$suppressRefErro = _ref2.suppressRefError,
664
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
645
+ this.rootRef = node => this._rootNode = node;
646
+ this.getRootProps = function (_temp, _temp2) {
647
+ let {
648
+ refKey = 'ref',
649
+ ref,
650
+ ...rest
651
+ } = _temp === void 0 ? {} : _temp;
652
+ let {
653
+ suppressRefError = false
654
+ } = _temp2 === void 0 ? {} : _temp2;
665
655
  // this is used in the render to know whether the user has called getRootProps.
666
656
  // It uses that to know whether to apply the props automatically
667
657
  _this.getRootProps.called = true;
668
658
  _this.getRootProps.refKey = refKey;
669
659
  _this.getRootProps.suppressRefError = suppressRefError;
670
- var _this$getState = _this.getState(),
671
- isOpen = _this$getState.isOpen;
672
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
660
+ const {
661
+ isOpen
662
+ } = _this.getState();
663
+ return {
664
+ [refKey]: handleRefs(ref, _this.rootRef),
665
+ role: 'combobox',
666
+ 'aria-expanded': isOpen,
667
+ 'aria-haspopup': 'listbox',
668
+ 'aria-owns': isOpen ? _this.menuId : null,
669
+ 'aria-labelledby': _this.labelId,
670
+ ...rest
671
+ };
673
672
  };
674
- _this.keyDownHandlers = {
675
- ArrowDown: function ArrowDown(event) {
676
- var _this2 = this;
673
+ this.keyDownHandlers = {
674
+ ArrowDown(event) {
677
675
  event.preventDefault();
678
676
  if (this.getState().isOpen) {
679
- var amount = event.shiftKey ? 5 : 1;
677
+ const amount = event.shiftKey ? 5 : 1;
680
678
  this.moveHighlightedIndex(amount, {
681
679
  type: keyDownArrowDown
682
680
  });
@@ -684,26 +682,24 @@ var Downshift = /*#__PURE__*/function () {
684
682
  this.internalSetState({
685
683
  isOpen: true,
686
684
  type: keyDownArrowDown
687
- }, function () {
688
- var itemCount = _this2.getItemCount();
685
+ }, () => {
686
+ const itemCount = this.getItemCount();
689
687
  if (itemCount > 0) {
690
- var _this2$getState = _this2.getState(),
691
- highlightedIndex = _this2$getState.highlightedIndex;
692
- var nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, function (index) {
693
- return _this2.getItemNodeFromIndex(index);
694
- });
695
- _this2.setHighlightedIndex(nextHighlightedIndex, {
688
+ const {
689
+ highlightedIndex
690
+ } = this.getState();
691
+ const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
692
+ this.setHighlightedIndex(nextHighlightedIndex, {
696
693
  type: keyDownArrowDown
697
694
  });
698
695
  }
699
696
  });
700
697
  }
701
698
  },
702
- ArrowUp: function ArrowUp(event) {
703
- var _this3 = this;
699
+ ArrowUp(event) {
704
700
  event.preventDefault();
705
701
  if (this.getState().isOpen) {
706
- var amount = event.shiftKey ? -5 : -1;
702
+ const amount = event.shiftKey ? -5 : -1;
707
703
  this.moveHighlightedIndex(amount, {
708
704
  type: keyDownArrowUp
709
705
  });
@@ -711,32 +707,32 @@ var Downshift = /*#__PURE__*/function () {
711
707
  this.internalSetState({
712
708
  isOpen: true,
713
709
  type: keyDownArrowUp
714
- }, function () {
715
- var itemCount = _this3.getItemCount();
710
+ }, () => {
711
+ const itemCount = this.getItemCount();
716
712
  if (itemCount > 0) {
717
- var _this3$getState = _this3.getState(),
718
- highlightedIndex = _this3$getState.highlightedIndex;
719
- var nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, function (index) {
720
- return _this3.getItemNodeFromIndex(index);
721
- });
722
- _this3.setHighlightedIndex(nextHighlightedIndex, {
713
+ const {
714
+ highlightedIndex
715
+ } = this.getState();
716
+ const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
717
+ this.setHighlightedIndex(nextHighlightedIndex, {
723
718
  type: keyDownArrowUp
724
719
  });
725
720
  }
726
721
  });
727
722
  }
728
723
  },
729
- Enter: function Enter(event) {
724
+ Enter(event) {
730
725
  if (event.which === 229) {
731
726
  return;
732
727
  }
733
- var _this$getState2 = this.getState(),
734
- isOpen = _this$getState2.isOpen,
735
- highlightedIndex = _this$getState2.highlightedIndex;
728
+ const {
729
+ isOpen,
730
+ highlightedIndex
731
+ } = this.getState();
736
732
  if (isOpen && highlightedIndex != null) {
737
733
  event.preventDefault();
738
- var item = this.items[highlightedIndex];
739
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
734
+ const item = this.items[highlightedIndex];
735
+ const itemNode = this.getItemNodeFromIndex(highlightedIndex);
740
736
  if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
741
737
  return;
742
738
  }
@@ -745,169 +741,176 @@ var Downshift = /*#__PURE__*/function () {
745
741
  });
746
742
  }
747
743
  },
748
- Escape: function Escape(event) {
744
+ Escape(event) {
749
745
  event.preventDefault();
750
- this.reset(_extends__default["default"]({
751
- type: keyDownEscape
752
- }, !this.state.isOpen && {
753
- selectedItem: null,
754
- inputValue: ''
755
- }));
746
+ this.reset({
747
+ type: keyDownEscape,
748
+ ...(!this.state.isOpen && {
749
+ selectedItem: null,
750
+ inputValue: ''
751
+ })
752
+ });
756
753
  }
757
754
  };
758
- _this.buttonKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
759
- ' ': function _(event) {
755
+ this.buttonKeyDownHandlers = {
756
+ ...this.keyDownHandlers,
757
+ ' '(event) {
760
758
  event.preventDefault();
761
759
  this.toggleMenu({
762
760
  type: keyDownSpaceButton
763
761
  });
764
762
  }
765
- });
766
- _this.inputKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
767
- Home: function Home(event) {
768
- var _this4 = this;
769
- var _this$getState3 = this.getState(),
770
- isOpen = _this$getState3.isOpen;
763
+ };
764
+ this.inputKeyDownHandlers = {
765
+ ...this.keyDownHandlers,
766
+ Home(event) {
767
+ const {
768
+ isOpen
769
+ } = this.getState();
771
770
  if (!isOpen) {
772
771
  return;
773
772
  }
774
773
  event.preventDefault();
775
- var itemCount = this.getItemCount();
774
+ const itemCount = this.getItemCount();
776
775
  if (itemCount <= 0 || !isOpen) {
777
776
  return;
778
777
  }
779
778
 
780
779
  // get next non-disabled starting downwards from 0 if that's disabled.
781
- var newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, function (index) {
782
- return _this4.getItemNodeFromIndex(index);
783
- }, false);
780
+ const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
784
781
  this.setHighlightedIndex(newHighlightedIndex, {
785
782
  type: keyDownHome
786
783
  });
787
784
  },
788
- End: function End(event) {
789
- var _this5 = this;
790
- var _this$getState4 = this.getState(),
791
- isOpen = _this$getState4.isOpen;
785
+ End(event) {
786
+ const {
787
+ isOpen
788
+ } = this.getState();
792
789
  if (!isOpen) {
793
790
  return;
794
791
  }
795
792
  event.preventDefault();
796
- var itemCount = this.getItemCount();
793
+ const itemCount = this.getItemCount();
797
794
  if (itemCount <= 0 || !isOpen) {
798
795
  return;
799
796
  }
800
797
 
801
798
  // get next non-disabled starting upwards from last index if that's disabled.
802
- var newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, function (index) {
803
- return _this5.getItemNodeFromIndex(index);
804
- }, false);
799
+ const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
805
800
  this.setHighlightedIndex(newHighlightedIndex, {
806
801
  type: keyDownEnd
807
802
  });
808
803
  }
809
- });
810
- _this.getToggleButtonProps = function (_temp3) {
811
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
812
- onClick = _ref3.onClick;
813
- _ref3.onPress;
814
- var onKeyDown = _ref3.onKeyDown,
815
- onKeyUp = _ref3.onKeyUp,
816
- onBlur = _ref3.onBlur,
817
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$3);
818
- var _this$getState5 = _this.getState(),
819
- isOpen = _this$getState5.isOpen;
820
- var enabledEventHandlers = {
804
+ };
805
+ this.getToggleButtonProps = function (_temp3) {
806
+ let {
807
+ onClick,
808
+ onPress,
809
+ onKeyDown,
810
+ onKeyUp,
811
+ onBlur,
812
+ ...rest
813
+ } = _temp3 === void 0 ? {} : _temp3;
814
+ const {
815
+ isOpen
816
+ } = _this.getState();
817
+ const enabledEventHandlers = {
821
818
  onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
822
819
  onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
823
820
  onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
824
821
  onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
825
822
  };
826
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
827
- return _extends__default["default"]({
823
+ const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
824
+ return {
828
825
  type: 'button',
829
826
  role: 'button',
830
827
  'aria-label': isOpen ? 'close menu' : 'open menu',
831
828
  'aria-haspopup': true,
832
- 'data-toggle': true
833
- }, eventHandlers, rest);
829
+ 'data-toggle': true,
830
+ ...eventHandlers,
831
+ ...rest
832
+ };
834
833
  };
835
- _this.buttonHandleKeyUp = function (event) {
834
+ this.buttonHandleKeyUp = event => {
836
835
  // Prevent click event from emitting in Firefox
837
836
  event.preventDefault();
838
837
  };
839
- _this.buttonHandleKeyDown = function (event) {
840
- var key = normalizeArrowKey(event);
841
- if (_this.buttonKeyDownHandlers[key]) {
842
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
838
+ this.buttonHandleKeyDown = event => {
839
+ const key = normalizeArrowKey(event);
840
+ if (this.buttonKeyDownHandlers[key]) {
841
+ this.buttonKeyDownHandlers[key].call(this, event);
843
842
  }
844
843
  };
845
- _this.buttonHandleClick = function (event) {
844
+ this.buttonHandleClick = event => {
846
845
  event.preventDefault();
847
846
  // handle odd case for Safari and Firefox which
848
847
  // don't give the button the focus properly.
849
848
  /* istanbul ignore if (can't reasonably test this) */
850
- if (_this.props.environment.document.activeElement === _this.props.environment.document.body) {
849
+ if (this.props.environment.document.activeElement === this.props.environment.document.body) {
851
850
  event.target.focus();
852
851
  }
853
852
  // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
854
853
  // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
855
854
  // when building for production and should therefore have no impact on production code.
856
855
  if (process.env.NODE_ENV === 'test') {
857
- _this.toggleMenu({
856
+ this.toggleMenu({
858
857
  type: clickButton
859
858
  });
860
859
  } else {
861
860
  // Ensure that toggle of menu occurs after the potential blur event in iOS
862
- _this.internalSetTimeout(function () {
863
- return _this.toggleMenu({
864
- type: clickButton
865
- });
866
- });
861
+ this.internalSetTimeout(() => this.toggleMenu({
862
+ type: clickButton
863
+ }));
867
864
  }
868
865
  };
869
- _this.buttonHandleBlur = function (event) {
870
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
866
+ this.buttonHandleBlur = event => {
867
+ const blurTarget = event.target; // Save blur target for comparison with activeElement later
871
868
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
872
- _this.internalSetTimeout(function () {
873
- if (!_this.isMouseDown && (_this.props.environment.document.activeElement == null || _this.props.environment.document.activeElement.id !== _this.inputId) && _this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
869
+ this.internalSetTimeout(() => {
870
+ if (!this.isMouseDown && (this.props.environment.document.activeElement == null || this.props.environment.document.activeElement.id !== this.inputId) && this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
874
871
  ) {
875
- _this.reset({
872
+ this.reset({
876
873
  type: blurButton
877
874
  });
878
875
  }
879
876
  });
880
877
  };
881
- _this.getLabelProps = function (props) {
882
- return _extends__default["default"]({
883
- htmlFor: _this.inputId,
884
- id: _this.labelId
885
- }, props);
886
- };
887
- _this.getInputProps = function (_temp4) {
888
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
889
- onKeyDown = _ref4.onKeyDown,
890
- onBlur = _ref4.onBlur,
891
- onChange = _ref4.onChange,
892
- onInput = _ref4.onInput;
893
- _ref4.onChangeText;
894
- var rest = _objectWithoutPropertiesLoose__default["default"](_ref4, _excluded3$2);
895
- var onChangeKey;
896
- var eventHandlers = {};
878
+ this.getLabelProps = props => {
879
+ return {
880
+ htmlFor: this.inputId,
881
+ id: this.labelId,
882
+ ...props
883
+ };
884
+ };
885
+ this.getInputProps = function (_temp4) {
886
+ let {
887
+ onKeyDown,
888
+ onBlur,
889
+ onChange,
890
+ onInput,
891
+ onChangeText,
892
+ ...rest
893
+ } = _temp4 === void 0 ? {} : _temp4;
894
+ let onChangeKey;
895
+ let eventHandlers = {};
897
896
 
898
897
  /* istanbul ignore next (preact) */
899
898
  {
900
899
  onChangeKey = 'onChange';
901
900
  }
902
- var _this$getState6 = _this.getState(),
903
- inputValue = _this$getState6.inputValue,
904
- isOpen = _this$getState6.isOpen,
905
- highlightedIndex = _this$getState6.highlightedIndex;
901
+ const {
902
+ inputValue,
903
+ isOpen,
904
+ highlightedIndex
905
+ } = _this.getState();
906
906
  if (!rest.disabled) {
907
- var _eventHandlers;
908
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
907
+ eventHandlers = {
908
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
909
+ onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
910
+ onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
911
+ };
909
912
  }
910
- return _extends__default["default"]({
913
+ return {
911
914
  'aria-autocomplete': 'list',
912
915
  'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
913
916
  'aria-controls': isOpen ? _this.menuId : null,
@@ -916,76 +919,82 @@ var Downshift = /*#__PURE__*/function () {
916
919
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
917
920
  autoComplete: 'off',
918
921
  value: inputValue,
919
- id: _this.inputId
920
- }, eventHandlers, rest);
922
+ id: _this.inputId,
923
+ ...eventHandlers,
924
+ ...rest
925
+ };
921
926
  };
922
- _this.inputHandleKeyDown = function (event) {
923
- var key = normalizeArrowKey(event);
924
- if (key && _this.inputKeyDownHandlers[key]) {
925
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized__default["default"](_this), event);
927
+ this.inputHandleKeyDown = event => {
928
+ const key = normalizeArrowKey(event);
929
+ if (key && this.inputKeyDownHandlers[key]) {
930
+ this.inputKeyDownHandlers[key].call(this, event);
926
931
  }
927
932
  };
928
- _this.inputHandleChange = function (event) {
929
- _this.internalSetState({
933
+ this.inputHandleChange = event => {
934
+ this.internalSetState({
930
935
  type: changeInput,
931
936
  isOpen: true,
932
937
  inputValue: event.target.value,
933
- highlightedIndex: _this.props.defaultHighlightedIndex
938
+ highlightedIndex: this.props.defaultHighlightedIndex
934
939
  });
935
940
  };
936
- _this.inputHandleBlur = function () {
941
+ this.inputHandleBlur = () => {
937
942
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
938
- _this.internalSetTimeout(function () {
939
- var downshiftButtonIsActive = _this.props.environment.document && !!_this.props.environment.document.activeElement && !!_this.props.environment.document.activeElement.dataset && _this.props.environment.document.activeElement.dataset.toggle && _this._rootNode && _this._rootNode.contains(_this.props.environment.document.activeElement);
940
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
941
- _this.reset({
943
+ this.internalSetTimeout(() => {
944
+ const downshiftButtonIsActive = this.props.environment.document && !!this.props.environment.document.activeElement && !!this.props.environment.document.activeElement.dataset && this.props.environment.document.activeElement.dataset.toggle && this._rootNode && this._rootNode.contains(this.props.environment.document.activeElement);
945
+ if (!this.isMouseDown && !downshiftButtonIsActive) {
946
+ this.reset({
942
947
  type: blurInput
943
948
  });
944
949
  }
945
950
  });
946
951
  };
947
- _this.menuRef = function (node) {
948
- _this._menuNode = node;
949
- };
950
- _this.getMenuProps = function (_temp5, _temp6) {
951
- var _extends3;
952
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
953
- _ref5$refKey = _ref5.refKey,
954
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
955
- ref = _ref5.ref,
956
- props = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded4$1);
957
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
958
- _ref6$suppressRefErro = _ref6.suppressRefError,
959
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
952
+ this.menuRef = node => {
953
+ this._menuNode = node;
954
+ };
955
+ this.getMenuProps = function (_temp5, _temp6) {
956
+ let {
957
+ refKey = 'ref',
958
+ ref,
959
+ ...props
960
+ } = _temp5 === void 0 ? {} : _temp5;
961
+ let {
962
+ suppressRefError = false
963
+ } = _temp6 === void 0 ? {} : _temp6;
960
964
  _this.getMenuProps.called = true;
961
965
  _this.getMenuProps.refKey = refKey;
962
966
  _this.getMenuProps.suppressRefError = suppressRefError;
963
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
964
- };
965
- _this.getItemProps = function (_temp7) {
966
- var _enabledEventHandlers;
967
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
968
- onMouseMove = _ref7.onMouseMove,
969
- onMouseDown = _ref7.onMouseDown,
970
- onClick = _ref7.onClick;
971
- _ref7.onPress;
972
- var index = _ref7.index,
973
- _ref7$item = _ref7.item,
974
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ? /* istanbul ignore next */undefined : requiredProp('getItemProps', 'item') : _ref7$item,
975
- rest = _objectWithoutPropertiesLoose__default["default"](_ref7, _excluded5);
967
+ return {
968
+ [refKey]: handleRefs(ref, _this.menuRef),
969
+ role: 'listbox',
970
+ 'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
971
+ id: _this.menuId,
972
+ ...props
973
+ };
974
+ };
975
+ this.getItemProps = function (_temp7) {
976
+ let {
977
+ onMouseMove,
978
+ onMouseDown,
979
+ onClick,
980
+ onPress,
981
+ index,
982
+ item = process.env.NODE_ENV === 'production' ? /* istanbul ignore next */undefined : requiredProp('getItemProps', 'item'),
983
+ ...rest
984
+ } = _temp7 === void 0 ? {} : _temp7;
976
985
  if (index === undefined) {
977
986
  _this.items.push(item);
978
987
  index = _this.items.indexOf(item);
979
988
  } else {
980
989
  _this.items[index] = item;
981
990
  }
982
- var onSelectKey = 'onClick';
983
- var customClickHandler = onClick;
984
- var enabledEventHandlers = (_enabledEventHandlers = {
991
+ const onSelectKey = 'onClick';
992
+ const customClickHandler = onClick;
993
+ const enabledEventHandlers = {
985
994
  // onMouseMove is used over onMouseEnter here. onMouseMove
986
995
  // is only triggered on actual mouse movement while onMouseEnter
987
996
  // can fire on DOM changes, interrupting keyboard navigation
988
- onMouseMove: callAllEventHandlers(onMouseMove, function () {
997
+ onMouseMove: callAllEventHandlers(onMouseMove, () => {
989
998
  if (index === _this.getState().highlightedIndex) {
990
999
  return;
991
1000
  }
@@ -998,66 +1007,75 @@ var Downshift = /*#__PURE__*/function () {
998
1007
  // from under the user which is currently scrolling/moving the
999
1008
  // cursor
1000
1009
  _this.avoidScrolling = true;
1001
- _this.internalSetTimeout(function () {
1002
- return _this.avoidScrolling = false;
1003
- }, 250);
1010
+ _this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
1004
1011
  }),
1005
- onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
1012
+ onMouseDown: callAllEventHandlers(onMouseDown, event => {
1006
1013
  // This prevents the activeElement from being changed
1007
1014
  // to the item so it can remain with the current activeElement
1008
1015
  // which is a more common use case.
1009
1016
  event.preventDefault();
1017
+ }),
1018
+ [onSelectKey]: callAllEventHandlers(customClickHandler, () => {
1019
+ _this.selectItemAtIndex(index, {
1020
+ type: clickItem
1021
+ });
1010
1022
  })
1011
- }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
1012
- _this.selectItemAtIndex(index, {
1013
- type: clickItem
1014
- });
1015
- }), _enabledEventHandlers);
1023
+ };
1016
1024
 
1017
1025
  // Passing down the onMouseDown handler to prevent redirect
1018
1026
  // of the activeElement if clicking on disabled items
1019
- var eventHandlers = rest.disabled ? {
1027
+ const eventHandlers = rest.disabled ? {
1020
1028
  onMouseDown: enabledEventHandlers.onMouseDown
1021
1029
  } : enabledEventHandlers;
1022
- return _extends__default["default"]({
1030
+ return {
1023
1031
  id: _this.getItemId(index),
1024
1032
  role: 'option',
1025
- 'aria-selected': _this.getState().highlightedIndex === index
1026
- }, eventHandlers, rest);
1033
+ 'aria-selected': _this.getState().highlightedIndex === index,
1034
+ ...eventHandlers,
1035
+ ...rest
1036
+ };
1027
1037
  };
1028
- _this.clearItems = function () {
1029
- _this.items = [];
1038
+ this.clearItems = () => {
1039
+ this.items = [];
1030
1040
  };
1031
- _this.reset = function (otherStateToSet, cb) {
1041
+ this.reset = function (otherStateToSet, cb) {
1032
1042
  if (otherStateToSet === void 0) {
1033
1043
  otherStateToSet = {};
1034
1044
  }
1035
1045
  otherStateToSet = pickState(otherStateToSet);
1036
- _this.internalSetState(function (_ref8) {
1037
- var selectedItem = _ref8.selectedItem;
1038
- return _extends__default["default"]({
1046
+ _this.internalSetState(_ref => {
1047
+ let {
1048
+ selectedItem
1049
+ } = _ref;
1050
+ return {
1039
1051
  isOpen: _this.props.defaultIsOpen,
1040
1052
  highlightedIndex: _this.props.defaultHighlightedIndex,
1041
- inputValue: _this.props.itemToString(selectedItem)
1042
- }, otherStateToSet);
1053
+ inputValue: _this.props.itemToString(selectedItem),
1054
+ ...otherStateToSet
1055
+ };
1043
1056
  }, cb);
1044
1057
  };
1045
- _this.toggleMenu = function (otherStateToSet, cb) {
1058
+ this.toggleMenu = function (otherStateToSet, cb) {
1046
1059
  if (otherStateToSet === void 0) {
1047
1060
  otherStateToSet = {};
1048
1061
  }
1049
1062
  otherStateToSet = pickState(otherStateToSet);
1050
- _this.internalSetState(function (_ref9) {
1051
- var isOpen = _ref9.isOpen;
1052
- return _extends__default["default"]({
1053
- isOpen: !isOpen
1054
- }, isOpen && {
1055
- highlightedIndex: _this.props.defaultHighlightedIndex
1056
- }, otherStateToSet);
1057
- }, function () {
1058
- var _this$getState7 = _this.getState(),
1059
- isOpen = _this$getState7.isOpen,
1060
- highlightedIndex = _this$getState7.highlightedIndex;
1063
+ _this.internalSetState(_ref2 => {
1064
+ let {
1065
+ isOpen
1066
+ } = _ref2;
1067
+ return {
1068
+ isOpen: !isOpen,
1069
+ ...(isOpen && {
1070
+ highlightedIndex: _this.props.defaultHighlightedIndex
1071
+ }),
1072
+ ...otherStateToSet
1073
+ };
1074
+ }, () => {
1075
+ const {
1076
+ isOpen,
1077
+ highlightedIndex
1078
+ } = _this.getState();
1061
1079
  if (isOpen) {
1062
1080
  if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
1063
1081
  _this.setHighlightedIndex(highlightedIndex, otherStateToSet);
@@ -1066,58 +1084,57 @@ var Downshift = /*#__PURE__*/function () {
1066
1084
  cbToCb(cb)();
1067
1085
  });
1068
1086
  };
1069
- _this.openMenu = function (cb) {
1070
- _this.internalSetState({
1087
+ this.openMenu = cb => {
1088
+ this.internalSetState({
1071
1089
  isOpen: true
1072
1090
  }, cb);
1073
1091
  };
1074
- _this.closeMenu = function (cb) {
1075
- _this.internalSetState({
1092
+ this.closeMenu = cb => {
1093
+ this.internalSetState({
1076
1094
  isOpen: false
1077
1095
  }, cb);
1078
1096
  };
1079
- _this.updateStatus = debounce(function () {
1080
- var state = _this.getState();
1081
- var item = _this.items[state.highlightedIndex];
1082
- var resultCount = _this.getItemCount();
1083
- var status = _this.props.getA11yStatusMessage(_extends__default["default"]({
1084
- itemToString: _this.props.itemToString,
1085
- previousResultCount: _this.previousResultCount,
1086
- resultCount: resultCount,
1087
- highlightedItem: item
1088
- }, state));
1089
- _this.previousResultCount = resultCount;
1090
- setStatus(status, _this.props.environment.document);
1097
+ this.updateStatus = debounce(() => {
1098
+ const state = this.getState();
1099
+ const item = this.items[state.highlightedIndex];
1100
+ const resultCount = this.getItemCount();
1101
+ const status = this.props.getA11yStatusMessage({
1102
+ itemToString: this.props.itemToString,
1103
+ previousResultCount: this.previousResultCount,
1104
+ resultCount,
1105
+ highlightedItem: item,
1106
+ ...state
1107
+ });
1108
+ this.previousResultCount = resultCount;
1109
+ setStatus(status, this.props.environment.document);
1091
1110
  }, 200);
1092
- var _this$props = _this.props,
1093
- defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1094
- _this$props$initialHi = _this$props.initialHighlightedIndex,
1095
- _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1096
- defaultIsOpen = _this$props.defaultIsOpen,
1097
- _this$props$initialIs = _this$props.initialIsOpen,
1098
- _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1099
- _this$props$initialIn = _this$props.initialInputValue,
1100
- _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1101
- _this$props$initialSe = _this$props.initialSelectedItem,
1102
- _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1103
- var _state = _this.getState({
1111
+ // fancy destructuring + defaults + aliases
1112
+ // this basically says each value of state should either be set to
1113
+ // the initial value or the default value if the initial value is not provided
1114
+ const {
1115
+ defaultHighlightedIndex,
1116
+ initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
1117
+ defaultIsOpen,
1118
+ initialIsOpen: _isOpen = defaultIsOpen,
1119
+ initialInputValue: _inputValue = '',
1120
+ initialSelectedItem: _selectedItem = null
1121
+ } = this.props;
1122
+ const _state = this.getState({
1104
1123
  highlightedIndex: _highlightedIndex,
1105
1124
  isOpen: _isOpen,
1106
1125
  inputValue: _inputValue,
1107
1126
  selectedItem: _selectedItem
1108
1127
  });
1109
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1110
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1128
+ if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
1129
+ _state.inputValue = this.props.itemToString(_state.selectedItem);
1111
1130
  }
1112
- _this.state = _state;
1113
- return _this;
1131
+ this.state = _state;
1114
1132
  }
1115
- var _proto = Downshift.prototype;
1116
1133
  /**
1117
1134
  * Clear all running timeouts
1118
1135
  */
1119
- _proto.internalClearTimeouts = function internalClearTimeouts() {
1120
- this.timeoutIds.forEach(function (id) {
1136
+ internalClearTimeouts() {
1137
+ this.timeoutIds.forEach(id => {
1121
1138
  clearTimeout(id);
1122
1139
  });
1123
1140
  this.timeoutIds = [];
@@ -1131,113 +1148,117 @@ var Downshift = /*#__PURE__*/function () {
1131
1148
  *
1132
1149
  * @param {Object} stateToMerge defaults to this.state
1133
1150
  * @return {Object} the state
1134
- */;
1135
- _proto.getState = function getState$1(stateToMerge) {
1151
+ */
1152
+ getState(stateToMerge) {
1136
1153
  if (stateToMerge === void 0) {
1137
1154
  stateToMerge = this.state;
1138
1155
  }
1139
1156
  return getState(stateToMerge, this.props);
1140
- };
1141
- _proto.getItemCount = function getItemCount() {
1157
+ }
1158
+ getItemCount() {
1142
1159
  // things read better this way. They're in priority order:
1143
1160
  // 1. `this.itemCount`
1144
1161
  // 2. `this.props.itemCount`
1145
1162
  // 3. `this.items.length`
1146
- var itemCount = this.items.length;
1163
+ let itemCount = this.items.length;
1147
1164
  if (this.itemCount != null) {
1148
1165
  itemCount = this.itemCount;
1149
1166
  } else if (this.props.itemCount !== undefined) {
1150
1167
  itemCount = this.props.itemCount;
1151
1168
  }
1152
1169
  return itemCount;
1153
- };
1154
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1170
+ }
1171
+ getItemNodeFromIndex(index) {
1155
1172
  return this.props.environment.document.getElementById(this.getItemId(index));
1156
- };
1157
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1173
+ }
1174
+ scrollHighlightedItemIntoView() {
1158
1175
  /* istanbul ignore else (react-native) */
1159
1176
  {
1160
- var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1177
+ const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1161
1178
  this.props.scrollIntoView(node, this._menuNode);
1162
1179
  }
1163
- };
1164
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1165
- var _this6 = this;
1166
- var itemCount = this.getItemCount();
1167
- var _this$getState8 = this.getState(),
1168
- highlightedIndex = _this$getState8.highlightedIndex;
1180
+ }
1181
+ moveHighlightedIndex(amount, otherStateToSet) {
1182
+ const itemCount = this.getItemCount();
1183
+ const {
1184
+ highlightedIndex
1185
+ } = this.getState();
1169
1186
  if (itemCount > 0) {
1170
- var nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, function (index) {
1171
- return _this6.getItemNodeFromIndex(index);
1172
- });
1187
+ const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
1173
1188
  this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1174
1189
  }
1175
- };
1176
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1177
- var _this$getState9 = this.getState(),
1178
- highlightedIndex = _this$getState9.highlightedIndex,
1179
- inputValue = _this$getState9.inputValue,
1180
- selectedItem = _this$getState9.selectedItem,
1181
- isOpen = _this$getState9.isOpen;
1182
- var itemToString = this.props.itemToString;
1183
- var id = this.id;
1184
- var getRootProps = this.getRootProps,
1185
- getToggleButtonProps = this.getToggleButtonProps,
1186
- getLabelProps = this.getLabelProps,
1187
- getMenuProps = this.getMenuProps,
1188
- getInputProps = this.getInputProps,
1189
- getItemProps = this.getItemProps,
1190
- openMenu = this.openMenu,
1191
- closeMenu = this.closeMenu,
1192
- toggleMenu = this.toggleMenu,
1193
- selectItem = this.selectItem,
1194
- selectItemAtIndex = this.selectItemAtIndex,
1195
- selectHighlightedItem = this.selectHighlightedItem,
1196
- setHighlightedIndex = this.setHighlightedIndex,
1197
- clearSelection = this.clearSelection,
1198
- clearItems = this.clearItems,
1199
- reset = this.reset,
1200
- setItemCount = this.setItemCount,
1201
- unsetItemCount = this.unsetItemCount,
1202
- setState = this.internalSetState;
1190
+ }
1191
+ getStateAndHelpers() {
1192
+ const {
1193
+ highlightedIndex,
1194
+ inputValue,
1195
+ selectedItem,
1196
+ isOpen
1197
+ } = this.getState();
1198
+ const {
1199
+ itemToString
1200
+ } = this.props;
1201
+ const {
1202
+ id
1203
+ } = this;
1204
+ const {
1205
+ getRootProps,
1206
+ getToggleButtonProps,
1207
+ getLabelProps,
1208
+ getMenuProps,
1209
+ getInputProps,
1210
+ getItemProps,
1211
+ openMenu,
1212
+ closeMenu,
1213
+ toggleMenu,
1214
+ selectItem,
1215
+ selectItemAtIndex,
1216
+ selectHighlightedItem,
1217
+ setHighlightedIndex,
1218
+ clearSelection,
1219
+ clearItems,
1220
+ reset,
1221
+ setItemCount,
1222
+ unsetItemCount,
1223
+ internalSetState: setState
1224
+ } = this;
1203
1225
  return {
1204
1226
  // prop getters
1205
- getRootProps: getRootProps,
1206
- getToggleButtonProps: getToggleButtonProps,
1207
- getLabelProps: getLabelProps,
1208
- getMenuProps: getMenuProps,
1209
- getInputProps: getInputProps,
1210
- getItemProps: getItemProps,
1227
+ getRootProps,
1228
+ getToggleButtonProps,
1229
+ getLabelProps,
1230
+ getMenuProps,
1231
+ getInputProps,
1232
+ getItemProps,
1211
1233
  // actions
1212
- reset: reset,
1213
- openMenu: openMenu,
1214
- closeMenu: closeMenu,
1215
- toggleMenu: toggleMenu,
1216
- selectItem: selectItem,
1217
- selectItemAtIndex: selectItemAtIndex,
1218
- selectHighlightedItem: selectHighlightedItem,
1219
- setHighlightedIndex: setHighlightedIndex,
1220
- clearSelection: clearSelection,
1221
- clearItems: clearItems,
1222
- setItemCount: setItemCount,
1223
- unsetItemCount: unsetItemCount,
1224
- setState: setState,
1234
+ reset,
1235
+ openMenu,
1236
+ closeMenu,
1237
+ toggleMenu,
1238
+ selectItem,
1239
+ selectItemAtIndex,
1240
+ selectHighlightedItem,
1241
+ setHighlightedIndex,
1242
+ clearSelection,
1243
+ clearItems,
1244
+ setItemCount,
1245
+ unsetItemCount,
1246
+ setState,
1225
1247
  // props
1226
- itemToString: itemToString,
1248
+ itemToString,
1227
1249
  // derived
1228
- id: id,
1250
+ id,
1229
1251
  // state
1230
- highlightedIndex: highlightedIndex,
1231
- inputValue: inputValue,
1232
- isOpen: isOpen,
1233
- selectedItem: selectedItem
1252
+ highlightedIndex,
1253
+ inputValue,
1254
+ isOpen,
1255
+ selectedItem
1234
1256
  };
1235
1257
  }
1236
1258
 
1237
1259
  //////////////////////////// ROOT
1238
- ;
1239
- _proto.componentDidMount = function componentDidMount() {
1240
- var _this7 = this;
1260
+
1261
+ componentDidMount() {
1241
1262
  /* istanbul ignore if (react-native) */
1242
1263
  if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1243
1264
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
@@ -1250,20 +1271,18 @@ var Downshift = /*#__PURE__*/function () {
1250
1271
  // down long enough for the list to disappear (because the blur event fires on the input)
1251
1272
  // this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
1252
1273
  // trigger hiding the menu.
1253
- var onMouseDown = function onMouseDown() {
1254
- _this7.isMouseDown = true;
1274
+ const onMouseDown = () => {
1275
+ this.isMouseDown = true;
1255
1276
  };
1256
- var onMouseUp = function onMouseUp(event) {
1257
- _this7.isMouseDown = false;
1277
+ const onMouseUp = event => {
1278
+ this.isMouseDown = false;
1258
1279
  // if the target element or the activeElement is within a downshift node
1259
1280
  // then we don't want to reset downshift
1260
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
1261
- if (!contextWithinDownshift && _this7.getState().isOpen) {
1262
- _this7.reset({
1281
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
1282
+ if (!contextWithinDownshift && this.getState().isOpen) {
1283
+ this.reset({
1263
1284
  type: mouseUp
1264
- }, function () {
1265
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1266
- });
1285
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1267
1286
  }
1268
1287
  };
1269
1288
  // Touching an element in iOS gives focus and hover states, but touching out of
@@ -1272,31 +1291,31 @@ var Downshift = /*#__PURE__*/function () {
1272
1291
  // this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
1273
1292
  // If the user taps outside of Downshift, the component should be reset,
1274
1293
  // but not if the user is swiping
1275
- var onTouchStart = function onTouchStart() {
1276
- _this7.isTouchMove = false;
1294
+ const onTouchStart = () => {
1295
+ this.isTouchMove = false;
1277
1296
  };
1278
- var onTouchMove = function onTouchMove() {
1279
- _this7.isTouchMove = true;
1297
+ const onTouchMove = () => {
1298
+ this.isTouchMove = true;
1280
1299
  };
1281
- var onTouchEnd = function onTouchEnd(event) {
1282
- var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
1283
- if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
1284
- _this7.reset({
1300
+ const onTouchEnd = event => {
1301
+ const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
1302
+ if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
1303
+ this.reset({
1285
1304
  type: touchEnd
1286
- }, function () {
1287
- return _this7.props.onOuterClick(_this7.getStateAndHelpers());
1288
- });
1305
+ }, () => this.props.onOuterClick(this.getStateAndHelpers()));
1289
1306
  }
1290
1307
  };
1291
- var environment = this.props.environment;
1308
+ const {
1309
+ environment
1310
+ } = this.props;
1292
1311
  environment.addEventListener('mousedown', onMouseDown);
1293
1312
  environment.addEventListener('mouseup', onMouseUp);
1294
1313
  environment.addEventListener('touchstart', onTouchStart);
1295
1314
  environment.addEventListener('touchmove', onTouchMove);
1296
1315
  environment.addEventListener('touchend', onTouchEnd);
1297
- this.cleanup = function () {
1298
- _this7.internalClearTimeouts();
1299
- _this7.updateStatus.cancel();
1316
+ this.cleanup = () => {
1317
+ this.internalClearTimeouts();
1318
+ this.updateStatus.cancel();
1300
1319
  environment.removeEventListener('mousedown', onMouseDown);
1301
1320
  environment.removeEventListener('mouseup', onMouseUp);
1302
1321
  environment.removeEventListener('touchstart', onTouchStart);
@@ -1304,17 +1323,19 @@ var Downshift = /*#__PURE__*/function () {
1304
1323
  environment.removeEventListener('touchend', onTouchEnd);
1305
1324
  };
1306
1325
  }
1307
- };
1308
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1309
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1310
- currentHighlightedIndex = _ref10.highlightedIndex;
1311
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1312
- prevHighlightedIndex = _ref11.highlightedIndex;
1313
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1314
- var scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1326
+ }
1327
+ shouldScroll(prevState, prevProps) {
1328
+ const {
1329
+ highlightedIndex: currentHighlightedIndex
1330
+ } = this.props.highlightedIndex === undefined ? this.getState() : this.props;
1331
+ const {
1332
+ highlightedIndex: prevHighlightedIndex
1333
+ } = prevProps.highlightedIndex === undefined ? prevState : prevProps;
1334
+ const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1335
+ const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1315
1336
  return scrollWhenOpen || scrollWhenNavigating;
1316
- };
1317
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1337
+ }
1338
+ componentDidUpdate(prevProps, prevState) {
1318
1339
  if (process.env.NODE_ENV !== 'production') {
1319
1340
  validateControlledUnchanged(this.state, prevProps, this.props);
1320
1341
  /* istanbul ignore if (react-native) */
@@ -1336,12 +1357,13 @@ var Downshift = /*#__PURE__*/function () {
1336
1357
  {
1337
1358
  this.updateStatus();
1338
1359
  }
1339
- };
1340
- _proto.componentWillUnmount = function componentWillUnmount() {
1360
+ }
1361
+ componentWillUnmount() {
1341
1362
  this.cleanup(); // avoids memory leak
1342
- };
1343
- _proto.render = function render() {
1344
- var children = unwrapArray(this.props.children, noop);
1363
+ }
1364
+
1365
+ render() {
1366
+ const children = unwrapArray(this.props.children, noop);
1345
1367
  // because the items are rerendered every time we call the children
1346
1368
  // we clear this out each render and it will be populated again as
1347
1369
  // getItemProps is called.
@@ -1361,7 +1383,7 @@ var Downshift = /*#__PURE__*/function () {
1361
1383
  this.getLabelProps.called = false;
1362
1384
  // and something similar for getInputProps
1363
1385
  this.getInputProps.called = false;
1364
- var element = unwrapArray(children(this.getStateAndHelpers()));
1386
+ const element = unwrapArray(children(this.getStateAndHelpers()));
1365
1387
  if (!element) {
1366
1388
  return null;
1367
1389
  }
@@ -1386,14 +1408,13 @@ var Downshift = /*#__PURE__*/function () {
1386
1408
 
1387
1409
  /* istanbul ignore next */
1388
1410
  return undefined;
1389
- };
1390
- return Downshift;
1391
- }(react.Component);
1411
+ }
1412
+ }
1392
1413
  Downshift.defaultProps = {
1393
1414
  defaultHighlightedIndex: null,
1394
1415
  defaultIsOpen: false,
1395
1416
  getA11yStatusMessage: getA11yStatusMessage$1,
1396
- itemToString: function itemToString(i) {
1417
+ itemToString: i => {
1397
1418
  if (i == null) {
1398
1419
  return '';
1399
1420
  }
@@ -1409,20 +1430,16 @@ var Downshift = /*#__PURE__*/function () {
1409
1430
  onChange: noop,
1410
1431
  onSelect: noop,
1411
1432
  onOuterClick: noop,
1412
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1413
- return prevItem !== item;
1414
- },
1433
+ selectedItemChanged: (prevItem, item) => prevItem !== item,
1415
1434
  environment: /* istanbul ignore next (ssr) */
1416
1435
  typeof window === 'undefined' ? {} : window,
1417
- stateReducer: function stateReducer(state, stateToSet) {
1418
- return stateToSet;
1419
- },
1436
+ stateReducer: (state, stateToSet) => stateToSet,
1420
1437
  suppressRefError: false,
1421
- scrollIntoView: scrollIntoView
1438
+ scrollIntoView
1422
1439
  };
1423
1440
  Downshift.stateChangeTypes = stateChangeTypes$3;
1424
1441
  return Downshift;
1425
- }();
1442
+ })();
1426
1443
  process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
1427
1444
  children: PropTypes__default["default"].func,
1428
1445
  defaultHighlightedIndex: PropTypes__default["default"].number,
@@ -1468,61 +1485,70 @@ process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
1468
1485
  /* eslint-enable react/no-unused-prop-types */
1469
1486
  } : void 0;
1470
1487
  var Downshift$1 = Downshift;
1471
- function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1472
- var refKey = _ref12.refKey;
1488
+ function validateGetMenuPropsCalledCorrectly(node, _ref3) {
1489
+ let {
1490
+ refKey
1491
+ } = _ref3;
1473
1492
  if (!node) {
1474
1493
  // eslint-disable-next-line no-console
1475
- console.error("downshift: The ref prop \"" + refKey + "\" from getMenuProps was not applied correctly on your menu element.");
1494
+ console.error(`downshift: The ref prop "${refKey}" from getMenuProps was not applied correctly on your menu element.`);
1476
1495
  }
1477
1496
  }
1478
- function validateGetRootPropsCalledCorrectly(element, _ref13) {
1479
- var refKey = _ref13.refKey;
1480
- var refKeySpecified = refKey !== 'ref';
1481
- var isComposite = !isDOMElement(element);
1497
+ function validateGetRootPropsCalledCorrectly(element, _ref4) {
1498
+ let {
1499
+ refKey
1500
+ } = _ref4;
1501
+ const refKeySpecified = refKey !== 'ref';
1502
+ const isComposite = !isDOMElement(element);
1482
1503
  if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
1483
1504
  // eslint-disable-next-line no-console
1484
1505
  console.error('downshift: You returned a non-DOM element. You must specify a refKey in getRootProps');
1485
1506
  } else if (!isComposite && refKeySpecified) {
1486
1507
  // eslint-disable-next-line no-console
1487
- console.error("downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified \"" + refKey + "\"");
1508
+ console.error(`downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "${refKey}"`);
1488
1509
  }
1489
1510
  if (!reactIs.isForwardRef(element) && !getElementProps(element)[refKey]) {
1490
1511
  // eslint-disable-next-line no-console
1491
- console.error("downshift: You must apply the ref prop \"" + refKey + "\" from getRootProps onto your root element.");
1512
+ console.error(`downshift: You must apply the ref prop "${refKey}" from getRootProps onto your root element.`);
1492
1513
  }
1493
1514
  }
1494
1515
 
1495
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1496
- var dropdownDefaultStateValues = {
1516
+ const dropdownDefaultStateValues = {
1497
1517
  highlightedIndex: -1,
1498
1518
  isOpen: false,
1499
1519
  selectedItem: null,
1500
1520
  inputValue: ''
1501
1521
  };
1502
1522
  function callOnChangeProps(action, state, newState) {
1503
- var props = action.props,
1504
- type = action.type;
1505
- var changes = {};
1506
- Object.keys(state).forEach(function (key) {
1523
+ const {
1524
+ props,
1525
+ type
1526
+ } = action;
1527
+ const changes = {};
1528
+ Object.keys(state).forEach(key => {
1507
1529
  invokeOnChangeHandler(key, action, state, newState);
1508
1530
  if (newState[key] !== state[key]) {
1509
1531
  changes[key] = newState[key];
1510
1532
  }
1511
1533
  });
1512
1534
  if (props.onStateChange && Object.keys(changes).length) {
1513
- props.onStateChange(_extends__default["default"]({
1514
- type: type
1515
- }, changes));
1535
+ props.onStateChange({
1536
+ type,
1537
+ ...changes
1538
+ });
1516
1539
  }
1517
1540
  }
1518
1541
  function invokeOnChangeHandler(key, action, state, newState) {
1519
- var props = action.props,
1520
- type = action.type;
1521
- var handler = "on" + capitalizeString(key) + "Change";
1542
+ const {
1543
+ props,
1544
+ type
1545
+ } = action;
1546
+ const handler = `on${capitalizeString(key)}Change`;
1522
1547
  if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1523
- props[handler](_extends__default["default"]({
1524
- type: type
1525
- }, newState));
1548
+ props[handler]({
1549
+ type,
1550
+ ...newState
1551
+ });
1526
1552
  }
1527
1553
  }
1528
1554
 
@@ -1544,36 +1570,37 @@ function stateReducer(s, a) {
1544
1570
  * @returns {string} The a11y message.
1545
1571
  */
1546
1572
  function getA11ySelectionMessage(selectionParameters) {
1547
- var selectedItem = selectionParameters.selectedItem,
1548
- itemToStringLocal = selectionParameters.itemToString;
1549
- return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
1573
+ const {
1574
+ selectedItem,
1575
+ itemToString: itemToStringLocal
1576
+ } = selectionParameters;
1577
+ return selectedItem ? `${itemToStringLocal(selectedItem)} has been selected.` : '';
1550
1578
  }
1551
1579
 
1552
1580
  /**
1553
1581
  * Debounced call for updating the a11y message.
1554
1582
  */
1555
- var updateA11yStatus = debounce(function (getA11yMessage, document) {
1583
+ const updateA11yStatus = debounce((getA11yMessage, document) => {
1556
1584
  setStatus(getA11yMessage(), document);
1557
1585
  }, 200);
1558
1586
 
1559
1587
  // istanbul ignore next
1560
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
1588
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
1561
1589
  function useElementIds(_ref) {
1562
- var _ref$id = _ref.id,
1563
- id = _ref$id === void 0 ? "downshift-" + generateId() : _ref$id,
1564
- labelId = _ref.labelId,
1565
- menuId = _ref.menuId,
1566
- getItemId = _ref.getItemId,
1567
- toggleButtonId = _ref.toggleButtonId,
1568
- inputId = _ref.inputId;
1569
- var elementIdsRef = react.useRef({
1570
- labelId: labelId || id + "-label",
1571
- menuId: menuId || id + "-menu",
1572
- getItemId: getItemId || function (index) {
1573
- return id + "-item-" + index;
1574
- },
1575
- toggleButtonId: toggleButtonId || id + "-toggle-button",
1576
- inputId: inputId || id + "-input"
1590
+ let {
1591
+ id = `downshift-${generateId()}`,
1592
+ labelId,
1593
+ menuId,
1594
+ getItemId,
1595
+ toggleButtonId,
1596
+ inputId
1597
+ } = _ref;
1598
+ const elementIdsRef = react.useRef({
1599
+ labelId: labelId || `${id}-label`,
1600
+ menuId: menuId || `${id}-menu`,
1601
+ getItemId: getItemId || (index => `${id}-item-${index}`),
1602
+ toggleButtonId: toggleButtonId || `${id}-toggle-button`,
1603
+ inputId: inputId || `${id}-input`
1577
1604
  });
1578
1605
  return elementIdsRef.current;
1579
1606
  }
@@ -1593,10 +1620,10 @@ function isAcceptedCharacterKey(key) {
1593
1620
  return /^\S{1}$/.test(key);
1594
1621
  }
1595
1622
  function capitalizeString(string) {
1596
- return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
1623
+ return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
1597
1624
  }
1598
1625
  function useLatestRef(val) {
1599
- var ref = react.useRef(val);
1626
+ const ref = react.useRef(val);
1600
1627
  // technically this is not "concurrent mode safe" because we're manipulating
1601
1628
  // the value during render (so it's not idempotent). However, the places this
1602
1629
  // hook is used is to support memoizing callbacks which will be called
@@ -1617,28 +1644,26 @@ function useLatestRef(val) {
1617
1644
  * @returns {Array} An array with the state and an action dispatcher.
1618
1645
  */
1619
1646
  function useEnhancedReducer(reducer, initialState, props) {
1620
- var prevStateRef = react.useRef();
1621
- var actionRef = react.useRef();
1622
- var enhancedReducer = react.useCallback(function (state, action) {
1647
+ const prevStateRef = react.useRef();
1648
+ const actionRef = react.useRef();
1649
+ const enhancedReducer = react.useCallback((state, action) => {
1623
1650
  actionRef.current = action;
1624
1651
  state = getState(state, action.props);
1625
- var changes = reducer(state, action);
1626
- var newState = action.props.stateReducer(state, _extends__default["default"]({}, action, {
1627
- changes: changes
1628
- }));
1652
+ const changes = reducer(state, action);
1653
+ const newState = action.props.stateReducer(state, {
1654
+ ...action,
1655
+ changes
1656
+ });
1629
1657
  return newState;
1630
1658
  }, [reducer]);
1631
- var _useReducer = react.useReducer(enhancedReducer, initialState),
1632
- state = _useReducer[0],
1633
- dispatch = _useReducer[1];
1634
- var propsRef = useLatestRef(props);
1635
- var dispatchWithProps = react.useCallback(function (action) {
1636
- return dispatch(_extends__default["default"]({
1637
- props: propsRef.current
1638
- }, action));
1639
- }, [propsRef]);
1640
- var action = actionRef.current;
1641
- react.useEffect(function () {
1659
+ const [state, dispatch] = react.useReducer(enhancedReducer, initialState);
1660
+ const propsRef = useLatestRef(props);
1661
+ const dispatchWithProps = react.useCallback(action => dispatch({
1662
+ props: propsRef.current,
1663
+ ...action
1664
+ }), [propsRef]);
1665
+ const action = actionRef.current;
1666
+ react.useEffect(() => {
1642
1667
  if (action && prevStateRef.current && prevStateRef.current !== state) {
1643
1668
  callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1644
1669
  }
@@ -1657,16 +1682,14 @@ function useEnhancedReducer(reducer, initialState, props) {
1657
1682
  * @returns {Array} An array with the state and an action dispatcher.
1658
1683
  */
1659
1684
  function useControlledReducer$1(reducer, initialState, props) {
1660
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
1661
- state = _useEnhancedReducer[0],
1662
- dispatch = _useEnhancedReducer[1];
1685
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
1663
1686
  return [getState(state, props), dispatch];
1664
1687
  }
1665
- var defaultProps$3 = {
1666
- itemToString: itemToString,
1667
- stateReducer: stateReducer,
1668
- getA11ySelectionMessage: getA11ySelectionMessage,
1669
- scrollIntoView: scrollIntoView,
1688
+ const defaultProps$3 = {
1689
+ itemToString,
1690
+ stateReducer,
1691
+ getA11ySelectionMessage,
1692
+ scrollIntoView,
1670
1693
  environment: /* istanbul ignore next (ssr) */
1671
1694
  typeof window === 'undefined' ? {} : window
1672
1695
  };
@@ -1674,7 +1697,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
1674
1697
  if (defaultStateValues === void 0) {
1675
1698
  defaultStateValues = dropdownDefaultStateValues;
1676
1699
  }
1677
- var defaultValue = props["default" + capitalizeString(propKey)];
1700
+ const defaultValue = props[`default${capitalizeString(propKey)}`];
1678
1701
  if (defaultValue !== undefined) {
1679
1702
  return defaultValue;
1680
1703
  }
@@ -1684,34 +1707,38 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1684
1707
  if (defaultStateValues === void 0) {
1685
1708
  defaultStateValues = dropdownDefaultStateValues;
1686
1709
  }
1687
- var value = props[propKey];
1710
+ const value = props[propKey];
1688
1711
  if (value !== undefined) {
1689
1712
  return value;
1690
1713
  }
1691
- var initialValue = props["initial" + capitalizeString(propKey)];
1714
+ const initialValue = props[`initial${capitalizeString(propKey)}`];
1692
1715
  if (initialValue !== undefined) {
1693
1716
  return initialValue;
1694
1717
  }
1695
1718
  return getDefaultValue$1(props, propKey, defaultStateValues);
1696
1719
  }
1697
1720
  function getInitialState$2(props) {
1698
- var selectedItem = getInitialValue$1(props, 'selectedItem');
1699
- var isOpen = getInitialValue$1(props, 'isOpen');
1700
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1701
- var inputValue = getInitialValue$1(props, 'inputValue');
1721
+ const selectedItem = getInitialValue$1(props, 'selectedItem');
1722
+ const isOpen = getInitialValue$1(props, 'isOpen');
1723
+ const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1724
+ const inputValue = getInitialValue$1(props, 'inputValue');
1702
1725
  return {
1703
1726
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
1704
- isOpen: isOpen,
1705
- selectedItem: selectedItem,
1706
- inputValue: inputValue
1727
+ isOpen,
1728
+ selectedItem,
1729
+ inputValue
1707
1730
  };
1708
1731
  }
1709
1732
  function getHighlightedIndexOnOpen(props, state, offset) {
1710
- var items = props.items,
1711
- initialHighlightedIndex = props.initialHighlightedIndex,
1712
- defaultHighlightedIndex = props.defaultHighlightedIndex;
1713
- var selectedItem = state.selectedItem,
1714
- highlightedIndex = state.highlightedIndex;
1733
+ const {
1734
+ items,
1735
+ initialHighlightedIndex,
1736
+ defaultHighlightedIndex
1737
+ } = props;
1738
+ const {
1739
+ selectedItem,
1740
+ highlightedIndex
1741
+ } = state;
1715
1742
  if (items.length === 0) {
1716
1743
  return -1;
1717
1744
  }
@@ -1742,34 +1769,30 @@ function getHighlightedIndexOnOpen(props, state, offset) {
1742
1769
  * @returns {Object} Ref containing whether mouseDown or touchMove event is happening
1743
1770
  */
1744
1771
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1745
- var mouseAndTouchTrackersRef = react.useRef({
1772
+ const mouseAndTouchTrackersRef = react.useRef({
1746
1773
  isMouseDown: false,
1747
1774
  isTouchMove: false
1748
1775
  });
1749
- react.useEffect(function () {
1776
+ react.useEffect(() => {
1750
1777
  // The same strategy for checking if a click occurred inside or outside downsift
1751
1778
  // as in downshift.js.
1752
- var onMouseDown = function onMouseDown() {
1779
+ const onMouseDown = () => {
1753
1780
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1754
1781
  };
1755
- var onMouseUp = function onMouseUp(event) {
1782
+ const onMouseUp = event => {
1756
1783
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1757
- if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1758
- return ref.current;
1759
- }), environment)) {
1784
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
1760
1785
  handleBlur();
1761
1786
  }
1762
1787
  };
1763
- var onTouchStart = function onTouchStart() {
1788
+ const onTouchStart = () => {
1764
1789
  mouseAndTouchTrackersRef.current.isTouchMove = false;
1765
1790
  };
1766
- var onTouchMove = function onTouchMove() {
1791
+ const onTouchMove = () => {
1767
1792
  mouseAndTouchTrackersRef.current.isTouchMove = true;
1768
1793
  };
1769
- var onTouchEnd = function onTouchEnd(event) {
1770
- if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1771
- return ref.current;
1772
- }), environment, false)) {
1794
+ const onTouchEnd = event => {
1795
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
1773
1796
  handleBlur();
1774
1797
  }
1775
1798
  };
@@ -1792,9 +1815,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1792
1815
 
1793
1816
  /* istanbul ignore next */
1794
1817
  // eslint-disable-next-line import/no-mutable-exports
1795
- var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1796
- return noop;
1797
- };
1818
+ let useGetterPropsCalledChecker = () => noop;
1798
1819
  /**
1799
1820
  * Custom hook that checks if getter props are called correctly.
1800
1821
  *
@@ -1803,77 +1824,82 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1803
1824
  */
1804
1825
  /* istanbul ignore next */
1805
1826
  if (process.env.NODE_ENV !== 'production') {
1806
- useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
1807
- var isInitialMountRef = react.useRef(true);
1827
+ useGetterPropsCalledChecker = function () {
1828
+ const isInitialMountRef = react.useRef(true);
1808
1829
  for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
1809
1830
  propKeys[_key] = arguments[_key];
1810
1831
  }
1811
- var getterPropsCalledRef = react.useRef(propKeys.reduce(function (acc, propKey) {
1832
+ const getterPropsCalledRef = react.useRef(propKeys.reduce((acc, propKey) => {
1812
1833
  acc[propKey] = {};
1813
1834
  return acc;
1814
1835
  }, {}));
1815
- react.useEffect(function () {
1816
- Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
1817
- var propCallInfo = getterPropsCalledRef.current[propKey];
1836
+ react.useEffect(() => {
1837
+ Object.keys(getterPropsCalledRef.current).forEach(propKey => {
1838
+ const propCallInfo = getterPropsCalledRef.current[propKey];
1818
1839
  if (isInitialMountRef.current) {
1819
1840
  if (!Object.keys(propCallInfo).length) {
1820
1841
  // eslint-disable-next-line no-console
1821
- console.error("downshift: You forgot to call the " + propKey + " getter function on your component / element.");
1842
+ console.error(`downshift: You forgot to call the ${propKey} getter function on your component / element.`);
1822
1843
  return;
1823
1844
  }
1824
1845
  }
1825
- var suppressRefError = propCallInfo.suppressRefError,
1826
- refKey = propCallInfo.refKey,
1827
- elementRef = propCallInfo.elementRef;
1846
+ const {
1847
+ suppressRefError,
1848
+ refKey,
1849
+ elementRef
1850
+ } = propCallInfo;
1828
1851
  if ((!elementRef || !elementRef.current) && !suppressRefError) {
1829
1852
  // eslint-disable-next-line no-console
1830
- console.error("downshift: The ref prop \"" + refKey + "\" from " + propKey + " was not applied correctly on your element.");
1853
+ console.error(`downshift: The ref prop "${refKey}" from ${propKey} was not applied correctly on your element.`);
1831
1854
  }
1832
1855
  });
1833
1856
  isInitialMountRef.current = false;
1834
1857
  });
1835
- var setGetterPropCallInfo = react.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
1858
+ const setGetterPropCallInfo = react.useCallback((propKey, suppressRefError, refKey, elementRef) => {
1836
1859
  getterPropsCalledRef.current[propKey] = {
1837
- suppressRefError: suppressRefError,
1838
- refKey: refKey,
1839
- elementRef: elementRef
1860
+ suppressRefError,
1861
+ refKey,
1862
+ elementRef
1840
1863
  };
1841
1864
  }, []);
1842
1865
  return setGetterPropCallInfo;
1843
1866
  };
1844
1867
  }
1845
1868
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
1846
- var isInitialMount = _ref2.isInitialMount,
1847
- highlightedIndex = _ref2.highlightedIndex,
1848
- items = _ref2.items,
1849
- environment = _ref2.environment,
1850
- rest = _objectWithoutPropertiesLoose__default["default"](_ref2, _excluded$3);
1869
+ let {
1870
+ isInitialMount,
1871
+ highlightedIndex,
1872
+ items,
1873
+ environment,
1874
+ ...rest
1875
+ } = _ref2;
1851
1876
  // Sets a11y status message on changes in state.
1852
- react.useEffect(function () {
1877
+ react.useEffect(() => {
1853
1878
  if (isInitialMount || false) {
1854
1879
  return;
1855
1880
  }
1856
- updateA11yStatus(function () {
1857
- return getA11yMessage(_extends__default["default"]({
1858
- highlightedIndex: highlightedIndex,
1859
- highlightedItem: items[highlightedIndex],
1860
- resultCount: items.length
1861
- }, rest));
1862
- }, environment.document);
1881
+ updateA11yStatus(() => getA11yMessage({
1882
+ highlightedIndex,
1883
+ highlightedItem: items[highlightedIndex],
1884
+ resultCount: items.length,
1885
+ ...rest
1886
+ }), environment.document);
1863
1887
  // eslint-disable-next-line react-hooks/exhaustive-deps
1864
1888
  }, dependencyArray);
1865
1889
  }
1866
1890
  function useScrollIntoView(_ref3) {
1867
- var highlightedIndex = _ref3.highlightedIndex,
1868
- isOpen = _ref3.isOpen,
1869
- itemRefs = _ref3.itemRefs,
1870
- getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
1871
- menuElement = _ref3.menuElement,
1872
- scrollIntoViewProp = _ref3.scrollIntoView;
1891
+ let {
1892
+ highlightedIndex,
1893
+ isOpen,
1894
+ itemRefs,
1895
+ getItemNodeFromIndex,
1896
+ menuElement,
1897
+ scrollIntoView: scrollIntoViewProp
1898
+ } = _ref3;
1873
1899
  // used not to scroll on highlight by mouse.
1874
- var shouldScrollRef = react.useRef(true);
1900
+ const shouldScrollRef = react.useRef(true);
1875
1901
  // Scroll on highlighted item if change comes from keyboard.
1876
- useIsomorphicLayoutEffect(function () {
1902
+ useIsomorphicLayoutEffect(() => {
1877
1903
  if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
1878
1904
  return;
1879
1905
  }
@@ -1888,16 +1914,18 @@ function useScrollIntoView(_ref3) {
1888
1914
  }
1889
1915
 
1890
1916
  // eslint-disable-next-line import/no-mutable-exports
1891
- var useControlPropsValidator = noop;
1917
+ let useControlPropsValidator = noop;
1892
1918
  /* istanbul ignore next */
1893
1919
  if (process.env.NODE_ENV !== 'production') {
1894
- useControlPropsValidator = function useControlPropsValidator(_ref4) {
1895
- var isInitialMount = _ref4.isInitialMount,
1896
- props = _ref4.props,
1897
- state = _ref4.state;
1920
+ useControlPropsValidator = _ref4 => {
1921
+ let {
1922
+ isInitialMount,
1923
+ props,
1924
+ state
1925
+ } = _ref4;
1898
1926
  // used for checking when props are moving from controlled to uncontrolled.
1899
- var prevPropsRef = react.useRef(props);
1900
- react.useEffect(function () {
1927
+ const prevPropsRef = react.useRef(props);
1928
+ react.useEffect(() => {
1901
1929
  if (isInitialMount) {
1902
1930
  return;
1903
1931
  }
@@ -1908,9 +1936,11 @@ if (process.env.NODE_ENV !== 'production') {
1908
1936
  }
1909
1937
 
1910
1938
  function downshiftCommonReducer(state, action, stateChangeTypes) {
1911
- var type = action.type,
1912
- props = action.props;
1913
- var changes;
1939
+ const {
1940
+ type,
1941
+ props
1942
+ } = action;
1943
+ let changes;
1914
1944
  switch (type) {
1915
1945
  case stateChangeTypes.ItemMouseMove:
1916
1946
  changes = {
@@ -1961,7 +1991,10 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
1961
1991
  default:
1962
1992
  throw new Error('Reducer called without proper action type.');
1963
1993
  }
1964
- return _extends__default["default"]({}, state, changes);
1994
+ return {
1995
+ ...state,
1996
+ ...changes
1997
+ };
1965
1998
  }
1966
1999
  /* eslint-enable complexity */
1967
2000
 
@@ -2047,28 +2080,28 @@ if (process.env.NODE_ENV !== 'production') {
2047
2080
  };
2048
2081
  }
2049
2082
 
2050
- var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
2051
- var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
2052
- var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
2053
- var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
2054
- var ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
2055
- var ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
2056
- var ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
2057
- var ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
2058
- var ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
2059
- var ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
2060
- var ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
2061
- var ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
2062
- var MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
2063
- var ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
2064
- var ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
2065
- var FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2066
- var FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2067
- var FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2068
- var FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2069
- var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2070
- var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2071
- var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2083
+ const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
2084
+ const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
2085
+ const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
2086
+ const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
2087
+ const ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
2088
+ const ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
2089
+ const ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
2090
+ const ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
2091
+ const ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
2092
+ const ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
2093
+ const ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
2094
+ const ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
2095
+ const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
2096
+ const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
2097
+ const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
2098
+ const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2099
+ const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2100
+ const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2101
+ const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2102
+ const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2103
+ const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2104
+ const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2072
2105
 
2073
2106
  var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2074
2107
  __proto__: null,
@@ -2098,10 +2131,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2098
2131
 
2099
2132
  /* eslint-disable complexity */
2100
2133
  function downshiftSelectReducer(state, action) {
2101
- var type = action.type,
2102
- props = action.props,
2103
- altKey = action.altKey;
2104
- var changes;
2134
+ const {
2135
+ type,
2136
+ props,
2137
+ altKey
2138
+ } = action;
2139
+ let changes;
2105
2140
  switch (type) {
2106
2141
  case ItemClick$1:
2107
2142
  changes = {
@@ -2112,10 +2147,10 @@ function downshiftSelectReducer(state, action) {
2112
2147
  break;
2113
2148
  case ToggleButtonKeyDownCharacter:
2114
2149
  {
2115
- var lowercasedKey = action.key;
2116
- var inputValue = "" + state.inputValue + lowercasedKey;
2117
- var prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
2118
- var highlightedIndex = getItemIndexByCharacterKey({
2150
+ const lowercasedKey = action.key;
2151
+ const inputValue = `${state.inputValue}${lowercasedKey}`;
2152
+ const prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
2153
+ const highlightedIndex = getItemIndexByCharacterKey({
2119
2154
  keysSoFar: inputValue,
2120
2155
  highlightedIndex: prevHighlightedIndex,
2121
2156
  items: props.items,
@@ -2123,33 +2158,34 @@ function downshiftSelectReducer(state, action) {
2123
2158
  getItemNodeFromIndex: action.getItemNodeFromIndex
2124
2159
  });
2125
2160
  changes = {
2126
- inputValue: inputValue,
2127
- highlightedIndex: highlightedIndex,
2161
+ inputValue,
2162
+ highlightedIndex,
2128
2163
  isOpen: true
2129
2164
  };
2130
2165
  }
2131
2166
  break;
2132
2167
  case ToggleButtonKeyDownArrowDown:
2133
2168
  {
2134
- var _highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2169
+ const highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
2135
2170
  changes = {
2136
- highlightedIndex: _highlightedIndex,
2171
+ highlightedIndex,
2137
2172
  isOpen: true
2138
2173
  };
2139
2174
  }
2140
2175
  break;
2141
2176
  case ToggleButtonKeyDownArrowUp:
2142
2177
  if (state.isOpen && altKey) {
2143
- changes = _extends__default["default"]({
2178
+ changes = {
2144
2179
  isOpen: getDefaultValue$1(props, 'isOpen'),
2145
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2146
- }, state.highlightedIndex >= 0 && {
2147
- selectedItem: props.items[state.highlightedIndex]
2148
- });
2180
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2181
+ ...(state.highlightedIndex >= 0 && {
2182
+ selectedItem: props.items[state.highlightedIndex]
2183
+ })
2184
+ };
2149
2185
  } else {
2150
- var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
2186
+ const highlightedIndex = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
2151
2187
  changes = {
2152
- highlightedIndex: _highlightedIndex2,
2188
+ highlightedIndex,
2153
2189
  isOpen: true
2154
2190
  };
2155
2191
  }
@@ -2157,12 +2193,13 @@ function downshiftSelectReducer(state, action) {
2157
2193
  // only triggered when menu is open.
2158
2194
  case ToggleButtonKeyDownEnter:
2159
2195
  case ToggleButtonKeyDownSpaceButton:
2160
- changes = _extends__default["default"]({
2196
+ changes = {
2161
2197
  isOpen: getDefaultValue$1(props, 'isOpen'),
2162
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2163
- }, state.highlightedIndex >= 0 && {
2164
- selectedItem: props.items[state.highlightedIndex]
2165
- });
2198
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2199
+ ...(state.highlightedIndex >= 0 && {
2200
+ selectedItem: props.items[state.highlightedIndex]
2201
+ })
2202
+ };
2166
2203
  break;
2167
2204
  case ToggleButtonKeyDownHome:
2168
2205
  changes = {
@@ -2193,12 +2230,13 @@ function downshiftSelectReducer(state, action) {
2193
2230
  };
2194
2231
  break;
2195
2232
  case ToggleButtonBlur:
2196
- changes = _extends__default["default"]({
2233
+ changes = {
2197
2234
  isOpen: false,
2198
- highlightedIndex: -1
2199
- }, state.highlightedIndex >= 0 && {
2200
- selectedItem: props.items[state.highlightedIndex]
2201
- });
2235
+ highlightedIndex: -1,
2236
+ ...(state.highlightedIndex >= 0 && {
2237
+ selectedItem: props.items[state.highlightedIndex]
2238
+ })
2239
+ };
2202
2240
  break;
2203
2241
  case FunctionSelectItem$1:
2204
2242
  changes = {
@@ -2208,13 +2246,13 @@ function downshiftSelectReducer(state, action) {
2208
2246
  default:
2209
2247
  return downshiftCommonReducer(state, action, stateChangeTypes$2);
2210
2248
  }
2211
- return _extends__default["default"]({}, state, changes);
2249
+ return {
2250
+ ...state,
2251
+ ...changes
2252
+ };
2212
2253
  }
2213
2254
  /* eslint-enable complexity */
2214
2255
 
2215
- var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
2216
- _excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
2217
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
2218
2256
  useSelect.stateChangeTypes = stateChangeTypes$2;
2219
2257
  function useSelect(userProps) {
2220
2258
  if (userProps === void 0) {
@@ -2222,76 +2260,81 @@ function useSelect(userProps) {
2222
2260
  }
2223
2261
  validatePropTypes$2(userProps, useSelect);
2224
2262
  // Props defaults and destructuring.
2225
- var props = _extends__default["default"]({}, defaultProps$2, userProps);
2226
- var items = props.items,
2227
- scrollIntoView = props.scrollIntoView,
2228
- environment = props.environment,
2229
- itemToString = props.itemToString,
2230
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2231
- getA11yStatusMessage = props.getA11yStatusMessage;
2263
+ const props = {
2264
+ ...defaultProps$2,
2265
+ ...userProps
2266
+ };
2267
+ const {
2268
+ items,
2269
+ scrollIntoView,
2270
+ environment,
2271
+ itemToString,
2272
+ getA11ySelectionMessage,
2273
+ getA11yStatusMessage
2274
+ } = props;
2232
2275
  // Initial state depending on controlled props.
2233
- var initialState = getInitialState$2(props);
2234
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
2235
- state = _useControlledReducer[0],
2236
- dispatch = _useControlledReducer[1];
2237
- var isOpen = state.isOpen,
2238
- highlightedIndex = state.highlightedIndex,
2239
- selectedItem = state.selectedItem,
2240
- inputValue = state.inputValue;
2276
+ const initialState = getInitialState$2(props);
2277
+ const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
2278
+ const {
2279
+ isOpen,
2280
+ highlightedIndex,
2281
+ selectedItem,
2282
+ inputValue
2283
+ } = state;
2241
2284
 
2242
2285
  // Element efs.
2243
- var toggleButtonRef = react.useRef(null);
2244
- var menuRef = react.useRef(null);
2245
- var itemRefs = react.useRef({});
2286
+ const toggleButtonRef = react.useRef(null);
2287
+ const menuRef = react.useRef(null);
2288
+ const itemRefs = react.useRef({});
2246
2289
  // used to keep the inputValue clearTimeout object between renders.
2247
- var clearTimeoutRef = react.useRef(null);
2290
+ const clearTimeoutRef = react.useRef(null);
2248
2291
  // prevent id re-generation between renders.
2249
- var elementIds = useElementIds(props);
2292
+ const elementIds = useElementIds(props);
2250
2293
  // used to keep track of how many items we had on previous cycle.
2251
- var previousResultCountRef = react.useRef();
2252
- var isInitialMountRef = react.useRef(true);
2294
+ const previousResultCountRef = react.useRef();
2295
+ const isInitialMountRef = react.useRef(true);
2253
2296
  // utility callback to get item element.
2254
- var latest = useLatestRef({
2255
- state: state,
2256
- props: props
2297
+ const latest = useLatestRef({
2298
+ state,
2299
+ props
2257
2300
  });
2258
2301
 
2259
2302
  // Some utils.
2260
- var getItemNodeFromIndex = react.useCallback(function (index) {
2261
- return itemRefs.current[elementIds.getItemId(index)];
2262
- }, [elementIds]);
2303
+ const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
2263
2304
 
2264
2305
  // Effects.
2265
2306
  // Sets a11y status message on changes in state.
2266
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
2307
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2267
2308
  isInitialMount: isInitialMountRef.current,
2268
2309
  previousResultCount: previousResultCountRef.current,
2269
- items: items,
2270
- environment: environment,
2271
- itemToString: itemToString
2272
- }, state));
2310
+ items,
2311
+ environment,
2312
+ itemToString,
2313
+ ...state
2314
+ });
2273
2315
  // Sets a11y status message on changes in selectedItem.
2274
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
2316
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2275
2317
  isInitialMount: isInitialMountRef.current,
2276
2318
  previousResultCount: previousResultCountRef.current,
2277
- items: items,
2278
- environment: environment,
2279
- itemToString: itemToString
2280
- }, state));
2319
+ items,
2320
+ environment,
2321
+ itemToString,
2322
+ ...state
2323
+ });
2281
2324
  // Scroll on highlighted item if change comes from keyboard.
2282
- var shouldScrollRef = useScrollIntoView({
2325
+ const shouldScrollRef = useScrollIntoView({
2283
2326
  menuElement: menuRef.current,
2284
- highlightedIndex: highlightedIndex,
2285
- isOpen: isOpen,
2286
- itemRefs: itemRefs,
2287
- scrollIntoView: scrollIntoView,
2288
- getItemNodeFromIndex: getItemNodeFromIndex
2327
+ highlightedIndex,
2328
+ isOpen,
2329
+ itemRefs,
2330
+ scrollIntoView,
2331
+ getItemNodeFromIndex
2289
2332
  });
2290
2333
 
2291
2334
  // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2292
- react.useEffect(function () {
2335
+ react.useEffect(() => {
2293
2336
  // init the clean function here as we need access to dispatch.
2294
- clearTimeoutRef.current = debounce(function (outerDispatch) {
2337
+ clearTimeoutRef.current = debounce(outerDispatch => {
2295
2338
  outerDispatch({
2296
2339
  type: FunctionSetInputValue$1,
2297
2340
  inputValue: ''
@@ -2299,13 +2342,13 @@ function useSelect(userProps) {
2299
2342
  }, 500);
2300
2343
 
2301
2344
  // Cancel any pending debounced calls on mount
2302
- return function () {
2345
+ return () => {
2303
2346
  clearTimeoutRef.current.cancel();
2304
2347
  };
2305
2348
  }, []);
2306
2349
 
2307
2350
  // Invokes the keysSoFar callback set up above.
2308
- react.useEffect(function () {
2351
+ react.useEffect(() => {
2309
2352
  if (!inputValue) {
2310
2353
  return;
2311
2354
  }
@@ -2313,234 +2356,249 @@ function useSelect(userProps) {
2313
2356
  }, [dispatch, inputValue]);
2314
2357
  useControlPropsValidator({
2315
2358
  isInitialMount: isInitialMountRef.current,
2316
- props: props,
2317
- state: state
2359
+ props,
2360
+ state
2318
2361
  });
2319
- react.useEffect(function () {
2362
+ react.useEffect(() => {
2320
2363
  if (isInitialMountRef.current) {
2321
2364
  return;
2322
2365
  }
2323
2366
  previousResultCountRef.current = items.length;
2324
2367
  });
2325
2368
  // Add mouse/touch events to document.
2326
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2369
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
2327
2370
  dispatch({
2328
2371
  type: ToggleButtonBlur
2329
2372
  });
2330
2373
  });
2331
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2374
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
2332
2375
  // Make initial ref false.
2333
- react.useEffect(function () {
2376
+ react.useEffect(() => {
2334
2377
  isInitialMountRef.current = false;
2335
- return function () {
2378
+ return () => {
2336
2379
  isInitialMountRef.current = true;
2337
2380
  };
2338
2381
  }, []);
2339
2382
  // Reset itemRefs on close.
2340
- react.useEffect(function () {
2383
+ react.useEffect(() => {
2341
2384
  if (!isOpen) {
2342
2385
  itemRefs.current = {};
2343
2386
  }
2344
2387
  }, [isOpen]);
2345
2388
 
2346
2389
  // Event handler functions.
2347
- var toggleButtonKeyDownHandlers = react.useMemo(function () {
2348
- return {
2349
- ArrowDown: function ArrowDown(event) {
2350
- event.preventDefault();
2390
+ const toggleButtonKeyDownHandlers = react.useMemo(() => ({
2391
+ ArrowDown(event) {
2392
+ event.preventDefault();
2393
+ dispatch({
2394
+ type: ToggleButtonKeyDownArrowDown,
2395
+ getItemNodeFromIndex,
2396
+ altKey: event.altKey
2397
+ });
2398
+ },
2399
+ ArrowUp(event) {
2400
+ event.preventDefault();
2401
+ dispatch({
2402
+ type: ToggleButtonKeyDownArrowUp,
2403
+ getItemNodeFromIndex,
2404
+ altKey: event.altKey
2405
+ });
2406
+ },
2407
+ Home(event) {
2408
+ event.preventDefault();
2409
+ dispatch({
2410
+ type: ToggleButtonKeyDownHome,
2411
+ getItemNodeFromIndex
2412
+ });
2413
+ },
2414
+ End(event) {
2415
+ event.preventDefault();
2416
+ dispatch({
2417
+ type: ToggleButtonKeyDownEnd,
2418
+ getItemNodeFromIndex
2419
+ });
2420
+ },
2421
+ Escape() {
2422
+ if (latest.current.state.isOpen) {
2351
2423
  dispatch({
2352
- type: ToggleButtonKeyDownArrowDown,
2353
- getItemNodeFromIndex: getItemNodeFromIndex,
2354
- altKey: event.altKey
2424
+ type: ToggleButtonKeyDownEscape
2355
2425
  });
2356
- },
2357
- ArrowUp: function ArrowUp(event) {
2426
+ }
2427
+ },
2428
+ Enter(event) {
2429
+ event.preventDefault();
2430
+ dispatch({
2431
+ type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
2432
+ });
2433
+ },
2434
+ PageUp(event) {
2435
+ if (latest.current.state.isOpen) {
2358
2436
  event.preventDefault();
2359
2437
  dispatch({
2360
- type: ToggleButtonKeyDownArrowUp,
2361
- getItemNodeFromIndex: getItemNodeFromIndex,
2362
- altKey: event.altKey
2438
+ type: ToggleButtonKeyDownPageUp,
2439
+ getItemNodeFromIndex
2363
2440
  });
2364
- },
2365
- Home: function Home(event) {
2441
+ }
2442
+ },
2443
+ PageDown(event) {
2444
+ if (latest.current.state.isOpen) {
2366
2445
  event.preventDefault();
2367
2446
  dispatch({
2368
- type: ToggleButtonKeyDownHome,
2369
- getItemNodeFromIndex: getItemNodeFromIndex
2447
+ type: ToggleButtonKeyDownPageDown,
2448
+ getItemNodeFromIndex
2370
2449
  });
2371
- },
2372
- End: function End(event) {
2373
- event.preventDefault();
2450
+ }
2451
+ },
2452
+ ' '(event) {
2453
+ event.preventDefault();
2454
+ const currentState = latest.current.state;
2455
+ if (!currentState.isOpen) {
2374
2456
  dispatch({
2375
- type: ToggleButtonKeyDownEnd,
2376
- getItemNodeFromIndex: getItemNodeFromIndex
2457
+ type: ToggleButtonClick$1
2377
2458
  });
2378
- },
2379
- Escape: function Escape() {
2380
- if (latest.current.state.isOpen) {
2381
- dispatch({
2382
- type: ToggleButtonKeyDownEscape
2383
- });
2384
- }
2385
- },
2386
- Enter: function Enter(event) {
2387
- event.preventDefault();
2459
+ return;
2460
+ }
2461
+ if (currentState.inputValue) {
2388
2462
  dispatch({
2389
- type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
2463
+ type: ToggleButtonKeyDownCharacter,
2464
+ key: ' ',
2465
+ getItemNodeFromIndex
2466
+ });
2467
+ } else {
2468
+ dispatch({
2469
+ type: ToggleButtonKeyDownSpaceButton
2390
2470
  });
2391
- },
2392
- PageUp: function PageUp(event) {
2393
- if (latest.current.state.isOpen) {
2394
- event.preventDefault();
2395
- dispatch({
2396
- type: ToggleButtonKeyDownPageUp,
2397
- getItemNodeFromIndex: getItemNodeFromIndex
2398
- });
2399
- }
2400
- },
2401
- PageDown: function PageDown(event) {
2402
- if (latest.current.state.isOpen) {
2403
- event.preventDefault();
2404
- dispatch({
2405
- type: ToggleButtonKeyDownPageDown,
2406
- getItemNodeFromIndex: getItemNodeFromIndex
2407
- });
2408
- }
2409
- },
2410
- ' ': function _(event) {
2411
- event.preventDefault();
2412
- var currentState = latest.current.state;
2413
- if (!currentState.isOpen) {
2414
- dispatch({
2415
- type: ToggleButtonClick$1
2416
- });
2417
- return;
2418
- }
2419
- if (currentState.inputValue) {
2420
- dispatch({
2421
- type: ToggleButtonKeyDownCharacter,
2422
- key: ' ',
2423
- getItemNodeFromIndex: getItemNodeFromIndex
2424
- });
2425
- } else {
2426
- dispatch({
2427
- type: ToggleButtonKeyDownSpaceButton
2428
- });
2429
- }
2430
2471
  }
2431
- };
2432
- }, [dispatch, getItemNodeFromIndex, latest]);
2472
+ }
2473
+ }), [dispatch, getItemNodeFromIndex, latest]);
2433
2474
 
2434
2475
  // Action functions.
2435
- var toggleMenu = react.useCallback(function () {
2476
+ const toggleMenu = react.useCallback(() => {
2436
2477
  dispatch({
2437
2478
  type: FunctionToggleMenu$1
2438
2479
  });
2439
2480
  }, [dispatch]);
2440
- var closeMenu = react.useCallback(function () {
2481
+ const closeMenu = react.useCallback(() => {
2441
2482
  dispatch({
2442
2483
  type: FunctionCloseMenu$1
2443
2484
  });
2444
2485
  }, [dispatch]);
2445
- var openMenu = react.useCallback(function () {
2486
+ const openMenu = react.useCallback(() => {
2446
2487
  dispatch({
2447
2488
  type: FunctionOpenMenu$1
2448
2489
  });
2449
2490
  }, [dispatch]);
2450
- var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
2491
+ const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
2451
2492
  dispatch({
2452
2493
  type: FunctionSetHighlightedIndex$1,
2453
2494
  highlightedIndex: newHighlightedIndex
2454
2495
  });
2455
2496
  }, [dispatch]);
2456
- var selectItem = react.useCallback(function (newSelectedItem) {
2497
+ const selectItem = react.useCallback(newSelectedItem => {
2457
2498
  dispatch({
2458
2499
  type: FunctionSelectItem$1,
2459
2500
  selectedItem: newSelectedItem
2460
2501
  });
2461
2502
  }, [dispatch]);
2462
- var reset = react.useCallback(function () {
2503
+ const reset = react.useCallback(() => {
2463
2504
  dispatch({
2464
2505
  type: FunctionReset$2
2465
2506
  });
2466
2507
  }, [dispatch]);
2467
- var setInputValue = react.useCallback(function (newInputValue) {
2508
+ const setInputValue = react.useCallback(newInputValue => {
2468
2509
  dispatch({
2469
2510
  type: FunctionSetInputValue$1,
2470
2511
  inputValue: newInputValue
2471
2512
  });
2472
2513
  }, [dispatch]);
2473
2514
  // Getter functions.
2474
- var getLabelProps = react.useCallback(function (labelProps) {
2475
- return _extends__default["default"]({
2476
- id: elementIds.labelId,
2477
- htmlFor: elementIds.toggleButtonId
2478
- }, labelProps);
2479
- }, [elementIds]);
2480
- var getMenuProps = react.useCallback(function (_temp, _temp2) {
2481
- var _extends2;
2482
- var _ref = _temp === void 0 ? {} : _temp,
2483
- onMouseLeave = _ref.onMouseLeave,
2484
- _ref$refKey = _ref.refKey,
2485
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey;
2486
- _ref.onKeyDown;
2487
- _ref.onBlur;
2488
- var ref = _ref.ref,
2489
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
2490
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2491
- _ref2$suppressRefErro = _ref2.suppressRefError,
2492
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
2493
- var menuHandleMouseLeave = function menuHandleMouseLeave() {
2515
+ const getLabelProps = react.useCallback(labelProps => ({
2516
+ id: elementIds.labelId,
2517
+ htmlFor: elementIds.toggleButtonId,
2518
+ ...labelProps
2519
+ }), [elementIds]);
2520
+ const getMenuProps = react.useCallback(function (_temp, _temp2) {
2521
+ let {
2522
+ onMouseLeave,
2523
+ refKey = 'ref',
2524
+ onKeyDown,
2525
+ onBlur,
2526
+ ref,
2527
+ ...rest
2528
+ } = _temp === void 0 ? {} : _temp;
2529
+ let {
2530
+ suppressRefError = false
2531
+ } = _temp2 === void 0 ? {} : _temp2;
2532
+ const menuHandleMouseLeave = () => {
2494
2533
  dispatch({
2495
2534
  type: MenuMouseLeave$1
2496
2535
  });
2497
2536
  };
2498
2537
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2499
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2500
- menuRef.current = menuNode;
2501
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.tabIndex = -1, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
2538
+ return {
2539
+ [refKey]: handleRefs(ref, menuNode => {
2540
+ menuRef.current = menuNode;
2541
+ }),
2542
+ id: elementIds.menuId,
2543
+ role: 'listbox',
2544
+ 'aria-labelledby': elementIds.labelId,
2545
+ tabIndex: -1,
2546
+ onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
2547
+ ...rest
2548
+ };
2502
2549
  }, [dispatch, setGetterPropCallInfo, elementIds]);
2503
- var getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
2504
- var _extends3;
2505
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2506
- onBlur = _ref3.onBlur,
2507
- onClick = _ref3.onClick,
2508
- onKeyDown = _ref3.onKeyDown,
2509
- _ref3$refKey = _ref3.refKey,
2510
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
2511
- ref = _ref3.ref,
2512
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$2);
2513
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2514
- _ref4$suppressRefErro = _ref4.suppressRefError,
2515
- suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
2516
- var latestState = latest.current.state;
2517
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
2550
+ const getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
2551
+ let {
2552
+ onBlur,
2553
+ onClick,
2554
+ onKeyDown,
2555
+ refKey = 'ref',
2556
+ ref,
2557
+ ...rest
2558
+ } = _temp3 === void 0 ? {} : _temp3;
2559
+ let {
2560
+ suppressRefError = false
2561
+ } = _temp4 === void 0 ? {} : _temp4;
2562
+ const latestState = latest.current.state;
2563
+ const toggleButtonHandleClick = () => {
2518
2564
  dispatch({
2519
2565
  type: ToggleButtonClick$1
2520
2566
  });
2521
2567
  };
2522
- var toggleButtonHandleBlur = function toggleButtonHandleBlur() {
2568
+ const toggleButtonHandleBlur = () => {
2523
2569
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
2524
2570
  dispatch({
2525
2571
  type: ToggleButtonBlur
2526
2572
  });
2527
2573
  }
2528
2574
  };
2529
- var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2530
- var key = normalizeArrowKey(event);
2575
+ const toggleButtonHandleKeyDown = event => {
2576
+ const key = normalizeArrowKey(event);
2531
2577
  if (key && toggleButtonKeyDownHandlers[key]) {
2532
2578
  toggleButtonKeyDownHandlers[key](event);
2533
2579
  } else if (isAcceptedCharacterKey(key)) {
2534
2580
  dispatch({
2535
2581
  type: ToggleButtonKeyDownCharacter,
2536
- key: key,
2537
- getItemNodeFromIndex: getItemNodeFromIndex
2582
+ key,
2583
+ getItemNodeFromIndex
2538
2584
  });
2539
2585
  }
2540
2586
  };
2541
- var toggleProps = _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2542
- toggleButtonRef.current = toggleButtonNode;
2543
- }), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
2587
+ const toggleProps = {
2588
+ [refKey]: handleRefs(ref, toggleButtonNode => {
2589
+ toggleButtonRef.current = toggleButtonNode;
2590
+ }),
2591
+ 'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
2592
+ 'aria-controls': elementIds.menuId,
2593
+ 'aria-expanded': latest.current.state.isOpen,
2594
+ 'aria-haspopup': 'listbox',
2595
+ 'aria-labelledby': `${elementIds.labelId}`,
2596
+ id: elementIds.toggleButtonId,
2597
+ role: 'combobox',
2598
+ tabIndex: 0,
2599
+ onBlur: callAllEventHandlers(onBlur, toggleButtonHandleBlur),
2600
+ ...rest
2601
+ };
2544
2602
  if (!rest.disabled) {
2545
2603
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
2546
2604
  toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
@@ -2548,54 +2606,56 @@ function useSelect(userProps) {
2548
2606
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2549
2607
  return toggleProps;
2550
2608
  }, [latest, elementIds, setGetterPropCallInfo, dispatch, mouseAndTouchTrackersRef, toggleButtonKeyDownHandlers, getItemNodeFromIndex]);
2551
- var getItemProps = react.useCallback(function (_temp5) {
2552
- var _extends4;
2553
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2554
- itemProp = _ref5.item,
2555
- indexProp = _ref5.index,
2556
- onMouseMove = _ref5.onMouseMove,
2557
- onClick = _ref5.onClick,
2558
- _ref5$refKey = _ref5.refKey,
2559
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
2560
- ref = _ref5.ref,
2561
- disabled = _ref5.disabled,
2562
- rest = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded3$1);
2563
- var _latest$current = latest.current,
2564
- latestState = _latest$current.state,
2565
- latestProps = _latest$current.props;
2566
- var item = itemProp != null ? itemProp : items[indexProp];
2567
- var index = getItemIndex(indexProp, item, latestProps.items);
2568
- var itemHandleMouseMove = function itemHandleMouseMove() {
2609
+ const getItemProps = react.useCallback(function (_temp5) {
2610
+ let {
2611
+ item: itemProp,
2612
+ index: indexProp,
2613
+ onMouseMove,
2614
+ onClick,
2615
+ refKey = 'ref',
2616
+ ref,
2617
+ disabled,
2618
+ ...rest
2619
+ } = _temp5 === void 0 ? {} : _temp5;
2620
+ const {
2621
+ state: latestState,
2622
+ props: latestProps
2623
+ } = latest.current;
2624
+ const item = itemProp ?? items[indexProp];
2625
+ const index = getItemIndex(indexProp, item, latestProps.items);
2626
+ const itemHandleMouseMove = () => {
2569
2627
  if (index === latestState.highlightedIndex) {
2570
2628
  return;
2571
2629
  }
2572
2630
  shouldScrollRef.current = false;
2573
2631
  dispatch({
2574
2632
  type: ItemMouseMove$1,
2575
- index: index,
2576
- disabled: disabled
2633
+ index,
2634
+ disabled
2577
2635
  });
2578
2636
  };
2579
- var itemHandleClick = function itemHandleClick() {
2637
+ const itemHandleClick = () => {
2580
2638
  dispatch({
2581
2639
  type: ItemClick$1,
2582
- index: index
2640
+ index
2583
2641
  });
2584
2642
  };
2585
- var itemIndex = getItemIndex(index, item, latestProps.items);
2643
+ const itemIndex = getItemIndex(index, item, latestProps.items);
2586
2644
  if (itemIndex < 0) {
2587
2645
  throw new Error('Pass either item or item index in getItemProps!');
2588
2646
  }
2589
- var itemProps = _extends__default["default"]((_extends4 = {
2590
- disabled: disabled,
2647
+ const itemProps = {
2648
+ disabled,
2591
2649
  role: 'option',
2592
- 'aria-selected': "" + (item === selectedItem),
2593
- id: elementIds.getItemId(itemIndex)
2594
- }, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2595
- if (itemNode) {
2596
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2597
- }
2598
- }), _extends4), rest);
2650
+ 'aria-selected': `${item === selectedItem}`,
2651
+ id: elementIds.getItemId(itemIndex),
2652
+ [refKey]: handleRefs(ref, itemNode => {
2653
+ if (itemNode) {
2654
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2655
+ }
2656
+ }),
2657
+ ...rest
2658
+ };
2599
2659
  if (!disabled) {
2600
2660
  itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
2601
2661
  }
@@ -2604,49 +2664,49 @@ function useSelect(userProps) {
2604
2664
  }, [latest, items, selectedItem, elementIds, shouldScrollRef, dispatch]);
2605
2665
  return {
2606
2666
  // prop getters.
2607
- getToggleButtonProps: getToggleButtonProps,
2608
- getLabelProps: getLabelProps,
2609
- getMenuProps: getMenuProps,
2610
- getItemProps: getItemProps,
2667
+ getToggleButtonProps,
2668
+ getLabelProps,
2669
+ getMenuProps,
2670
+ getItemProps,
2611
2671
  // actions.
2612
- toggleMenu: toggleMenu,
2613
- openMenu: openMenu,
2614
- closeMenu: closeMenu,
2615
- setHighlightedIndex: setHighlightedIndex,
2616
- selectItem: selectItem,
2617
- reset: reset,
2618
- setInputValue: setInputValue,
2672
+ toggleMenu,
2673
+ openMenu,
2674
+ closeMenu,
2675
+ setHighlightedIndex,
2676
+ selectItem,
2677
+ reset,
2678
+ setInputValue,
2619
2679
  // state.
2620
- highlightedIndex: highlightedIndex,
2621
- isOpen: isOpen,
2622
- selectedItem: selectedItem,
2623
- inputValue: inputValue
2680
+ highlightedIndex,
2681
+ isOpen,
2682
+ selectedItem,
2683
+ inputValue
2624
2684
  };
2625
2685
  }
2626
2686
 
2627
- var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2628
- var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2629
- var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2630
- var InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2631
- var InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2632
- var InputKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__input_keydown_page_up__' : 5;
2633
- var InputKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__input_keydown_page_down__' : 6;
2634
- var InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 7;
2635
- var InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 8;
2636
- var InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 9;
2637
- var InputFocus = process.env.NODE_ENV !== "production" ? '__input_focus__' : 10;
2638
- var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 11;
2639
- var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 12;
2640
- var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 13;
2641
- var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 14;
2642
- var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2643
- var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2644
- var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2645
- var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2646
- var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2647
- var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2648
- var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2649
- var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
2687
+ const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2688
+ const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2689
+ const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2690
+ const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2691
+ const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2692
+ const InputKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__input_keydown_page_up__' : 5;
2693
+ const InputKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__input_keydown_page_down__' : 6;
2694
+ const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 7;
2695
+ const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 8;
2696
+ const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 9;
2697
+ const InputFocus = process.env.NODE_ENV !== "production" ? '__input_focus__' : 10;
2698
+ const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 11;
2699
+ const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 12;
2700
+ const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 13;
2701
+ const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 14;
2702
+ const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
2703
+ const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
2704
+ const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
2705
+ const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
2706
+ const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
2707
+ const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
2708
+ const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
2709
+ const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
2650
2710
 
2651
2711
  var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2652
2712
  __proto__: null,
@@ -2676,17 +2736,22 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2676
2736
  });
2677
2737
 
2678
2738
  function getInitialState$1(props) {
2679
- var initialState = getInitialState$2(props);
2680
- var selectedItem = initialState.selectedItem;
2681
- var inputValue = initialState.inputValue;
2739
+ const initialState = getInitialState$2(props);
2740
+ const {
2741
+ selectedItem
2742
+ } = initialState;
2743
+ let {
2744
+ inputValue
2745
+ } = initialState;
2682
2746
  if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2683
2747
  inputValue = props.itemToString(selectedItem);
2684
2748
  }
2685
- return _extends__default["default"]({}, initialState, {
2686
- inputValue: inputValue
2687
- });
2749
+ return {
2750
+ ...initialState,
2751
+ inputValue
2752
+ };
2688
2753
  }
2689
- var propTypes$1 = {
2754
+ const propTypes$1 = {
2690
2755
  items: PropTypes__default["default"].array.isRequired,
2691
2756
  itemToString: PropTypes__default["default"].func,
2692
2757
  getA11yStatusMessage: PropTypes__default["default"].func,
@@ -2739,13 +2804,11 @@ var propTypes$1 = {
2739
2804
  * @returns {Array} An array with the state and an action dispatcher.
2740
2805
  */
2741
2806
  function useControlledReducer(reducer, initialState, props) {
2742
- var previousSelectedItemRef = react.useRef();
2743
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
2744
- state = _useEnhancedReducer[0],
2745
- dispatch = _useEnhancedReducer[1];
2807
+ const previousSelectedItemRef = react.useRef();
2808
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
2746
2809
 
2747
2810
  // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
2748
- react.useEffect(function () {
2811
+ react.useEffect(() => {
2749
2812
  if (isControlledProp(props, 'selectedItem')) {
2750
2813
  if (previousSelectedItemRef.current !== props.selectedItem) {
2751
2814
  dispatch({
@@ -2760,23 +2823,26 @@ function useControlledReducer(reducer, initialState, props) {
2760
2823
  }
2761
2824
 
2762
2825
  // eslint-disable-next-line import/no-mutable-exports
2763
- var validatePropTypes$1 = noop;
2826
+ let validatePropTypes$1 = noop;
2764
2827
  /* istanbul ignore next */
2765
2828
  if (process.env.NODE_ENV !== 'production') {
2766
- validatePropTypes$1 = function validatePropTypes(options, caller) {
2829
+ validatePropTypes$1 = (options, caller) => {
2767
2830
  PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
2768
2831
  };
2769
2832
  }
2770
- var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
2833
+ const defaultProps$1 = {
2834
+ ...defaultProps$3,
2771
2835
  getA11yStatusMessage: getA11yStatusMessage$1
2772
- });
2836
+ };
2773
2837
 
2774
2838
  /* eslint-disable complexity */
2775
2839
  function downshiftUseComboboxReducer(state, action) {
2776
- var type = action.type,
2777
- props = action.props,
2778
- altKey = action.altKey;
2779
- var changes;
2840
+ const {
2841
+ type,
2842
+ props,
2843
+ altKey
2844
+ } = action;
2845
+ let changes;
2780
2846
  switch (type) {
2781
2847
  case ItemClick:
2782
2848
  changes = {
@@ -2801,13 +2867,14 @@ function downshiftUseComboboxReducer(state, action) {
2801
2867
  case InputKeyDownArrowUp:
2802
2868
  if (state.isOpen) {
2803
2869
  if (altKey) {
2804
- changes = _extends__default["default"]({
2870
+ changes = {
2805
2871
  isOpen: getDefaultValue$1(props, 'isOpen'),
2806
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2807
- }, state.highlightedIndex >= 0 && {
2808
- selectedItem: props.items[state.highlightedIndex],
2809
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2810
- });
2872
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2873
+ ...(state.highlightedIndex >= 0 && {
2874
+ selectedItem: props.items[state.highlightedIndex],
2875
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2876
+ })
2877
+ };
2811
2878
  } else {
2812
2879
  changes = {
2813
2880
  highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
@@ -2821,22 +2888,24 @@ function downshiftUseComboboxReducer(state, action) {
2821
2888
  }
2822
2889
  break;
2823
2890
  case InputKeyDownEnter:
2824
- changes = _extends__default["default"]({
2891
+ changes = {
2825
2892
  isOpen: getDefaultValue$1(props, 'isOpen'),
2826
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2827
- }, state.highlightedIndex >= 0 && {
2828
- selectedItem: props.items[state.highlightedIndex],
2829
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2830
- });
2893
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2894
+ ...(state.highlightedIndex >= 0 && {
2895
+ selectedItem: props.items[state.highlightedIndex],
2896
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2897
+ })
2898
+ };
2831
2899
  break;
2832
2900
  case InputKeyDownEscape:
2833
- changes = _extends__default["default"]({
2901
+ changes = {
2834
2902
  isOpen: false,
2835
- highlightedIndex: -1
2836
- }, !state.isOpen && {
2837
- selectedItem: null,
2838
- inputValue: ''
2839
- });
2903
+ highlightedIndex: -1,
2904
+ ...(!state.isOpen && {
2905
+ selectedItem: null,
2906
+ inputValue: ''
2907
+ })
2908
+ };
2840
2909
  break;
2841
2910
  case InputKeyDownPageUp:
2842
2911
  changes = {
@@ -2859,13 +2928,14 @@ function downshiftUseComboboxReducer(state, action) {
2859
2928
  };
2860
2929
  break;
2861
2930
  case InputBlur:
2862
- changes = _extends__default["default"]({
2931
+ changes = {
2863
2932
  isOpen: false,
2864
- highlightedIndex: -1
2865
- }, state.highlightedIndex >= 0 && action.selectItem && {
2866
- selectedItem: props.items[state.highlightedIndex],
2867
- inputValue: props.itemToString(props.items[state.highlightedIndex])
2868
- });
2933
+ highlightedIndex: -1,
2934
+ ...(state.highlightedIndex >= 0 && action.selectItem && {
2935
+ selectedItem: props.items[state.highlightedIndex],
2936
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
2937
+ })
2938
+ };
2869
2939
  break;
2870
2940
  case InputChange:
2871
2941
  changes = {
@@ -2894,14 +2964,14 @@ function downshiftUseComboboxReducer(state, action) {
2894
2964
  default:
2895
2965
  return downshiftCommonReducer(state, action, stateChangeTypes$1);
2896
2966
  }
2897
- return _extends__default["default"]({}, state, changes);
2967
+ return {
2968
+ ...state,
2969
+ ...changes
2970
+ };
2898
2971
  }
2899
2972
  /* eslint-enable complexity */
2900
2973
 
2901
- var _excluded$1 = ["onMouseLeave", "refKey", "ref"],
2902
- _excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
2903
- _excluded3 = ["onClick", "onPress", "refKey", "ref"],
2904
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onFocus", "onBlur", "onChangeText", "refKey", "ref"];
2974
+ /* eslint-disable max-statements */
2905
2975
  useCombobox.stateChangeTypes = stateChangeTypes$1;
2906
2976
  function useCombobox(userProps) {
2907
2977
  if (userProps === void 0) {
@@ -2909,327 +2979,349 @@ function useCombobox(userProps) {
2909
2979
  }
2910
2980
  validatePropTypes$1(userProps, useCombobox);
2911
2981
  // Props defaults and destructuring.
2912
- var props = _extends__default["default"]({}, defaultProps$1, userProps);
2913
- var initialIsOpen = props.initialIsOpen,
2914
- defaultIsOpen = props.defaultIsOpen,
2915
- items = props.items,
2916
- scrollIntoView = props.scrollIntoView,
2917
- environment = props.environment,
2918
- getA11yStatusMessage = props.getA11yStatusMessage,
2919
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2920
- itemToString = props.itemToString;
2982
+ const props = {
2983
+ ...defaultProps$1,
2984
+ ...userProps
2985
+ };
2986
+ const {
2987
+ initialIsOpen,
2988
+ defaultIsOpen,
2989
+ items,
2990
+ scrollIntoView,
2991
+ environment,
2992
+ getA11yStatusMessage,
2993
+ getA11ySelectionMessage,
2994
+ itemToString
2995
+ } = props;
2921
2996
  // Initial state depending on controlled props.
2922
- var initialState = getInitialState$1(props);
2923
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
2924
- state = _useControlledReducer[0],
2925
- dispatch = _useControlledReducer[1];
2926
- var isOpen = state.isOpen,
2927
- highlightedIndex = state.highlightedIndex,
2928
- selectedItem = state.selectedItem,
2929
- inputValue = state.inputValue;
2997
+ const initialState = getInitialState$1(props);
2998
+ const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
2999
+ const {
3000
+ isOpen,
3001
+ highlightedIndex,
3002
+ selectedItem,
3003
+ inputValue
3004
+ } = state;
2930
3005
 
2931
3006
  // Element refs.
2932
- var menuRef = react.useRef(null);
2933
- var itemRefs = react.useRef({});
2934
- var inputRef = react.useRef(null);
2935
- var toggleButtonRef = react.useRef(null);
2936
- var isInitialMountRef = react.useRef(true);
3007
+ const menuRef = react.useRef(null);
3008
+ const itemRefs = react.useRef({});
3009
+ const inputRef = react.useRef(null);
3010
+ const toggleButtonRef = react.useRef(null);
3011
+ const isInitialMountRef = react.useRef(true);
2937
3012
  // prevent id re-generation between renders.
2938
- var elementIds = useElementIds(props);
3013
+ const elementIds = useElementIds(props);
2939
3014
  // used to keep track of how many items we had on previous cycle.
2940
- var previousResultCountRef = react.useRef();
3015
+ const previousResultCountRef = react.useRef();
2941
3016
  // utility callback to get item element.
2942
- var latest = useLatestRef({
2943
- state: state,
2944
- props: props
3017
+ const latest = useLatestRef({
3018
+ state,
3019
+ props
2945
3020
  });
2946
- var getItemNodeFromIndex = react.useCallback(function (index) {
2947
- return itemRefs.current[elementIds.getItemId(index)];
2948
- }, [elementIds]);
3021
+ const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
2949
3022
 
2950
3023
  // Effects.
2951
3024
  // Sets a11y status message on changes in state.
2952
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default["default"]({
3025
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2953
3026
  isInitialMount: isInitialMountRef.current,
2954
3027
  previousResultCount: previousResultCountRef.current,
2955
- items: items,
2956
- environment: environment,
2957
- itemToString: itemToString
2958
- }, state));
3028
+ items,
3029
+ environment,
3030
+ itemToString,
3031
+ ...state
3032
+ });
2959
3033
  // Sets a11y status message on changes in selectedItem.
2960
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default["default"]({
3034
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2961
3035
  isInitialMount: isInitialMountRef.current,
2962
3036
  previousResultCount: previousResultCountRef.current,
2963
- items: items,
2964
- environment: environment,
2965
- itemToString: itemToString
2966
- }, state));
3037
+ items,
3038
+ environment,
3039
+ itemToString,
3040
+ ...state
3041
+ });
2967
3042
  // Scroll on highlighted item if change comes from keyboard.
2968
- var shouldScrollRef = useScrollIntoView({
3043
+ const shouldScrollRef = useScrollIntoView({
2969
3044
  menuElement: menuRef.current,
2970
- highlightedIndex: highlightedIndex,
2971
- isOpen: isOpen,
2972
- itemRefs: itemRefs,
2973
- scrollIntoView: scrollIntoView,
2974
- getItemNodeFromIndex: getItemNodeFromIndex
3045
+ highlightedIndex,
3046
+ isOpen,
3047
+ itemRefs,
3048
+ scrollIntoView,
3049
+ getItemNodeFromIndex
2975
3050
  });
2976
3051
  useControlPropsValidator({
2977
3052
  isInitialMount: isInitialMountRef.current,
2978
- props: props,
2979
- state: state
3053
+ props,
3054
+ state
2980
3055
  });
2981
3056
  // Focus the input on first render if required.
2982
- react.useEffect(function () {
2983
- var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3057
+ react.useEffect(() => {
3058
+ const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
2984
3059
  if (focusOnOpen && inputRef.current) {
2985
3060
  inputRef.current.focus();
2986
3061
  }
2987
3062
  // eslint-disable-next-line react-hooks/exhaustive-deps
2988
3063
  }, []);
2989
- react.useEffect(function () {
3064
+ react.useEffect(() => {
2990
3065
  if (isInitialMountRef.current) {
2991
3066
  return;
2992
3067
  }
2993
3068
  previousResultCountRef.current = items.length;
2994
3069
  });
2995
3070
  // Add mouse/touch events to document.
2996
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
3071
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, () => {
2997
3072
  dispatch({
2998
3073
  type: InputBlur,
2999
3074
  selectItem: false
3000
3075
  });
3001
3076
  });
3002
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3077
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
3003
3078
  // Make initial ref false.
3004
- react.useEffect(function () {
3079
+ react.useEffect(() => {
3005
3080
  isInitialMountRef.current = false;
3006
- return function () {
3081
+ return () => {
3007
3082
  isInitialMountRef.current = true;
3008
3083
  };
3009
3084
  }, []);
3010
3085
  // Reset itemRefs on close.
3011
- react.useEffect(function () {
3086
+ react.useEffect(() => {
3012
3087
  if (!isOpen) {
3013
3088
  itemRefs.current = {};
3014
3089
  } else if (document.activeElement !== inputRef.current) {
3015
- var _inputRef$current;
3016
- inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
3090
+ inputRef?.current?.focus();
3017
3091
  }
3018
3092
  }, [isOpen]);
3019
3093
 
3020
3094
  /* Event handler functions */
3021
- var inputKeyDownHandlers = react.useMemo(function () {
3022
- return {
3023
- ArrowDown: function ArrowDown(event) {
3024
- event.preventDefault();
3025
- dispatch({
3026
- type: InputKeyDownArrowDown,
3027
- altKey: event.altKey,
3028
- getItemNodeFromIndex: getItemNodeFromIndex
3029
- });
3030
- },
3031
- ArrowUp: function ArrowUp(event) {
3032
- event.preventDefault();
3033
- dispatch({
3034
- type: InputKeyDownArrowUp,
3035
- altKey: event.altKey,
3036
- getItemNodeFromIndex: getItemNodeFromIndex
3037
- });
3038
- },
3039
- Home: function Home(event) {
3040
- if (!latest.current.state.isOpen) {
3041
- return;
3042
- }
3095
+ const inputKeyDownHandlers = react.useMemo(() => ({
3096
+ ArrowDown(event) {
3097
+ event.preventDefault();
3098
+ dispatch({
3099
+ type: InputKeyDownArrowDown,
3100
+ altKey: event.altKey,
3101
+ getItemNodeFromIndex
3102
+ });
3103
+ },
3104
+ ArrowUp(event) {
3105
+ event.preventDefault();
3106
+ dispatch({
3107
+ type: InputKeyDownArrowUp,
3108
+ altKey: event.altKey,
3109
+ getItemNodeFromIndex
3110
+ });
3111
+ },
3112
+ Home(event) {
3113
+ if (!latest.current.state.isOpen) {
3114
+ return;
3115
+ }
3116
+ event.preventDefault();
3117
+ dispatch({
3118
+ type: InputKeyDownHome,
3119
+ getItemNodeFromIndex
3120
+ });
3121
+ },
3122
+ End(event) {
3123
+ if (!latest.current.state.isOpen) {
3124
+ return;
3125
+ }
3126
+ event.preventDefault();
3127
+ dispatch({
3128
+ type: InputKeyDownEnd,
3129
+ getItemNodeFromIndex
3130
+ });
3131
+ },
3132
+ Escape(event) {
3133
+ const latestState = latest.current.state;
3134
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3043
3135
  event.preventDefault();
3044
3136
  dispatch({
3045
- type: InputKeyDownHome,
3046
- getItemNodeFromIndex: getItemNodeFromIndex
3137
+ type: InputKeyDownEscape
3047
3138
  });
3048
- },
3049
- End: function End(event) {
3050
- if (!latest.current.state.isOpen) {
3051
- return;
3052
- }
3139
+ }
3140
+ },
3141
+ Enter(event) {
3142
+ const latestState = latest.current.state;
3143
+ // if closed or no highlighted index, do nothing.
3144
+ if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
3145
+ ) {
3146
+ return;
3147
+ }
3148
+ event.preventDefault();
3149
+ dispatch({
3150
+ type: InputKeyDownEnter,
3151
+ getItemNodeFromIndex
3152
+ });
3153
+ },
3154
+ PageUp(event) {
3155
+ if (latest.current.state.isOpen) {
3053
3156
  event.preventDefault();
3054
3157
  dispatch({
3055
- type: InputKeyDownEnd,
3056
- getItemNodeFromIndex: getItemNodeFromIndex
3158
+ type: InputKeyDownPageUp,
3159
+ getItemNodeFromIndex
3057
3160
  });
3058
- },
3059
- Escape: function Escape(event) {
3060
- var latestState = latest.current.state;
3061
- if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3062
- event.preventDefault();
3063
- dispatch({
3064
- type: InputKeyDownEscape
3065
- });
3066
- }
3067
- },
3068
- Enter: function Enter(event) {
3069
- var latestState = latest.current.state;
3070
- // if closed or no highlighted index, do nothing.
3071
- if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
3072
- ) {
3073
- return;
3074
- }
3161
+ }
3162
+ },
3163
+ PageDown(event) {
3164
+ if (latest.current.state.isOpen) {
3075
3165
  event.preventDefault();
3076
3166
  dispatch({
3077
- type: InputKeyDownEnter,
3078
- getItemNodeFromIndex: getItemNodeFromIndex
3167
+ type: InputKeyDownPageDown,
3168
+ getItemNodeFromIndex
3079
3169
  });
3080
- },
3081
- PageUp: function PageUp(event) {
3082
- if (latest.current.state.isOpen) {
3083
- event.preventDefault();
3084
- dispatch({
3085
- type: InputKeyDownPageUp,
3086
- getItemNodeFromIndex: getItemNodeFromIndex
3087
- });
3088
- }
3089
- },
3090
- PageDown: function PageDown(event) {
3091
- if (latest.current.state.isOpen) {
3092
- event.preventDefault();
3093
- dispatch({
3094
- type: InputKeyDownPageDown,
3095
- getItemNodeFromIndex: getItemNodeFromIndex
3096
- });
3097
- }
3098
3170
  }
3099
- };
3100
- }, [dispatch, latest, getItemNodeFromIndex]);
3171
+ }
3172
+ }), [dispatch, latest, getItemNodeFromIndex]);
3101
3173
 
3102
3174
  // Getter props.
3103
- var getLabelProps = react.useCallback(function (labelProps) {
3104
- return _extends__default["default"]({
3105
- id: elementIds.labelId,
3106
- htmlFor: elementIds.inputId
3107
- }, labelProps);
3108
- }, [elementIds]);
3109
- var getMenuProps = react.useCallback(function (_temp, _temp2) {
3110
- var _extends2;
3111
- var _ref = _temp === void 0 ? {} : _temp,
3112
- onMouseLeave = _ref.onMouseLeave,
3113
- _ref$refKey = _ref.refKey,
3114
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3115
- ref = _ref.ref,
3116
- rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$1);
3117
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3118
- _ref2$suppressRefErro = _ref2.suppressRefError,
3119
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3175
+ const getLabelProps = react.useCallback(labelProps => ({
3176
+ id: elementIds.labelId,
3177
+ htmlFor: elementIds.inputId,
3178
+ ...labelProps
3179
+ }), [elementIds]);
3180
+ const getMenuProps = react.useCallback(function (_temp, _temp2) {
3181
+ let {
3182
+ onMouseLeave,
3183
+ refKey = 'ref',
3184
+ ref,
3185
+ ...rest
3186
+ } = _temp === void 0 ? {} : _temp;
3187
+ let {
3188
+ suppressRefError = false
3189
+ } = _temp2 === void 0 ? {} : _temp2;
3120
3190
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3121
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3122
- menuRef.current = menuNode;
3123
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3124
- dispatch({
3125
- type: MenuMouseLeave
3126
- });
3127
- }), _extends2), rest);
3191
+ return {
3192
+ [refKey]: handleRefs(ref, menuNode => {
3193
+ menuRef.current = menuNode;
3194
+ }),
3195
+ id: elementIds.menuId,
3196
+ role: 'listbox',
3197
+ 'aria-labelledby': elementIds.labelId,
3198
+ onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
3199
+ dispatch({
3200
+ type: MenuMouseLeave
3201
+ });
3202
+ }),
3203
+ ...rest
3204
+ };
3128
3205
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3129
- var getItemProps = react.useCallback(function (_temp3) {
3130
- var _extends3, _ref4;
3131
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3132
- item = _ref3.item,
3133
- index = _ref3.index,
3134
- _ref3$refKey = _ref3.refKey,
3135
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3136
- ref = _ref3.ref,
3137
- onMouseMove = _ref3.onMouseMove,
3138
- onMouseDown = _ref3.onMouseDown,
3139
- onClick = _ref3.onClick;
3140
- _ref3.onPress;
3141
- var disabled = _ref3.disabled,
3142
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded2$1);
3143
- var _latest$current = latest.current,
3144
- latestProps = _latest$current.props,
3145
- latestState = _latest$current.state;
3146
- var itemIndex = getItemIndex(index, item, latestProps.items);
3206
+ const getItemProps = react.useCallback(function (_temp3) {
3207
+ let {
3208
+ item,
3209
+ index,
3210
+ refKey = 'ref',
3211
+ ref,
3212
+ onMouseMove,
3213
+ onMouseDown,
3214
+ onClick,
3215
+ onPress,
3216
+ disabled,
3217
+ ...rest
3218
+ } = _temp3 === void 0 ? {} : _temp3;
3219
+ const {
3220
+ props: latestProps,
3221
+ state: latestState
3222
+ } = latest.current;
3223
+ const itemIndex = getItemIndex(index, item, latestProps.items);
3147
3224
  if (itemIndex < 0) {
3148
3225
  throw new Error('Pass either item or item index in getItemProps!');
3149
3226
  }
3150
- var onSelectKey = 'onClick';
3151
- var customClickHandler = onClick;
3152
- var itemHandleMouseMove = function itemHandleMouseMove() {
3227
+ const onSelectKey = 'onClick';
3228
+ const customClickHandler = onClick;
3229
+ const itemHandleMouseMove = () => {
3153
3230
  if (index === latestState.highlightedIndex) {
3154
3231
  return;
3155
3232
  }
3156
3233
  shouldScrollRef.current = false;
3157
3234
  dispatch({
3158
3235
  type: ItemMouseMove,
3159
- index: index,
3160
- disabled: disabled
3236
+ index,
3237
+ disabled
3161
3238
  });
3162
3239
  };
3163
- var itemHandleClick = function itemHandleClick() {
3240
+ const itemHandleClick = () => {
3164
3241
  dispatch({
3165
3242
  type: ItemClick,
3166
- index: index
3243
+ index
3167
3244
  });
3168
3245
  };
3169
- var itemHandleMouseDown = function itemHandleMouseDown(e) {
3170
- return e.preventDefault();
3171
- };
3172
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3173
- if (itemNode) {
3174
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3175
- }
3176
- }), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(itemIndex), _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
3246
+ const itemHandleMouseDown = e => e.preventDefault();
3247
+ return {
3248
+ [refKey]: handleRefs(ref, itemNode => {
3249
+ if (itemNode) {
3250
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3251
+ }
3252
+ }),
3253
+ disabled,
3254
+ role: 'option',
3255
+ 'aria-selected': `${itemIndex === latestState.highlightedIndex}`,
3256
+ id: elementIds.getItemId(itemIndex),
3257
+ ...(!disabled && {
3258
+ [onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
3259
+ }),
3177
3260
  onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3178
- onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
3179
- }, rest);
3261
+ onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown),
3262
+ ...rest
3263
+ };
3180
3264
  }, [dispatch, latest, shouldScrollRef, elementIds]);
3181
- var getToggleButtonProps = react.useCallback(function (_temp4) {
3182
- var _extends4;
3183
- var _ref5 = _temp4 === void 0 ? {} : _temp4,
3184
- onClick = _ref5.onClick;
3185
- _ref5.onPress;
3186
- var _ref5$refKey = _ref5.refKey,
3187
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3188
- ref = _ref5.ref,
3189
- rest = _objectWithoutPropertiesLoose__default["default"](_ref5, _excluded3);
3190
- var latestState = latest.current.state;
3191
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
3265
+ const getToggleButtonProps = react.useCallback(function (_temp4) {
3266
+ let {
3267
+ onClick,
3268
+ onPress,
3269
+ refKey = 'ref',
3270
+ ref,
3271
+ ...rest
3272
+ } = _temp4 === void 0 ? {} : _temp4;
3273
+ const latestState = latest.current.state;
3274
+ const toggleButtonHandleClick = () => {
3192
3275
  dispatch({
3193
3276
  type: ToggleButtonClick
3194
3277
  });
3195
3278
  };
3196
- return _extends__default["default"]((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3197
- toggleButtonRef.current = toggleButtonNode;
3198
- }), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends__default["default"]({}, {
3199
- onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3200
- }), rest);
3279
+ return {
3280
+ [refKey]: handleRefs(ref, toggleButtonNode => {
3281
+ toggleButtonRef.current = toggleButtonNode;
3282
+ }),
3283
+ 'aria-controls': elementIds.menuId,
3284
+ 'aria-expanded': latestState.isOpen,
3285
+ id: elementIds.toggleButtonId,
3286
+ tabIndex: -1,
3287
+ ...(!rest.disabled && {
3288
+ ...({
3289
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3290
+ })
3291
+ }),
3292
+ ...rest
3293
+ };
3201
3294
  }, [dispatch, latest, elementIds]);
3202
- var getInputProps = react.useCallback(function (_temp5, _temp6) {
3203
- var _extends5;
3204
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3205
- onKeyDown = _ref6.onKeyDown,
3206
- onChange = _ref6.onChange,
3207
- onInput = _ref6.onInput,
3208
- onFocus = _ref6.onFocus,
3209
- onBlur = _ref6.onBlur;
3210
- _ref6.onChangeText;
3211
- var _ref6$refKey = _ref6.refKey,
3212
- refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3213
- ref = _ref6.ref,
3214
- rest = _objectWithoutPropertiesLoose__default["default"](_ref6, _excluded4);
3215
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3216
- _ref7$suppressRefErro = _ref7.suppressRefError,
3217
- suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3295
+ const getInputProps = react.useCallback(function (_temp5, _temp6) {
3296
+ let {
3297
+ onKeyDown,
3298
+ onChange,
3299
+ onInput,
3300
+ onFocus,
3301
+ onBlur,
3302
+ onChangeText,
3303
+ refKey = 'ref',
3304
+ ref,
3305
+ ...rest
3306
+ } = _temp5 === void 0 ? {} : _temp5;
3307
+ let {
3308
+ suppressRefError = false
3309
+ } = _temp6 === void 0 ? {} : _temp6;
3218
3310
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3219
- var latestState = latest.current.state;
3220
- var inputHandleKeyDown = function inputHandleKeyDown(event) {
3221
- var key = normalizeArrowKey(event);
3311
+ const latestState = latest.current.state;
3312
+ const inputHandleKeyDown = event => {
3313
+ const key = normalizeArrowKey(event);
3222
3314
  if (key && inputKeyDownHandlers[key]) {
3223
3315
  inputKeyDownHandlers[key](event);
3224
3316
  }
3225
3317
  };
3226
- var inputHandleChange = function inputHandleChange(event) {
3318
+ const inputHandleChange = event => {
3227
3319
  dispatch({
3228
3320
  type: InputChange,
3229
3321
  inputValue: event.target.value
3230
3322
  });
3231
3323
  };
3232
- var inputHandleBlur = function inputHandleBlur() {
3324
+ const inputHandleBlur = () => {
3233
3325
  /* istanbul ignore else */
3234
3326
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3235
3327
  dispatch({
@@ -3238,7 +3330,7 @@ function useCombobox(userProps) {
3238
3330
  });
3239
3331
  }
3240
3332
  };
3241
- var inputHandleFocus = function inputHandleFocus() {
3333
+ const inputHandleFocus = () => {
3242
3334
  if (!latestState.isOpen) {
3243
3335
  dispatch({
3244
3336
  type: InputFocus
@@ -3247,80 +3339,99 @@ function useCombobox(userProps) {
3247
3339
  };
3248
3340
 
3249
3341
  /* istanbul ignore next (preact) */
3250
- var onChangeKey = 'onChange';
3251
- var eventHandlers = {};
3342
+ const onChangeKey = 'onChange';
3343
+ let eventHandlers = {};
3252
3344
  if (!rest.disabled) {
3253
- var _eventHandlers;
3254
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onFocus = callAllEventHandlers(onFocus, inputHandleFocus), _eventHandlers);
3345
+ eventHandlers = {
3346
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
3347
+ onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
3348
+ onBlur: callAllEventHandlers(onBlur, inputHandleBlur),
3349
+ onFocus: callAllEventHandlers(onFocus, inputHandleFocus)
3350
+ };
3255
3351
  }
3256
- return _extends__default["default"]((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3257
- inputRef.current = inputNode;
3258
- }), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
3352
+ return {
3353
+ [refKey]: handleRefs(ref, inputNode => {
3354
+ inputRef.current = inputNode;
3355
+ }),
3356
+ 'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
3357
+ 'aria-autocomplete': 'list',
3358
+ 'aria-controls': elementIds.menuId,
3359
+ 'aria-expanded': latestState.isOpen,
3360
+ 'aria-labelledby': elementIds.labelId,
3361
+ // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
3362
+ // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
3363
+ autoComplete: 'off',
3364
+ id: elementIds.inputId,
3365
+ role: 'combobox',
3366
+ value: latestState.inputValue,
3367
+ ...eventHandlers,
3368
+ ...rest
3369
+ };
3259
3370
  }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3260
3371
 
3261
3372
  // returns
3262
- var toggleMenu = react.useCallback(function () {
3373
+ const toggleMenu = react.useCallback(() => {
3263
3374
  dispatch({
3264
3375
  type: FunctionToggleMenu
3265
3376
  });
3266
3377
  }, [dispatch]);
3267
- var closeMenu = react.useCallback(function () {
3378
+ const closeMenu = react.useCallback(() => {
3268
3379
  dispatch({
3269
3380
  type: FunctionCloseMenu
3270
3381
  });
3271
3382
  }, [dispatch]);
3272
- var openMenu = react.useCallback(function () {
3383
+ const openMenu = react.useCallback(() => {
3273
3384
  dispatch({
3274
3385
  type: FunctionOpenMenu
3275
3386
  });
3276
3387
  }, [dispatch]);
3277
- var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
3388
+ const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
3278
3389
  dispatch({
3279
3390
  type: FunctionSetHighlightedIndex,
3280
3391
  highlightedIndex: newHighlightedIndex
3281
3392
  });
3282
3393
  }, [dispatch]);
3283
- var selectItem = react.useCallback(function (newSelectedItem) {
3394
+ const selectItem = react.useCallback(newSelectedItem => {
3284
3395
  dispatch({
3285
3396
  type: FunctionSelectItem,
3286
3397
  selectedItem: newSelectedItem
3287
3398
  });
3288
3399
  }, [dispatch]);
3289
- var setInputValue = react.useCallback(function (newInputValue) {
3400
+ const setInputValue = react.useCallback(newInputValue => {
3290
3401
  dispatch({
3291
3402
  type: FunctionSetInputValue,
3292
3403
  inputValue: newInputValue
3293
3404
  });
3294
3405
  }, [dispatch]);
3295
- var reset = react.useCallback(function () {
3406
+ const reset = react.useCallback(() => {
3296
3407
  dispatch({
3297
3408
  type: FunctionReset$1
3298
3409
  });
3299
3410
  }, [dispatch]);
3300
3411
  return {
3301
3412
  // prop getters.
3302
- getItemProps: getItemProps,
3303
- getLabelProps: getLabelProps,
3304
- getMenuProps: getMenuProps,
3305
- getInputProps: getInputProps,
3306
- getToggleButtonProps: getToggleButtonProps,
3413
+ getItemProps,
3414
+ getLabelProps,
3415
+ getMenuProps,
3416
+ getInputProps,
3417
+ getToggleButtonProps,
3307
3418
  // actions.
3308
- toggleMenu: toggleMenu,
3309
- openMenu: openMenu,
3310
- closeMenu: closeMenu,
3311
- setHighlightedIndex: setHighlightedIndex,
3312
- setInputValue: setInputValue,
3313
- selectItem: selectItem,
3314
- reset: reset,
3419
+ toggleMenu,
3420
+ openMenu,
3421
+ closeMenu,
3422
+ setHighlightedIndex,
3423
+ setInputValue,
3424
+ selectItem,
3425
+ reset,
3315
3426
  // state.
3316
- highlightedIndex: highlightedIndex,
3317
- isOpen: isOpen,
3318
- selectedItem: selectedItem,
3319
- inputValue: inputValue
3427
+ highlightedIndex,
3428
+ isOpen,
3429
+ selectedItem,
3430
+ inputValue
3320
3431
  };
3321
3432
  }
3322
3433
 
3323
- var defaultStateValues = {
3434
+ const defaultStateValues = {
3324
3435
  activeIndex: -1,
3325
3436
  selectedItems: []
3326
3437
  };
@@ -3358,11 +3469,11 @@ function getDefaultValue(props, propKey) {
3358
3469
  * @returns {Object} The initial state.
3359
3470
  */
3360
3471
  function getInitialState(props) {
3361
- var activeIndex = getInitialValue(props, 'activeIndex');
3362
- var selectedItems = getInitialValue(props, 'selectedItems');
3472
+ const activeIndex = getInitialValue(props, 'activeIndex');
3473
+ const selectedItems = getInitialValue(props, 'selectedItems');
3363
3474
  return {
3364
- activeIndex: activeIndex,
3365
- selectedItems: selectedItems
3475
+ activeIndex,
3476
+ selectedItems
3366
3477
  };
3367
3478
  }
3368
3479
 
@@ -3379,7 +3490,7 @@ function isKeyDownOperationPermitted(event) {
3379
3490
  if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) {
3380
3491
  return false;
3381
3492
  }
3382
- var element = event.target;
3493
+ const element = event.target;
3383
3494
  if (element instanceof HTMLInputElement &&
3384
3495
  // if element is a text input
3385
3496
  element.value !== '' && (
@@ -3398,11 +3509,13 @@ function isKeyDownOperationPermitted(event) {
3398
3509
  * @returns {string} The a11y message.
3399
3510
  */
3400
3511
  function getA11yRemovalMessage(selectionParameters) {
3401
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3402
- itemToStringLocal = selectionParameters.itemToString;
3403
- return itemToStringLocal(removedSelectedItem) + " has been removed.";
3512
+ const {
3513
+ removedSelectedItem,
3514
+ itemToString: itemToStringLocal
3515
+ } = selectionParameters;
3516
+ return `${itemToStringLocal(removedSelectedItem)} has been removed.`;
3404
3517
  }
3405
- var propTypes = {
3518
+ const propTypes = {
3406
3519
  selectedItems: PropTypes__default["default"].array,
3407
3520
  initialSelectedItems: PropTypes__default["default"].array,
3408
3521
  defaultSelectedItems: PropTypes__default["default"].array,
@@ -3426,37 +3539,37 @@ var propTypes = {
3426
3539
  })
3427
3540
  })
3428
3541
  };
3429
- var defaultProps = {
3542
+ const defaultProps = {
3430
3543
  itemToString: defaultProps$3.itemToString,
3431
3544
  stateReducer: defaultProps$3.stateReducer,
3432
3545
  environment: defaultProps$3.environment,
3433
- getA11yRemovalMessage: getA11yRemovalMessage,
3546
+ getA11yRemovalMessage,
3434
3547
  keyNavigationNext: 'ArrowRight',
3435
3548
  keyNavigationPrevious: 'ArrowLeft'
3436
3549
  };
3437
3550
 
3438
3551
  // eslint-disable-next-line import/no-mutable-exports
3439
- var validatePropTypes = noop;
3552
+ let validatePropTypes = noop;
3440
3553
  /* istanbul ignore next */
3441
3554
  if (process.env.NODE_ENV !== 'production') {
3442
- validatePropTypes = function validatePropTypes(options, caller) {
3555
+ validatePropTypes = (options, caller) => {
3443
3556
  PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
3444
3557
  };
3445
3558
  }
3446
3559
 
3447
- var SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3448
- var SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3449
- var SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3450
- var SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3451
- var SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3452
- var DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3453
- var DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3454
- var DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3455
- var FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3456
- var FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3457
- var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3458
- var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3459
- var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3560
+ const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3561
+ const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3562
+ const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3563
+ const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3564
+ const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3565
+ const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3566
+ const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3567
+ const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3568
+ const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3569
+ const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3570
+ const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3571
+ const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3572
+ const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3460
3573
 
3461
3574
  var stateChangeTypes = /*#__PURE__*/Object.freeze({
3462
3575
  __proto__: null,
@@ -3477,13 +3590,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3477
3590
 
3478
3591
  /* eslint-disable complexity */
3479
3592
  function downshiftMultipleSelectionReducer(state, action) {
3480
- var type = action.type,
3481
- index = action.index,
3482
- props = action.props,
3483
- selectedItem = action.selectedItem;
3484
- var activeIndex = state.activeIndex,
3485
- selectedItems = state.selectedItems;
3486
- var changes;
3593
+ const {
3594
+ type,
3595
+ index,
3596
+ props,
3597
+ selectedItem
3598
+ } = action;
3599
+ const {
3600
+ activeIndex,
3601
+ selectedItems
3602
+ } = state;
3603
+ let changes;
3487
3604
  switch (type) {
3488
3605
  case SelectedItemClick:
3489
3606
  changes = {
@@ -3506,17 +3623,18 @@ function downshiftMultipleSelectionReducer(state, action) {
3506
3623
  if (activeIndex < 0) {
3507
3624
  break;
3508
3625
  }
3509
- var newActiveIndex = activeIndex;
3626
+ let newActiveIndex = activeIndex;
3510
3627
  if (selectedItems.length === 1) {
3511
3628
  newActiveIndex = -1;
3512
3629
  } else if (activeIndex === selectedItems.length - 1) {
3513
3630
  newActiveIndex = selectedItems.length - 2;
3514
3631
  }
3515
- changes = _extends__default["default"]({
3516
- selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
3517
- }, {
3518
- activeIndex: newActiveIndex
3519
- });
3632
+ changes = {
3633
+ selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
3634
+ ...{
3635
+ activeIndex: newActiveIndex
3636
+ }
3637
+ };
3520
3638
  break;
3521
3639
  }
3522
3640
  case DropdownKeyDownNavigationPrevious:
@@ -3531,7 +3649,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3531
3649
  break;
3532
3650
  case FunctionAddSelectedItem:
3533
3651
  changes = {
3534
- selectedItems: [].concat(selectedItems, [selectedItem])
3652
+ selectedItems: [...selectedItems, selectedItem]
3535
3653
  };
3536
3654
  break;
3537
3655
  case DropdownClick:
@@ -3541,25 +3659,27 @@ function downshiftMultipleSelectionReducer(state, action) {
3541
3659
  break;
3542
3660
  case FunctionRemoveSelectedItem:
3543
3661
  {
3544
- var _newActiveIndex = activeIndex;
3545
- var selectedItemIndex = selectedItems.indexOf(selectedItem);
3662
+ let newActiveIndex = activeIndex;
3663
+ const selectedItemIndex = selectedItems.indexOf(selectedItem);
3546
3664
  if (selectedItemIndex < 0) {
3547
3665
  break;
3548
3666
  }
3549
3667
  if (selectedItems.length === 1) {
3550
- _newActiveIndex = -1;
3668
+ newActiveIndex = -1;
3551
3669
  } else if (selectedItemIndex === selectedItems.length - 1) {
3552
- _newActiveIndex = selectedItems.length - 2;
3670
+ newActiveIndex = selectedItems.length - 2;
3553
3671
  }
3554
3672
  changes = {
3555
- selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1)),
3556
- activeIndex: _newActiveIndex
3673
+ selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
3674
+ activeIndex: newActiveIndex
3557
3675
  };
3558
3676
  break;
3559
3677
  }
3560
3678
  case FunctionSetSelectedItems:
3561
3679
  {
3562
- var newSelectedItems = action.selectedItems;
3680
+ const {
3681
+ selectedItems: newSelectedItems
3682
+ } = action;
3563
3683
  changes = {
3564
3684
  selectedItems: newSelectedItems
3565
3685
  };
@@ -3567,9 +3687,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3567
3687
  }
3568
3688
  case FunctionSetActiveIndex:
3569
3689
  {
3570
- var _newActiveIndex2 = action.activeIndex;
3690
+ const {
3691
+ activeIndex: newActiveIndex
3692
+ } = action;
3571
3693
  changes = {
3572
- activeIndex: _newActiveIndex2
3694
+ activeIndex: newActiveIndex
3573
3695
  };
3574
3696
  break;
3575
3697
  }
@@ -3582,11 +3704,12 @@ function downshiftMultipleSelectionReducer(state, action) {
3582
3704
  default:
3583
3705
  throw new Error('Reducer called without proper action type.');
3584
3706
  }
3585
- return _extends__default["default"]({}, state, changes);
3707
+ return {
3708
+ ...state,
3709
+ ...changes
3710
+ };
3586
3711
  }
3587
3712
 
3588
- var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
3589
- _excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
3590
3713
  useMultipleSelection.stateChangeTypes = stateChangeTypes;
3591
3714
  function useMultipleSelection(userProps) {
3592
3715
  if (userProps === void 0) {
@@ -3594,46 +3717,49 @@ function useMultipleSelection(userProps) {
3594
3717
  }
3595
3718
  validatePropTypes(userProps, useMultipleSelection);
3596
3719
  // Props defaults and destructuring.
3597
- var props = _extends__default["default"]({}, defaultProps, userProps);
3598
- var getA11yRemovalMessage = props.getA11yRemovalMessage,
3599
- itemToString = props.itemToString,
3600
- environment = props.environment,
3601
- keyNavigationNext = props.keyNavigationNext,
3602
- keyNavigationPrevious = props.keyNavigationPrevious;
3720
+ const props = {
3721
+ ...defaultProps,
3722
+ ...userProps
3723
+ };
3724
+ const {
3725
+ getA11yRemovalMessage,
3726
+ itemToString,
3727
+ environment,
3728
+ keyNavigationNext,
3729
+ keyNavigationPrevious
3730
+ } = props;
3603
3731
 
3604
3732
  // Reducer init.
3605
- var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
3606
- state = _useControlledReducer[0],
3607
- dispatch = _useControlledReducer[1];
3608
- var activeIndex = state.activeIndex,
3609
- selectedItems = state.selectedItems;
3733
+ const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
3734
+ const {
3735
+ activeIndex,
3736
+ selectedItems
3737
+ } = state;
3610
3738
 
3611
3739
  // Refs.
3612
- var isInitialMountRef = react.useRef(true);
3613
- var dropdownRef = react.useRef(null);
3614
- var previousSelectedItemsRef = react.useRef(selectedItems);
3615
- var selectedItemRefs = react.useRef();
3740
+ const isInitialMountRef = react.useRef(true);
3741
+ const dropdownRef = react.useRef(null);
3742
+ const previousSelectedItemsRef = react.useRef(selectedItems);
3743
+ const selectedItemRefs = react.useRef();
3616
3744
  selectedItemRefs.current = [];
3617
- var latest = useLatestRef({
3618
- state: state,
3619
- props: props
3745
+ const latest = useLatestRef({
3746
+ state,
3747
+ props
3620
3748
  });
3621
3749
 
3622
3750
  // Effects.
3623
3751
  /* Sets a11y status message on changes in selectedItem. */
3624
- react.useEffect(function () {
3752
+ react.useEffect(() => {
3625
3753
  if (isInitialMountRef.current) {
3626
3754
  return;
3627
3755
  }
3628
3756
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
3629
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
3630
- return selectedItems.indexOf(item) < 0;
3631
- });
3757
+ const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
3632
3758
  setStatus(getA11yRemovalMessage({
3633
- itemToString: itemToString,
3759
+ itemToString,
3634
3760
  resultCount: selectedItems.length,
3635
- removedSelectedItem: removedSelectedItem,
3636
- activeIndex: activeIndex,
3761
+ removedSelectedItem,
3762
+ activeIndex,
3637
3763
  activeSelectedItem: selectedItems[activeIndex]
3638
3764
  }), environment.document);
3639
3765
  }
@@ -3642,7 +3768,7 @@ function useMultipleSelection(userProps) {
3642
3768
  // eslint-disable-next-line react-hooks/exhaustive-deps
3643
3769
  }, [selectedItems.length]);
3644
3770
  // Sets focus on active item.
3645
- react.useEffect(function () {
3771
+ react.useEffect(() => {
3646
3772
  if (isInitialMountRef.current) {
3647
3773
  return;
3648
3774
  }
@@ -3654,167 +3780,178 @@ function useMultipleSelection(userProps) {
3654
3780
  }, [activeIndex]);
3655
3781
  useControlPropsValidator({
3656
3782
  isInitialMount: isInitialMountRef.current,
3657
- props: props,
3658
- state: state
3783
+ props,
3784
+ state
3659
3785
  });
3660
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3786
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
3661
3787
  // Make initial ref false.
3662
- react.useEffect(function () {
3788
+ react.useEffect(() => {
3663
3789
  isInitialMountRef.current = false;
3664
- return function () {
3790
+ return () => {
3665
3791
  isInitialMountRef.current = true;
3666
3792
  };
3667
3793
  }, []);
3668
3794
 
3669
3795
  // Event handler functions.
3670
- var selectedItemKeyDownHandlers = react.useMemo(function () {
3671
- var _ref;
3672
- return _ref = {}, _ref[keyNavigationPrevious] = function () {
3796
+ const selectedItemKeyDownHandlers = react.useMemo(() => ({
3797
+ [keyNavigationPrevious]() {
3673
3798
  dispatch({
3674
3799
  type: SelectedItemKeyDownNavigationPrevious
3675
3800
  });
3676
- }, _ref[keyNavigationNext] = function () {
3801
+ },
3802
+ [keyNavigationNext]() {
3677
3803
  dispatch({
3678
3804
  type: SelectedItemKeyDownNavigationNext
3679
3805
  });
3680
- }, _ref.Delete = function Delete() {
3806
+ },
3807
+ Delete() {
3681
3808
  dispatch({
3682
3809
  type: SelectedItemKeyDownDelete
3683
3810
  });
3684
- }, _ref.Backspace = function Backspace() {
3811
+ },
3812
+ Backspace() {
3685
3813
  dispatch({
3686
3814
  type: SelectedItemKeyDownBackspace
3687
3815
  });
3688
- }, _ref;
3689
- }, [dispatch, keyNavigationNext, keyNavigationPrevious]);
3690
- var dropdownKeyDownHandlers = react.useMemo(function () {
3691
- var _ref2;
3692
- return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
3816
+ }
3817
+ }), [dispatch, keyNavigationNext, keyNavigationPrevious]);
3818
+ const dropdownKeyDownHandlers = react.useMemo(() => ({
3819
+ [keyNavigationPrevious](event) {
3693
3820
  if (isKeyDownOperationPermitted(event)) {
3694
3821
  dispatch({
3695
3822
  type: DropdownKeyDownNavigationPrevious
3696
3823
  });
3697
3824
  }
3698
- }, _ref2.Backspace = function Backspace(event) {
3825
+ },
3826
+ Backspace(event) {
3699
3827
  if (isKeyDownOperationPermitted(event)) {
3700
3828
  dispatch({
3701
3829
  type: DropdownKeyDownBackspace
3702
3830
  });
3703
3831
  }
3704
- }, _ref2;
3705
- }, [dispatch, keyNavigationPrevious]);
3832
+ }
3833
+ }), [dispatch, keyNavigationPrevious]);
3706
3834
 
3707
3835
  // Getter props.
3708
- var getSelectedItemProps = react.useCallback(function (_temp) {
3709
- var _extends2;
3710
- var _ref3 = _temp === void 0 ? {} : _temp,
3711
- _ref3$refKey = _ref3.refKey,
3712
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3713
- ref = _ref3.ref,
3714
- onClick = _ref3.onClick,
3715
- onKeyDown = _ref3.onKeyDown,
3716
- selectedItem = _ref3.selectedItem,
3717
- index = _ref3.index,
3718
- rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded);
3719
- var latestState = latest.current.state;
3720
- var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
3836
+ const getSelectedItemProps = react.useCallback(function (_temp) {
3837
+ let {
3838
+ refKey = 'ref',
3839
+ ref,
3840
+ onClick,
3841
+ onKeyDown,
3842
+ selectedItem,
3843
+ index,
3844
+ ...rest
3845
+ } = _temp === void 0 ? {} : _temp;
3846
+ const {
3847
+ state: latestState
3848
+ } = latest.current;
3849
+ const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
3721
3850
  if (itemIndex < 0) {
3722
3851
  throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
3723
3852
  }
3724
- var selectedItemHandleClick = function selectedItemHandleClick() {
3853
+ const selectedItemHandleClick = () => {
3725
3854
  dispatch({
3726
3855
  type: SelectedItemClick,
3727
- index: index
3856
+ index
3728
3857
  });
3729
3858
  };
3730
- var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
3731
- var key = normalizeArrowKey(event);
3859
+ const selectedItemHandleKeyDown = event => {
3860
+ const key = normalizeArrowKey(event);
3732
3861
  if (key && selectedItemKeyDownHandlers[key]) {
3733
3862
  selectedItemKeyDownHandlers[key](event);
3734
3863
  }
3735
3864
  };
3736
- return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
3737
- if (selectedItemNode) {
3738
- selectedItemRefs.current.push(selectedItemNode);
3739
- }
3740
- }), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
3865
+ return {
3866
+ [refKey]: handleRefs(ref, selectedItemNode => {
3867
+ if (selectedItemNode) {
3868
+ selectedItemRefs.current.push(selectedItemNode);
3869
+ }
3870
+ }),
3871
+ tabIndex: index === latestState.activeIndex ? 0 : -1,
3872
+ onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
3873
+ onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
3874
+ ...rest
3875
+ };
3741
3876
  }, [dispatch, latest, selectedItemKeyDownHandlers]);
3742
- var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
3743
- var _extends3;
3744
- var _ref4 = _temp2 === void 0 ? {} : _temp2,
3745
- _ref4$refKey = _ref4.refKey,
3746
- refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
3747
- ref = _ref4.ref,
3748
- onKeyDown = _ref4.onKeyDown,
3749
- onClick = _ref4.onClick,
3750
- _ref4$preventKeyActio = _ref4.preventKeyAction,
3751
- preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
3752
- rest = _objectWithoutPropertiesLoose__default["default"](_ref4, _excluded2);
3753
- var _ref5 = _temp3 === void 0 ? {} : _temp3,
3754
- _ref5$suppressRefErro = _ref5.suppressRefError,
3755
- suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
3877
+ const getDropdownProps = react.useCallback(function (_temp2, _temp3) {
3878
+ let {
3879
+ refKey = 'ref',
3880
+ ref,
3881
+ onKeyDown,
3882
+ onClick,
3883
+ preventKeyAction = false,
3884
+ ...rest
3885
+ } = _temp2 === void 0 ? {} : _temp2;
3886
+ let {
3887
+ suppressRefError = false
3888
+ } = _temp3 === void 0 ? {} : _temp3;
3756
3889
  setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
3757
- var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
3758
- var key = normalizeArrowKey(event);
3890
+ const dropdownHandleKeyDown = event => {
3891
+ const key = normalizeArrowKey(event);
3759
3892
  if (key && dropdownKeyDownHandlers[key]) {
3760
3893
  dropdownKeyDownHandlers[key](event);
3761
3894
  }
3762
3895
  };
3763
- var dropdownHandleClick = function dropdownHandleClick() {
3896
+ const dropdownHandleClick = () => {
3764
3897
  dispatch({
3765
3898
  type: DropdownClick
3766
3899
  });
3767
3900
  };
3768
- return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
3769
- if (dropdownNode) {
3770
- dropdownRef.current = dropdownNode;
3771
- }
3772
- }), _extends3), !preventKeyAction && {
3773
- onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
3774
- onClick: callAllEventHandlers(onClick, dropdownHandleClick)
3775
- }, rest);
3901
+ return {
3902
+ [refKey]: handleRefs(ref, dropdownNode => {
3903
+ if (dropdownNode) {
3904
+ dropdownRef.current = dropdownNode;
3905
+ }
3906
+ }),
3907
+ ...(!preventKeyAction && {
3908
+ onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
3909
+ onClick: callAllEventHandlers(onClick, dropdownHandleClick)
3910
+ }),
3911
+ ...rest
3912
+ };
3776
3913
  }, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]);
3777
3914
 
3778
3915
  // returns
3779
- var addSelectedItem = react.useCallback(function (selectedItem) {
3916
+ const addSelectedItem = react.useCallback(selectedItem => {
3780
3917
  dispatch({
3781
3918
  type: FunctionAddSelectedItem,
3782
- selectedItem: selectedItem
3919
+ selectedItem
3783
3920
  });
3784
3921
  }, [dispatch]);
3785
- var removeSelectedItem = react.useCallback(function (selectedItem) {
3922
+ const removeSelectedItem = react.useCallback(selectedItem => {
3786
3923
  dispatch({
3787
3924
  type: FunctionRemoveSelectedItem,
3788
- selectedItem: selectedItem
3925
+ selectedItem
3789
3926
  });
3790
3927
  }, [dispatch]);
3791
- var setSelectedItems = react.useCallback(function (newSelectedItems) {
3928
+ const setSelectedItems = react.useCallback(newSelectedItems => {
3792
3929
  dispatch({
3793
3930
  type: FunctionSetSelectedItems,
3794
3931
  selectedItems: newSelectedItems
3795
3932
  });
3796
3933
  }, [dispatch]);
3797
- var setActiveIndex = react.useCallback(function (newActiveIndex) {
3934
+ const setActiveIndex = react.useCallback(newActiveIndex => {
3798
3935
  dispatch({
3799
3936
  type: FunctionSetActiveIndex,
3800
3937
  activeIndex: newActiveIndex
3801
3938
  });
3802
3939
  }, [dispatch]);
3803
- var reset = react.useCallback(function () {
3940
+ const reset = react.useCallback(() => {
3804
3941
  dispatch({
3805
3942
  type: FunctionReset
3806
3943
  });
3807
3944
  }, [dispatch]);
3808
3945
  return {
3809
- getSelectedItemProps: getSelectedItemProps,
3810
- getDropdownProps: getDropdownProps,
3811
- addSelectedItem: addSelectedItem,
3812
- removeSelectedItem: removeSelectedItem,
3813
- setSelectedItems: setSelectedItems,
3814
- setActiveIndex: setActiveIndex,
3815
- reset: reset,
3816
- selectedItems: selectedItems,
3817
- activeIndex: activeIndex
3946
+ getSelectedItemProps,
3947
+ getDropdownProps,
3948
+ addSelectedItem,
3949
+ removeSelectedItem,
3950
+ setSelectedItems,
3951
+ setActiveIndex,
3952
+ reset,
3953
+ selectedItems,
3954
+ activeIndex
3818
3955
  };
3819
3956
  }
3820
3957