downshift 6.1.7 → 6.1.8

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,10 +2,6 @@
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');
@@ -14,14 +10,10 @@ 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
14
  var computeScrollIntoView__default = /*#__PURE__*/_interopDefaultLegacy(computeScrollIntoView);
23
15
 
24
- var idCounter = 0;
16
+ let idCounter = 0;
25
17
  /**
26
18
  * Accepts a parameter and returns it if it's a function
27
19
  * or a noop function if it's not. This allows us to
@@ -48,15 +40,17 @@ function scrollIntoView(node, menuNode) {
48
40
  return;
49
41
  }
50
42
 
51
- var actions = computeScrollIntoView__default['default'](node, {
43
+ const actions = computeScrollIntoView__default["default"](node, {
52
44
  boundary: menuNode,
53
45
  block: 'nearest',
54
46
  scrollMode: 'if-needed'
55
47
  });
56
- actions.forEach(function (_ref) {
57
- var el = _ref.el,
58
- top = _ref.top,
59
- left = _ref.left;
48
+ actions.forEach(_ref => {
49
+ let {
50
+ el,
51
+ top,
52
+ left
53
+ } = _ref;
60
54
  el.scrollTop = top;
61
55
  el.scrollLeft = left;
62
56
  });
@@ -70,7 +64,7 @@ function scrollIntoView(node, menuNode) {
70
64
 
71
65
 
72
66
  function isOrContainsNode(parent, child, environment) {
73
- var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
67
+ const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
74
68
  return result;
75
69
  }
76
70
  /**
@@ -84,7 +78,7 @@ function isOrContainsNode(parent, child, environment) {
84
78
 
85
79
 
86
80
  function debounce(fn, time) {
87
- var timeoutId;
81
+ let timeoutId;
88
82
 
89
83
  function cancel() {
90
84
  if (timeoutId) {
@@ -98,9 +92,9 @@ function debounce(fn, time) {
98
92
  }
99
93
 
100
94
  cancel();
101
- timeoutId = setTimeout(function () {
95
+ timeoutId = setTimeout(() => {
102
96
  timeoutId = null;
103
- fn.apply(void 0, args);
97
+ fn(...args);
104
98
  }, time);
105
99
  }
106
100
 
@@ -126,9 +120,9 @@ function callAllEventHandlers() {
126
120
  args[_key3 - 1] = arguments[_key3];
127
121
  }
128
122
 
129
- return fns.some(function (fn) {
123
+ return fns.some(fn => {
130
124
  if (fn) {
131
- fn.apply(void 0, [event].concat(args));
125
+ fn(event, ...args);
132
126
  }
133
127
 
134
128
  return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
@@ -141,8 +135,8 @@ function handleRefs() {
141
135
  refs[_key4] = arguments[_key4];
142
136
  }
143
137
 
144
- return function (node) {
145
- refs.forEach(function (ref) {
138
+ return node => {
139
+ refs.forEach(ref => {
146
140
  if (typeof ref === 'function') {
147
141
  ref(node);
148
142
  } else if (ref) {
@@ -179,9 +173,11 @@ function resetIdCounter() {
179
173
 
180
174
 
181
175
  function getA11yStatusMessage$1(_ref2) {
182
- var isOpen = _ref2.isOpen,
183
- resultCount = _ref2.resultCount,
184
- previousResultCount = _ref2.previousResultCount;
176
+ let {
177
+ isOpen,
178
+ resultCount,
179
+ previousResultCount
180
+ } = _ref2;
185
181
 
186
182
  if (!isOpen) {
187
183
  return '';
@@ -251,7 +247,7 @@ function requiredProp(fnName, propName) {
251
247
  console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
252
248
  }
253
249
 
254
- var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
250
+ const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
255
251
  /**
256
252
  * @param {Object} state the state object
257
253
  * @return {Object} state that is relevant to downshift
@@ -262,8 +258,8 @@ function pickState(state) {
262
258
  state = {};
263
259
  }
264
260
 
265
- var result = {};
266
- stateKeys.forEach(function (k) {
261
+ const result = {};
262
+ stateKeys.forEach(k => {
267
263
  if (state.hasOwnProperty(k)) {
268
264
  result[k] = state[k];
269
265
  }
@@ -284,7 +280,7 @@ function pickState(state) {
284
280
 
285
281
 
286
282
  function getState(state, props) {
287
- return Object.keys(state).reduce(function (prevState, key) {
283
+ return Object.keys(state).reduce((prevState, key) => {
288
284
  prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
289
285
  return prevState;
290
286
  }, {});
@@ -311,8 +307,10 @@ function isControlledProp(props, key) {
311
307
 
312
308
 
313
309
  function normalizeArrowKey(event) {
314
- var key = event.key,
315
- keyCode = event.keyCode;
310
+ const {
311
+ key,
312
+ keyCode
313
+ } = event;
316
314
  /* istanbul ignore next (ie) */
317
315
 
318
316
  if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
@@ -353,13 +351,13 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
353
351
  return -1;
354
352
  }
355
353
 
356
- var itemsLastIndex = itemCount - 1;
354
+ const itemsLastIndex = itemCount - 1;
357
355
 
358
356
  if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
359
357
  baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
360
358
  }
361
359
 
362
- var newIndex = baseIndex + moveAmount;
360
+ let newIndex = baseIndex + moveAmount;
363
361
 
364
362
  if (newIndex < 0) {
365
363
  newIndex = circular ? itemsLastIndex : 0;
@@ -367,7 +365,7 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
367
365
  newIndex = circular ? 0 : itemsLastIndex;
368
366
  }
369
367
 
370
- var nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
368
+ const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
371
369
 
372
370
  if (nonDisabledNewIndex === -1) {
373
371
  return baseIndex >= itemCount ? -1 : baseIndex;
@@ -388,22 +386,22 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
388
386
 
389
387
 
390
388
  function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
391
- var currentElementNode = getItemNodeFromIndex(baseIndex);
389
+ const currentElementNode = getItemNodeFromIndex(baseIndex);
392
390
 
393
391
  if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
394
392
  return baseIndex;
395
393
  }
396
394
 
397
395
  if (moveAmount > 0) {
398
- for (var index = baseIndex + 1; index < itemCount; index++) {
396
+ for (let index = baseIndex + 1; index < itemCount; index++) {
399
397
  if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
400
398
  return index;
401
399
  }
402
400
  }
403
401
  } else {
404
- for (var _index = baseIndex - 1; _index >= 0; _index--) {
405
- if (!getItemNodeFromIndex(_index).hasAttribute('disabled')) {
406
- return _index;
402
+ for (let index = baseIndex - 1; index >= 0; index--) {
403
+ if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
404
+ return index;
407
405
  }
408
406
  }
409
407
  }
@@ -431,19 +429,17 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
431
429
  checkActiveElement = true;
432
430
  }
433
431
 
434
- return downshiftElements.some(function (contextNode) {
435
- return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
436
- });
432
+ return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
437
433
  } // eslint-disable-next-line import/no-mutable-exports
438
434
 
439
435
 
440
- var validateControlledUnchanged = noop;
436
+ let validateControlledUnchanged = noop;
441
437
  /* istanbul ignore next */
442
438
 
