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