downshift 6.1.6 → 6.1.9

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