443
439
  if (process.env.NODE_ENV !== 'production') {
444
- validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
445
- 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";
446
- Object.keys(state).forEach(function (propKey) {
440
+ validateControlledUnchanged = (state, prevProps, nextProps) => {
441
+ 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";
442
+ Object.keys(state).forEach(propKey => {
447
443
  if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
448
444
  // eslint-disable-next-line no-console
449
445
  console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
@@ -455,7 +451,7 @@ if (process.env.NODE_ENV !== 'production') {
455
451
  };
456
452
  }
457
453
 
458
- var cleanupStatus = debounce(function (documentProp) {
454
+ const cleanupStatus = debounce(documentProp => {
459
455
  getStatusDiv(documentProp).textContent = '';
460
456
  }, 500);
461
457
  /**
@@ -464,7 +460,7 @@ var cleanupStatus = debounce(function (documentProp) {
464
460
  */
465
461
 
466
462
  function setStatus(status, documentProp) {
467
- var div = getStatusDiv(documentProp);
463
+ const div = getStatusDiv(documentProp);
468
464
 
469
465
  if (!status) {
470
466
  return;
@@ -485,7 +481,7 @@ function getStatusDiv(documentProp) {
485
481
  documentProp = document;
486
482
  }
487
483
 
488
- var statusDiv = documentProp.getElementById('a11y-status-message');
484
+ let statusDiv = documentProp.getElementById('a11y-status-message');
489
485
 
490
486
  if (statusDiv) {
491
487
  return statusDiv;
@@ -510,23 +506,23 @@ function getStatusDiv(documentProp) {
510
506
  return statusDiv;
511
507
  }
512
508
 
513
- var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
514
- var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
515
- var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
516
- var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
517
- var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
518
- var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
519
- var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
520
- var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
521
- var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
522
- var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
523
- var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
524
- var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
525
- var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
526
- var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
527
- var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
528
- var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
529
- var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
509
+ const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
510
+ const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
511
+ const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
512
+ const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
513
+ const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
514
+ const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
515
+ const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
516
+ const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
517
+ const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
518
+ const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
519
+ const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
520
+ const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
521
+ const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
522
+ const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
523
+ const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
524
+ const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
525
+ const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
530
526
 
531
527
  var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
532
528
  __proto__: null,
@@ -549,58 +545,45 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
549
545
  touchEnd: touchEnd
550
546
  });
551
547
 
552
- var _excluded$4 = ["refKey", "ref"],
553
- _excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
554
- _excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
555
- _excluded4$1 = ["refKey", "ref"],
556
- _excluded5$1 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
548
+ /* eslint camelcase:0 */
557
549
 
558
- var Downshift = /*#__PURE__*/function () {
559
- var Downshift = /*#__PURE__*/function (_Component) {
560
- _inheritsLoose__default['default'](Downshift, _Component);
561
-
562
- function Downshift(_props) {
550
+ const Downshift = /*#__PURE__*/(() => {
551
+ class Downshift extends react.Component {
552
+ constructor(_props) {
563
553
  var _this;
564
554
 
565
- _this = _Component.call(this, _props) || this; // fancy destructuring + defaults + aliases
566
- // this basically says each value of state should either be set to
567
- // the initial value or the default value if the initial value is not provided
568
-
569
- _this.id = _this.props.id || "downshift-" + generateId();
570
- _this.menuId = _this.props.menuId || _this.id + "-menu";
571
- _this.labelId = _this.props.labelId || _this.id + "-label";
572
- _this.inputId = _this.props.inputId || _this.id + "-input";
555
+ super(_props);
556
+ _this = this;
557
+ this.id = this.props.id || "downshift-" + generateId();
558
+ this.menuId = this.props.menuId || this.id + "-menu";
559
+ this.labelId = this.props.labelId || this.id + "-label";
560
+ this.inputId = this.props.inputId || this.id + "-input";
573
561
 
574
- _this.getItemId = _this.props.getItemId || function (index) {
575
- return _this.id + "-item-" + index;
576
- };
562
+ this.getItemId = this.props.getItemId || (index => this.id + "-item-" + index);
577
563
 
578
- _this.input = null;
579
- _this.items = [];
580
- _this.itemCount = null;
581
- _this.previousResultCount = 0;
582
- _this.timeoutIds = [];
564
+ this.input = null;
565
+ this.items = [];
566
+ this.itemCount = null;
567
+ this.previousResultCount = 0;
568
+ this.timeoutIds = [];
583
569
 
584
- _this.internalSetTimeout = function (fn, time) {
585
- var id = setTimeout(function () {
586
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
587
- return i !== id;
588
- });
570
+ this.internalSetTimeout = (fn, time) => {
571
+ const id = setTimeout(() => {
572
+ this.timeoutIds = this.timeoutIds.filter(i => i !== id);
589
573
  fn();
590
574
  }, time);
591
-
592
- _this.timeoutIds.push(id);
575
+ this.timeoutIds.push(id);
593
576
  };
594
577
 
595
- _this.setItemCount = function (count) {
596
- _this.itemCount = count;
578
+ this.setItemCount = count => {
579
+ this.itemCount = count;
597
580
  };
598
581
 
599
- _this.unsetItemCount = function () {
600
- _this.itemCount = null;
582
+ this.unsetItemCount = () => {
583
+ this.itemCount = null;
601
584
  };
602
585
 
603
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
586
+ this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
604
587
  if (highlightedIndex === void 0) {
605
588
  highlightedIndex = _this.props.defaultHighlightedIndex;
606
589
  }
@@ -611,71 +594,72 @@ var Downshift = /*#__PURE__*/function () {
611
594
 
612
595
  otherStateToSet = pickState(otherStateToSet);
613
596
 
614
- _this.internalSetState(_extends__default['default']({
615
- highlightedIndex: highlightedIndex
616
- }, otherStateToSet));
597
+ _this.internalSetState({
598
+ highlightedIndex,
599
+ ...otherStateToSet
600
+ });
617
601
  };
618
602
 
619
- _this.clearSelection = function (cb) {
620
- _this.internalSetState({
603
+ this.clearSelection = cb => {
604
+ this.internalSetState({
621
605
  selectedItem: null,
622
606
  inputValue: '',
623
- highlightedIndex: _this.props.defaultHighlightedIndex,
624
- isOpen: _this.props.defaultIsOpen
607
+ highlightedIndex: this.props.defaultHighlightedIndex,
608
+ isOpen: this.props.defaultIsOpen
625
609
  }, cb);
626
610
  };
627
611
 
628
- _this.selectItem = function (item, otherStateToSet, cb) {
612
+ this.selectItem = (item, otherStateToSet, cb) => {
629
613
  otherStateToSet = pickState(otherStateToSet);
630
-
631
- _this.internalSetState(_extends__default['default']({
632
- isOpen: _this.props.defaultIsOpen,
633
- highlightedIndex: _this.props.defaultHighlightedIndex,
614
+ this.internalSetState({
615
+ isOpen: this.props.defaultIsOpen,
616
+ highlightedIndex: this.props.defaultHighlightedIndex,
634
617
  selectedItem: item,
635
- inputValue: _this.props.itemToString(item)
636
- }, otherStateToSet), cb);
618
+ inputValue: this.props.itemToString(item),
619
+ ...otherStateToSet
620
+ }, cb);
637
621
  };
638
622
 
639
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
640
- var item = _this.items[itemIndex];
623
+ this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
624
+ const item = this.items[itemIndex];
641
625
 
642
626
  if (item == null) {
643
627
  return;
644
628
  }
645
629
 
646
- _this.selectItem(item, otherStateToSet, cb);
630
+ this.selectItem(item, otherStateToSet, cb);
647
631
  };
648
632
 
649
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
650
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
633
+ this.selectHighlightedItem = (otherStateToSet, cb) => {
634
+ return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
651
635
  };
652
636
 
653
- _this.internalSetState = function (stateToSet, cb) {
654
- var isItemSelected, onChangeArg;
655
- var onStateChangeArg = {};
656
- var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
637
+ this.internalSetState = (stateToSet, cb) => {
638
+ let isItemSelected, onChangeArg;
639
+ const onStateChangeArg = {};
640
+ const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
657
641
  // so someone controlling the `inputValue` state gets notified of
658
642
  // the input change as soon as possible. This avoids issues with
659
643
  // preserving the cursor position.
660
644
  // See https://github.com/downshift-js/downshift/issues/217 for more info.
661
645
 
662
646
  if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
663
- _this.props.onInputValueChange(stateToSet.inputValue, _extends__default['default']({}, _this.getStateAndHelpers(), stateToSet));
647
+ this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
648
+ ...stateToSet
649
+ });
664
650
  }
665
651
 
666
- return _this.setState(function (state) {
667
- state = _this.getState(state);
668
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
652
+ return this.setState(state => {
653
+ state = this.getState(state);
654
+ let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
669
655
 
670
- newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
656
+ newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
671
657
  // what was selected before
672
658
  // used to determine if onSelect and onChange callbacks should be called
673
659
 
674
660
  isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
675
661
 
676
- var nextState = {}; // this is just used to tell whether the state changed
677
-
678
- var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
662
+ const nextState = {}; // this is just used to tell whether the state changed
679
663
  // and we're trying to update that state. OR if the selection has changed and we're
680
664
  // trying to update the selection
681
665
 
@@ -684,7 +668,7 @@ var Downshift = /*#__PURE__*/function () {
684
668
  }
685
669
 
686
670
  newStateToSet.type = newStateToSet.type || unknown;
687
- Object.keys(newStateToSet).forEach(function (key) {
671
+ Object.keys(newStateToSet).forEach(key => {
688
672
  // onStateChangeArg should only have the state that is
689
673
  // actually changing
690
674
  if (state[key] !== newStateToSet[key]) {
@@ -701,81 +685,84 @@ var Downshift = /*#__PURE__*/function () {
701
685
  return;
702
686
  }
703
687
 
704
- nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
688
+ newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
705
689
 
706
- if (!isControlledProp(_this.props, key)) {
690
+ if (!isControlledProp(this.props, key)) {
707
691
  nextState[key] = newStateToSet[key];
708
692
  }
709
693
  }); // if stateToSet is a function, then we weren't able to call onInputValueChange
710
694
  // earlier, so we'll call it now that we know what the inputValue state will be.
711
695
 
712
696
  if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
713
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends__default['default']({}, _this.getStateAndHelpers(), newStateToSet));
697
+ this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
698
+ ...newStateToSet
699
+ });
714
700
  }
715
701
 
716
702
  return nextState;
717
- }, function () {
703
+ }, () => {
718
704
  // call the provided callback if it's a function
719
705
  cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
720
706
  // we have relevant information to pass them.
721
707
 
722
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
708
+ const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
723
709
 
724
710
  if (hasMoreStateThanType) {
725
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
711
+ this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
726
712
  }
727
713
 
728
714
  if (isItemSelected) {
729
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
715
+ this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
730
716
  }
731
717
 
732
718
  if (onChangeArg !== undefined) {
733
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
719
+ this.props.onChange(onChangeArg, this.getStateAndHelpers());
734
720
  } // this is currently undocumented and therefore subject to change
735
721
  // We'll try to not break it, but just be warned.
736
722
 
737
723
 
738
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
724
+ this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
739
725
  });
740
726
  };
741
727
 
742
- _this.rootRef = function (node) {
743
- return _this._rootNode = node;
744
- };
745
-
746
- _this.getRootProps = function (_temp, _temp2) {
747
- var _extends2;
748
-
749
- var _ref = _temp === void 0 ? {} : _temp,
750
- _ref$refKey = _ref.refKey,
751
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
752
- ref = _ref.ref,
753
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$4);
754
-
755
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
756
- _ref2$suppressRefErro = _ref2.suppressRefError,
757
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
758
-
728
+ this.rootRef = node => this._rootNode = node;
729
+
730
+ this.getRootProps = function (_temp, _temp2) {
731
+ let {
732
+ refKey = 'ref',
733
+ ref,
734
+ ...rest
735
+ } = _temp === void 0 ? {} : _temp;
736
+ let {
737
+ suppressRefError = false
738
+ } = _temp2 === void 0 ? {} : _temp2;
759
739
  // this is used in the render to know whether the user has called getRootProps.
760
740
  // It uses that to know whether to apply the props automatically
761
741
  _this.getRootProps.called = true;
762
742
  _this.getRootProps.refKey = refKey;
763
743
  _this.getRootProps.suppressRefError = suppressRefError;
764
744
 
765
- var _this$getState = _this.getState(),
766
- isOpen = _this$getState.isOpen;
745
+ const {
746
+ isOpen
747
+ } = _this.getState();
767
748
 
768
- 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);
749
+ return {
750
+ [refKey]: handleRefs(ref, _this.rootRef),
751
+ role: 'combobox',
752
+ 'aria-expanded': isOpen,
753
+ 'aria-haspopup': 'listbox',
754
+ 'aria-owns': isOpen ? _this.menuId : null,
755
+ 'aria-labelledby': _this.labelId,
756
+ ...rest
757
+ };
769
758
  };
770
759
 
771
- _this.keyDownHandlers = {
772
- ArrowDown: function ArrowDown(event) {
773
- var _this2 = this;
774
-
760
+ this.keyDownHandlers = {
761
+ ArrowDown(event) {
775
762
  event.preventDefault();
776
763
 
777
764
  if (this.getState().isOpen) {
778
- var amount = event.shiftKey ? 5 : 1;
765
+ const amount = event.shiftKey ? 5 : 1;
779
766
  this.moveHighlightedIndex(amount, {
780
767
  type: keyDownArrowDown
781
768
  });
@@ -783,31 +770,27 @@ var Downshift = /*#__PURE__*/function () {
783
770
  this.internalSetState({
784
771
  isOpen: true,
785
772
  type: keyDownArrowDown
786
- }, function () {
787
- var itemCount = _this2.getItemCount();
773
+ }, () => {
774
+ const itemCount = this.getItemCount();
788
775
 
789
776
  if (itemCount > 0) {
790
- var _this2$getState = _this2.getState(),
791
- highlightedIndex = _this2$getState.highlightedIndex;
792
-
793
- var nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, function (index) {
794
- return _this2.getItemNodeFromIndex(index);
795
- });
796
-
797
- _this2.setHighlightedIndex(nextHighlightedIndex, {
777
+ const {
778
+ highlightedIndex
779
+ } = this.getState();
780
+ const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
781
+ this.setHighlightedIndex(nextHighlightedIndex, {
798
782
  type: keyDownArrowDown
799
783
  });
800
784
  }
801
785
  });
802
786
  }
803
787
  },
804
- ArrowUp: function ArrowUp(event) {
805
- var _this3 = this;
806
788
 
789
+ ArrowUp(event) {
807
790
  event.preventDefault();
808
791
 
809
792
  if (this.getState().isOpen) {
810
- var amount = event.shiftKey ? -5 : -1;
793
+ const amount = event.shiftKey ? -5 : -1;
811
794
  this.moveHighlightedIndex(amount, {
812
795
  type: keyDownArrowUp
813
796
  });
@@ -815,37 +798,36 @@ var Downshift = /*#__PURE__*/function () {
815
798
  this.internalSetState({
816
799
  isOpen: true,
817
800
  type: keyDownArrowUp
818
- }, function () {
819
- var itemCount = _this3.getItemCount();
801
+ }, () => {
802
+ const itemCount = this.getItemCount();
820
803
 
821
804
  if (itemCount > 0) {
822
- var _this3$getState = _this3.getState(),
823
- highlightedIndex = _this3$getState.highlightedIndex;
824
-
825
- var nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, function (index) {
826
- return _this3.getItemNodeFromIndex(index);
827
- });
828
-
829
- _this3.setHighlightedIndex(nextHighlightedIndex, {
805
+ const {
806
+ highlightedIndex
807
+ } = this.getState();
808
+ const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
809
+ this.setHighlightedIndex(nextHighlightedIndex, {
830
810
  type: keyDownArrowUp
831
811
  });
832
812
  }
833
813
  });
834
814
  }
835
815
  },
836
- Enter: function Enter(event) {
816
+
817
+ Enter(event) {
837
818
  if (event.which === 229) {
838
819
  return;
839
820
  }
840
821
 
841
- var _this$getState2 = this.getState(),
842
- isOpen = _this$getState2.isOpen,
843
- highlightedIndex = _this$getState2.highlightedIndex;
822
+ const {
823
+ isOpen,
824
+ highlightedIndex
825
+ } = this.getState();
844
826
 
845
827
  if (isOpen && highlightedIndex != null) {
846
828
  event.preventDefault();
847
- var item = this.items[highlightedIndex];
848
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
829
+ const item = this.items[highlightedIndex];
830
+ const itemNode = this.getItemNodeFromIndex(highlightedIndex);
849
831
 
850
832
  if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
851
833
  return;
@@ -856,183 +838,191 @@ var Downshift = /*#__PURE__*/function () {
856
838
  });
857
839
  }
858
840
  },
859
- Escape: function Escape(event) {
841
+
842
+ Escape(event) {
860
843
  event.preventDefault();
861
- this.reset(_extends__default['default']({
862
- type: keyDownEscape
863
- }, !this.state.isOpen && {
864
- selectedItem: null,
865
- inputValue: ''
866
- }));
844
+ this.reset({
845
+ type: keyDownEscape,
846
+ ...(!this.state.isOpen && {
847
+ selectedItem: null,
848
+ inputValue: ''
849
+ })
850
+ });
867
851
  }
852
+
868
853
  };
869
- _this.buttonKeyDownHandlers = _extends__default['default']({}, _this.keyDownHandlers, {
870
- ' ': function _(event) {
854
+ this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
855
+
856
+ ' '(event) {
871
857
  event.preventDefault();
872
858
  this.toggleMenu({
873
859
  type: keyDownSpaceButton
874
860
  });
875
861
  }
876
- });
877
- _this.inputKeyDownHandlers = _extends__default['default']({}, _this.keyDownHandlers, {
878
- Home: function Home(event) {
879
- var _this4 = this;
880
862
 
881
- var _this$getState3 = this.getState(),
882
- isOpen = _this$getState3.isOpen;
863
+ };
864
+ this.inputKeyDownHandlers = { ...this.keyDownHandlers,
865
+
866
+ Home(event) {
867
+ const {
868
+ isOpen
869
+ } = this.getState();
883
870
 
884
871
  if (!isOpen) {
885
872
  return;
886
873
  }
887
874
 
888
875
  event.preventDefault();
889
- var itemCount = this.getItemCount();
876
+ const itemCount = this.getItemCount();
890
877
 
891
878
  if (itemCount <= 0 || !isOpen) {
892
879
  return;
893
880
  } // get next non-disabled starting downwards from 0 if that's disabled.
894
881
 
895
882
 
896
- var newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, function (index) {
897
- return _this4.getItemNodeFromIndex(index);
898
- }, false);
883
+ const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
899
884
  this.setHighlightedIndex(newHighlightedIndex, {
900
885
  type: keyDownHome
901
886
  });
902
887
  },
903
- End: function End(event) {
904
- var _this5 = this;
905
888
 
906
- var _this$getState4 = this.getState(),
907
- isOpen = _this$getState4.isOpen;
889
+ End(event) {
890
+ const {
891
+ isOpen
892
+ } = this.getState();
908
893
 
909
894
  if (!isOpen) {
910
895
  return;
911
896
  }
912
897
 
913
898
  event.preventDefault();
914
- var itemCount = this.getItemCount();
899
+ const itemCount = this.getItemCount();
915
900
 
916
901
  if (itemCount <= 0 || !isOpen) {
917
902
  return;
918
903
  } // get next non-disabled starting upwards from last index if that's disabled.
919
904
 
920
905
 
921
- var newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, function (index) {
922
- return _this5.getItemNodeFromIndex(index);
923
- }, false);
906
+ const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
924
907
  this.setHighlightedIndex(newHighlightedIndex, {
925
908
  type: keyDownEnd
926
909
  });
927
910
  }
928
- });
929
911
 
930
- _this.getToggleButtonProps = function (_temp3) {
931
- var _ref3 = _temp3 === void 0 ? {} : _temp3;
932
- _ref3.onClick;
933
- var onPress = _ref3.onPress;
934
- _ref3.onKeyDown;
935
- _ref3.onKeyUp;
936
- _ref3.onBlur;
937
- var rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$3);
938
-
939
- var _this$getState5 = _this.getState(),
940
- isOpen = _this$getState5.isOpen;
912
+ };
941
913
 
942
- var enabledEventHandlers = /* istanbul ignore next (react-native) */
914
+ this.getToggleButtonProps = function (_temp3) {
915
+ let {
916
+ onClick,
917
+ onPress,
918
+ onKeyDown,
919
+ onKeyUp,
920
+ onBlur,
921
+ ...rest
922
+ } = _temp3 === void 0 ? {} : _temp3;
923
+
924
+ const {
925
+ isOpen
926
+ } = _this.getState();
927
+
928
+ const enabledEventHandlers = /* istanbul ignore next (react-native) */
943
929
  {
944
930
  onPress: callAllEventHandlers(onPress, _this.buttonHandleClick)
945
931
  } ;
946
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
947
- return _extends__default['default']({
932
+ const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
933
+ return {
948
934
  type: 'button',
949
935
  role: 'button',
950
936
  'aria-label': isOpen ? 'close menu' : 'open menu',
951
937
  'aria-haspopup': true,
952
- 'data-toggle': true
953
- }, eventHandlers, rest);
938
+ 'data-toggle': true,
939
+ ...eventHandlers,
940
+ ...rest
941
+ };
954
942
  };
955
943
 
956
- _this.buttonHandleKeyUp = function (event) {
944
+ this.buttonHandleKeyUp = event => {
957
945
  // Prevent click event from emitting in Firefox
958
946
  event.preventDefault();
959
947
  };
960
948
 
961
- _this.buttonHandleKeyDown = function (event) {
962
- var key = normalizeArrowKey(event);
949
+ this.buttonHandleKeyDown = event => {
950
+ const key = normalizeArrowKey(event);
963
951
 
964
- if (_this.buttonKeyDownHandlers[key]) {
965
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized__default['default'](_this), event);
952
+ if (this.buttonKeyDownHandlers[key]) {
953
+ this.buttonKeyDownHandlers[key].call(this, event);
966
954
  }
967
955
  };
968
956
 
969
- _this.buttonHandleClick = function (event) {
957
+ this.buttonHandleClick = event => {
970
958
  event.preventDefault(); // handle odd case for Safari and Firefox which
971
959
  // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
972
960
  // when building for production and should therefore have no impact on production code.
973
961
 
974
962
 
975
963
  if (process.env.NODE_ENV === 'test') {
976
- _this.toggleMenu({
964
+ this.toggleMenu({
977
965
  type: clickButton
978
966
  });
979
967
  } else {
980
968
  // Ensure that toggle of menu occurs after the potential blur event in iOS
981
- _this.internalSetTimeout(function () {
982
- return _this.toggleMenu({
983
- type: clickButton
984
- });
985
- });
969
+ this.internalSetTimeout(() => this.toggleMenu({
970
+ type: clickButton
971
+ }));
986
972
  }
987
973
  };
988
974
 
989
- _this.buttonHandleBlur = function (event) {
990
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
975
+ this.buttonHandleBlur = event => {
976
+ const blurTarget = event.target; // Save blur target for comparison with activeElement later
991
977
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
992
978
 
993
- _this.internalSetTimeout(function () {
994
- 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)
979
+ this.internalSetTimeout(() => {
980
+ 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)
995
981
  ) {
996
- _this.reset({
982
+ this.reset({
997
983
  type: blurButton
998
984
  });
999
985
  }
1000
986
  });
1001
987
  };
1002
988
 
1003
- _this.getLabelProps = function (props) {
1004
- return _extends__default['default']({
1005
- htmlFor: _this.inputId,
1006
- id: _this.labelId
1007
- }, props);
989
+ this.getLabelProps = props => {
990
+ return {
991
+ htmlFor: this.inputId,
992
+ id: this.labelId,
993
+ ...props
994
+ };
1008
995
  };
1009
996
 
1010
- _this.getInputProps = function (_temp4) {
1011
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
1012
- onKeyDown = _ref4.onKeyDown,
1013
- onBlur = _ref4.onBlur,
1014
- onChange = _ref4.onChange,
1015
- onInput = _ref4.onInput,
1016
- onChangeText = _ref4.onChangeText,
1017
- rest = _objectWithoutPropertiesLoose__default['default'](_ref4, _excluded3$2);
1018
-
1019
- var onChangeKey;
1020
- var eventHandlers = {};
997
+ this.getInputProps = function (_temp4) {
998
+ let {
999
+ onKeyDown,
1000
+ onBlur,
1001
+ onChange,
1002
+ onInput,
1003
+ onChangeText,
1004
+ ...rest
1005
+ } = _temp4 === void 0 ? {} : _temp4;
1006
+ let onChangeKey;
1007
+ let eventHandlers = {};
1021
1008
  /* istanbul ignore next (preact) */
1022
1009
 
1023
1010
  {
1024
1011
  onChangeKey = 'onChange';
1025
1012
  }
1026
1013
 
1027
- var _this$getState6 = _this.getState(),
1028
- inputValue = _this$getState6.inputValue,
1029
- isOpen = _this$getState6.isOpen,
1030
- highlightedIndex = _this$getState6.highlightedIndex;
1014
+ const {
1015
+ inputValue,
1016
+ isOpen,
1017
+ highlightedIndex
1018
+ } = _this.getState();
1031
1019
 
1032
1020
  if (!rest.disabled) {
1033
- var _eventHandlers;
1034
-
1035
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
1021
+ eventHandlers = {
1022
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
1023
+ onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
1024
+ onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
1025
+ };
1036
1026
  }
1037
1027
  /* istanbul ignore if (react-native) */
1038
1028
 
@@ -1040,18 +1030,16 @@ var Downshift = /*#__PURE__*/function () {
1040
1030
  {
1041
1031
  eventHandlers = {
1042
1032
  onChange: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
1043
- onChangeText: callAllEventHandlers(onChangeText, onInput, function (text) {
1044
- return _this.inputHandleChange({
1045
- nativeEvent: {
1046
- text: text
1047
- }
1048
- });
1049
- }),
1033
+ onChangeText: callAllEventHandlers(onChangeText, onInput, text => _this.inputHandleChange({
1034
+ nativeEvent: {
1035
+ text
1036
+ }
1037
+ })),
1050
1038
  onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
1051
1039
  };
1052
1040
  }
1053
1041
 
1054
- return _extends__default['default']({
1042
+ return {
1055
1043
  'aria-autocomplete': 'list',
1056
1044
  'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
1057
1045
  'aria-controls': isOpen ? _this.menuId : null,
@@ -1060,78 +1048,80 @@ var Downshift = /*#__PURE__*/function () {
1060
1048
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
1061
1049
  autoComplete: 'off',
1062
1050
  value: inputValue,
1063
- id: _this.inputId
1064
- }, eventHandlers, rest);
1051
+ id: _this.inputId,
1052
+ ...eventHandlers,
1053
+ ...rest
1054
+ };
1065
1055
  };
1066
1056
 
1067
- _this.inputHandleKeyDown = function (event) {
1068
- var key = normalizeArrowKey(event);
1057
+ this.inputHandleKeyDown = event => {
1058
+ const key = normalizeArrowKey(event);
1069
1059
 
1070
- if (key && _this.inputKeyDownHandlers[key]) {
1071
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized__default['default'](_this), event);
1060
+ if (key && this.inputKeyDownHandlers[key]) {
1061
+ this.inputKeyDownHandlers[key].call(this, event);
1072
1062
  }
1073
1063
  };
1074
1064
 
1075
- _this.inputHandleChange = function (event) {
1076
- _this.internalSetState({
1065
+ this.inputHandleChange = event => {
1066
+ this.internalSetState({
1077
1067
  type: changeInput,
1078
1068
  isOpen: true,
1079
1069
  inputValue: /* istanbul ignore next (react-native) */
1080
1070
  event.nativeEvent.text ,
1081
- highlightedIndex: _this.props.defaultHighlightedIndex
1071
+ highlightedIndex: this.props.defaultHighlightedIndex
1082
1072
  });
1083
1073
  };
1084
1074
 
1085
- _this.inputHandleBlur = function () {
1075
+ this.inputHandleBlur = () => {
1086
1076
  // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
1087
- _this.internalSetTimeout(function () {
1088
- 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);
1077
+ this.internalSetTimeout(() => {
1078
+ 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);
1089
1079
 
1090
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
1091
- _this.reset({
1080
+ if (!this.isMouseDown && !downshiftButtonIsActive) {
1081
+ this.reset({
1092
1082
  type: blurInput
1093
1083
  });
1094
1084
  }
1095
1085
  });
1096
1086
  };
1097
1087
 
1098
- _this.menuRef = function (node) {
1099
- _this._menuNode = node;
1088
+ this.menuRef = node => {
1089
+ this._menuNode = node;
1100
1090
  };
1101
1091
 
1102
- _this.getMenuProps = function (_temp5, _temp6) {
1103
- var _extends3;
1104
-
1105
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
1106
- _ref5$refKey = _ref5.refKey,
1107
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
1108
- ref = _ref5.ref,
1109
- props = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded4$1);
1110
-
1111
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
1112
- _ref6$suppressRefErro = _ref6.suppressRefError,
1113
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
1114
-
1092
+ this.getMenuProps = function (_temp5, _temp6) {
1093
+ let {
1094
+ refKey = 'ref',
1095
+ ref,
1096
+ ...props
1097
+ } = _temp5 === void 0 ? {} : _temp5;
1098
+ let {
1099
+ suppressRefError = false
1100
+ } = _temp6 === void 0 ? {} : _temp6;
1115
1101
  _this.getMenuProps.called = true;
1116
1102
  _this.getMenuProps.refKey = refKey;
1117
1103
  _this.getMenuProps.suppressRefError = suppressRefError;
1118
- 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);
1104
+ return {
1105
+ [refKey]: handleRefs(ref, _this.menuRef),
1106
+ role: 'listbox',
1107
+ 'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
1108
+ id: _this.menuId,
1109
+ ...props
1110
+ };
1119
1111
  };
1120
1112
 
1121
- _this.getItemProps = function (_temp7) {
1122
- var _enabledEventHandlers;
1123
-
1124
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
1125
- onMouseMove = _ref7.onMouseMove,
1126
- onMouseDown = _ref7.onMouseDown;
1127
- _ref7.onClick;
1128
- var onPress = _ref7.onPress,
1129
- index = _ref7.index,
1130
- _ref7$item = _ref7.item,
1131
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
1132
- /* istanbul ignore next */
1133
- undefined : requiredProp('getItemProps', 'item') : _ref7$item,
1134
- rest = _objectWithoutPropertiesLoose__default['default'](_ref7, _excluded5$1);
1113
+ this.getItemProps = function (_temp7) {
1114
+ let {
1115
+ onMouseMove,
1116
+ onMouseDown,
1117
+ onClick,
1118
+ onPress,
1119
+ index,
1120
+ item = process.env.NODE_ENV === 'production' ?
1121
+ /* istanbul ignore next */
1122
+ undefined : requiredProp('getItemProps', 'item'),
1123
+ ...rest
1124
+ } = _temp7 === void 0 ? {} : _temp7;
1135
1125
 
1136
1126
  if (index === undefined) {
1137
1127
  _this.items.push(item);
@@ -1141,15 +1131,15 @@ var Downshift = /*#__PURE__*/function () {
1141
1131
  _this.items[index] = item;
1142
1132
  }
1143
1133
 
1144
- var onSelectKey = /* istanbul ignore next (react-native) */
1134
+ const onSelectKey = /* istanbul ignore next (react-native) */
1145
1135
  'onPress' ;
1146
- var customClickHandler = /* istanbul ignore next (react-native) */
1136
+ const customClickHandler = /* istanbul ignore next (react-native) */
1147
1137
  onPress ;
1148
- var enabledEventHandlers = (_enabledEventHandlers = {
1138
+ const enabledEventHandlers = {
1149
1139
  // onMouseMove is used over onMouseEnter here. onMouseMove
1150
1140
  // is only triggered on actual mouse movement while onMouseEnter
1151
1141
  // can fire on DOM changes, interrupting keyboard navigation
1152
- onMouseMove: callAllEventHandlers(onMouseMove, function () {
1142
+ onMouseMove: callAllEventHandlers(onMouseMove, () => {
1153
1143
  if (index === _this.getState().highlightedIndex) {
1154
1144
  return;
1155
1145
  }
@@ -1164,72 +1154,81 @@ var Downshift = /*#__PURE__*/function () {
1164
1154
 
1165
1155
  _this.avoidScrolling = true;
1166
1156
 
1167
- _this.internalSetTimeout(function () {
1168
- return _this.avoidScrolling = false;
1169
- }, 250);
1157
+ _this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
1170
1158
  }),
1171
- onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
1159
+ onMouseDown: callAllEventHandlers(onMouseDown, event => {
1172
1160
  // This prevents the activeElement from being changed
1173
1161
  // to the item so it can remain with the current activeElement
1174
1162
  // which is a more common use case.
1175
1163
  event.preventDefault();
1164
+ }),
1165
+ [onSelectKey]: callAllEventHandlers(customClickHandler, () => {
1166
+ _this.selectItemAtIndex(index, {
1167
+ type: clickItem
1168
+ });
1176
1169
  })
1177
- }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
1178
- _this.selectItemAtIndex(index, {
1179
- type: clickItem
1180
- });
1181
- }), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
1170
+ }; // Passing down the onMouseDown handler to prevent redirect
1182
1171
  // of the activeElement if clicking on disabled items
1183
1172
 
1184
- var eventHandlers = rest.disabled ? {
1173
+ const eventHandlers = rest.disabled ? {
1185
1174
  onMouseDown: enabledEventHandlers.onMouseDown
1186
1175
  } : enabledEventHandlers;
1187
- return _extends__default['default']({
1176
+ return {
1188
1177
  id: _this.getItemId(index),
1189
1178
  role: 'option',
1190
- 'aria-selected': _this.getState().highlightedIndex === index
1191
- }, eventHandlers, rest);
1179
+ 'aria-selected': _this.getState().highlightedIndex === index,
1180
+ ...eventHandlers,
1181
+ ...rest
1182
+ };
1192
1183
  };
1193
1184
 
1194
- _this.clearItems = function () {
1195
- _this.items = [];
1185
+ this.clearItems = () => {
1186
+ this.items = [];
1196
1187
  };
1197
1188
 
1198
- _this.reset = function (otherStateToSet, cb) {
1189
+ this.reset = function (otherStateToSet, cb) {
1199
1190
  if (otherStateToSet === void 0) {
1200
1191
  otherStateToSet = {};
1201
1192
  }
1202
1193
 
1203
1194
  otherStateToSet = pickState(otherStateToSet);
1204
1195
 
1205
- _this.internalSetState(function (_ref8) {
1206
- var selectedItem = _ref8.selectedItem;
1207
- return _extends__default['default']({
1196
+ _this.internalSetState(_ref => {
1197
+ let {
1198
+ selectedItem
1199
+ } = _ref;
1200
+ return {
1208
1201
  isOpen: _this.props.defaultIsOpen,
1209
1202
  highlightedIndex: _this.props.defaultHighlightedIndex,
1210
- inputValue: _this.props.itemToString(selectedItem)
1211
- }, otherStateToSet);
1203
+ inputValue: _this.props.itemToString(selectedItem),
1204
+ ...otherStateToSet
1205
+ };
1212
1206
  }, cb);
1213
1207
  };
1214
1208
 
1215
- _this.toggleMenu = function (otherStateToSet, cb) {
1209
+ this.toggleMenu = function (otherStateToSet, cb) {
1216
1210
  if (otherStateToSet === void 0) {
1217
1211
  otherStateToSet = {};
1218
1212
  }
1219
1213
 
1220
1214
  otherStateToSet = pickState(otherStateToSet);
1221
1215
 
1222
- _this.internalSetState(function (_ref9) {
1223
- var isOpen = _ref9.isOpen;
1224
- return _extends__default['default']({
1225
- isOpen: !isOpen
1226
- }, isOpen && {
1227
- highlightedIndex: _this.props.defaultHighlightedIndex
1228
- }, otherStateToSet);
1229
- }, function () {
1230
- var _this$getState7 = _this.getState(),
1231
- isOpen = _this$getState7.isOpen,
1232
- highlightedIndex = _this$getState7.highlightedIndex;
1216
+ _this.internalSetState(_ref2 => {
1217
+ let {
1218
+ isOpen
1219
+ } = _ref2;
1220
+ return {
1221
+ isOpen: !isOpen,
1222
+ ...(isOpen && {
1223
+ highlightedIndex: _this.props.defaultHighlightedIndex
1224
+ }),
1225
+ ...otherStateToSet
1226
+ };
1227
+ }, () => {
1228
+ const {
1229
+ isOpen,
1230
+ highlightedIndex
1231
+ } = _this.getState();
1233
1232
 
1234
1233
  if (isOpen) {
1235
1234
  if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
@@ -1241,70 +1240,63 @@ var Downshift = /*#__PURE__*/function () {
1241
1240
  });
1242
1241
  };
1243
1242
 
1244
- _this.openMenu = function (cb) {
1245
- _this.internalSetState({
1243
+ this.openMenu = cb => {
1244
+ this.internalSetState({
1246
1245
  isOpen: true
1247
1246
  }, cb);
1248
1247
  };
1249
1248
 
1250
- _this.closeMenu = function (cb) {
1251
- _this.internalSetState({
1249
+ this.closeMenu = cb => {
1250
+ this.internalSetState({
1252
1251
  isOpen: false
1253
1252
  }, cb);
1254
1253
  };
1255
1254
 
1256
- _this.updateStatus = debounce(function () {
1257
- var state = _this.getState();
1258
-
1259
- var item = _this.items[state.highlightedIndex];
1260
-
1261
- var resultCount = _this.getItemCount();
1262
-
1263
- var status = _this.props.getA11yStatusMessage(_extends__default['default']({
1264
- itemToString: _this.props.itemToString,
1265
- previousResultCount: _this.previousResultCount,
1266
- resultCount: resultCount,
1267
- highlightedItem: item
1268
- }, state));
1269
-
1270
- _this.previousResultCount = resultCount;
1271
- setStatus(status, _this.props.environment.document);
1255
+ this.updateStatus = debounce(() => {
1256
+ const state = this.getState();
1257
+ const item = this.items[state.highlightedIndex];
1258
+ const resultCount = this.getItemCount();
1259
+ const status = this.props.getA11yStatusMessage({
1260
+ itemToString: this.props.itemToString,
1261
+ previousResultCount: this.previousResultCount,
1262
+ resultCount,
1263
+ highlightedItem: item,
1264
+ ...state
1265
+ });
1266
+ this.previousResultCount = resultCount;
1267
+ setStatus(status, this.props.environment.document);
1272
1268
  }, 200);
1273
-
1274
- var _this$props = _this.props,
1275
- defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1276
- _this$props$initialHi = _this$props.initialHighlightedIndex,
1277
- _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1278
- defaultIsOpen = _this$props.defaultIsOpen,
1279
- _this$props$initialIs = _this$props.initialIsOpen,
1280
- _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1281
- _this$props$initialIn = _this$props.initialInputValue,
1282
- _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1283
- _this$props$initialSe = _this$props.initialSelectedItem,
1284
- _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1285
-
1286
- var _state = _this.getState({
1269
+ // fancy destructuring + defaults + aliases
1270
+ // this basically says each value of state should either be set to
1271
+ // the initial value or the default value if the initial value is not provided
1272
+ const {
1273
+ defaultHighlightedIndex,
1274
+ initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
1275
+ defaultIsOpen,
1276
+ initialIsOpen: _isOpen = defaultIsOpen,
1277
+ initialInputValue: _inputValue = '',
1278
+ initialSelectedItem: _selectedItem = null
1279
+ } = this.props;
1280
+
1281
+ const _state = this.getState({
1287
1282
  highlightedIndex: _highlightedIndex,
1288
1283
  isOpen: _isOpen,
1289
1284
  inputValue: _inputValue,
1290
1285
  selectedItem: _selectedItem
1291
1286
  });
1292
1287
 
1293
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1294
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1288
+ if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
1289
+ _state.inputValue = this.props.itemToString(_state.selectedItem);
1295
1290
  }
1296
1291
 
1297
- _this.state = _state;
1298
- return _this;
1292
+ this.state = _state;
1299
1293
  }
1300
1294
 
1301
- var _proto = Downshift.prototype;
1302
-
1303
1295
  /**
1304
1296
  * Clear all running timeouts
1305
1297
  */
1306
- _proto.internalClearTimeouts = function internalClearTimeouts() {
1307
- this.timeoutIds.forEach(function (id) {
1298
+ internalClearTimeouts() {
1299
+ this.timeoutIds.forEach(id => {
1308
1300
  clearTimeout(id);
1309
1301
  });
1310
1302
  this.timeoutIds = [];
@@ -1318,22 +1310,22 @@ var Downshift = /*#__PURE__*/function () {
1318
1310
  * @param {Object} stateToMerge defaults to this.state
1319
1311
  * @return {Object} the state
1320
1312
  */
1321
- ;
1322
1313
 
1323
- _proto.getState = function getState$1(stateToMerge) {
1314
+
1315
+ getState(stateToMerge) {
1324
1316
  if (stateToMerge === void 0) {
1325
1317
  stateToMerge = this.state;
1326
1318
  }
1327
1319
 
1328
1320
  return getState(stateToMerge, this.props);
1329
- };
1321
+ }
1330
1322
 
1331
- _proto.getItemCount = function getItemCount() {
1323
+ getItemCount() {
1332
1324
  // things read better this way. They're in priority order:
1333
1325
  // 1. `this.itemCount`
1334
1326
  // 2. `this.props.itemCount`
1335
1327
  // 3. `this.items.length`
1336
- var itemCount = this.items.length;
1328
+ let itemCount = this.items.length;
1337
1329
 
1338
1330
  if (this.itemCount != null) {
1339
1331
  itemCount = this.itemCount;
@@ -1342,97 +1334,97 @@ var Downshift = /*#__PURE__*/function () {
1342
1334
  }
1343
1335
 
1344
1336
  return itemCount;
1345
- };
1337
+ }
1346
1338
 
1347
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1339
+ getItemNodeFromIndex(index) {
1348
1340
  return this.props.environment.document.getElementById(this.getItemId(index));
1349
- };
1350
-
1351
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1352
- };
1353
-
1354
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1355
- var _this6 = this;
1341
+ }
1356
1342
 
1357
- var itemCount = this.getItemCount();
1343
+ scrollHighlightedItemIntoView() {
1344
+ }
1358
1345
 
1359
- var _this$getState8 = this.getState(),
1360
- highlightedIndex = _this$getState8.highlightedIndex;
1346
+ moveHighlightedIndex(amount, otherStateToSet) {
1347
+ const itemCount = this.getItemCount();
1348
+ const {
1349
+ highlightedIndex
1350
+ } = this.getState();
1361
1351
 
1362
1352
  if (itemCount > 0) {
1363
- var nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, function (index) {
1364
- return _this6.getItemNodeFromIndex(index);
1365
- });
1353
+ const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
1366
1354
  this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1367
1355
  }
1368
- };
1356
+ }
1369
1357
 
1370
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1371
- var _this$getState9 = this.getState(),
1372
- highlightedIndex = _this$getState9.highlightedIndex,
1373
- inputValue = _this$getState9.inputValue,
1374
- selectedItem = _this$getState9.selectedItem,
1375
- isOpen = _this$getState9.isOpen;
1376
-
1377
- var itemToString = this.props.itemToString;
1378
- var id = this.id;
1379
- var getRootProps = this.getRootProps,
1380
- getToggleButtonProps = this.getToggleButtonProps,
1381
- getLabelProps = this.getLabelProps,
1382
- getMenuProps = this.getMenuProps,
1383
- getInputProps = this.getInputProps,
1384
- getItemProps = this.getItemProps,
1385
- openMenu = this.openMenu,
1386
- closeMenu = this.closeMenu,
1387
- toggleMenu = this.toggleMenu,
1388
- selectItem = this.selectItem,
1389
- selectItemAtIndex = this.selectItemAtIndex,
1390
- selectHighlightedItem = this.selectHighlightedItem,
1391
- setHighlightedIndex = this.setHighlightedIndex,
1392
- clearSelection = this.clearSelection,
1393
- clearItems = this.clearItems,
1394
- reset = this.reset,
1395
- setItemCount = this.setItemCount,
1396
- unsetItemCount = this.unsetItemCount,
1397
- setState = this.internalSetState;
1358
+ getStateAndHelpers() {
1359
+ const {
1360
+ highlightedIndex,
1361
+ inputValue,
1362
+ selectedItem,
1363
+ isOpen
1364
+ } = this.getState();
1365
+ const {
1366
+ itemToString
1367
+ } = this.props;
1368
+ const {
1369
+ id
1370
+ } = this;
1371
+ const {
1372
+ getRootProps,
1373
+ getToggleButtonProps,
1374
+ getLabelProps,
1375
+ getMenuProps,
1376
+ getInputProps,
1377
+ getItemProps,
1378
+ openMenu,
1379
+ closeMenu,
1380
+ toggleMenu,
1381
+ selectItem,
1382
+ selectItemAtIndex,
1383
+ selectHighlightedItem,
1384
+ setHighlightedIndex,
1385
+ clearSelection,
1386
+ clearItems,
1387
+ reset,
1388
+ setItemCount,
1389
+ unsetItemCount,
1390
+ internalSetState: setState
1391
+ } = this;
1398
1392
  return {
1399
1393
  // prop getters
1400
- getRootProps: getRootProps,
1401
- getToggleButtonProps: getToggleButtonProps,
1402
- getLabelProps: getLabelProps,
1403
- getMenuProps: getMenuProps,
1404
- getInputProps: getInputProps,
1405
- getItemProps: getItemProps,
1394
+ getRootProps,
1395
+ getToggleButtonProps,
1396
+ getLabelProps,
1397
+ getMenuProps,
1398
+ getInputProps,
1399
+ getItemProps,
1406
1400
  // actions
1407
- reset: reset,
1408
- openMenu: openMenu,
1409
- closeMenu: closeMenu,
1410
- toggleMenu: toggleMenu,
1411
- selectItem: selectItem,
1412
- selectItemAtIndex: selectItemAtIndex,
1413
- selectHighlightedItem: selectHighlightedItem,
1414
- setHighlightedIndex: setHighlightedIndex,
1415
- clearSelection: clearSelection,
1416
- clearItems: clearItems,
1417
- setItemCount: setItemCount,
1418
- unsetItemCount: unsetItemCount,
1419
- setState: setState,
1401
+ reset,
1402
+ openMenu,
1403
+ closeMenu,
1404
+ toggleMenu,
1405
+ selectItem,
1406
+ selectItemAtIndex,
1407
+ selectHighlightedItem,
1408
+ setHighlightedIndex,
1409
+ clearSelection,
1410
+ clearItems,
1411
+ setItemCount,
1412
+ unsetItemCount,
1413
+ setState,
1420
1414
  // props
1421
- itemToString: itemToString,
1415
+ itemToString,
1422
1416
  // derived
1423
- id: id,
1417
+ id,
1424
1418
  // state
1425
- highlightedIndex: highlightedIndex,
1426
- inputValue: inputValue,
1427
- isOpen: isOpen,
1428
- selectedItem: selectedItem
1419
+ highlightedIndex,
1420
+ inputValue,
1421
+ isOpen,
1422
+ selectedItem
1429
1423
  };
1430
1424
  } //////////////////////////// ROOT
1431
- ;
1432
1425
 
1433
- _proto.componentDidMount = function componentDidMount() {
1434
- var _this7 = this;
1435
1426
 
1427
+ componentDidMount() {
1436
1428
  /* istanbul ignore if (react-native) */
1437
1429
  if (process.env.NODE_ENV !== 'production' && !true && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1438
1430
  validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
@@ -1441,25 +1433,25 @@ var Downshift = /*#__PURE__*/function () {
1441
1433
 
1442
1434
 
1443
1435
  {
1444
- this.cleanup = function () {
1445
- _this7.internalClearTimeouts();
1436
+ this.cleanup = () => {
1437
+ this.internalClearTimeouts();
1446
1438
  };
1447
1439
  }
1448
- };
1449
-
1450
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1451
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1452
- currentHighlightedIndex = _ref10.highlightedIndex;
1453
-
1454
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1455
- prevHighlightedIndex = _ref11.highlightedIndex;
1440
+ }
1456
1441
 
1457
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1458
- var scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1442
+ shouldScroll(prevState, prevProps) {
1443
+ const {
1444
+ highlightedIndex: currentHighlightedIndex
1445
+ } = this.props.highlightedIndex === undefined ? this.getState() : this.props;
1446
+ const {
1447
+ highlightedIndex: prevHighlightedIndex
1448
+ } = prevProps.highlightedIndex === undefined ? prevState : prevProps;
1449
+ const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1450
+ const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
1459
1451
  return scrollWhenOpen || scrollWhenNavigating;
1460
- };
1452
+ }
1461
1453
 
1462
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1454
+ componentDidUpdate(prevProps, prevState) {
1463
1455
  if (process.env.NODE_ENV !== 'production') {
1464
1456
  validateControlledUnchanged(this.state, prevProps, this.props);
1465
1457
  }
@@ -1474,14 +1466,14 @@ var Downshift = /*#__PURE__*/function () {
1474
1466
  if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
1475
1467
  this.scrollHighlightedItemIntoView();
1476
1468
  }
1477
- };
1469
+ }
1478
1470
 
1479
- _proto.componentWillUnmount = function componentWillUnmount() {
1471
+ componentWillUnmount() {
1480
1472
  this.cleanup(); // avoids memory leak
1481
- };
1473
+ }
1482
1474
 
1483
- _proto.render = function render() {
1484
- var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1475
+ render() {
1476
+ const children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1485
1477
  // we clear this out each render and it will be populated again as
1486
1478
  // getItemProps is called.
1487
1479
 
@@ -1501,7 +1493,7 @@ var Downshift = /*#__PURE__*/function () {
1501
1493
  this.getLabelProps.called = false; // and something similar for getInputProps
1502
1494
 
1503
1495
  this.getInputProps.called = false;
1504
- var element = unwrapArray(children(this.getStateAndHelpers()));
1496
+ const element = unwrapArray(children(this.getStateAndHelpers()));
1505
1497
 
1506
1498
  if (!element) {
1507
1499
  return null;
@@ -1530,16 +1522,15 @@ var Downshift = /*#__PURE__*/function () {
1530
1522
 
1531
1523
 
1532
1524
  return undefined;
1533
- };
1525
+ }
1534
1526
 
1535
- return Downshift;
1536
- }(react.Component);
1527
+ }
1537
1528
 
1538
1529
  Downshift.defaultProps = {
1539
1530
  defaultHighlightedIndex: null,
1540
1531
  defaultIsOpen: false,
1541
1532
  getA11yStatusMessage: getA11yStatusMessage$1,
1542
- itemToString: function itemToString(i) {
1533
+ itemToString: i => {
1543
1534
  if (i == null) {
1544
1535
  return '';
1545
1536
  }
@@ -1557,72 +1548,70 @@ var Downshift = /*#__PURE__*/function () {
1557
1548
  onChange: noop,
1558
1549
  onSelect: noop,
1559
1550
  onOuterClick: noop,
1560
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1561
- return prevItem !== item;
1562
- },
1551
+ selectedItemChanged: (prevItem, item) => prevItem !== item,
1563
1552
  environment:
1564
1553
  /* istanbul ignore next (ssr) */
1565
1554
  typeof window === 'undefined' ? {} : window,
1566
- stateReducer: function stateReducer(state, stateToSet) {
1567
- return stateToSet;
1568
- },
1555
+ stateReducer: (state, stateToSet) => stateToSet,
1569
1556
  suppressRefError: false,
1570
- scrollIntoView: scrollIntoView
1557
+ scrollIntoView
1571
1558
  };
1572
1559
  Downshift.stateChangeTypes = stateChangeTypes$3;
1573
1560
  return Downshift;
1574
- }();
1561
+ })();
1575
1562
 
1576
1563
  process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
1577
- children: PropTypes__default['default'].func,
1578
- defaultHighlightedIndex: PropTypes__default['default'].number,
1579
- defaultIsOpen: PropTypes__default['default'].bool,
1580
- initialHighlightedIndex: PropTypes__default['default'].number,
1581
- initialSelectedItem: PropTypes__default['default'].any,
1582
- initialInputValue: PropTypes__default['default'].string,
1583
- initialIsOpen: PropTypes__default['default'].bool,
1584
- getA11yStatusMessage: PropTypes__default['default'].func,
1585
- itemToString: PropTypes__default['default'].func,
1586
- onChange: PropTypes__default['default'].func,
1587
- onSelect: PropTypes__default['default'].func,
1588
- onStateChange: PropTypes__default['default'].func,
1589
- onInputValueChange: PropTypes__default['default'].func,
1590
- onUserAction: PropTypes__default['default'].func,
1591
- onOuterClick: PropTypes__default['default'].func,
1592
- selectedItemChanged: PropTypes__default['default'].func,
1593
- stateReducer: PropTypes__default['default'].func,
1594
- itemCount: PropTypes__default['default'].number,
1595
- id: PropTypes__default['default'].string,
1596
- environment: PropTypes__default['default'].shape({
1597
- addEventListener: PropTypes__default['default'].func,
1598
- removeEventListener: PropTypes__default['default'].func,
1599
- document: PropTypes__default['default'].shape({
1600
- getElementById: PropTypes__default['default'].func,
1601
- activeElement: PropTypes__default['default'].any,
1602
- body: PropTypes__default['default'].any
1564
+ children: PropTypes__default["default"].func,
1565
+ defaultHighlightedIndex: PropTypes__default["default"].number,
1566
+ defaultIsOpen: PropTypes__default["default"].bool,
1567
+ initialHighlightedIndex: PropTypes__default["default"].number,
1568
+ initialSelectedItem: PropTypes__default["default"].any,
1569
+ initialInputValue: PropTypes__default["default"].string,
1570
+ initialIsOpen: PropTypes__default["default"].bool,
1571
+ getA11yStatusMessage: PropTypes__default["default"].func,
1572
+ itemToString: PropTypes__default["default"].func,
1573
+ onChange: PropTypes__default["default"].func,
1574
+ onSelect: PropTypes__default["default"].func,
1575
+ onStateChange: PropTypes__default["default"].func,
1576
+ onInputValueChange: PropTypes__default["default"].func,
1577
+ onUserAction: PropTypes__default["default"].func,
1578
+ onOuterClick: PropTypes__default["default"].func,
1579
+ selectedItemChanged: PropTypes__default["default"].func,
1580
+ stateReducer: PropTypes__default["default"].func,
1581
+ itemCount: PropTypes__default["default"].number,
1582
+ id: PropTypes__default["default"].string,
1583
+ environment: PropTypes__default["default"].shape({
1584
+ addEventListener: PropTypes__default["default"].func,
1585
+ removeEventListener: PropTypes__default["default"].func,
1586
+ document: PropTypes__default["default"].shape({
1587
+ getElementById: PropTypes__default["default"].func,
1588
+ activeElement: PropTypes__default["default"].any,
1589
+ body: PropTypes__default["default"].any
1603
1590
  })
1604
1591
  }),
1605
- suppressRefError: PropTypes__default['default'].bool,
1606
- scrollIntoView: PropTypes__default['default'].func,
1592
+ suppressRefError: PropTypes__default["default"].bool,
1593
+ scrollIntoView: PropTypes__default["default"].func,
1607
1594
  // things we keep in state for uncontrolled components
1608
1595
  // but can accept as props for controlled components
1609
1596
 
1610
1597
  /* eslint-disable react/no-unused-prop-types */
1611
- selectedItem: PropTypes__default['default'].any,
1612
- isOpen: PropTypes__default['default'].bool,
1613
- inputValue: PropTypes__default['default'].string,
1614
- highlightedIndex: PropTypes__default['default'].number,
1615
- labelId: PropTypes__default['default'].string,
1616
- inputId: PropTypes__default['default'].string,
1617
- menuId: PropTypes__default['default'].string,
1618
- getItemId: PropTypes__default['default'].func
1598
+ selectedItem: PropTypes__default["default"].any,
1599
+ isOpen: PropTypes__default["default"].bool,
1600
+ inputValue: PropTypes__default["default"].string,
1601
+ highlightedIndex: PropTypes__default["default"].number,
1602
+ labelId: PropTypes__default["default"].string,
1603
+ inputId: PropTypes__default["default"].string,
1604
+ menuId: PropTypes__default["default"].string,
1605
+ getItemId: PropTypes__default["default"].func
1619
1606
  /* eslint-enable react/no-unused-prop-types */
1620
1607
 
1621
1608
  } : void 0;
1622
1609
  var Downshift$1 = Downshift;
1623
1610
 
1624
- function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1625
- var refKey = _ref12.refKey;
1611
+ function validateGetMenuPropsCalledCorrectly(node, _ref3) {
1612
+ let {
1613
+ refKey
1614
+ } = _ref3;
1626
1615
 
1627
1616
  if (!node) {
1628
1617
  // eslint-disable-next-line no-console
@@ -1630,10 +1619,12 @@ function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1630
1619
  }
1631
1620
  }
1632
1621
 
1633
- function validateGetRootPropsCalledCorrectly(element, _ref13) {
1634
- var refKey = _ref13.refKey;
1635
- var refKeySpecified = refKey !== 'ref';
1636
- var isComposite = !isDOMElement(element);
1622
+ function validateGetRootPropsCalledCorrectly(element, _ref4) {
1623
+ let {
1624
+ refKey
1625
+ } = _ref4;
1626
+ const refKeySpecified = refKey !== 'ref';
1627
+ const isComposite = !isDOMElement(element);
1637
1628
 
1638
1629
  if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
1639
1630
  // eslint-disable-next-line no-console
@@ -1649,8 +1640,7 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
1649
1640
  }
1650
1641
  }
1651
1642
 
1652
- var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
1653
- var dropdownDefaultStateValues = {
1643
+ const dropdownDefaultStateValues = {
1654
1644
  highlightedIndex: -1,
1655
1645
  isOpen: false,
1656
1646
  selectedItem: null,
@@ -1658,10 +1648,12 @@ var dropdownDefaultStateValues = {
1658
1648
  };
1659
1649
 
1660
1650
  function callOnChangeProps(action, state, newState) {
1661
- var props = action.props,
1662
- type = action.type;
1663
- var changes = {};
1664
- Object.keys(state).forEach(function (key) {
1651
+ const {
1652
+ props,
1653
+ type
1654
+ } = action;
1655
+ const changes = {};
1656
+ Object.keys(state).forEach(key => {
1665
1657
  invokeOnChangeHandler(key, action, state, newState);
1666
1658
 
1667
1659
  if (newState[key] !== state[key]) {
@@ -1670,21 +1662,25 @@ function callOnChangeProps(action, state, newState) {
1670
1662
  });
1671
1663
 
1672
1664
  if (props.onStateChange && Object.keys(changes).length) {
1673
- props.onStateChange(_extends__default['default']({
1674
- type: type
1675
- }, changes));
1665
+ props.onStateChange({
1666
+ type,
1667
+ ...changes
1668
+ });
1676
1669
  }
1677
1670
  }
1678
1671
 
1679
1672
  function invokeOnChangeHandler(key, action, state, newState) {
1680
- var props = action.props,
1681
- type = action.type;
1682
- var handler = "on" + capitalizeString(key) + "Change";
1673
+ const {
1674
+ props,
1675
+ type
1676
+ } = action;
1677
+ const handler = "on" + capitalizeString(key) + "Change";
1683
1678
 
1684
1679
  if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
1685
- props[handler](_extends__default['default']({
1686
- type: type
1687
- }, newState));
1680
+ props[handler]({
1681
+ type,
1682
+ ...newState
1683
+ });
1688
1684
  }
1689
1685
  }
1690
1686
  /**
@@ -1708,8 +1704,10 @@ function stateReducer(s, a) {
1708
1704
 
1709
1705
 
1710
1706
  function getA11ySelectionMessage(selectionParameters) {
1711
- var selectedItem = selectionParameters.selectedItem,
1712
- itemToStringLocal = selectionParameters.itemToString;
1707
+ const {
1708
+ selectedItem,
1709
+ itemToString: itemToStringLocal
1710
+ } = selectionParameters;
1713
1711
  return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
1714
1712
  }
1715
1713
  /**
@@ -1717,26 +1715,25 @@ function getA11ySelectionMessage(selectionParameters) {
1717
1715
  */
1718
1716
 
1719
1717
 
1720
- var updateA11yStatus = debounce(function (getA11yMessage, document) {
1718
+ const updateA11yStatus = debounce((getA11yMessage, document) => {
1721
1719
  setStatus(getA11yMessage(), document);
1722
1720
  }, 200); // istanbul ignore next
1723
1721
 
1724
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
1722
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
1725
1723
 
1726
1724
  function useElementIds(_ref) {
1727
- var _ref$id = _ref.id,
1728
- id = _ref$id === void 0 ? "downshift-" + generateId() : _ref$id,
1729
- labelId = _ref.labelId,
1730
- menuId = _ref.menuId,
1731
- getItemId = _ref.getItemId,
1732
- toggleButtonId = _ref.toggleButtonId,
1733
- inputId = _ref.inputId;
1734
- var elementIdsRef = react.useRef({
1725
+ let {
1726
+ id = "downshift-" + generateId(),
1727
+ labelId,
1728
+ menuId,
1729
+ getItemId,
1730
+ toggleButtonId,
1731
+ inputId
1732
+ } = _ref;
1733
+ const elementIdsRef = react.useRef({
1735
1734
  labelId: labelId || id + "-label",
1736
1735
  menuId: menuId || id + "-menu",
1737
- getItemId: getItemId || function (index) {
1738
- return id + "-item-" + index;
1739
- },
1736
+ getItemId: getItemId || (index => id + "-item-" + index),
1740
1737
  toggleButtonId: toggleButtonId || id + "-toggle-button",
1741
1738
  inputId: inputId || id + "-input"
1742
1739
  });
@@ -1768,7 +1765,7 @@ function capitalizeString(string) {
1768
1765
  }
1769
1766
 
1770
1767
  function useLatestRef(val) {
1771
- var ref = react.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
1768
+ const ref = react.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
1772
1769
  // the value during render (so it's not idempotent). However, the places this
1773
1770
  // hook is used is to support memoizing callbacks which will be called
1774
1771
  // *during* render, so we need the latest values *during* render.
@@ -1790,30 +1787,25 @@ function useLatestRef(val) {
1790
1787
 
1791
1788
 
1792
1789
  function useEnhancedReducer(reducer, initialState, props) {
1793
- var prevStateRef = react.useRef();
1794
- var actionRef = react.useRef();
1795
- var enhancedReducer = react.useCallback(function (state, action) {
1790
+ const prevStateRef = react.useRef();
1791
+ const actionRef = react.useRef();
1792
+ const enhancedReducer = react.useCallback((state, action) => {
1796
1793
  actionRef.current = action;
1797
1794
  state = getState(state, action.props);
1798
- var changes = reducer(state, action);
1799
- var newState = action.props.stateReducer(state, _extends__default['default']({}, action, {
1800
- changes: changes
1801
- }));
1795
+ const changes = reducer(state, action);
1796
+ const newState = action.props.stateReducer(state, { ...action,
1797
+ changes
1798
+ });
1802
1799
  return newState;
1803
1800
  }, [reducer]);
1804
-
1805
- var _useReducer = react.useReducer(enhancedReducer, initialState),
1806
- state = _useReducer[0],
1807
- dispatch = _useReducer[1];
1808
-
1809
- var propsRef = useLatestRef(props);
1810
- var dispatchWithProps = react.useCallback(function (action) {
1811
- return dispatch(_extends__default['default']({
1812
- props: propsRef.current
1813
- }, action));
1814
- }, [propsRef]);
1815
- var action = actionRef.current;
1816
- react.useEffect(function () {
1801
+ const [state, dispatch] = react.useReducer(enhancedReducer, initialState);
1802
+ const propsRef = useLatestRef(props);
1803
+ const dispatchWithProps = react.useCallback(action => dispatch({
1804
+ props: propsRef.current,
1805
+ ...action
1806
+ }), [propsRef]);
1807
+ const action = actionRef.current;
1808
+ react.useEffect(() => {
1817
1809
  if (action && prevStateRef.current && prevStateRef.current !== state) {
1818
1810
  callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
1819
1811
  }
@@ -1834,18 +1826,15 @@ function useEnhancedReducer(reducer, initialState, props) {
1834
1826
 
1835
1827
 
1836
1828
  function useControlledReducer$1(reducer, initialState, props) {
1837
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
1838
- state = _useEnhancedReducer[0],
1839
- dispatch = _useEnhancedReducer[1];
1840
-
1829
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
1841
1830
  return [getState(state, props), dispatch];
1842
1831
  }
1843
1832
 
1844
- var defaultProps$3 = {
1845
- itemToString: itemToString,
1846
- stateReducer: stateReducer,
1847
- getA11ySelectionMessage: getA11ySelectionMessage,
1848
- scrollIntoView: scrollIntoView,
1833
+ const defaultProps$3 = {
1834
+ itemToString,
1835
+ stateReducer,
1836
+ getA11ySelectionMessage,
1837
+ scrollIntoView,
1849
1838
  circularNavigation: false,
1850
1839
  environment:
1851
1840
  /* istanbul ignore next (ssr) */
@@ -1857,7 +1846,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
1857
1846
  defaultStateValues = dropdownDefaultStateValues;
1858
1847
  }
1859
1848
 
1860
- var defaultPropKey = "default" + capitalizeString(propKey);
1849
+ const defaultPropKey = "default" + capitalizeString(propKey);
1861
1850
 
1862
1851
  if (defaultPropKey in props) {
1863
1852
  return props[defaultPropKey];
@@ -1875,7 +1864,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1875
1864
  return props[propKey];
1876
1865
  }
1877
1866
 
1878
- var initialPropKey = "initial" + capitalizeString(propKey);
1867
+ const initialPropKey = "initial" + capitalizeString(propKey);
1879
1868
 
1880
1869
  if (initialPropKey in props) {
1881
1870
  return props[initialPropKey];
@@ -1885,24 +1874,28 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1885
1874
  }
1886
1875
 
1887
1876
  function getInitialState$2(props) {
1888
- var selectedItem = getInitialValue$1(props, 'selectedItem');
1889
- var isOpen = getInitialValue$1(props, 'isOpen');
1890
- var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1891
- var inputValue = getInitialValue$1(props, 'inputValue');
1877
+ const selectedItem = getInitialValue$1(props, 'selectedItem');
1878
+ const isOpen = getInitialValue$1(props, 'isOpen');
1879
+ const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1880
+ const inputValue = getInitialValue$1(props, 'inputValue');
1892
1881
  return {
1893
1882
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
1894
- isOpen: isOpen,
1895
- selectedItem: selectedItem,
1896
- inputValue: inputValue
1883
+ isOpen,
1884
+ selectedItem,
1885
+ inputValue
1897
1886
  };
1898
1887
  }
1899
1888
 
1900
1889
  function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
1901
- var items = props.items,
1902
- initialHighlightedIndex = props.initialHighlightedIndex,
1903
- defaultHighlightedIndex = props.defaultHighlightedIndex;
1904
- var selectedItem = state.selectedItem,
1905
- highlightedIndex = state.highlightedIndex;
1890
+ const {
1891
+ items,
1892
+ initialHighlightedIndex,
1893
+ defaultHighlightedIndex
1894
+ } = props;
1895
+ const {
1896
+ selectedItem,
1897
+ highlightedIndex
1898
+ } = state;
1906
1899
 
1907
1900
  if (items.length === 0) {
1908
1901
  return -1;
@@ -1943,39 +1936,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
1943
1936
 
1944
1937
 
1945
1938
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
1946
- var mouseAndTouchTrackersRef = react.useRef({
1939
+ const mouseAndTouchTrackersRef = react.useRef({
1947
1940
  isMouseDown: false,
1948
1941
  isTouchMove: false
1949
1942
  });
1950
- react.useEffect(function () {
1943
+ react.useEffect(() => {
1951
1944
  // The same strategy for checking if a click occurred inside or outside downsift
1952
1945
  // as in downshift.js.
1953
- var onMouseDown = function onMouseDown() {
1946
+ const onMouseDown = () => {
1954
1947
  mouseAndTouchTrackersRef.current.isMouseDown = true;
1955
1948
  };
1956
1949
 
1957
- var onMouseUp = function onMouseUp(event) {
1950
+ const onMouseUp = event => {
1958
1951
  mouseAndTouchTrackersRef.current.isMouseDown = false;
1959
1952
 
1960
- if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1961
- return ref.current;
1962
- }), environment)) {
1953
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
1963
1954
  handleBlur();
1964
1955
  }
1965
1956
  };
1966
1957
 
1967
- var onTouchStart = function onTouchStart() {
1958
+ const onTouchStart = () => {
1968
1959
  mouseAndTouchTrackersRef.current.isTouchMove = false;
1969
1960
  };
1970
1961
 
1971
- var onTouchMove = function onTouchMove() {
1962
+ const onTouchMove = () => {
1972
1963
  mouseAndTouchTrackersRef.current.isTouchMove = true;
1973
1964
  };
1974
1965
 
1975
- var onTouchEnd = function onTouchEnd(event) {
1976
- if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
1977
- return ref.current;
1978
- }), environment, false)) {
1966
+ const onTouchEnd = event => {
1967
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
1979
1968
  handleBlur();
1980
1969
  }
1981
1970
  };
@@ -1999,9 +1988,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
1999
1988
  // eslint-disable-next-line import/no-mutable-exports
2000
1989
 
2001
1990
 
2002
- var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2003
- return noop;
2004
- };
1991
+ let useGetterPropsCalledChecker = () => noop;
2005
1992
  /**
2006
1993
  * Custom hook that checks if getter props are called correctly.
2007
1994
  *
@@ -2013,20 +2000,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2013
2000
 
2014
2001
 
2015
2002
  if (process.env.NODE_ENV !== 'production') {
2016
- useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2017
- var isInitialMountRef = react.useRef(true);
2003
+ useGetterPropsCalledChecker = function () {
2004
+ const isInitialMountRef = react.useRef(true);
2018
2005
 
2019
2006
  for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
2020
2007
  propKeys[_key] = arguments[_key];
2021
2008
  }
2022
2009
 
2023
- var getterPropsCalledRef = react.useRef(propKeys.reduce(function (acc, propKey) {
2010
+ const getterPropsCalledRef = react.useRef(propKeys.reduce((acc, propKey) => {
2024
2011
  acc[propKey] = {};
2025
2012
  return acc;
2026
2013
  }, {}));
2027
- react.useEffect(function () {
2028
- Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
2029
- var propCallInfo = getterPropsCalledRef.current[propKey];
2014
+ react.useEffect(() => {
2015
+ Object.keys(getterPropsCalledRef.current).forEach(propKey => {
2016
+ const propCallInfo = getterPropsCalledRef.current[propKey];
2030
2017
 
2031
2018
  if (isInitialMountRef.current) {
2032
2019
  if (!Object.keys(propCallInfo).length) {
@@ -2036,9 +2023,11 @@ if (process.env.NODE_ENV !== 'production') {
2036
2023
  }
2037
2024
  }
2038
2025
 
2039
- var suppressRefError = propCallInfo.suppressRefError,
2040
- refKey = propCallInfo.refKey,
2041
- elementRef = propCallInfo.elementRef;
2026
+ const {
2027
+ suppressRefError,
2028
+ refKey,
2029
+ elementRef
2030
+ } = propCallInfo;
2042
2031
 
2043
2032
  if ((!elementRef || !elementRef.current) && !suppressRefError) {
2044
2033
  // eslint-disable-next-line no-console
@@ -2047,11 +2036,11 @@ if (process.env.NODE_ENV !== 'production') {
2047
2036
  });
2048
2037
  isInitialMountRef.current = false;
2049
2038
  });
2050
- var setGetterPropCallInfo = react.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
2039
+ const setGetterPropCallInfo = react.useCallback((propKey, suppressRefError, refKey, elementRef) => {
2051
2040
  getterPropsCalledRef.current[propKey] = {
2052
- suppressRefError: suppressRefError,
2053
- refKey: refKey,
2054
- elementRef: elementRef
2041
+ suppressRefError,
2042
+ refKey,
2043
+ elementRef
2055
2044
  };
2056
2045
  }, []);
2057
2046
  return setGetterPropCallInfo;
@@ -2059,39 +2048,41 @@ if (process.env.NODE_ENV !== 'production') {
2059
2048
  }
2060
2049
 
2061
2050
  function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
2062
- var isInitialMount = _ref2.isInitialMount,
2063
- highlightedIndex = _ref2.highlightedIndex,
2064
- items = _ref2.items,
2065
- environment = _ref2.environment,
2066
- rest = _objectWithoutPropertiesLoose__default['default'](_ref2, _excluded$3);
2067
-
2051
+ let {
2052
+ isInitialMount,
2053
+ highlightedIndex,
2054
+ items,
2055
+ environment,
2056
+ ...rest
2057
+ } = _ref2;
2068
2058
  // Sets a11y status message on changes in state.
2069
- react.useEffect(function () {
2059
+ react.useEffect(() => {
2070
2060
  if (isInitialMount || true) {
2071
2061
  return;
2072
2062
  }
2073
2063
 
2074
- updateA11yStatus(function () {
2075
- return getA11yMessage(_extends__default['default']({
2076
- highlightedIndex: highlightedIndex,
2077
- highlightedItem: items[highlightedIndex],
2078
- resultCount: items.length
2079
- }, rest));
2080
- }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
2064
+ updateA11yStatus(() => getA11yMessage({
2065
+ highlightedIndex,
2066
+ highlightedItem: items[highlightedIndex],
2067
+ resultCount: items.length,
2068
+ ...rest
2069
+ }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
2081
2070
  }, dependencyArray);
2082
2071
  }
2083
2072
 
2084
2073
  function useScrollIntoView(_ref3) {
2085
- var highlightedIndex = _ref3.highlightedIndex,
2086
- isOpen = _ref3.isOpen,
2087
- itemRefs = _ref3.itemRefs,
2088
- getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
2089
- menuElement = _ref3.menuElement,
2090
- scrollIntoViewProp = _ref3.scrollIntoView;
2074
+ let {
2075
+ highlightedIndex,
2076
+ isOpen,
2077
+ itemRefs,
2078
+ getItemNodeFromIndex,
2079
+ menuElement,
2080
+ scrollIntoView: scrollIntoViewProp
2081
+ } = _ref3;
2091
2082
  // used not to scroll on highlight by mouse.
2092
- var shouldScrollRef = react.useRef(true); // Scroll on highlighted item if change comes from keyboard.
2083
+ const shouldScrollRef = react.useRef(true); // Scroll on highlighted item if change comes from keyboard.
2093
2084
 
2094
- useIsomorphicLayoutEffect(function () {
2085
+ useIsomorphicLayoutEffect(() => {
2095
2086
  if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2096
2087
  return;
2097
2088
  }
@@ -2107,17 +2098,19 @@ function useScrollIntoView(_ref3) {
2107
2098
  } // eslint-disable-next-line import/no-mutable-exports
2108
2099
 
2109
2100
 
2110
- var useControlPropsValidator = noop;
2101
+ let useControlPropsValidator = noop;
2111
2102
  /* istanbul ignore next */
2112
2103
 
2113
2104
  if (process.env.NODE_ENV !== 'production') {
2114
- useControlPropsValidator = function useControlPropsValidator(_ref4) {
2115
- var isInitialMount = _ref4.isInitialMount,
2116
- props = _ref4.props,
2117
- state = _ref4.state;
2105
+ useControlPropsValidator = _ref4 => {
2106
+ let {
2107
+ isInitialMount,
2108
+ props,
2109
+ state
2110
+ } = _ref4;
2118
2111
  // used for checking when props are moving from controlled to uncontrolled.
2119
- var prevPropsRef = react.useRef(props);
2120
- react.useEffect(function () {
2112
+ const prevPropsRef = react.useRef(props);
2113
+ react.useEffect(() => {
2121
2114
  if (isInitialMount) {
2122
2115
  return;
2123
2116
  }
@@ -2131,9 +2124,11 @@ if (process.env.NODE_ENV !== 'production') {
2131
2124
  /* eslint-disable complexity */
2132
2125
 
2133
2126
  function downshiftCommonReducer(state, action, stateChangeTypes) {
2134
- var type = action.type,
2135
- props = action.props;
2136
- var changes;
2127
+ const {
2128
+ type,
2129
+ props
2130
+ } = action;
2131
+ let changes;
2137
2132
 
2138
2133
  switch (type) {
2139
2134
  case stateChangeTypes.ItemMouseMove:
@@ -2194,7 +2189,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2194
2189
  throw new Error('Reducer called without proper action type.');
2195
2190
  }
2196
2191
 
2197
- return _extends__default['default']({}, state, changes);
2192
+ return { ...state,
2193
+ ...changes
2194
+ };
2198
2195
  }
2199
2196
  /* eslint-enable complexity */
2200
2197
 
@@ -2217,37 +2214,37 @@ function getItemIndexByCharacterKey(_a) {
2217
2214
  return highlightedIndex;
2218
2215
  }
2219
2216
  var propTypes$2 = {
2220
- items: PropTypes__default['default'].array.isRequired,
2221
- itemToString: PropTypes__default['default'].func,
2222
- getA11yStatusMessage: PropTypes__default['default'].func,
2223
- getA11ySelectionMessage: PropTypes__default['default'].func,
2224
- circularNavigation: PropTypes__default['default'].bool,
2225
- highlightedIndex: PropTypes__default['default'].number,
2226
- defaultHighlightedIndex: PropTypes__default['default'].number,
2227
- initialHighlightedIndex: PropTypes__default['default'].number,
2228
- isOpen: PropTypes__default['default'].bool,
2229
- defaultIsOpen: PropTypes__default['default'].bool,
2230
- initialIsOpen: PropTypes__default['default'].bool,
2231
- selectedItem: PropTypes__default['default'].any,
2232
- initialSelectedItem: PropTypes__default['default'].any,
2233
- defaultSelectedItem: PropTypes__default['default'].any,
2234
- id: PropTypes__default['default'].string,
2235
- labelId: PropTypes__default['default'].string,
2236
- menuId: PropTypes__default['default'].string,
2237
- getItemId: PropTypes__default['default'].func,
2238
- toggleButtonId: PropTypes__default['default'].string,
2239
- stateReducer: PropTypes__default['default'].func,
2240
- onSelectedItemChange: PropTypes__default['default'].func,
2241
- onHighlightedIndexChange: PropTypes__default['default'].func,
2242
- onStateChange: PropTypes__default['default'].func,
2243
- onIsOpenChange: PropTypes__default['default'].func,
2244
- environment: PropTypes__default['default'].shape({
2245
- addEventListener: PropTypes__default['default'].func,
2246
- removeEventListener: PropTypes__default['default'].func,
2247
- document: PropTypes__default['default'].shape({
2248
- getElementById: PropTypes__default['default'].func,
2249
- activeElement: PropTypes__default['default'].any,
2250
- body: PropTypes__default['default'].any
2217
+ items: PropTypes__default["default"].array.isRequired,
2218
+ itemToString: PropTypes__default["default"].func,
2219
+ getA11yStatusMessage: PropTypes__default["default"].func,
2220
+ getA11ySelectionMessage: PropTypes__default["default"].func,
2221
+ circularNavigation: PropTypes__default["default"].bool,
2222
+ highlightedIndex: PropTypes__default["default"].number,
2223
+ defaultHighlightedIndex: PropTypes__default["default"].number,
2224
+ initialHighlightedIndex: PropTypes__default["default"].number,
2225
+ isOpen: PropTypes__default["default"].bool,
2226
+ defaultIsOpen: PropTypes__default["default"].bool,
2227
+ initialIsOpen: PropTypes__default["default"].bool,
2228
+ selectedItem: PropTypes__default["default"].any,
2229
+ initialSelectedItem: PropTypes__default["default"].any,
2230
+ defaultSelectedItem: PropTypes__default["default"].any,
2231
+ id: PropTypes__default["default"].string,
2232
+ labelId: PropTypes__default["default"].string,
2233
+ menuId: PropTypes__default["default"].string,
2234
+ getItemId: PropTypes__default["default"].func,
2235
+ toggleButtonId: PropTypes__default["default"].string,
2236
+ stateReducer: PropTypes__default["default"].func,
2237
+ onSelectedItemChange: PropTypes__default["default"].func,
2238
+ onHighlightedIndexChange: PropTypes__default["default"].func,
2239
+ onStateChange: PropTypes__default["default"].func,
2240
+ onIsOpenChange: PropTypes__default["default"].func,
2241
+ environment: PropTypes__default["default"].shape({
2242
+ addEventListener: PropTypes__default["default"].func,
2243
+ removeEventListener: PropTypes__default["default"].func,
2244
+ document: PropTypes__default["default"].shape({
2245
+ getElementById: PropTypes__default["default"].func,
2246
+ activeElement: PropTypes__default["default"].any,
2247
+ body: PropTypes__default["default"].any
2251
2248
  })
2252
2249
  })
2253
2250
  };
@@ -2268,7 +2265,7 @@ function getA11yStatusMessage(_a) {
2268
2265
  return 'No results are available.';
2269
2266
  }
2270
2267
  if (resultCount !== previousResultCount) {
2271
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.";
2268
+ return "".concat(resultCount, " result").concat(resultCount === 1 ? ' is' : 's are', " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.");
2272
2269
  }
2273
2270
  return '';
2274
2271
  }
@@ -2278,33 +2275,33 @@ var validatePropTypes$2 = noop;
2278
2275
  /* istanbul ignore next */
2279
2276
  if (process.env.NODE_ENV !== 'production') {
2280
2277
  validatePropTypes$2 = function (options, caller) {
2281
- PropTypes__default['default'].checkPropTypes(propTypes$2, options, 'prop', caller.name);
2278
+ PropTypes__default["default"].checkPropTypes(propTypes$2, options, 'prop', caller.name);
2282
2279
  };
2283
2280
  }
2284
2281
 
2285
- var MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
2286
- var MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
2287
- var MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
2288
- var MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
2289
- var MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
2290
- var MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
2291
- var MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
2292
- var MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
2293
- var MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
2294
- var MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
2295
- var ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
2296
- var ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
2297
- var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
2298
- var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
2299
- var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
2300
- var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
2301
- var FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
2302
- var FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
2303
- var FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
2304
- var FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
2305
- var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
2306
- var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
2307
- var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
2282
+ const MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
2283
+ const MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
2284
+ const MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
2285
+ const MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
2286
+ const MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
2287
+ const MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
2288
+ const MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
2289
+ const MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
2290
+ const MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
2291
+ const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
2292
+ const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
2293
+ const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
2294
+ const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
2295
+ const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
2296
+ const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
2297
+ const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
2298
+ const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
2299
+ const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
2300
+ const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
2301
+ const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
2302
+ const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
2303
+ const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
2304
+ const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
2308
2305
 
2309
2306
  var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2310
2307
  __proto__: null,
@@ -2336,10 +2333,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2336
2333
  /* eslint-disable complexity */
2337
2334
 
2338
2335
  function downshiftSelectReducer(state, action) {
2339
- var type = action.type,
2340
- props = action.props,
2341
- shiftKey = action.shiftKey;
2342
- var changes;
2336
+ const {
2337
+ type,
2338
+ props,
2339
+ shiftKey
2340
+ } = action;
2341
+ let changes;
2343
2342
 
2344
2343
  switch (type) {
2345
2344
  case ItemClick$1:
@@ -2352,20 +2351,21 @@ function downshiftSelectReducer(state, action) {
2352
2351
 
2353
2352
  case ToggleButtonKeyDownCharacter:
2354
2353
  {
2355
- var lowercasedKey = action.key;
2356
- var inputValue = "" + state.inputValue + lowercasedKey;
2357
- var itemIndex = getItemIndexByCharacterKey({
2354
+ const lowercasedKey = action.key;
2355
+ const inputValue = "" + state.inputValue + lowercasedKey;
2356
+ const itemIndex = getItemIndexByCharacterKey({
2358
2357
  keysSoFar: inputValue,
2359
2358
  highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
2360
2359
  items: props.items,
2361
2360
  itemToString: props.itemToString,
2362
2361
  getItemNodeFromIndex: action.getItemNodeFromIndex
2363
2362
  });
2364
- changes = _extends__default['default']({
2365
- inputValue: inputValue
2366
- }, itemIndex >= 0 && {
2367
- selectedItem: props.items[itemIndex]
2368
- });
2363
+ changes = {
2364
+ inputValue,
2365
+ ...(itemIndex >= 0 && {
2366
+ selectedItem: props.items[itemIndex]
2367
+ })
2368
+ };
2369
2369
  }
2370
2370
  break;
2371
2371
 
@@ -2385,12 +2385,13 @@ function downshiftSelectReducer(state, action) {
2385
2385
 
2386
2386
  case MenuKeyDownEnter:
2387
2387
  case MenuKeyDownSpaceButton:
2388
- changes = _extends__default['default']({
2388
+ changes = {
2389
2389
  isOpen: getDefaultValue$1(props, 'isOpen'),
2390
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2391
- }, state.highlightedIndex >= 0 && {
2392
- selectedItem: props.items[state.highlightedIndex]
2393
- });
2390
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2391
+ ...(state.highlightedIndex >= 0 && {
2392
+ selectedItem: props.items[state.highlightedIndex]
2393
+ })
2394
+ };
2394
2395
  break;
2395
2396
 
2396
2397
  case MenuKeyDownHome:
@@ -2421,22 +2422,21 @@ function downshiftSelectReducer(state, action) {
2421
2422
 
2422
2423
  case MenuKeyDownCharacter:
2423
2424
  {
2424
- var _lowercasedKey = action.key;
2425
-
2426
- var _inputValue = "" + state.inputValue + _lowercasedKey;
2427
-
2428
- var highlightedIndex = getItemIndexByCharacterKey({
2429
- keysSoFar: _inputValue,
2425
+ const lowercasedKey = action.key;
2426
+ const inputValue = "" + state.inputValue + lowercasedKey;
2427
+ const highlightedIndex = getItemIndexByCharacterKey({
2428
+ keysSoFar: inputValue,
2430
2429
  highlightedIndex: state.highlightedIndex,
2431
2430
  items: props.items,
2432
2431
  itemToString: props.itemToString,
2433
2432
  getItemNodeFromIndex: action.getItemNodeFromIndex
2434
2433
  });
2435
- changes = _extends__default['default']({
2436
- inputValue: _inputValue
2437
- }, highlightedIndex >= 0 && {
2438
- highlightedIndex: highlightedIndex
2439
- });
2434
+ changes = {
2435
+ inputValue,
2436
+ ...(highlightedIndex >= 0 && {
2437
+ highlightedIndex
2438
+ })
2439
+ };
2440
2440
  }
2441
2441
  break;
2442
2442
 
@@ -2462,13 +2462,13 @@ function downshiftSelectReducer(state, action) {
2462
2462
  return downshiftCommonReducer(state, action, stateChangeTypes$2);
2463
2463
  }
2464
2464
 
2465
- return _extends__default['default']({}, state, changes);
2465
+ return { ...state,
2466
+ ...changes
2467
+ };
2466
2468
  }
2467
2469
  /* eslint-enable complexity */
2468
2470
 
2469
- var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
2470
- _excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
2471
- _excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
2471
+ /* eslint-disable max-statements */
2472
2472
  useSelect.stateChangeTypes = stateChangeTypes$2;
2473
2473
 
2474
2474
  function useSelect(userProps) {
@@ -2478,91 +2478,92 @@ function useSelect(userProps) {
2478
2478
 
2479
2479
  validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
2480
2480
 
2481
- var props = _extends__default['default']({}, defaultProps$2, userProps);
2482
-
2483
- var items = props.items,
2484
- scrollIntoView = props.scrollIntoView,
2485
- environment = props.environment,
2486
- initialIsOpen = props.initialIsOpen,
2487
- defaultIsOpen = props.defaultIsOpen,
2488
- itemToString = props.itemToString,
2489
- getA11ySelectionMessage = props.getA11ySelectionMessage,
2490
- getA11yStatusMessage = props.getA11yStatusMessage; // Initial state depending on controlled props.
2491
-
2492
- var initialState = getInitialState$2(props);
2493
-
2494
- var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
2495
- state = _useControlledReducer[0],
2496
- dispatch = _useControlledReducer[1];
2497
-
2498
- var isOpen = state.isOpen,
2499
- highlightedIndex = state.highlightedIndex,
2500
- selectedItem = state.selectedItem,
2501
- inputValue = state.inputValue; // Element efs.
2502
-
2503
- var toggleButtonRef = react.useRef(null);
2504
- var menuRef = react.useRef(null);
2505
- var itemRefs = react.useRef({}); // used not to trigger menu blur action in some scenarios.
2506
-
2507
- var shouldBlurRef = react.useRef(true); // used to keep the inputValue clearTimeout object between renders.
2508
-
2509
- var clearTimeoutRef = react.useRef(null); // prevent id re-generation between renders.
2510
-
2511
- var elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
2512
-
2513
- var previousResultCountRef = react.useRef();
2514
- var isInitialMountRef = react.useRef(true); // utility callback to get item element.
2515
-
2516
- var latest = useLatestRef({
2517
- state: state,
2518
- props: props
2481
+ const props = { ...defaultProps$2,
2482
+ ...userProps
2483
+ };
2484
+ const {
2485
+ items,
2486
+ scrollIntoView,
2487
+ environment,
2488
+ initialIsOpen,
2489
+ defaultIsOpen,
2490
+ itemToString,
2491
+ getA11ySelectionMessage,
2492
+ getA11yStatusMessage
2493
+ } = props; // Initial state depending on controlled props.
2494
+
2495
+ const initialState = getInitialState$2(props);
2496
+ const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
2497
+ const {
2498
+ isOpen,
2499
+ highlightedIndex,
2500
+ selectedItem,
2501
+ inputValue
2502
+ } = state; // Element efs.
2503
+
2504
+ const toggleButtonRef = react.useRef(null);
2505
+ const menuRef = react.useRef(null);
2506
+ const itemRefs = react.useRef({}); // used not to trigger menu blur action in some scenarios.
2507
+
2508
+ const shouldBlurRef = react.useRef(true); // used to keep the inputValue clearTimeout object between renders.
2509
+
2510
+ const clearTimeoutRef = react.useRef(null); // prevent id re-generation between renders.
2511
+
2512
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
2513
+
2514
+ const previousResultCountRef = react.useRef();
2515
+ const isInitialMountRef = react.useRef(true); // utility callback to get item element.
2516
+
2517
+ const latest = useLatestRef({
2518
+ state,
2519
+ props
2519
2520
  }); // Some utils.
2520
2521
 
2521
- var getItemNodeFromIndex = react.useCallback(function (index) {
2522
- return itemRefs.current[elementIds.getItemId(index)];
2523
- }, [elementIds]); // Effects.
2522
+ const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
2524
2523
  // Sets a11y status message on changes in state.
2525
2524
 
2526
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default['default']({
2525
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2527
2526
  isInitialMount: isInitialMountRef.current,
2528
2527
  previousResultCount: previousResultCountRef.current,
2529
- items: items,
2530
- environment: environment,
2531
- itemToString: itemToString
2532
- }, state)); // Sets a11y status message on changes in selectedItem.
2528
+ items,
2529
+ environment,
2530
+ itemToString,
2531
+ ...state
2532
+ }); // Sets a11y status message on changes in selectedItem.
2533
2533
 
2534
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default['default']({
2534
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2535
2535
  isInitialMount: isInitialMountRef.current,
2536
2536
  previousResultCount: previousResultCountRef.current,
2537
- items: items,
2538
- environment: environment,
2539
- itemToString: itemToString
2540
- }, state)); // Scroll on highlighted item if change comes from keyboard.
2537
+ items,
2538
+ environment,
2539
+ itemToString,
2540
+ ...state
2541
+ }); // Scroll on highlighted item if change comes from keyboard.
2541
2542
 
2542
- var shouldScrollRef = useScrollIntoView({
2543
+ const shouldScrollRef = useScrollIntoView({
2543
2544
  menuElement: menuRef.current,
2544
- highlightedIndex: highlightedIndex,
2545
- isOpen: isOpen,
2546
- itemRefs: itemRefs,
2547
- scrollIntoView: scrollIntoView,
2548
- getItemNodeFromIndex: getItemNodeFromIndex
2545
+ highlightedIndex,
2546
+ isOpen,
2547
+ itemRefs,
2548
+ scrollIntoView,
2549
+ getItemNodeFromIndex
2549
2550
  }); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2550
2551
 
2551
- react.useEffect(function () {
2552
+ react.useEffect(() => {
2552
2553
  // init the clean function here as we need access to dispatch.
2553
- clearTimeoutRef.current = debounce(function (outerDispatch) {
2554
+ clearTimeoutRef.current = debounce(outerDispatch => {
2554
2555
  outerDispatch({
2555
2556
  type: FunctionSetInputValue$1,
2556
2557
  inputValue: ''
2557
2558
  });
2558
2559
  }, 500); // Cancel any pending debounced calls on mount
2559
2560
 
2560
- return function () {
2561
+ return () => {
2561
2562
  clearTimeoutRef.current.cancel();
2562
2563
  };
2563
2564
  }, []); // Invokes the keysSoFar callback set up above.
2564
2565
 
2565
- react.useEffect(function () {
2566
+ react.useEffect(() => {
2566
2567
  if (!inputValue) {
2567
2568
  return;
2568
2569
  }
@@ -2571,12 +2572,12 @@ function useSelect(userProps) {
2571
2572
  }, [dispatch, inputValue]);
2572
2573
  useControlPropsValidator({
2573
2574
  isInitialMount: isInitialMountRef.current,
2574
- props: props,
2575
- state: state
2575
+ props,
2576
+ state
2576
2577
  });
2577
2578
  /* Controls the focus on the menu or the toggle button. */
2578
2579
 
2579
- react.useEffect(function () {
2580
+ react.useEffect(() => {
2580
2581
  // Don't focus menu on first render.
2581
2582
  if (isInitialMountRef.current) {
2582
2583
  // Unless it was initialised as open.
@@ -2607,7 +2608,7 @@ function useSelect(userProps) {
2607
2608
  } // eslint-disable-next-line react-hooks/exhaustive-deps
2608
2609
 
2609
2610
  }, [isOpen]);
2610
- react.useEffect(function () {
2611
+ react.useEffect(() => {
2611
2612
  if (isInitialMountRef.current) {
2612
2613
  return;
2613
2614
  }
@@ -2615,180 +2616,180 @@ function useSelect(userProps) {
2615
2616
  previousResultCountRef.current = items.length;
2616
2617
  }); // Add mouse/touch events to document.
2617
2618
 
2618
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2619
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
2619
2620
  dispatch({
2620
2621
  type: MenuBlur
2621
2622
  });
2622
2623
  });
2623
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2624
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2624
2625
 
2625
- react.useEffect(function () {
2626
+ react.useEffect(() => {
2626
2627
  isInitialMountRef.current = false;
2627
2628
  }, []); // Reset itemRefs on close.
2628
2629
 
2629
- react.useEffect(function () {
2630
+ react.useEffect(() => {
2630
2631
  if (!isOpen) {
2631
2632
  itemRefs.current = {};
2632
2633
  }
2633
2634
  }, [isOpen]); // Event handler functions.
2634
2635
 
2635
- var toggleButtonKeyDownHandlers = react.useMemo(function () {
2636
- return {
2637
- ArrowDown: function ArrowDown(event) {
2638
- event.preventDefault();
2639
- dispatch({
2640
- type: ToggleButtonKeyDownArrowDown,
2641
- getItemNodeFromIndex: getItemNodeFromIndex,
2642
- shiftKey: event.shiftKey
2643
- });
2644
- },
2645
- ArrowUp: function ArrowUp(event) {
2646
- event.preventDefault();
2647
- dispatch({
2648
- type: ToggleButtonKeyDownArrowUp,
2649
- getItemNodeFromIndex: getItemNodeFromIndex,
2650
- shiftKey: event.shiftKey
2651
- });
2652
- }
2653
- };
2654
- }, [dispatch, getItemNodeFromIndex]);
2655
- var menuKeyDownHandlers = react.useMemo(function () {
2656
- return {
2657
- ArrowDown: function ArrowDown(event) {
2658
- event.preventDefault();
2659
- dispatch({
2660
- type: MenuKeyDownArrowDown,
2661
- getItemNodeFromIndex: getItemNodeFromIndex,
2662
- shiftKey: event.shiftKey
2663
- });
2664
- },
2665
- ArrowUp: function ArrowUp(event) {
2666
- event.preventDefault();
2667
- dispatch({
2668
- type: MenuKeyDownArrowUp,
2669
- getItemNodeFromIndex: getItemNodeFromIndex,
2670
- shiftKey: event.shiftKey
2671
- });
2672
- },
2673
- Home: function Home(event) {
2674
- event.preventDefault();
2675
- dispatch({
2676
- type: MenuKeyDownHome,
2677
- getItemNodeFromIndex: getItemNodeFromIndex
2678
- });
2679
- },
2680
- End: function End(event) {
2681
- event.preventDefault();
2682
- dispatch({
2683
- type: MenuKeyDownEnd,
2684
- getItemNodeFromIndex: getItemNodeFromIndex
2685
- });
2686
- },
2687
- Escape: function Escape() {
2688
- dispatch({
2689
- type: MenuKeyDownEscape
2690
- });
2691
- },
2692
- Enter: function Enter(event) {
2693
- event.preventDefault();
2694
- dispatch({
2695
- type: MenuKeyDownEnter
2696
- });
2697
- },
2698
- ' ': function _(event) {
2699
- event.preventDefault();
2700
- dispatch({
2701
- type: MenuKeyDownSpaceButton
2702
- });
2703
- }
2704
- };
2705
- }, [dispatch, getItemNodeFromIndex]); // Action functions.
2636
+ const toggleButtonKeyDownHandlers = react.useMemo(() => ({
2637
+ ArrowDown(event) {
2638
+ event.preventDefault();
2639
+ dispatch({
2640
+ type: ToggleButtonKeyDownArrowDown,
2641
+ getItemNodeFromIndex,
2642
+ shiftKey: event.shiftKey
2643
+ });
2644
+ },
2706
2645
 
2707
- var toggleMenu = react.useCallback(function () {
2646
+ ArrowUp(event) {
2647
+ event.preventDefault();
2648
+ dispatch({
2649
+ type: ToggleButtonKeyDownArrowUp,
2650
+ getItemNodeFromIndex,
2651
+ shiftKey: event.shiftKey
2652
+ });
2653
+ }
2654
+
2655
+ }), [dispatch, getItemNodeFromIndex]);
2656
+ const menuKeyDownHandlers = react.useMemo(() => ({
2657
+ ArrowDown(event) {
2658
+ event.preventDefault();
2659
+ dispatch({
2660
+ type: MenuKeyDownArrowDown,
2661
+ getItemNodeFromIndex,
2662
+ shiftKey: event.shiftKey
2663
+ });
2664
+ },
2665
+
2666
+ ArrowUp(event) {
2667
+ event.preventDefault();
2668
+ dispatch({
2669
+ type: MenuKeyDownArrowUp,
2670
+ getItemNodeFromIndex,
2671
+ shiftKey: event.shiftKey
2672
+ });
2673
+ },
2674
+
2675
+ Home(event) {
2676
+ event.preventDefault();
2677
+ dispatch({
2678
+ type: MenuKeyDownHome,
2679
+ getItemNodeFromIndex
2680
+ });
2681
+ },
2682
+
2683
+ End(event) {
2684
+ event.preventDefault();
2685
+ dispatch({
2686
+ type: MenuKeyDownEnd,
2687
+ getItemNodeFromIndex
2688
+ });
2689
+ },
2690
+
2691
+ Escape() {
2692
+ dispatch({
2693
+ type: MenuKeyDownEscape
2694
+ });
2695
+ },
2696
+
2697
+ Enter(event) {
2698
+ event.preventDefault();
2699
+ dispatch({
2700
+ type: MenuKeyDownEnter
2701
+ });
2702
+ },
2703
+
2704
+ ' '(event) {
2705
+ event.preventDefault();
2706
+ dispatch({
2707
+ type: MenuKeyDownSpaceButton
2708
+ });
2709
+ }
2710
+
2711
+ }), [dispatch, getItemNodeFromIndex]); // Action functions.
2712
+
2713
+ const toggleMenu = react.useCallback(() => {
2708
2714
  dispatch({
2709
2715
  type: FunctionToggleMenu$1
2710
2716
  });
2711
2717
  }, [dispatch]);
2712
- var closeMenu = react.useCallback(function () {
2718
+ const closeMenu = react.useCallback(() => {
2713
2719
  dispatch({
2714
2720
  type: FunctionCloseMenu$1
2715
2721
  });
2716
2722
  }, [dispatch]);
2717
- var openMenu = react.useCallback(function () {
2723
+ const openMenu = react.useCallback(() => {
2718
2724
  dispatch({
2719
2725
  type: FunctionOpenMenu$1
2720
2726
  });
2721
2727
  }, [dispatch]);
2722
- var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
2728
+ const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
2723
2729
  dispatch({
2724
2730
  type: FunctionSetHighlightedIndex$1,
2725
2731
  highlightedIndex: newHighlightedIndex
2726
2732
  });
2727
2733
  }, [dispatch]);
2728
- var selectItem = react.useCallback(function (newSelectedItem) {
2734
+ const selectItem = react.useCallback(newSelectedItem => {
2729
2735
  dispatch({
2730
2736
  type: FunctionSelectItem$1,
2731
2737
  selectedItem: newSelectedItem
2732
2738
  });
2733
2739
  }, [dispatch]);
2734
- var reset = react.useCallback(function () {
2740
+ const reset = react.useCallback(() => {
2735
2741
  dispatch({
2736
2742
  type: FunctionReset$2
2737
2743
  });
2738
2744
  }, [dispatch]);
2739
- var setInputValue = react.useCallback(function (newInputValue) {
2745
+ const setInputValue = react.useCallback(newInputValue => {
2740
2746
  dispatch({
2741
2747
  type: FunctionSetInputValue$1,
2742
2748
  inputValue: newInputValue
2743
2749
  });
2744
2750
  }, [dispatch]); // Getter functions.
2745
2751
 
2746
- var getLabelProps = react.useCallback(function (labelProps) {
2747
- return _extends__default['default']({
2748
- id: elementIds.labelId,
2749
- htmlFor: elementIds.toggleButtonId
2750
- }, labelProps);
2751
- }, [elementIds]);
2752
- var getMenuProps = react.useCallback(function (_temp, _temp2) {
2753
- var _extends2;
2754
-
2755
- var _ref = _temp === void 0 ? {} : _temp,
2756
- onMouseLeave = _ref.onMouseLeave,
2757
- _ref$refKey = _ref.refKey,
2758
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
2759
- onKeyDown = _ref.onKeyDown,
2760
- onBlur = _ref.onBlur,
2761
- ref = _ref.ref,
2762
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$2);
2763
-
2764
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
2765
- _ref2$suppressRefErro = _ref2.suppressRefError,
2766
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
2767
-
2768
- var latestState = latest.current.state;
2769
-
2770
- var menuHandleKeyDown = function menuHandleKeyDown(event) {
2771
- var key = normalizeArrowKey(event);
2752
+ const getLabelProps = react.useCallback(labelProps => ({
2753
+ id: elementIds.labelId,
2754
+ htmlFor: elementIds.toggleButtonId,
2755
+ ...labelProps
2756
+ }), [elementIds]);
2757
+ const getMenuProps = react.useCallback(function (_temp, _temp2) {
2758
+ let {
2759
+ onMouseLeave,
2760
+ refKey = 'ref',
2761
+ onKeyDown,
2762
+ onBlur,
2763
+ ref,
2764
+ ...rest
2765
+ } = _temp === void 0 ? {} : _temp;
2766
+ let {
2767
+ suppressRefError = false
2768
+ } = _temp2 === void 0 ? {} : _temp2;
2769
+ const latestState = latest.current.state;
2770
+
2771
+ const menuHandleKeyDown = event => {
2772
+ const key = normalizeArrowKey(event);
2772
2773
 
2773
2774
  if (key && menuKeyDownHandlers[key]) {
2774
2775
  menuKeyDownHandlers[key](event);
2775
2776
  } else if (isAcceptedCharacterKey(key)) {
2776
2777
  dispatch({
2777
2778
  type: MenuKeyDownCharacter,
2778
- key: key,
2779
- getItemNodeFromIndex: getItemNodeFromIndex
2779
+ key,
2780
+ getItemNodeFromIndex
2780
2781
  });
2781
2782
  }
2782
2783
  };
2783
2784
 
2784
- var menuHandleBlur = function menuHandleBlur() {
2785
+ const menuHandleBlur = () => {
2785
2786
  // if the blur was a result of selection, we don't trigger this action.
2786
2787
  if (shouldBlurRef.current === false) {
2787
2788
  shouldBlurRef.current = true;
2788
2789
  return;
2789
2790
  }
2790
2791
 
2791
- var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2792
+ const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2792
2793
  /* istanbul ignore else */
2793
2794
 
2794
2795
  if (shouldBlur) {
@@ -2798,61 +2799,72 @@ function useSelect(userProps) {
2798
2799
  }
2799
2800
  };
2800
2801
 
2801
- var menuHandleMouseLeave = function menuHandleMouseLeave() {
2802
+ const menuHandleMouseLeave = () => {
2802
2803
  dispatch({
2803
2804
  type: MenuMouseLeave$1
2804
2805
  });
2805
2806
  };
2806
2807
 
2807
2808
  setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
2808
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
2809
- menuRef.current = menuNode;
2810
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.tabIndex = -1, _extends2), latestState.isOpen && latestState.highlightedIndex > -1 && {
2811
- 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
2812
- }, {
2809
+ return {
2810
+ [refKey]: handleRefs(ref, menuNode => {
2811
+ menuRef.current = menuNode;
2812
+ }),
2813
+ id: elementIds.menuId,
2814
+ role: 'listbox',
2815
+ 'aria-labelledby': elementIds.labelId,
2816
+ tabIndex: -1,
2817
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
2818
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
2819
+ }),
2813
2820
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
2814
2821
  onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
2815
- onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
2816
- }, rest);
2822
+ onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
2823
+ ...rest
2824
+ };
2817
2825
  }, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
2818
- var getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
2819
- var _extends3;
2820
-
2821
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
2822
- onClick = _ref3.onClick,
2823
- onKeyDown = _ref3.onKeyDown,
2824
- _ref3$refKey = _ref3.refKey,
2825
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
2826
- ref = _ref3.ref,
2827
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$2);
2828
-
2829
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
2830
- _ref4$suppressRefErro = _ref4.suppressRefError,
2831
- suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
2832
-
2833
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
2826
+ const getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
2827
+ let {
2828
+ onClick,
2829
+ onKeyDown,
2830
+ refKey = 'ref',
2831
+ ref,
2832
+ ...rest
2833
+ } = _temp3 === void 0 ? {} : _temp3;
2834
+ let {
2835
+ suppressRefError = false
2836
+ } = _temp4 === void 0 ? {} : _temp4;
2837
+
2838
+ const toggleButtonHandleClick = () => {
2834
2839
  dispatch({
2835
2840
  type: ToggleButtonClick$1
2836
2841
  });
2837
2842
  };
2838
2843
 
2839
- var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2840
- var key = normalizeArrowKey(event);
2844
+ const toggleButtonHandleKeyDown = event => {
2845
+ const key = normalizeArrowKey(event);
2841
2846
 
2842
2847
  if (key && toggleButtonKeyDownHandlers[key]) {
2843
2848
  toggleButtonKeyDownHandlers[key](event);
2844
2849
  } else if (isAcceptedCharacterKey(key)) {
2845
2850
  dispatch({
2846
2851
  type: ToggleButtonKeyDownCharacter,
2847
- key: key,
2848
- getItemNodeFromIndex: getItemNodeFromIndex
2852
+ key,
2853
+ getItemNodeFromIndex
2849
2854
  });
2850
2855
  }
2851
2856
  };
2852
2857
 
2853
- var toggleProps = _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
2854
- toggleButtonRef.current = toggleButtonNode;
2855
- }), _extends3.id = elementIds.toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-labelledby'] = elementIds.labelId + " " + elementIds.toggleButtonId, _extends3), rest);
2858
+ const toggleProps = {
2859
+ [refKey]: handleRefs(ref, toggleButtonNode => {
2860
+ toggleButtonRef.current = toggleButtonNode;
2861
+ }),
2862
+ id: elementIds.toggleButtonId,
2863
+ 'aria-haspopup': 'listbox',
2864
+ 'aria-expanded': latest.current.state.isOpen,
2865
+ 'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
2866
+ ...rest
2867
+ };
2856
2868
 
2857
2869
  if (!rest.disabled) {
2858
2870
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
@@ -2862,24 +2874,22 @@ function useSelect(userProps) {
2862
2874
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2863
2875
  return toggleProps;
2864
2876
  }, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
2865
- var getItemProps = react.useCallback(function (_temp5) {
2866
- var _extends4;
2867
-
2868
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
2869
- item = _ref5.item,
2870
- index = _ref5.index,
2871
- onMouseMove = _ref5.onMouseMove,
2872
- onClick = _ref5.onClick,
2873
- _ref5$refKey = _ref5.refKey,
2874
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
2875
- ref = _ref5.ref,
2876
- rest = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded3$1);
2877
-
2878
- var _latest$current = latest.current,
2879
- latestState = _latest$current.state,
2880
- latestProps = _latest$current.props;
2881
-
2882
- var itemHandleMouseMove = function itemHandleMouseMove() {
2877
+ const getItemProps = react.useCallback(function (_temp5) {
2878
+ let {
2879
+ item,
2880
+ index,
2881
+ onMouseMove,
2882
+ onClick,
2883
+ refKey = 'ref',
2884
+ ref,
2885
+ ...rest
2886
+ } = _temp5 === void 0 ? {} : _temp5;
2887
+ const {
2888
+ state: latestState,
2889
+ props: latestProps
2890
+ } = latest.current;
2891
+
2892
+ const itemHandleMouseMove = () => {
2883
2893
  if (index === latestState.highlightedIndex) {
2884
2894
  return;
2885
2895
  }
@@ -2887,32 +2897,34 @@ function useSelect(userProps) {
2887
2897
  shouldScrollRef.current = false;
2888
2898
  dispatch({
2889
2899
  type: ItemMouseMove$1,
2890
- index: index
2900
+ index
2891
2901
  });
2892
2902
  };
2893
2903
 
2894
- var itemHandleClick = function itemHandleClick() {
2904
+ const itemHandleClick = () => {
2895
2905
  dispatch({
2896
2906
  type: ItemClick$1,
2897
- index: index
2907
+ index
2898
2908
  });
2899
2909
  };
2900
2910
 
2901
- var itemIndex = getItemIndex(index, item, latestProps.items);
2911
+ const itemIndex = getItemIndex(index, item, latestProps.items);
2902
2912
 
2903
2913
  if (itemIndex < 0) {
2904
2914
  throw new Error('Pass either item or item index in getItemProps!');
2905
2915
  }
2906
2916
 
2907
- var itemProps = _extends__default['default']((_extends4 = {
2917
+ const itemProps = {
2908
2918
  role: 'option',
2909
2919
  'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
2910
- id: elementIds.getItemId(itemIndex)
2911
- }, _extends4[refKey] = handleRefs(ref, function (itemNode) {
2912
- if (itemNode) {
2913
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2914
- }
2915
- }), _extends4), rest);
2920
+ id: elementIds.getItemId(itemIndex),
2921
+ [refKey]: handleRefs(ref, itemNode => {
2922
+ if (itemNode) {
2923
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2924
+ }
2925
+ }),
2926
+ ...rest
2927
+ };
2916
2928
 
2917
2929
  if (!rest.disabled) {
2918
2930
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
@@ -2923,46 +2935,46 @@ function useSelect(userProps) {
2923
2935
  }, [dispatch, latest, shouldScrollRef, elementIds]);
2924
2936
  return {
2925
2937
  // prop getters.
2926
- getToggleButtonProps: getToggleButtonProps,
2927
- getLabelProps: getLabelProps,
2928
- getMenuProps: getMenuProps,
2929
- getItemProps: getItemProps,
2938
+ getToggleButtonProps,
2939
+ getLabelProps,
2940
+ getMenuProps,
2941
+ getItemProps,
2930
2942
  // actions.
2931
- toggleMenu: toggleMenu,
2932
- openMenu: openMenu,
2933
- closeMenu: closeMenu,
2934
- setHighlightedIndex: setHighlightedIndex,
2935
- selectItem: selectItem,
2936
- reset: reset,
2937
- setInputValue: setInputValue,
2943
+ toggleMenu,
2944
+ openMenu,
2945
+ closeMenu,
2946
+ setHighlightedIndex,
2947
+ selectItem,
2948
+ reset,
2949
+ setInputValue,
2938
2950
  // state.
2939
- highlightedIndex: highlightedIndex,
2940
- isOpen: isOpen,
2941
- selectedItem: selectedItem,
2942
- inputValue: inputValue
2951
+ highlightedIndex,
2952
+ isOpen,
2953
+ selectedItem,
2954
+ inputValue
2943
2955
  };
2944
2956
  }
2945
2957
 
2946
- var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2947
- var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2948
- var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2949
- var InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2950
- var InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2951
- var InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
2952
- var InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
2953
- var InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
2954
- var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
2955
- var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
2956
- var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
2957
- var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
2958
- var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
2959
- var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
2960
- var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
2961
- var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
2962
- var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
2963
- var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
2964
- var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
2965
- var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
2958
+ const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
2959
+ const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
2960
+ const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
2961
+ const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
2962
+ const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
2963
+ const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
2964
+ const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
2965
+ const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
2966
+ const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
2967
+ const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
2968
+ const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
2969
+ const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
2970
+ const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
2971
+ const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
2972
+ const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
2973
+ const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
2974
+ const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
2975
+ const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
2976
+ const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
2977
+ const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
2966
2978
 
2967
2979
  var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2968
2980
  __proto__: null,
@@ -2989,56 +3001,60 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
2989
3001
  });
2990
3002
 
2991
3003
  function getInitialState$1(props) {
2992
- var initialState = getInitialState$2(props);
2993
- var selectedItem = initialState.selectedItem;
2994
- var inputValue = initialState.inputValue;
3004
+ const initialState = getInitialState$2(props);
3005
+ const {
3006
+ selectedItem
3007
+ } = initialState;
3008
+ let {
3009
+ inputValue
3010
+ } = initialState;
2995
3011
 
2996
3012
  if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
2997
3013
  inputValue = props.itemToString(selectedItem);
2998
3014
  }
2999
3015
 
3000
- return _extends__default['default']({}, initialState, {
3001
- inputValue: inputValue
3002
- });
3016
+ return { ...initialState,
3017
+ inputValue
3018
+ };
3003
3019
  }
3004
3020
 
3005
- var propTypes$1 = {
3006
- items: PropTypes__default['default'].array.isRequired,
3007
- itemToString: PropTypes__default['default'].func,
3008
- getA11yStatusMessage: PropTypes__default['default'].func,
3009
- getA11ySelectionMessage: PropTypes__default['default'].func,
3010
- circularNavigation: PropTypes__default['default'].bool,
3011
- highlightedIndex: PropTypes__default['default'].number,
3012
- defaultHighlightedIndex: PropTypes__default['default'].number,
3013
- initialHighlightedIndex: PropTypes__default['default'].number,
3014
- isOpen: PropTypes__default['default'].bool,
3015
- defaultIsOpen: PropTypes__default['default'].bool,
3016
- initialIsOpen: PropTypes__default['default'].bool,
3017
- selectedItem: PropTypes__default['default'].any,
3018
- initialSelectedItem: PropTypes__default['default'].any,
3019
- defaultSelectedItem: PropTypes__default['default'].any,
3020
- inputValue: PropTypes__default['default'].string,
3021
- defaultInputValue: PropTypes__default['default'].string,
3022
- initialInputValue: PropTypes__default['default'].string,
3023
- id: PropTypes__default['default'].string,
3024
- labelId: PropTypes__default['default'].string,
3025
- menuId: PropTypes__default['default'].string,
3026
- getItemId: PropTypes__default['default'].func,
3027
- inputId: PropTypes__default['default'].string,
3028
- toggleButtonId: PropTypes__default['default'].string,
3029
- stateReducer: PropTypes__default['default'].func,
3030
- onSelectedItemChange: PropTypes__default['default'].func,
3031
- onHighlightedIndexChange: PropTypes__default['default'].func,
3032
- onStateChange: PropTypes__default['default'].func,
3033
- onIsOpenChange: PropTypes__default['default'].func,
3034
- onInputValueChange: PropTypes__default['default'].func,
3035
- environment: PropTypes__default['default'].shape({
3036
- addEventListener: PropTypes__default['default'].func,
3037
- removeEventListener: PropTypes__default['default'].func,
3038
- document: PropTypes__default['default'].shape({
3039
- getElementById: PropTypes__default['default'].func,
3040
- activeElement: PropTypes__default['default'].any,
3041
- body: PropTypes__default['default'].any
3021
+ const propTypes$1 = {
3022
+ items: PropTypes__default["default"].array.isRequired,
3023
+ itemToString: PropTypes__default["default"].func,
3024
+ getA11yStatusMessage: PropTypes__default["default"].func,
3025
+ getA11ySelectionMessage: PropTypes__default["default"].func,
3026
+ circularNavigation: PropTypes__default["default"].bool,
3027
+ highlightedIndex: PropTypes__default["default"].number,
3028
+ defaultHighlightedIndex: PropTypes__default["default"].number,
3029
+ initialHighlightedIndex: PropTypes__default["default"].number,
3030
+ isOpen: PropTypes__default["default"].bool,
3031
+ defaultIsOpen: PropTypes__default["default"].bool,
3032
+ initialIsOpen: PropTypes__default["default"].bool,
3033
+ selectedItem: PropTypes__default["default"].any,
3034
+ initialSelectedItem: PropTypes__default["default"].any,
3035
+ defaultSelectedItem: PropTypes__default["default"].any,
3036
+ inputValue: PropTypes__default["default"].string,
3037
+ defaultInputValue: PropTypes__default["default"].string,
3038
+ initialInputValue: PropTypes__default["default"].string,
3039
+ id: PropTypes__default["default"].string,
3040
+ labelId: PropTypes__default["default"].string,
3041
+ menuId: PropTypes__default["default"].string,
3042
+ getItemId: PropTypes__default["default"].func,
3043
+ inputId: PropTypes__default["default"].string,
3044
+ toggleButtonId: PropTypes__default["default"].string,
3045
+ stateReducer: PropTypes__default["default"].func,
3046
+ onSelectedItemChange: PropTypes__default["default"].func,
3047
+ onHighlightedIndexChange: PropTypes__default["default"].func,
3048
+ onStateChange: PropTypes__default["default"].func,
3049
+ onIsOpenChange: PropTypes__default["default"].func,
3050
+ onInputValueChange: PropTypes__default["default"].func,
3051
+ environment: PropTypes__default["default"].shape({
3052
+ addEventListener: PropTypes__default["default"].func,
3053
+ removeEventListener: PropTypes__default["default"].func,
3054
+ document: PropTypes__default["default"].shape({
3055
+ getElementById: PropTypes__default["default"].func,
3056
+ activeElement: PropTypes__default["default"].any,
3057
+ body: PropTypes__default["default"].any
3042
3058
  })
3043
3059
  })
3044
3060
  };
@@ -3056,14 +3072,10 @@ var propTypes$1 = {
3056
3072
  */
3057
3073
 
3058
3074
  function useControlledReducer(reducer, initialState, props) {
3059
- var previousSelectedItemRef = react.useRef();
3060
-
3061
- var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
3062
- state = _useEnhancedReducer[0],
3063
- dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
3075
+ const previousSelectedItemRef = react.useRef();
3076
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
3064
3077
 
3065
-
3066
- react.useEffect(function () {
3078
+ react.useEffect(() => {
3067
3079
  if (isControlledProp(props, 'selectedItem')) {
3068
3080
  if (previousSelectedItemRef.current !== props.selectedItem) {
3069
3081
  dispatch({
@@ -3079,27 +3091,29 @@ function useControlledReducer(reducer, initialState, props) {
3079
3091
  } // eslint-disable-next-line import/no-mutable-exports
3080
3092
 
3081
3093
 
3082
- var validatePropTypes$1 = noop;
3094
+ let validatePropTypes$1 = noop;
3083
3095
  /* istanbul ignore next */
3084
3096
 
3085
3097
  if (process.env.NODE_ENV !== 'production') {
3086
- validatePropTypes$1 = function validatePropTypes(options, caller) {
3087
- PropTypes__default['default'].checkPropTypes(propTypes$1, options, 'prop', caller.name);
3098
+ validatePropTypes$1 = (options, caller) => {
3099
+ PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
3088
3100
  };
3089
3101
  }
3090
3102
 
3091
- var defaultProps$1 = _extends__default['default']({}, defaultProps$3, {
3103
+ const defaultProps$1 = { ...defaultProps$3,
3092
3104
  getA11yStatusMessage: getA11yStatusMessage$1,
3093
3105
  circularNavigation: true
3094
- });
3106
+ };
3095
3107
 
3096
3108
  /* eslint-disable complexity */
3097
3109
 
3098
3110
  function downshiftUseComboboxReducer(state, action) {
3099
- var type = action.type,
3100
- props = action.props,
3101
- shiftKey = action.shiftKey;
3102
- var changes;
3111
+ const {
3112
+ type,
3113
+ props,
3114
+ shiftKey
3115
+ } = action;
3116
+ let changes;
3103
3117
 
3104
3118
  switch (type) {
3105
3119
  case ItemClick:
@@ -3140,22 +3154,24 @@ function downshiftUseComboboxReducer(state, action) {
3140
3154
  break;
3141
3155
 
3142
3156
  case InputKeyDownEnter:
3143
- changes = _extends__default['default']({}, state.isOpen && state.highlightedIndex >= 0 && {
3144
- selectedItem: props.items[state.highlightedIndex],
3145
- isOpen: getDefaultValue$1(props, 'isOpen'),
3146
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
3147
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3148
- });
3157
+ changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
3158
+ selectedItem: props.items[state.highlightedIndex],
3159
+ isOpen: getDefaultValue$1(props, 'isOpen'),
3160
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
3161
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3162
+ })
3163
+ };
3149
3164
  break;
3150
3165
 
3151
3166
  case InputKeyDownEscape:
3152
- changes = _extends__default['default']({
3167
+ changes = {
3153
3168
  isOpen: false,
3154
- highlightedIndex: -1
3155
- }, !state.isOpen && {
3156
- selectedItem: null,
3157
- inputValue: ''
3158
- });
3169
+ highlightedIndex: -1,
3170
+ ...(!state.isOpen && {
3171
+ selectedItem: null,
3172
+ inputValue: ''
3173
+ })
3174
+ };
3159
3175
  break;
3160
3176
 
3161
3177
  case InputKeyDownHome:
@@ -3171,13 +3187,14 @@ function downshiftUseComboboxReducer(state, action) {
3171
3187
  break;
3172
3188
 
3173
3189
  case InputBlur:
3174
- changes = _extends__default['default']({
3190
+ changes = {
3175
3191
  isOpen: false,
3176
- highlightedIndex: -1
3177
- }, state.highlightedIndex >= 0 && action.selectItem && {
3178
- selectedItem: props.items[state.highlightedIndex],
3179
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3180
- });
3192
+ highlightedIndex: -1,
3193
+ ...(state.highlightedIndex >= 0 && action.selectItem && {
3194
+ selectedItem: props.items[state.highlightedIndex],
3195
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3196
+ })
3197
+ };
3181
3198
  break;
3182
3199
 
3183
3200
  case InputChange:
@@ -3205,15 +3222,13 @@ function downshiftUseComboboxReducer(state, action) {
3205
3222
  return downshiftCommonReducer(state, action, stateChangeTypes$1);
3206
3223
  }
3207
3224
 
3208
- return _extends__default['default']({}, state, changes);
3225
+ return { ...state,
3226
+ ...changes
3227
+ };
3209
3228
  }
3210
3229
  /* eslint-enable complexity */
3211
3230
 
3212
- var _excluded$1 = ["onMouseLeave", "refKey", "ref"],
3213
- _excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"],
3214
- _excluded3 = ["onClick", "onPress", "refKey", "ref"],
3215
- _excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"],
3216
- _excluded5 = ["refKey", "ref"];
3231
+ /* eslint-disable max-statements */
3217
3232
  useCombobox.stateChangeTypes = stateChangeTypes$1;
3218
3233
 
3219
3234
  function useCombobox(userProps) {
@@ -3223,87 +3238,88 @@ function useCombobox(userProps) {
3223
3238
 
3224
3239
  validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
3225
3240
 
3226
- var props = _extends__default['default']({}, defaultProps$1, userProps);
3227
-
3228
- var initialIsOpen = props.initialIsOpen,
3229
- defaultIsOpen = props.defaultIsOpen,
3230
- items = props.items,
3231
- scrollIntoView = props.scrollIntoView,
3232
- environment = props.environment,
3233
- getA11yStatusMessage = props.getA11yStatusMessage,
3234
- getA11ySelectionMessage = props.getA11ySelectionMessage,
3235
- itemToString = props.itemToString; // Initial state depending on controlled props.
3236
-
3237
- var initialState = getInitialState$1(props);
3238
-
3239
- var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
3240
- state = _useControlledReducer[0],
3241
- dispatch = _useControlledReducer[1];
3242
-
3243
- var isOpen = state.isOpen,
3244
- highlightedIndex = state.highlightedIndex,
3245
- selectedItem = state.selectedItem,
3246
- inputValue = state.inputValue; // Element refs.
3247
-
3248
- var menuRef = react.useRef(null);
3249
- var itemRefs = react.useRef({});
3250
- var inputRef = react.useRef(null);
3251
- var toggleButtonRef = react.useRef(null);
3252
- var comboboxRef = react.useRef(null);
3253
- var isInitialMountRef = react.useRef(true); // prevent id re-generation between renders.
3254
-
3255
- var elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
3256
-
3257
- var previousResultCountRef = react.useRef(); // utility callback to get item element.
3258
-
3259
- var latest = useLatestRef({
3260
- state: state,
3261
- props: props
3241
+ const props = { ...defaultProps$1,
3242
+ ...userProps
3243
+ };
3244
+ const {
3245
+ initialIsOpen,
3246
+ defaultIsOpen,
3247
+ items,
3248
+ scrollIntoView,
3249
+ environment,
3250
+ getA11yStatusMessage,
3251
+ getA11ySelectionMessage,
3252
+ itemToString
3253
+ } = props; // Initial state depending on controlled props.
3254
+
3255
+ const initialState = getInitialState$1(props);
3256
+ const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
3257
+ const {
3258
+ isOpen,
3259
+ highlightedIndex,
3260
+ selectedItem,
3261
+ inputValue
3262
+ } = state; // Element refs.
3263
+
3264
+ const menuRef = react.useRef(null);
3265
+ const itemRefs = react.useRef({});
3266
+ const inputRef = react.useRef(null);
3267
+ const toggleButtonRef = react.useRef(null);
3268
+ const comboboxRef = react.useRef(null);
3269
+ const isInitialMountRef = react.useRef(true); // prevent id re-generation between renders.
3270
+
3271
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
3272
+
3273
+ const previousResultCountRef = react.useRef(); // utility callback to get item element.
3274
+
3275
+ const latest = useLatestRef({
3276
+ state,
3277
+ props
3262
3278
  });
3263
- var getItemNodeFromIndex = react.useCallback(function (index) {
3264
- return itemRefs.current[elementIds.getItemId(index)];
3265
- }, [elementIds]); // Effects.
3279
+ const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
3266
3280
  // Sets a11y status message on changes in state.
3267
3281
 
3268
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends__default['default']({
3282
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
3269
3283
  isInitialMount: isInitialMountRef.current,
3270
3284
  previousResultCount: previousResultCountRef.current,
3271
- items: items,
3272
- environment: environment,
3273
- itemToString: itemToString
3274
- }, state)); // Sets a11y status message on changes in selectedItem.
3285
+ items,
3286
+ environment,
3287
+ itemToString,
3288
+ ...state
3289
+ }); // Sets a11y status message on changes in selectedItem.
3275
3290
 
3276
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends__default['default']({
3291
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
3277
3292
  isInitialMount: isInitialMountRef.current,
3278
3293
  previousResultCount: previousResultCountRef.current,
3279
- items: items,
3280
- environment: environment,
3281
- itemToString: itemToString
3282
- }, state)); // Scroll on highlighted item if change comes from keyboard.
3294
+ items,
3295
+ environment,
3296
+ itemToString,
3297
+ ...state
3298
+ }); // Scroll on highlighted item if change comes from keyboard.
3283
3299
 
3284
- var shouldScrollRef = useScrollIntoView({
3300
+ const shouldScrollRef = useScrollIntoView({
3285
3301
  menuElement: menuRef.current,
3286
- highlightedIndex: highlightedIndex,
3287
- isOpen: isOpen,
3288
- itemRefs: itemRefs,
3289
- scrollIntoView: scrollIntoView,
3290
- getItemNodeFromIndex: getItemNodeFromIndex
3302
+ highlightedIndex,
3303
+ isOpen,
3304
+ itemRefs,
3305
+ scrollIntoView,
3306
+ getItemNodeFromIndex
3291
3307
  });
3292
3308
  useControlPropsValidator({
3293
3309
  isInitialMount: isInitialMountRef.current,
3294
- props: props,
3295
- state: state
3310
+ props,
3311
+ state
3296
3312
  }); // Focus the input on first render if required.
3297
3313
 
3298
- react.useEffect(function () {
3299
- var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3314
+ react.useEffect(() => {
3315
+ const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3300
3316
 
3301
3317
  if (focusOnOpen && inputRef.current) {
3302
3318
  inputRef.current.focus();
3303
3319
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3304
3320
 
3305
3321
  }, []);
3306
- react.useEffect(function () {
3322
+ react.useEffect(() => {
3307
3323
  if (isInitialMountRef.current) {
3308
3324
  return;
3309
3325
  }
@@ -3311,149 +3327,153 @@ function useCombobox(userProps) {
3311
3327
  previousResultCountRef.current = items.length;
3312
3328
  }); // Add mouse/touch events to document.
3313
3329
 
3314
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, function () {
3330
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
3315
3331
  dispatch({
3316
3332
  type: InputBlur,
3317
3333
  selectItem: false
3318
3334
  });
3319
3335
  });
3320
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3336
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3321
3337
 
3322
- react.useEffect(function () {
3338
+ react.useEffect(() => {
3323
3339
  isInitialMountRef.current = false;
3324
3340
  }, []); // Reset itemRefs on close.
3325
3341
 
3326
- react.useEffect(function () {
3342
+ react.useEffect(() => {
3327
3343
  if (!isOpen) {
3328
3344
  itemRefs.current = {};
3329
3345
  }
3330
3346
  }, [isOpen]);
3331
3347
  /* Event handler functions */
3332
3348
 
3333
- var inputKeyDownHandlers = react.useMemo(function () {
3334
- return {
3335
- ArrowDown: function ArrowDown(event) {
3336
- event.preventDefault();
3337
- dispatch({
3338
- type: InputKeyDownArrowDown,
3339
- shiftKey: event.shiftKey,
3340
- getItemNodeFromIndex: getItemNodeFromIndex
3341
- });
3342
- },
3343
- ArrowUp: function ArrowUp(event) {
3344
- event.preventDefault();
3345
- dispatch({
3346
- type: InputKeyDownArrowUp,
3347
- shiftKey: event.shiftKey,
3348
- getItemNodeFromIndex: getItemNodeFromIndex
3349
- });
3350
- },
3351
- Home: function Home(event) {
3352
- if (!latest.current.state.isOpen) {
3353
- return;
3354
- }
3349
+ const inputKeyDownHandlers = react.useMemo(() => ({
3350
+ ArrowDown(event) {
3351
+ event.preventDefault();
3352
+ dispatch({
3353
+ type: InputKeyDownArrowDown,
3354
+ shiftKey: event.shiftKey,
3355
+ getItemNodeFromIndex
3356
+ });
3357
+ },
3355
3358
 
3356
- event.preventDefault();
3357
- dispatch({
3358
- type: InputKeyDownHome,
3359
- getItemNodeFromIndex: getItemNodeFromIndex
3360
- });
3361
- },
3362
- End: function End(event) {
3363
- if (!latest.current.state.isOpen) {
3364
- return;
3365
- }
3359
+ ArrowUp(event) {
3360
+ event.preventDefault();
3361
+ dispatch({
3362
+ type: InputKeyDownArrowUp,
3363
+ shiftKey: event.shiftKey,
3364
+ getItemNodeFromIndex
3365
+ });
3366
+ },
3366
3367
 
3367
- event.preventDefault();
3368
- dispatch({
3369
- type: InputKeyDownEnd,
3370
- getItemNodeFromIndex: getItemNodeFromIndex
3371
- });
3372
- },
3373
- Escape: function Escape() {
3374
- var latestState = latest.current.state;
3368
+ Home(event) {
3369
+ if (!latest.current.state.isOpen) {
3370
+ return;
3371
+ }
3375
3372
 
3376
- if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3377
- dispatch({
3378
- type: InputKeyDownEscape
3379
- });
3380
- }
3381
- },
3382
- Enter: function Enter(event) {
3383
- var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3373
+ event.preventDefault();
3374
+ dispatch({
3375
+ type: InputKeyDownHome,
3376
+ getItemNodeFromIndex
3377
+ });
3378
+ },
3384
3379
 
3385
- if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3386
- ) {
3387
- return;
3388
- }
3380
+ End(event) {
3381
+ if (!latest.current.state.isOpen) {
3382
+ return;
3383
+ }
3389
3384
 
3390
- event.preventDefault();
3385
+ event.preventDefault();
3386
+ dispatch({
3387
+ type: InputKeyDownEnd,
3388
+ getItemNodeFromIndex
3389
+ });
3390
+ },
3391
+
3392
+ Escape() {
3393
+ const latestState = latest.current.state;
3394
+
3395
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3391
3396
  dispatch({
3392
- type: InputKeyDownEnter,
3393
- getItemNodeFromIndex: getItemNodeFromIndex
3397
+ type: InputKeyDownEscape
3394
3398
  });
3395
3399
  }
3396
- };
3397
- }, [dispatch, latest, getItemNodeFromIndex]); // Getter props.
3398
-
3399
- var getLabelProps = react.useCallback(function (labelProps) {
3400
- return _extends__default['default']({
3401
- id: elementIds.labelId,
3402
- htmlFor: elementIds.inputId
3403
- }, labelProps);
3404
- }, [elementIds]);
3405
- var getMenuProps = react.useCallback(function (_temp, _temp2) {
3406
- var _extends2;
3407
-
3408
- var _ref = _temp === void 0 ? {} : _temp,
3409
- onMouseLeave = _ref.onMouseLeave,
3410
- _ref$refKey = _ref.refKey,
3411
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
3412
- ref = _ref.ref,
3413
- rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$1);
3414
-
3415
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
3416
- _ref2$suppressRefErro = _ref2.suppressRefError,
3417
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
3400
+ },
3418
3401
 
3419
- setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3420
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
3421
- menuRef.current = menuNode;
3422
- }), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
3402
+ Enter(event) {
3403
+ const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3404
+
3405
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3406
+ ) {
3407
+ return;
3408
+ }
3409
+
3410
+ event.preventDefault();
3423
3411
  dispatch({
3424
- type: MenuMouseLeave
3412
+ type: InputKeyDownEnter,
3413
+ getItemNodeFromIndex
3425
3414
  });
3426
- }), _extends2), rest);
3415
+ }
3416
+
3417
+ }), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
3418
+
3419
+ const getLabelProps = react.useCallback(labelProps => ({
3420
+ id: elementIds.labelId,
3421
+ htmlFor: elementIds.inputId,
3422
+ ...labelProps
3423
+ }), [elementIds]);
3424
+ const getMenuProps = react.useCallback(function (_temp, _temp2) {
3425
+ let {
3426
+ onMouseLeave,
3427
+ refKey = 'ref',
3428
+ ref,
3429
+ ...rest
3430
+ } = _temp === void 0 ? {} : _temp;
3431
+ let {
3432
+ suppressRefError = false
3433
+ } = _temp2 === void 0 ? {} : _temp2;
3434
+ setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3435
+ return {
3436
+ [refKey]: handleRefs(ref, menuNode => {
3437
+ menuRef.current = menuNode;
3438
+ }),
3439
+ id: elementIds.menuId,
3440
+ role: 'listbox',
3441
+ 'aria-labelledby': elementIds.labelId,
3442
+ onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
3443
+ dispatch({
3444
+ type: MenuMouseLeave
3445
+ });
3446
+ }),
3447
+ ...rest
3448
+ };
3427
3449
  }, [dispatch, setGetterPropCallInfo, elementIds]);
3428
- var getItemProps = react.useCallback(function (_temp3) {
3429
- var _extends3, _ref4;
3430
-
3431
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
3432
- item = _ref3.item,
3433
- index = _ref3.index,
3434
- _ref3$refKey = _ref3.refKey,
3435
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
3436
- ref = _ref3.ref,
3437
- onMouseMove = _ref3.onMouseMove;
3438
- _ref3.onClick;
3439
- var onPress = _ref3.onPress,
3440
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$1);
3441
-
3442
- var _latest$current = latest.current,
3443
- latestProps = _latest$current.props,
3444
- latestState = _latest$current.state;
3445
- var itemIndex = getItemIndex(index, item, latestProps.items);
3450
+ const getItemProps = react.useCallback(function (_temp3) {
3451
+ let {
3452
+ item,
3453
+ index,
3454
+ refKey = 'ref',
3455
+ ref,
3456
+ onMouseMove,
3457
+ onClick,
3458
+ onPress,
3459
+ ...rest
3460
+ } = _temp3 === void 0 ? {} : _temp3;
3461
+ const {
3462
+ props: latestProps,
3463
+ state: latestState
3464
+ } = latest.current;
3465
+ const itemIndex = getItemIndex(index, item, latestProps.items);
3446
3466
 
3447
3467
  if (itemIndex < 0) {
3448
3468
  throw new Error('Pass either item or item index in getItemProps!');
3449
3469
  }
3450
3470
 
3451
- var onSelectKey = /* istanbul ignore next (react-native) */
3471
+ const onSelectKey = /* istanbul ignore next (react-native) */
3452
3472
  'onPress' ;
3453
- var customClickHandler = /* istanbul ignore next (react-native) */
3473
+ const customClickHandler = /* istanbul ignore next (react-native) */
3454
3474
  onPress ;
3455
3475
 
3456
- var itemHandleMouseMove = function itemHandleMouseMove() {
3476
+ const itemHandleMouseMove = () => {
3457
3477
  if (index === latestState.highlightedIndex) {
3458
3478
  return;
3459
3479
  }
@@ -3461,14 +3481,14 @@ function useCombobox(userProps) {
3461
3481
  shouldScrollRef.current = false;
3462
3482
  dispatch({
3463
3483
  type: ItemMouseMove,
3464
- index: index
3484
+ index
3465
3485
  });
3466
3486
  };
3467
3487
 
3468
- var itemHandleClick = function itemHandleClick() {
3488
+ const itemHandleClick = () => {
3469
3489
  dispatch({
3470
3490
  type: ItemClick,
3471
- index: index
3491
+ index
3472
3492
  });
3473
3493
 
3474
3494
  if (inputRef.current) {
@@ -3476,26 +3496,32 @@ function useCombobox(userProps) {
3476
3496
  }
3477
3497
  };
3478
3498
 
3479
- return _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
3480
- if (itemNode) {
3481
- itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3482
- }
3483
- }), _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(itemIndex), _extends3), !rest.disabled && (_ref4 = {
3484
- onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove)
3485
- }, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), rest);
3499
+ return {
3500
+ [refKey]: handleRefs(ref, itemNode => {
3501
+ if (itemNode) {
3502
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3503
+ }
3504
+ }),
3505
+ role: 'option',
3506
+ 'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
3507
+ id: elementIds.getItemId(itemIndex),
3508
+ ...(!rest.disabled && {
3509
+ onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3510
+ [onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
3511
+ }),
3512
+ ...rest
3513
+ };
3486
3514
  }, [dispatch, latest, shouldScrollRef, elementIds]);
3487
- var getToggleButtonProps = react.useCallback(function (_temp4) {
3488
- var _extends4;
3489
-
3490
- var _ref5 = _temp4 === void 0 ? {} : _temp4;
3491
- _ref5.onClick;
3492
- var onPress = _ref5.onPress,
3493
- _ref5$refKey = _ref5.refKey,
3494
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
3495
- ref = _ref5.ref,
3496
- rest = _objectWithoutPropertiesLoose__default['default'](_ref5, _excluded3);
3497
-
3498
- var toggleButtonHandleClick = function toggleButtonHandleClick() {
3515
+ const getToggleButtonProps = react.useCallback(function (_temp4) {
3516
+ let {
3517
+ onClick,
3518
+ onPress,
3519
+ refKey = 'ref',
3520
+ ref,
3521
+ ...rest
3522
+ } = _temp4 === void 0 ? {} : _temp4;
3523
+
3524
+ const toggleButtonHandleClick = () => {
3499
3525
  dispatch({
3500
3526
  type: ToggleButtonClick
3501
3527
  });
@@ -3505,43 +3531,46 @@ function useCombobox(userProps) {
3505
3531
  }
3506
3532
  };
3507
3533
 
3508
- return _extends__default['default']((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
3509
- toggleButtonRef.current = toggleButtonNode;
3510
- }), _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends__default['default']({}, /* istanbul ignore next (react-native) */
3511
- {
3512
- onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
3513
- } ), rest);
3534
+ return {
3535
+ [refKey]: handleRefs(ref, toggleButtonNode => {
3536
+ toggleButtonRef.current = toggleButtonNode;
3537
+ }),
3538
+ id: elementIds.toggleButtonId,
3539
+ tabIndex: -1,
3540
+ ...(!rest.disabled && { ...(/* istanbul ignore next (react-native) */
3541
+ {
3542
+ onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
3543
+ } )
3544
+ }),
3545
+ ...rest
3546
+ };
3514
3547
  }, [dispatch, latest, elementIds]);
3515
- var getInputProps = react.useCallback(function (_temp5, _temp6) {
3516
- var _extends5;
3517
-
3518
- var _ref6 = _temp5 === void 0 ? {} : _temp5,
3519
- onKeyDown = _ref6.onKeyDown,
3520
- onChange = _ref6.onChange,
3521
- onInput = _ref6.onInput,
3522
- onBlur = _ref6.onBlur,
3523
- onChangeText = _ref6.onChangeText,
3524
- _ref6$refKey = _ref6.refKey,
3525
- refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
3526
- ref = _ref6.ref,
3527
- rest = _objectWithoutPropertiesLoose__default['default'](_ref6, _excluded4);
3528
-
3529
- var _ref7 = _temp6 === void 0 ? {} : _temp6,
3530
- _ref7$suppressRefErro = _ref7.suppressRefError,
3531
- suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
3532
-
3548
+ const getInputProps = react.useCallback(function (_temp5, _temp6) {
3549
+ let {
3550
+ onKeyDown,
3551
+ onChange,
3552
+ onInput,
3553
+ onBlur,
3554
+ onChangeText,
3555
+ refKey = 'ref',
3556
+ ref,
3557
+ ...rest
3558
+ } = _temp5 === void 0 ? {} : _temp5;
3559
+ let {
3560
+ suppressRefError = false
3561
+ } = _temp6 === void 0 ? {} : _temp6;
3533
3562
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3534
- var latestState = latest.current.state;
3563
+ const latestState = latest.current.state;
3535
3564
 
3536
- var inputHandleKeyDown = function inputHandleKeyDown(event) {
3537
- var key = normalizeArrowKey(event);
3565
+ const inputHandleKeyDown = event => {
3566
+ const key = normalizeArrowKey(event);
3538
3567
 
3539
3568
  if (key && inputKeyDownHandlers[key]) {
3540
3569
  inputKeyDownHandlers[key](event);
3541
3570
  }
3542
3571
  };
3543
3572
 
3544
- var inputHandleChange = function inputHandleChange(event) {
3573
+ const inputHandleChange = event => {
3545
3574
  dispatch({
3546
3575
  type: InputChange,
3547
3576
  inputValue: /* istanbul ignore next (react-native) */
@@ -3549,7 +3578,7 @@ function useCombobox(userProps) {
3549
3578
  });
3550
3579
  };
3551
3580
 
3552
- var inputHandleBlur = function inputHandleBlur() {
3581
+ const inputHandleBlur = () => {
3553
3582
  /* istanbul ignore else */
3554
3583
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3555
3584
  dispatch({
@@ -3561,122 +3590,134 @@ function useCombobox(userProps) {
3561
3590
  /* istanbul ignore next (preact) */
3562
3591
 
3563
3592
 
3564
- var onChangeKey = 'onChange';
3565
- var eventHandlers = {};
3593
+ const onChangeKey = 'onChange';
3594
+ let eventHandlers = {};
3566
3595
 
3567
3596
  if (!rest.disabled) {
3568
- var _eventHandlers;
3569
-
3570
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers);
3597
+ eventHandlers = {
3598
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
3599
+ onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
3600
+ onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
3601
+ };
3571
3602
  }
3572
3603
  /* istanbul ignore if (react-native) */
3573
3604
 
3574
3605
 
3575
3606
  {
3576
3607
  eventHandlers.onChange = callAllEventHandlers(onChange, onInput, inputHandleChange);
3577
- eventHandlers.onChangeText = callAllEventHandlers(onChangeText, onInput, function (text) {
3608
+ eventHandlers.onChangeText = callAllEventHandlers(onChangeText, onInput, text => {
3578
3609
  inputHandleChange({
3579
3610
  nativeEvent: {
3580
- text: text
3611
+ text
3581
3612
  }
3582
3613
  });
3583
3614
  });
3584
3615
  }
3585
3616
 
3586
- return _extends__default['default']((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
3587
- inputRef.current = inputNode;
3588
- }), _extends5.id = elementIds.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5), latestState.isOpen && latestState.highlightedIndex > -1 && {
3589
- 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
3590
- }, {
3617
+ return {
3618
+ [refKey]: handleRefs(ref, inputNode => {
3619
+ inputRef.current = inputNode;
3620
+ }),
3621
+ id: elementIds.inputId,
3622
+ 'aria-autocomplete': 'list',
3623
+ 'aria-controls': elementIds.menuId,
3624
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
3625
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
3626
+ }),
3591
3627
  'aria-labelledby': elementIds.labelId,
3592
3628
  // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
3593
3629
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
3594
3630
  autoComplete: 'off',
3595
- value: latestState.inputValue
3596
- }, eventHandlers, rest);
3631
+ value: latestState.inputValue,
3632
+ ...eventHandlers,
3633
+ ...rest
3634
+ };
3597
3635
  }, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
3598
- var getComboboxProps = react.useCallback(function (_temp7, _temp8) {
3599
- var _extends6;
3600
-
3601
- var _ref8 = _temp7 === void 0 ? {} : _temp7,
3602
- _ref8$refKey = _ref8.refKey,
3603
- refKey = _ref8$refKey === void 0 ? 'ref' : _ref8$refKey,
3604
- ref = _ref8.ref,
3605
- rest = _objectWithoutPropertiesLoose__default['default'](_ref8, _excluded5);
3606
-
3607
- var _ref9 = _temp8 === void 0 ? {} : _temp8,
3608
- _ref9$suppressRefErro = _ref9.suppressRefError,
3609
- suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
3610
-
3636
+ const getComboboxProps = react.useCallback(function (_temp7, _temp8) {
3637
+ let {
3638
+ refKey = 'ref',
3639
+ ref,
3640
+ ...rest
3641
+ } = _temp7 === void 0 ? {} : _temp7;
3642
+ let {
3643
+ suppressRefError = false
3644
+ } = _temp8 === void 0 ? {} : _temp8;
3611
3645
  setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
3612
- return _extends__default['default']((_extends6 = {}, _extends6[refKey] = handleRefs(ref, function (comboboxNode) {
3613
- comboboxRef.current = comboboxNode;
3614
- }), _extends6.role = 'combobox', _extends6['aria-haspopup'] = 'listbox', _extends6['aria-owns'] = elementIds.menuId, _extends6['aria-expanded'] = latest.current.state.isOpen, _extends6), rest);
3646
+ return {
3647
+ [refKey]: handleRefs(ref, comboboxNode => {
3648
+ comboboxRef.current = comboboxNode;
3649
+ }),
3650
+ role: 'combobox',
3651
+ 'aria-haspopup': 'listbox',
3652
+ 'aria-owns': elementIds.menuId,
3653
+ 'aria-expanded': latest.current.state.isOpen,
3654
+ ...rest
3655
+ };
3615
3656
  }, [latest, setGetterPropCallInfo, elementIds]); // returns
3616
3657
 
3617
- var toggleMenu = react.useCallback(function () {
3658
+ const toggleMenu = react.useCallback(() => {
3618
3659
  dispatch({
3619
3660
  type: FunctionToggleMenu
3620
3661
  });
3621
3662
  }, [dispatch]);
3622
- var closeMenu = react.useCallback(function () {
3663
+ const closeMenu = react.useCallback(() => {
3623
3664
  dispatch({
3624
3665
  type: FunctionCloseMenu
3625
3666
  });
3626
3667
  }, [dispatch]);
3627
- var openMenu = react.useCallback(function () {
3668
+ const openMenu = react.useCallback(() => {
3628
3669
  dispatch({
3629
3670
  type: FunctionOpenMenu
3630
3671
  });
3631
3672
  }, [dispatch]);
3632
- var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
3673
+ const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
3633
3674
  dispatch({
3634
3675
  type: FunctionSetHighlightedIndex,
3635
3676
  highlightedIndex: newHighlightedIndex
3636
3677
  });
3637
3678
  }, [dispatch]);
3638
- var selectItem = react.useCallback(function (newSelectedItem) {
3679
+ const selectItem = react.useCallback(newSelectedItem => {
3639
3680
  dispatch({
3640
3681
  type: FunctionSelectItem,
3641
3682
  selectedItem: newSelectedItem
3642
3683
  });
3643
3684
  }, [dispatch]);
3644
- var setInputValue = react.useCallback(function (newInputValue) {
3685
+ const setInputValue = react.useCallback(newInputValue => {
3645
3686
  dispatch({
3646
3687
  type: FunctionSetInputValue,
3647
3688
  inputValue: newInputValue
3648
3689
  });
3649
3690
  }, [dispatch]);
3650
- var reset = react.useCallback(function () {
3691
+ const reset = react.useCallback(() => {
3651
3692
  dispatch({
3652
3693
  type: FunctionReset$1
3653
3694
  });
3654
3695
  }, [dispatch]);
3655
3696
  return {
3656
3697
  // prop getters.
3657
- getItemProps: getItemProps,
3658
- getLabelProps: getLabelProps,
3659
- getMenuProps: getMenuProps,
3660
- getInputProps: getInputProps,
3661
- getComboboxProps: getComboboxProps,
3662
- getToggleButtonProps: getToggleButtonProps,
3698
+ getItemProps,
3699
+ getLabelProps,
3700
+ getMenuProps,
3701
+ getInputProps,
3702
+ getComboboxProps,
3703
+ getToggleButtonProps,
3663
3704
  // actions.
3664
- toggleMenu: toggleMenu,
3665
- openMenu: openMenu,
3666
- closeMenu: closeMenu,
3667
- setHighlightedIndex: setHighlightedIndex,
3668
- setInputValue: setInputValue,
3669
- selectItem: selectItem,
3670
- reset: reset,
3705
+ toggleMenu,
3706
+ openMenu,
3707
+ closeMenu,
3708
+ setHighlightedIndex,
3709
+ setInputValue,
3710
+ selectItem,
3711
+ reset,
3671
3712
  // state.
3672
- highlightedIndex: highlightedIndex,
3673
- isOpen: isOpen,
3674
- selectedItem: selectedItem,
3675
- inputValue: inputValue
3713
+ highlightedIndex,
3714
+ isOpen,
3715
+ selectedItem,
3716
+ inputValue
3676
3717
  };
3677
3718
  }
3678
3719
 
3679
- var defaultStateValues = {
3720
+ const defaultStateValues = {
3680
3721
  activeIndex: -1,
3681
3722
  selectedItems: []
3682
3723
  };
@@ -3716,11 +3757,11 @@ function getDefaultValue(props, propKey) {
3716
3757
 
3717
3758
 
3718
3759
  function getInitialState(props) {
3719
- var activeIndex = getInitialValue(props, 'activeIndex');
3720
- var selectedItems = getInitialValue(props, 'selectedItems');
3760
+ const activeIndex = getInitialValue(props, 'activeIndex');
3761
+ const selectedItems = getInitialValue(props, 'selectedItems');
3721
3762
  return {
3722
- activeIndex: activeIndex,
3723
- selectedItems: selectedItems
3763
+ activeIndex,
3764
+ selectedItems
3724
3765
  };
3725
3766
  }
3726
3767
  /**
@@ -3739,10 +3780,12 @@ function isKeyDownOperationPermitted(event) {
3739
3780
  return false;
3740
3781
  }
3741
3782
 
3742
- var element = event.target;
3783
+ const element = event.target;
3743
3784
 
3744
3785
  if (element instanceof HTMLInputElement && // if element is a text input
3745
- element.value !== '' && (element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3786
+ element.value !== '' && ( // and we have text in it
3787
+ // and cursor is either not at the start or is currently highlighting text.
3788
+ element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3746
3789
  return false;
3747
3790
  }
3748
3791
 
@@ -3757,66 +3800,68 @@ function isKeyDownOperationPermitted(event) {
3757
3800
 
3758
3801
 
3759
3802
  function getA11yRemovalMessage(selectionParameters) {
3760
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3761
- itemToStringLocal = selectionParameters.itemToString;
3803
+ const {
3804
+ removedSelectedItem,
3805
+ itemToString: itemToStringLocal
3806
+ } = selectionParameters;
3762
3807
  return itemToStringLocal(removedSelectedItem) + " has been removed.";
3763
3808
  }
3764
3809
 
3765
- var propTypes = {
3766
- selectedItems: PropTypes__default['default'].array,
3767
- initialSelectedItems: PropTypes__default['default'].array,
3768
- defaultSelectedItems: PropTypes__default['default'].array,
3769
- itemToString: PropTypes__default['default'].func,
3770
- getA11yRemovalMessage: PropTypes__default['default'].func,
3771
- stateReducer: PropTypes__default['default'].func,
3772
- activeIndex: PropTypes__default['default'].number,
3773
- initialActiveIndex: PropTypes__default['default'].number,
3774
- defaultActiveIndex: PropTypes__default['default'].number,
3775
- onActiveIndexChange: PropTypes__default['default'].func,
3776
- onSelectedItemsChange: PropTypes__default['default'].func,
3777
- keyNavigationNext: PropTypes__default['default'].string,
3778
- keyNavigationPrevious: PropTypes__default['default'].string,
3779
- environment: PropTypes__default['default'].shape({
3780
- addEventListener: PropTypes__default['default'].func,
3781
- removeEventListener: PropTypes__default['default'].func,
3782
- document: PropTypes__default['default'].shape({
3783
- getElementById: PropTypes__default['default'].func,
3784
- activeElement: PropTypes__default['default'].any,
3785
- body: PropTypes__default['default'].any
3810
+ const propTypes = {
3811
+ selectedItems: PropTypes__default["default"].array,
3812
+ initialSelectedItems: PropTypes__default["default"].array,
3813
+ defaultSelectedItems: PropTypes__default["default"].array,
3814
+ itemToString: PropTypes__default["default"].func,
3815
+ getA11yRemovalMessage: PropTypes__default["default"].func,
3816
+ stateReducer: PropTypes__default["default"].func,
3817
+ activeIndex: PropTypes__default["default"].number,
3818
+ initialActiveIndex: PropTypes__default["default"].number,
3819
+ defaultActiveIndex: PropTypes__default["default"].number,
3820
+ onActiveIndexChange: PropTypes__default["default"].func,
3821
+ onSelectedItemsChange: PropTypes__default["default"].func,
3822
+ keyNavigationNext: PropTypes__default["default"].string,
3823
+ keyNavigationPrevious: PropTypes__default["default"].string,
3824
+ environment: PropTypes__default["default"].shape({
3825
+ addEventListener: PropTypes__default["default"].func,
3826
+ removeEventListener: PropTypes__default["default"].func,
3827
+ document: PropTypes__default["default"].shape({
3828
+ getElementById: PropTypes__default["default"].func,
3829
+ activeElement: PropTypes__default["default"].any,
3830
+ body: PropTypes__default["default"].any
3786
3831
  })
3787
3832
  })
3788
3833
  };
3789
- var defaultProps = {
3834
+ const defaultProps = {
3790
3835
  itemToString: defaultProps$3.itemToString,
3791
3836
  stateReducer: defaultProps$3.stateReducer,
3792
3837
  environment: defaultProps$3.environment,
3793
- getA11yRemovalMessage: getA11yRemovalMessage,
3838
+ getA11yRemovalMessage,
3794
3839
  keyNavigationNext: 'ArrowRight',
3795
3840
  keyNavigationPrevious: 'ArrowLeft'
3796
3841
  }; // eslint-disable-next-line import/no-mutable-exports
3797
3842
 
3798
- var validatePropTypes = noop;
3843
+ let validatePropTypes = noop;
3799
3844
  /* istanbul ignore next */
3800
3845
 
3801
3846
  if (process.env.NODE_ENV !== 'production') {
3802
- validatePropTypes = function validatePropTypes(options, caller) {
3803
- PropTypes__default['default'].checkPropTypes(propTypes, options, 'prop', caller.name);
3847
+ validatePropTypes = (options, caller) => {
3848
+ PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
3804
3849
  };
3805
3850
  }
3806
3851
 
3807
- var SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3808
- var SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3809
- var SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3810
- var SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3811
- var SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3812
- var DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3813
- var DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3814
- var DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3815
- var FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3816
- var FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3817
- var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3818
- var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3819
- var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3852
+ const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3853
+ const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3854
+ const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3855
+ const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3856
+ const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3857
+ const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3858
+ const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3859
+ const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3860
+ const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3861
+ const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3862
+ const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3863
+ const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3864
+ const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3820
3865
 
3821
3866
  var stateChangeTypes = /*#__PURE__*/Object.freeze({
3822
3867
  __proto__: null,
@@ -3838,13 +3883,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3838
3883
  /* eslint-disable complexity */
3839
3884
 
3840
3885
  function downshiftMultipleSelectionReducer(state, action) {
3841
- var type = action.type,
3842
- index = action.index,
3843
- props = action.props,
3844
- selectedItem = action.selectedItem;
3845
- var activeIndex = state.activeIndex,
3846
- selectedItems = state.selectedItems;
3847
- var changes;
3886
+ const {
3887
+ type,
3888
+ index,
3889
+ props,
3890
+ selectedItem
3891
+ } = action;
3892
+ const {
3893
+ activeIndex,
3894
+ selectedItems
3895
+ } = state;
3896
+ let changes;
3848
3897
 
3849
3898
  switch (type) {
3850
3899
  case SelectedItemClick:
@@ -3868,7 +3917,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3868
3917
  case SelectedItemKeyDownBackspace:
3869
3918
  case SelectedItemKeyDownDelete:
3870
3919
  {
3871
- var newActiveIndex = activeIndex;
3920
+ let newActiveIndex = activeIndex;
3872
3921
 
3873
3922
  if (selectedItems.length === 1) {
3874
3923
  newActiveIndex = -1;
@@ -3876,11 +3925,12 @@ function downshiftMultipleSelectionReducer(state, action) {
3876
3925
  newActiveIndex = selectedItems.length - 2;
3877
3926
  }
3878
3927
 
3879
- changes = _extends__default['default']({
3880
- selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
3881
- }, {
3882
- activeIndex: newActiveIndex
3883
- });
3928
+ changes = {
3929
+ selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
3930
+ ...{
3931
+ activeIndex: newActiveIndex
3932
+ }
3933
+ };
3884
3934
  break;
3885
3935
  }
3886
3936
 
@@ -3898,7 +3948,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3898
3948
 
3899
3949
  case FunctionAddSelectedItem:
3900
3950
  changes = {
3901
- selectedItems: [].concat(selectedItems, [selectedItem])
3951
+ selectedItems: [...selectedItems, selectedItem]
3902
3952
  };
3903
3953
  break;
3904
3954
 
@@ -3910,26 +3960,30 @@ function downshiftMultipleSelectionReducer(state, action) {
3910
3960
 
3911
3961
  case FunctionRemoveSelectedItem:
3912
3962
  {
3913
- var _newActiveIndex = activeIndex;
3914
- var selectedItemIndex = selectedItems.indexOf(selectedItem);
3963
+ let newActiveIndex = activeIndex;
3964
+ const selectedItemIndex = selectedItems.indexOf(selectedItem);
3965
+
3966
+ if (selectedItemIndex >= 0) {
3967
+ if (selectedItems.length === 1) {
3968
+ newActiveIndex = -1;
3969
+ } else if (selectedItemIndex === selectedItems.length - 1) {
3970
+ newActiveIndex = selectedItems.length - 2;
3971
+ }
3915
3972
 
3916
- if (selectedItems.length === 1) {
3917
- _newActiveIndex = -1;
3918
- } else if (selectedItemIndex === selectedItems.length - 1) {
3919
- _newActiveIndex = selectedItems.length - 2;
3973
+ changes = {
3974
+ selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
3975
+ activeIndex: newActiveIndex
3976
+ };
3920
3977
  }
3921
3978
 
3922
- changes = _extends__default['default']({
3923
- selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
3924
- }, {
3925
- activeIndex: _newActiveIndex
3926
- });
3927
3979
  break;
3928
3980
  }
3929
3981
 
3930
3982
  case FunctionSetSelectedItems:
3931
3983
  {
3932
- var newSelectedItems = action.selectedItems;
3984
+ const {
3985
+ selectedItems: newSelectedItems
3986
+ } = action;
3933
3987
  changes = {
3934
3988
  selectedItems: newSelectedItems
3935
3989
  };
@@ -3938,9 +3992,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3938
3992
 
3939
3993
  case FunctionSetActiveIndex:
3940
3994
  {
3941
- var _newActiveIndex2 = action.activeIndex;
3995
+ const {
3996
+ activeIndex: newActiveIndex
3997
+ } = action;
3942
3998
  changes = {
3943
- activeIndex: _newActiveIndex2
3999
+ activeIndex: newActiveIndex
3944
4000
  };
3945
4001
  break;
3946
4002
  }
@@ -3956,11 +4012,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3956
4012
  throw new Error('Reducer called without proper action type.');
3957
4013
  }
3958
4014
 
3959
- return _extends__default['default']({}, state, changes);
4015
+ return { ...state,
4016
+ ...changes
4017
+ };
3960
4018
  }
3961
4019
 
3962
- var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
3963
- _excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
3964
4020
  useMultipleSelection.stateChangeTypes = stateChangeTypes;
3965
4021
 
3966
4022
  function useMultipleSelection(userProps) {
@@ -3970,47 +4026,47 @@ function useMultipleSelection(userProps) {
3970
4026
 
3971
4027
  validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
3972
4028
 
3973
- var props = _extends__default['default']({}, defaultProps, userProps);
3974
-
3975
- var getA11yRemovalMessage = props.getA11yRemovalMessage,
3976
- itemToString = props.itemToString,
3977
- environment = props.environment,
3978
- keyNavigationNext = props.keyNavigationNext,
3979
- keyNavigationPrevious = props.keyNavigationPrevious; // Reducer init.
3980
-
3981
- var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
3982
- state = _useControlledReducer[0],
3983
- dispatch = _useControlledReducer[1];
3984
-
3985
- var activeIndex = state.activeIndex,
3986
- selectedItems = state.selectedItems; // Refs.
3987
-
3988
- var isInitialMountRef = react.useRef(true);
3989
- var dropdownRef = react.useRef(null);
3990
- var previousSelectedItemsRef = react.useRef(selectedItems);
3991
- var selectedItemRefs = react.useRef();
4029
+ const props = { ...defaultProps,
4030
+ ...userProps
4031
+ };
4032
+ const {
4033
+ getA11yRemovalMessage,
4034
+ itemToString,
4035
+ environment,
4036
+ keyNavigationNext,
4037
+ keyNavigationPrevious
4038
+ } = props; // Reducer init.
4039
+
4040
+ const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
4041
+ const {
4042
+ activeIndex,
4043
+ selectedItems
4044
+ } = state; // Refs.
4045
+
4046
+ const isInitialMountRef = react.useRef(true);
4047
+ const dropdownRef = react.useRef(null);
4048
+ const previousSelectedItemsRef = react.useRef(selectedItems);
4049
+ const selectedItemRefs = react.useRef();
3992
4050
  selectedItemRefs.current = [];
3993
- var latest = useLatestRef({
3994
- state: state,
3995
- props: props
4051
+ const latest = useLatestRef({
4052
+ state,
4053
+ props
3996
4054
  }); // Effects.
3997
4055
 
3998
4056
  /* Sets a11y status message on changes in selectedItem. */
3999
4057
 
4000
- react.useEffect(function () {
4058
+ react.useEffect(() => {
4001
4059
  if (isInitialMountRef.current) {
4002
4060
  return;
4003
4061
  }
4004
4062
 
4005
4063
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
4006
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
4007
- return selectedItems.indexOf(item) < 0;
4008
- });
4064
+ const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
4009
4065
  setStatus(getA11yRemovalMessage({
4010
- itemToString: itemToString,
4066
+ itemToString,
4011
4067
  resultCount: selectedItems.length,
4012
- removedSelectedItem: removedSelectedItem,
4013
- activeIndex: activeIndex,
4068
+ removedSelectedItem,
4069
+ activeIndex,
4014
4070
  activeSelectedItem: selectedItems[activeIndex]
4015
4071
  }), environment.document);
4016
4072
  }
@@ -4018,7 +4074,7 @@ function useMultipleSelection(userProps) {
4018
4074
  previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
4019
4075
  }, [selectedItems.length]); // Sets focus on active item.
4020
4076
 
4021
- react.useEffect(function () {
4077
+ react.useEffect(() => {
4022
4078
  if (isInitialMountRef.current) {
4023
4079
  return;
4024
4080
  }
@@ -4031,181 +4087,191 @@ function useMultipleSelection(userProps) {
4031
4087
  }, [activeIndex]);
4032
4088
  useControlPropsValidator({
4033
4089
  isInitialMount: isInitialMountRef.current,
4034
- props: props,
4035
- state: state
4090
+ props,
4091
+ state
4036
4092
  });
4037
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4093
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4038
4094
 
4039
- react.useEffect(function () {
4095
+ react.useEffect(() => {
4040
4096
  isInitialMountRef.current = false;
4041
4097
  }, []); // Event handler functions.
4042
4098
 
4043
- var selectedItemKeyDownHandlers = react.useMemo(function () {
4044
- var _ref;
4045
-
4046
- return _ref = {}, _ref[keyNavigationPrevious] = function () {
4099
+ const selectedItemKeyDownHandlers = react.useMemo(() => ({
4100
+ [keyNavigationPrevious]() {
4047
4101
  dispatch({
4048
4102
  type: SelectedItemKeyDownNavigationPrevious
4049
4103
  });
4050
- }, _ref[keyNavigationNext] = function () {
4104
+ },
4105
+
4106
+ [keyNavigationNext]() {
4051
4107
  dispatch({
4052
4108
  type: SelectedItemKeyDownNavigationNext
4053
4109
  });
4054
- }, _ref.Delete = function Delete() {
4110
+ },
4111
+
4112
+ Delete() {
4055
4113
  dispatch({
4056
4114
  type: SelectedItemKeyDownDelete
4057
4115
  });
4058
- }, _ref.Backspace = function Backspace() {
4116
+ },
4117
+
4118
+ Backspace() {
4059
4119
  dispatch({
4060
4120
  type: SelectedItemKeyDownBackspace
4061
4121
  });
4062
- }, _ref;
4063
- }, [dispatch, keyNavigationNext, keyNavigationPrevious]);
4064
- var dropdownKeyDownHandlers = react.useMemo(function () {
4065
- var _ref2;
4122
+ }
4066
4123
 
4067
- return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
4124
+ }), [dispatch, keyNavigationNext, keyNavigationPrevious]);
4125
+ const dropdownKeyDownHandlers = react.useMemo(() => ({
4126
+ [keyNavigationPrevious](event) {
4068
4127
  if (isKeyDownOperationPermitted(event)) {
4069
4128
  dispatch({
4070
4129
  type: DropdownKeyDownNavigationPrevious
4071
4130
  });
4072
4131
  }
4073
- }, _ref2.Backspace = function Backspace(event) {
4132
+ },
4133
+
4134
+ Backspace(event) {
4074
4135
  if (isKeyDownOperationPermitted(event)) {
4075
4136
  dispatch({
4076
4137
  type: DropdownKeyDownBackspace
4077
4138
  });
4078
4139
  }
4079
- }, _ref2;
4080
- }, [dispatch, keyNavigationPrevious]); // Getter props.
4081
-
4082
- var getSelectedItemProps = react.useCallback(function (_temp) {
4083
- var _extends2;
4084
-
4085
- var _ref3 = _temp === void 0 ? {} : _temp,
4086
- _ref3$refKey = _ref3.refKey,
4087
- refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
4088
- ref = _ref3.ref,
4089
- onClick = _ref3.onClick,
4090
- onKeyDown = _ref3.onKeyDown,
4091
- selectedItem = _ref3.selectedItem,
4092
- index = _ref3.index,
4093
- rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded);
4140
+ }
4094
4141
 
4095
- var latestState = latest.current.state;
4096
- var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4142
+ }), [dispatch, keyNavigationPrevious]); // Getter props.
4143
+
4144
+ const getSelectedItemProps = react.useCallback(function (_temp) {
4145
+ let {
4146
+ refKey = 'ref',
4147
+ ref,
4148
+ onClick,
4149
+ onKeyDown,
4150
+ selectedItem,
4151
+ index,
4152
+ ...rest
4153
+ } = _temp === void 0 ? {} : _temp;
4154
+ const {
4155
+ state: latestState
4156
+ } = latest.current;
4157
+ const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4097
4158
 
4098
4159
  if (itemIndex < 0) {
4099
4160
  throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
4100
4161
  }
4101
4162
 
4102
- var selectedItemHandleClick = function selectedItemHandleClick() {
4163
+ const selectedItemHandleClick = () => {
4103
4164
  dispatch({
4104
4165
  type: SelectedItemClick,
4105
- index: index
4166
+ index
4106
4167
  });
4107
4168
  };
4108
4169
 
4109
- var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
4110
- var key = normalizeArrowKey(event);
4170
+ const selectedItemHandleKeyDown = event => {
4171
+ const key = normalizeArrowKey(event);
4111
4172
 
4112
4173
  if (key && selectedItemKeyDownHandlers[key]) {
4113
4174
  selectedItemKeyDownHandlers[key](event);
4114
4175
  }
4115
4176
  };
4116
4177
 
4117
- return _extends__default['default']((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
4118
- if (selectedItemNode) {
4119
- selectedItemRefs.current.push(selectedItemNode);
4120
- }
4121
- }), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
4178
+ return {
4179
+ [refKey]: handleRefs(ref, selectedItemNode => {
4180
+ if (selectedItemNode) {
4181
+ selectedItemRefs.current.push(selectedItemNode);
4182
+ }
4183
+ }),
4184
+ tabIndex: index === latestState.activeIndex ? 0 : -1,
4185
+ onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
4186
+ onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
4187
+ ...rest
4188
+ };
4122
4189
  }, [dispatch, latest, selectedItemKeyDownHandlers]);
4123
- var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
4124
- var _extends3;
4125
-
4126
- var _ref4 = _temp2 === void 0 ? {} : _temp2,
4127
- _ref4$refKey = _ref4.refKey,
4128
- refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
4129
- ref = _ref4.ref,
4130
- onKeyDown = _ref4.onKeyDown,
4131
- onClick = _ref4.onClick,
4132
- _ref4$preventKeyActio = _ref4.preventKeyAction,
4133
- preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
4134
- rest = _objectWithoutPropertiesLoose__default['default'](_ref4, _excluded2);
4135
-
4136
- var _ref5 = _temp3 === void 0 ? {} : _temp3,
4137
- _ref5$suppressRefErro = _ref5.suppressRefError,
4138
- suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
4139
-
4190
+ const getDropdownProps = react.useCallback(function (_temp2, _temp3) {
4191
+ let {
4192
+ refKey = 'ref',
4193
+ ref,
4194
+ onKeyDown,
4195
+ onClick,
4196
+ preventKeyAction = false,
4197
+ ...rest
4198
+ } = _temp2 === void 0 ? {} : _temp2;
4199
+ let {
4200
+ suppressRefError = false
4201
+ } = _temp3 === void 0 ? {} : _temp3;
4140
4202
  setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
4141
4203
 
4142
- var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
4143
- var key = normalizeArrowKey(event);
4204
+ const dropdownHandleKeyDown = event => {
4205
+ const key = normalizeArrowKey(event);
4144
4206
 
4145
4207
  if (key && dropdownKeyDownHandlers[key]) {
4146
4208
  dropdownKeyDownHandlers[key](event);
4147
4209
  }
4148
4210
  };
4149
4211
 
4150
- var dropdownHandleClick = function dropdownHandleClick() {
4212
+ const dropdownHandleClick = () => {
4151
4213
  dispatch({
4152
4214
  type: DropdownClick
4153
4215
  });
4154
4216
  };
4155
4217
 
4156
- return _extends__default['default']((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
4157
- if (dropdownNode) {
4158
- dropdownRef.current = dropdownNode;
4159
- }
4160
- }), _extends3), !preventKeyAction && {
4161
- onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
4162
- onClick: callAllEventHandlers(onClick, dropdownHandleClick)
4163
- }, rest);
4218
+ return {
4219
+ [refKey]: handleRefs(ref, dropdownNode => {
4220
+ if (dropdownNode) {
4221
+ dropdownRef.current = dropdownNode;
4222
+ }
4223
+ }),
4224
+ ...(!preventKeyAction && {
4225
+ onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
4226
+ onClick: callAllEventHandlers(onClick, dropdownHandleClick)
4227
+ }),
4228
+ ...rest
4229
+ };
4164
4230
  }, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
4165
4231
 
4166
- var addSelectedItem = react.useCallback(function (selectedItem) {
4232
+ const addSelectedItem = react.useCallback(selectedItem => {
4167
4233
  dispatch({
4168
4234
  type: FunctionAddSelectedItem,
4169
- selectedItem: selectedItem
4235
+ selectedItem
4170
4236
  });
4171
4237
  }, [dispatch]);
4172
- var removeSelectedItem = react.useCallback(function (selectedItem) {
4238
+ const removeSelectedItem = react.useCallback(selectedItem => {
4173
4239
  dispatch({
4174
4240
  type: FunctionRemoveSelectedItem,
4175
- selectedItem: selectedItem
4241
+ selectedItem
4176
4242
  });
4177
4243
  }, [dispatch]);
4178
- var setSelectedItems = react.useCallback(function (newSelectedItems) {
4244
+ const setSelectedItems = react.useCallback(newSelectedItems => {
4179
4245
  dispatch({
4180
4246
  type: FunctionSetSelectedItems,
4181
4247
  selectedItems: newSelectedItems
4182
4248
  });
4183
4249
  }, [dispatch]);
4184
- var setActiveIndex = react.useCallback(function (newActiveIndex) {
4250
+ const setActiveIndex = react.useCallback(newActiveIndex => {
4185
4251
  dispatch({
4186
4252
  type: FunctionSetActiveIndex,
4187
4253
  activeIndex: newActiveIndex
4188
4254
  });
4189
4255
  }, [dispatch]);
4190
- var reset = react.useCallback(function () {
4256
+ const reset = react.useCallback(() => {
4191
4257
  dispatch({
4192
4258
  type: FunctionReset
4193
4259
  });
4194
4260
  }, [dispatch]);
4195
4261
  return {
4196
- getSelectedItemProps: getSelectedItemProps,
4197
- getDropdownProps: getDropdownProps,
4198
- addSelectedItem: addSelectedItem,
4199
- removeSelectedItem: removeSelectedItem,
4200
- setSelectedItems: setSelectedItems,
4201
- setActiveIndex: setActiveIndex,
4202
- reset: reset,
4203
- selectedItems: selectedItems,
4204
- activeIndex: activeIndex
4262
+ getSelectedItemProps,
4263
+ getDropdownProps,
4264
+ addSelectedItem,
4265
+ removeSelectedItem,
4266
+ setSelectedItems,
4267
+ setActiveIndex,
4268
+ reset,
4269
+ selectedItems,
4270
+ activeIndex
4205
4271
  };
4206
4272
  }
4207
4273
 
4208
- exports['default'] = Downshift$1;
4274
+ exports["default"] = Downshift$1;
4209
4275
  exports.resetIdCounter = resetIdCounter;
4210
4276
  exports.useCombobox = useCombobox;
4211
4277
  exports.useMultipleSelection = useMultipleSelection;