downshift 6.1.7 → 6.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,7 +1906,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
1915
1906
  defaultStateValues = dropdownDefaultStateValues;
1916
1907
  }
1917
1908
 
1918
- var defaultPropKey = "default" + capitalizeString(propKey);
1909
+ const defaultPropKey = "default" + capitalizeString(propKey);
1919
1910
 
1920
1911
  if (defaultPropKey in props) {
1921
1912
  return props[defaultPropKey];
@@ -1933,7 +1924,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1933
1924
  return props[propKey];
1934
1925
  }
1935
1926
 
1936
- var initialPropKey = "initial" + capitalizeString(propKey);
1927
+ const initialPropKey = "initial" + capitalizeString(propKey);
1937
1928
 
1938
1929
  if (initialPropKey in props) {
1939
1930
  return props[initialPropKey];
@@ -1943,24 +1934,28 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
1943
1934
  }
1944
1935
 
1945
1936
  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');
1937
+ const selectedItem = getInitialValue$1(props, 'selectedItem');
1938
+ const isOpen = getInitialValue$1(props, 'isOpen');
1939
+ const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
1940
+ const inputValue = getInitialValue$1(props, 'inputValue');
1950
1941
  return {
1951
1942
  highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
1952
- isOpen: isOpen,
1953
- selectedItem: selectedItem,
1954
- inputValue: inputValue
1943
+ isOpen,
1944
+ selectedItem,
1945
+ inputValue
1955
1946
  };
1956
1947
  }
1957
1948
 
1958
1949
  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;
1950
+ const {
1951
+ items,
1952
+ initialHighlightedIndex,
1953
+ defaultHighlightedIndex
1954
+ } = props;
1955
+ const {
1956
+ selectedItem,
1957
+ highlightedIndex
1958
+ } = state;
1964
1959
 
1965
1960
  if (items.length === 0) {
1966
1961
  return -1;
@@ -2001,39 +1996,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
2001
1996
 
2002
1997
 
2003
1998
  function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
2004
- var mouseAndTouchTrackersRef = useRef({
1999
+ const mouseAndTouchTrackersRef = useRef({
2005
2000
  isMouseDown: false,
2006
2001
  isTouchMove: false
2007
2002
  });
2008
- useEffect(function () {
2003
+ useEffect(() => {
2009
2004
  // The same strategy for checking if a click occurred inside or outside downsift
2010
2005
  // as in downshift.js.
2011
- var onMouseDown = function onMouseDown() {
2006
+ const onMouseDown = () => {
2012
2007
  mouseAndTouchTrackersRef.current.isMouseDown = true;
2013
2008
  };
2014
2009
 
2015
- var onMouseUp = function onMouseUp(event) {
2010
+ const onMouseUp = event => {
2016
2011
  mouseAndTouchTrackersRef.current.isMouseDown = false;
2017
2012
 
2018
- if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
2019
- return ref.current;
2020
- }), environment)) {
2013
+ if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
2021
2014
  handleBlur();
2022
2015
  }
2023
2016
  };
2024
2017
 
2025
- var onTouchStart = function onTouchStart() {
2018
+ const onTouchStart = () => {
2026
2019
  mouseAndTouchTrackersRef.current.isTouchMove = false;
2027
2020
  };
2028
2021
 
2029
- var onTouchMove = function onTouchMove() {
2022
+ const onTouchMove = () => {
2030
2023
  mouseAndTouchTrackersRef.current.isTouchMove = true;
2031
2024
  };
2032
2025
 
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)) {
2026
+ const onTouchEnd = event => {
2027
+ if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
2037
2028
  handleBlur();
2038
2029
  }
2039
2030
  };
@@ -2057,9 +2048,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
2057
2048
  // eslint-disable-next-line import/no-mutable-exports
2058
2049
 
2059
2050
 
2060
- var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2061
- return noop;
2062
- };
2051
+ let useGetterPropsCalledChecker = () => noop;
2063
2052
  /**
2064
2053
  * Custom hook that checks if getter props are called correctly.
2065
2054
  *
@@ -2071,20 +2060,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2071
2060
 
2072
2061
 
2073
2062
  if (process.env.NODE_ENV !== 'production') {
2074
- useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
2075
- var isInitialMountRef = useRef(true);
2063
+ useGetterPropsCalledChecker = function () {
2064
+ const isInitialMountRef = useRef(true);
2076
2065
 
2077
2066
  for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
2078
2067
  propKeys[_key] = arguments[_key];
2079
2068
  }
2080
2069
 
2081
- var getterPropsCalledRef = useRef(propKeys.reduce(function (acc, propKey) {
2070
+ const getterPropsCalledRef = useRef(propKeys.reduce((acc, propKey) => {
2082
2071
  acc[propKey] = {};
2083
2072
  return acc;
2084
2073
  }, {}));
2085
- useEffect(function () {
2086
- Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
2087
- var propCallInfo = getterPropsCalledRef.current[propKey];
2074
+ useEffect(() => {
2075
+ Object.keys(getterPropsCalledRef.current).forEach(propKey => {
2076
+ const propCallInfo = getterPropsCalledRef.current[propKey];
2088
2077
 
2089
2078
  if (isInitialMountRef.current) {
2090
2079
  if (!Object.keys(propCallInfo).length) {
@@ -2094,9 +2083,11 @@ if (process.env.NODE_ENV !== 'production') {
2094
2083
  }
2095
2084
  }
2096
2085
 
2097
- var suppressRefError = propCallInfo.suppressRefError,
2098
- refKey = propCallInfo.refKey,
2099
- elementRef = propCallInfo.elementRef;
2086
+ const {
2087
+ suppressRefError,
2088
+ refKey,
2089
+ elementRef
2090
+ } = propCallInfo;
2100
2091
 
2101
2092
  if ((!elementRef || !elementRef.current) && !suppressRefError) {
2102
2093
  // eslint-disable-next-line no-console
@@ -2105,11 +2096,11 @@ if (process.env.NODE_ENV !== 'production') {
2105
2096
  });
2106
2097
  isInitialMountRef.current = false;
2107
2098
  });
2108
- var setGetterPropCallInfo = useCallback(function (propKey, suppressRefError, refKey, elementRef) {
2099
+ const setGetterPropCallInfo = useCallback((propKey, suppressRefError, refKey, elementRef) => {
2109
2100
  getterPropsCalledRef.current[propKey] = {
2110
- suppressRefError: suppressRefError,
2111
- refKey: refKey,
2112
- elementRef: elementRef
2101
+ suppressRefError,
2102
+ refKey,
2103
+ elementRef
2113
2104
  };
2114
2105
  }, []);
2115
2106
  return setGetterPropCallInfo;
@@ -2117,39 +2108,41 @@ if (process.env.NODE_ENV !== 'production') {
2117
2108
  }
2118
2109
 
2119
2110
  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
-
2111
+ let {
2112
+ isInitialMount,
2113
+ highlightedIndex,
2114
+ items,
2115
+ environment,
2116
+ ...rest
2117
+ } = _ref2;
2126
2118
  // Sets a11y status message on changes in state.
2127
- useEffect(function () {
2119
+ useEffect(() => {
2128
2120
  if (isInitialMount || false) {
2129
2121
  return;
2130
2122
  }
2131
2123
 
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
2124
+ updateA11yStatus(() => getA11yMessage({
2125
+ highlightedIndex,
2126
+ highlightedItem: items[highlightedIndex],
2127
+ resultCount: items.length,
2128
+ ...rest
2129
+ }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
2139
2130
  }, dependencyArray);
2140
2131
  }
2141
2132
 
2142
2133
  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;
2134
+ let {
2135
+ highlightedIndex,
2136
+ isOpen,
2137
+ itemRefs,
2138
+ getItemNodeFromIndex,
2139
+ menuElement,
2140
+ scrollIntoView: scrollIntoViewProp
2141
+ } = _ref3;
2149
2142
  // used not to scroll on highlight by mouse.
2150
- var shouldScrollRef = useRef(true); // Scroll on highlighted item if change comes from keyboard.
2143
+ const shouldScrollRef = useRef(true); // Scroll on highlighted item if change comes from keyboard.
2151
2144
 
2152
- useIsomorphicLayoutEffect(function () {
2145
+ useIsomorphicLayoutEffect(() => {
2153
2146
  if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
2154
2147
  return;
2155
2148
  }
@@ -2165,17 +2158,19 @@ function useScrollIntoView(_ref3) {
2165
2158
  } // eslint-disable-next-line import/no-mutable-exports
2166
2159
 
2167
2160
 
2168
- var useControlPropsValidator = noop;
2161
+ let useControlPropsValidator = noop;
2169
2162
  /* istanbul ignore next */
2170
2163
 
2171
2164
  if (process.env.NODE_ENV !== 'production') {
2172
- useControlPropsValidator = function useControlPropsValidator(_ref4) {
2173
- var isInitialMount = _ref4.isInitialMount,
2174
- props = _ref4.props,
2175
- state = _ref4.state;
2165
+ useControlPropsValidator = _ref4 => {
2166
+ let {
2167
+ isInitialMount,
2168
+ props,
2169
+ state
2170
+ } = _ref4;
2176
2171
  // used for checking when props are moving from controlled to uncontrolled.
2177
- var prevPropsRef = useRef(props);
2178
- useEffect(function () {
2172
+ const prevPropsRef = useRef(props);
2173
+ useEffect(() => {
2179
2174
  if (isInitialMount) {
2180
2175
  return;
2181
2176
  }
@@ -2189,9 +2184,11 @@ if (process.env.NODE_ENV !== 'production') {
2189
2184
  /* eslint-disable complexity */
2190
2185
 
2191
2186
  function downshiftCommonReducer(state, action, stateChangeTypes) {
2192
- var type = action.type,
2193
- props = action.props;
2194
- var changes;
2187
+ const {
2188
+ type,
2189
+ props
2190
+ } = action;
2191
+ let changes;
2195
2192
 
2196
2193
  switch (type) {
2197
2194
  case stateChangeTypes.ItemMouseMove:
@@ -2252,7 +2249,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
2252
2249
  throw new Error('Reducer called without proper action type.');
2253
2250
  }
2254
2251
 
2255
- return _extends({}, state, changes);
2252
+ return { ...state,
2253
+ ...changes
2254
+ };
2256
2255
  }
2257
2256
  /* eslint-enable complexity */
2258
2257
 
@@ -2326,7 +2325,7 @@ function getA11yStatusMessage(_a) {
2326
2325
  return 'No results are available.';
2327
2326
  }
2328
2327
  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.";
2328
+ 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
2329
  }
2331
2330
  return '';
2332
2331
  }
@@ -2340,29 +2339,29 @@ if (process.env.NODE_ENV !== 'production') {
2340
2339
  };
2341
2340
  }
2342
2341
 
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;
2342
+ const MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
2343
+ const MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
2344
+ const MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
2345
+ const MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
2346
+ const MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
2347
+ const MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
2348
+ const MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
2349
+ const MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
2350
+ const MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
2351
+ const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
2352
+ const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
2353
+ const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
2354
+ const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
2355
+ const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
2356
+ const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
2357
+ const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
2358
+ const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
2359
+ const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
2360
+ const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
2361
+ const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
2362
+ const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
2363
+ const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
2364
+ const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
2366
2365
 
2367
2366
  var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2368
2367
  __proto__: null,
@@ -2394,10 +2393,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
2394
2393
  /* eslint-disable complexity */
2395
2394
 
2396
2395
  function downshiftSelectReducer(state, action) {
2397
- var type = action.type,
2398
- props = action.props,
2399
- shiftKey = action.shiftKey;
2400
- var changes;
2396
+ const {
2397
+ type,
2398
+ props,
2399
+ shiftKey
2400
+ } = action;
2401
+ let changes;
2401
2402
 
2402
2403
  switch (type) {
2403
2404
  case ItemClick$1:
@@ -2410,20 +2411,21 @@ function downshiftSelectReducer(state, action) {
2410
2411
 
2411
2412
  case ToggleButtonKeyDownCharacter:
2412
2413
  {
2413
- var lowercasedKey = action.key;
2414
- var inputValue = "" + state.inputValue + lowercasedKey;
2415
- var itemIndex = getItemIndexByCharacterKey({
2414
+ const lowercasedKey = action.key;
2415
+ const inputValue = "" + state.inputValue + lowercasedKey;
2416
+ const itemIndex = getItemIndexByCharacterKey({
2416
2417
  keysSoFar: inputValue,
2417
2418
  highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
2418
2419
  items: props.items,
2419
2420
  itemToString: props.itemToString,
2420
2421
  getItemNodeFromIndex: action.getItemNodeFromIndex
2421
2422
  });
2422
- changes = _extends({
2423
- inputValue: inputValue
2424
- }, itemIndex >= 0 && {
2425
- selectedItem: props.items[itemIndex]
2426
- });
2423
+ changes = {
2424
+ inputValue,
2425
+ ...(itemIndex >= 0 && {
2426
+ selectedItem: props.items[itemIndex]
2427
+ })
2428
+ };
2427
2429
  }
2428
2430
  break;
2429
2431
 
@@ -2443,12 +2445,13 @@ function downshiftSelectReducer(state, action) {
2443
2445
 
2444
2446
  case MenuKeyDownEnter:
2445
2447
  case MenuKeyDownSpaceButton:
2446
- changes = _extends({
2448
+ changes = {
2447
2449
  isOpen: getDefaultValue$1(props, 'isOpen'),
2448
- highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
2449
- }, state.highlightedIndex >= 0 && {
2450
- selectedItem: props.items[state.highlightedIndex]
2451
- });
2450
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
2451
+ ...(state.highlightedIndex >= 0 && {
2452
+ selectedItem: props.items[state.highlightedIndex]
2453
+ })
2454
+ };
2452
2455
  break;
2453
2456
 
2454
2457
  case MenuKeyDownHome:
@@ -2479,22 +2482,21 @@ function downshiftSelectReducer(state, action) {
2479
2482
 
2480
2483
  case MenuKeyDownCharacter:
2481
2484
  {
2482
- var _lowercasedKey = action.key;
2483
-
2484
- var _inputValue = "" + state.inputValue + _lowercasedKey;
2485
-
2486
- var highlightedIndex = getItemIndexByCharacterKey({
2487
- keysSoFar: _inputValue,
2485
+ const lowercasedKey = action.key;
2486
+ const inputValue = "" + state.inputValue + lowercasedKey;
2487
+ const highlightedIndex = getItemIndexByCharacterKey({
2488
+ keysSoFar: inputValue,
2488
2489
  highlightedIndex: state.highlightedIndex,
2489
2490
  items: props.items,
2490
2491
  itemToString: props.itemToString,
2491
2492
  getItemNodeFromIndex: action.getItemNodeFromIndex
2492
2493
  });
2493
- changes = _extends({
2494
- inputValue: _inputValue
2495
- }, highlightedIndex >= 0 && {
2496
- highlightedIndex: highlightedIndex
2497
- });
2494
+ changes = {
2495
+ inputValue,
2496
+ ...(highlightedIndex >= 0 && {
2497
+ highlightedIndex
2498
+ })
2499
+ };
2498
2500
  }
2499
2501
  break;
2500
2502
 
@@ -2520,13 +2522,13 @@ function downshiftSelectReducer(state, action) {
2520
2522
  return downshiftCommonReducer(state, action, stateChangeTypes$2);
2521
2523
  }
2522
2524
 
2523
- return _extends({}, state, changes);
2525
+ return { ...state,
2526
+ ...changes
2527
+ };
2524
2528
  }
2525
2529
  /* eslint-enable complexity */
2526
2530
 
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"];
2531
+ /* eslint-disable max-statements */
2530
2532
  useSelect.stateChangeTypes = stateChangeTypes$2;
2531
2533
 
2532
2534
  function useSelect(userProps) {
@@ -2536,91 +2538,92 @@ function useSelect(userProps) {
2536
2538
 
2537
2539
  validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
2538
2540
 
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
2541
+ const props = { ...defaultProps$2,
2542
+ ...userProps
2543
+ };
2544
+ const {
2545
+ items,
2546
+ scrollIntoView,
2547
+ environment,
2548
+ initialIsOpen,
2549
+ defaultIsOpen,
2550
+ itemToString,
2551
+ getA11ySelectionMessage,
2552
+ getA11yStatusMessage
2553
+ } = props; // Initial state depending on controlled props.
2554
+
2555
+ const initialState = getInitialState$2(props);
2556
+ const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
2557
+ const {
2558
+ isOpen,
2559
+ highlightedIndex,
2560
+ selectedItem,
2561
+ inputValue
2562
+ } = state; // Element efs.
2563
+
2564
+ const toggleButtonRef = useRef(null);
2565
+ const menuRef = useRef(null);
2566
+ const itemRefs = useRef({}); // used not to trigger menu blur action in some scenarios.
2567
+
2568
+ const shouldBlurRef = useRef(true); // used to keep the inputValue clearTimeout object between renders.
2569
+
2570
+ const clearTimeoutRef = useRef(null); // prevent id re-generation between renders.
2571
+
2572
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
2573
+
2574
+ const previousResultCountRef = useRef();
2575
+ const isInitialMountRef = useRef(true); // utility callback to get item element.
2576
+
2577
+ const latest = useLatestRef({
2578
+ state,
2579
+ props
2577
2580
  }); // Some utils.
2578
2581
 
2579
- var getItemNodeFromIndex = useCallback(function (index) {
2580
- return itemRefs.current[elementIds.getItemId(index)];
2581
- }, [elementIds]); // Effects.
2582
+ const getItemNodeFromIndex = useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
2582
2583
  // Sets a11y status message on changes in state.
2583
2584
 
2584
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
2585
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
2585
2586
  isInitialMount: isInitialMountRef.current,
2586
2587
  previousResultCount: previousResultCountRef.current,
2587
- items: items,
2588
- environment: environment,
2589
- itemToString: itemToString
2590
- }, state)); // Sets a11y status message on changes in selectedItem.
2588
+ items,
2589
+ environment,
2590
+ itemToString,
2591
+ ...state
2592
+ }); // Sets a11y status message on changes in selectedItem.
2591
2593
 
2592
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
2594
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
2593
2595
  isInitialMount: isInitialMountRef.current,
2594
2596
  previousResultCount: previousResultCountRef.current,
2595
- items: items,
2596
- environment: environment,
2597
- itemToString: itemToString
2598
- }, state)); // Scroll on highlighted item if change comes from keyboard.
2597
+ items,
2598
+ environment,
2599
+ itemToString,
2600
+ ...state
2601
+ }); // Scroll on highlighted item if change comes from keyboard.
2599
2602
 
2600
- var shouldScrollRef = useScrollIntoView({
2603
+ const shouldScrollRef = useScrollIntoView({
2601
2604
  menuElement: menuRef.current,
2602
- highlightedIndex: highlightedIndex,
2603
- isOpen: isOpen,
2604
- itemRefs: itemRefs,
2605
- scrollIntoView: scrollIntoView,
2606
- getItemNodeFromIndex: getItemNodeFromIndex
2605
+ highlightedIndex,
2606
+ isOpen,
2607
+ itemRefs,
2608
+ scrollIntoView,
2609
+ getItemNodeFromIndex
2607
2610
  }); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
2608
2611
 
2609
- useEffect(function () {
2612
+ useEffect(() => {
2610
2613
  // init the clean function here as we need access to dispatch.
2611
- clearTimeoutRef.current = debounce(function (outerDispatch) {
2614
+ clearTimeoutRef.current = debounce(outerDispatch => {
2612
2615
  outerDispatch({
2613
2616
  type: FunctionSetInputValue$1,
2614
2617
  inputValue: ''
2615
2618
  });
2616
2619
  }, 500); // Cancel any pending debounced calls on mount
2617
2620
 
2618
- return function () {
2621
+ return () => {
2619
2622
  clearTimeoutRef.current.cancel();
2620
2623
  };
2621
2624
  }, []); // Invokes the keysSoFar callback set up above.
2622
2625
 
2623
- useEffect(function () {
2626
+ useEffect(() => {
2624
2627
  if (!inputValue) {
2625
2628
  return;
2626
2629
  }
@@ -2629,12 +2632,12 @@ function useSelect(userProps) {
2629
2632
  }, [dispatch, inputValue]);
2630
2633
  useControlPropsValidator({
2631
2634
  isInitialMount: isInitialMountRef.current,
2632
- props: props,
2633
- state: state
2635
+ props,
2636
+ state
2634
2637
  });
2635
2638
  /* Controls the focus on the menu or the toggle button. */
2636
2639
 
2637
- useEffect(function () {
2640
+ useEffect(() => {
2638
2641
  // Don't focus menu on first render.
2639
2642
  if (isInitialMountRef.current) {
2640
2643
  // Unless it was initialised as open.
@@ -2665,7 +2668,7 @@ function useSelect(userProps) {
2665
2668
  } // eslint-disable-next-line react-hooks/exhaustive-deps
2666
2669
 
2667
2670
  }, [isOpen]);
2668
- useEffect(function () {
2671
+ useEffect(() => {
2669
2672
  if (isInitialMountRef.current) {
2670
2673
  return;
2671
2674
  }
@@ -2673,180 +2676,180 @@ function useSelect(userProps) {
2673
2676
  previousResultCountRef.current = items.length;
2674
2677
  }); // Add mouse/touch events to document.
2675
2678
 
2676
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
2679
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
2677
2680
  dispatch({
2678
2681
  type: MenuBlur
2679
2682
  });
2680
2683
  });
2681
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2684
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
2682
2685
 
2683
- useEffect(function () {
2686
+ useEffect(() => {
2684
2687
  isInitialMountRef.current = false;
2685
2688
  }, []); // Reset itemRefs on close.
2686
2689
 
2687
- useEffect(function () {
2690
+ useEffect(() => {
2688
2691
  if (!isOpen) {
2689
2692
  itemRefs.current = {};
2690
2693
  }
2691
2694
  }, [isOpen]); // Event handler functions.
2692
2695
 
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.
2696
+ const toggleButtonKeyDownHandlers = useMemo(() => ({
2697
+ ArrowDown(event) {
2698
+ event.preventDefault();
2699
+ dispatch({
2700
+ type: ToggleButtonKeyDownArrowDown,
2701
+ getItemNodeFromIndex,
2702
+ shiftKey: event.shiftKey
2703
+ });
2704
+ },
2764
2705
 
2765
- var toggleMenu = useCallback(function () {
2706
+ ArrowUp(event) {
2707
+ event.preventDefault();
2708
+ dispatch({
2709
+ type: ToggleButtonKeyDownArrowUp,
2710
+ getItemNodeFromIndex,
2711
+ shiftKey: event.shiftKey
2712
+ });
2713
+ }
2714
+
2715
+ }), [dispatch, getItemNodeFromIndex]);
2716
+ const menuKeyDownHandlers = useMemo(() => ({
2717
+ ArrowDown(event) {
2718
+ event.preventDefault();
2719
+ dispatch({
2720
+ type: MenuKeyDownArrowDown,
2721
+ getItemNodeFromIndex,
2722
+ shiftKey: event.shiftKey
2723
+ });
2724
+ },
2725
+
2726
+ ArrowUp(event) {
2727
+ event.preventDefault();
2728
+ dispatch({
2729
+ type: MenuKeyDownArrowUp,
2730
+ getItemNodeFromIndex,
2731
+ shiftKey: event.shiftKey
2732
+ });
2733
+ },
2734
+
2735
+ Home(event) {
2736
+ event.preventDefault();
2737
+ dispatch({
2738
+ type: MenuKeyDownHome,
2739
+ getItemNodeFromIndex
2740
+ });
2741
+ },
2742
+
2743
+ End(event) {
2744
+ event.preventDefault();
2745
+ dispatch({
2746
+ type: MenuKeyDownEnd,
2747
+ getItemNodeFromIndex
2748
+ });
2749
+ },
2750
+
2751
+ Escape() {
2752
+ dispatch({
2753
+ type: MenuKeyDownEscape
2754
+ });
2755
+ },
2756
+
2757
+ Enter(event) {
2758
+ event.preventDefault();
2759
+ dispatch({
2760
+ type: MenuKeyDownEnter
2761
+ });
2762
+ },
2763
+
2764
+ ' '(event) {
2765
+ event.preventDefault();
2766
+ dispatch({
2767
+ type: MenuKeyDownSpaceButton
2768
+ });
2769
+ }
2770
+
2771
+ }), [dispatch, getItemNodeFromIndex]); // Action functions.
2772
+
2773
+ const toggleMenu = useCallback(() => {
2766
2774
  dispatch({
2767
2775
  type: FunctionToggleMenu$1
2768
2776
  });
2769
2777
  }, [dispatch]);
2770
- var closeMenu = useCallback(function () {
2778
+ const closeMenu = useCallback(() => {
2771
2779
  dispatch({
2772
2780
  type: FunctionCloseMenu$1
2773
2781
  });
2774
2782
  }, [dispatch]);
2775
- var openMenu = useCallback(function () {
2783
+ const openMenu = useCallback(() => {
2776
2784
  dispatch({
2777
2785
  type: FunctionOpenMenu$1
2778
2786
  });
2779
2787
  }, [dispatch]);
2780
- var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
2788
+ const setHighlightedIndex = useCallback(newHighlightedIndex => {
2781
2789
  dispatch({
2782
2790
  type: FunctionSetHighlightedIndex$1,
2783
2791
  highlightedIndex: newHighlightedIndex
2784
2792
  });
2785
2793
  }, [dispatch]);
2786
- var selectItem = useCallback(function (newSelectedItem) {
2794
+ const selectItem = useCallback(newSelectedItem => {
2787
2795
  dispatch({
2788
2796
  type: FunctionSelectItem$1,
2789
2797
  selectedItem: newSelectedItem
2790
2798
  });
2791
2799
  }, [dispatch]);
2792
- var reset = useCallback(function () {
2800
+ const reset = useCallback(() => {
2793
2801
  dispatch({
2794
2802
  type: FunctionReset$2
2795
2803
  });
2796
2804
  }, [dispatch]);
2797
- var setInputValue = useCallback(function (newInputValue) {
2805
+ const setInputValue = useCallback(newInputValue => {
2798
2806
  dispatch({
2799
2807
  type: FunctionSetInputValue$1,
2800
2808
  inputValue: newInputValue
2801
2809
  });
2802
2810
  }, [dispatch]); // Getter functions.
2803
2811
 
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);
2812
+ const getLabelProps = useCallback(labelProps => ({
2813
+ id: elementIds.labelId,
2814
+ htmlFor: elementIds.toggleButtonId,
2815
+ ...labelProps
2816
+ }), [elementIds]);
2817
+ const getMenuProps = useCallback(function (_temp, _temp2) {
2818
+ let {
2819
+ onMouseLeave,
2820
+ refKey = 'ref',
2821
+ onKeyDown,
2822
+ onBlur,
2823
+ ref,
2824
+ ...rest
2825
+ } = _temp === void 0 ? {} : _temp;
2826
+ let {
2827
+ suppressRefError = false
2828
+ } = _temp2 === void 0 ? {} : _temp2;
2829
+ const latestState = latest.current.state;
2830
+
2831
+ const menuHandleKeyDown = event => {
2832
+ const key = normalizeArrowKey(event);
2830
2833
 
2831
2834
  if (key && menuKeyDownHandlers[key]) {
2832
2835
  menuKeyDownHandlers[key](event);
2833
2836
  } else if (isAcceptedCharacterKey(key)) {
2834
2837
  dispatch({
2835
2838
  type: MenuKeyDownCharacter,
2836
- key: key,
2837
- getItemNodeFromIndex: getItemNodeFromIndex
2839
+ key,
2840
+ getItemNodeFromIndex
2838
2841
  });
2839
2842
  }
2840
2843
  };
2841
2844
 
2842
- var menuHandleBlur = function menuHandleBlur() {
2845
+ const menuHandleBlur = () => {
2843
2846
  // if the blur was a result of selection, we don't trigger this action.
2844
2847
  if (shouldBlurRef.current === false) {
2845
2848
  shouldBlurRef.current = true;
2846
2849
  return;
2847
2850
  }
2848
2851
 
2849
- var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2852
+ const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
2850
2853
  /* istanbul ignore else */
2851
2854
 
2852
2855
  if (shouldBlur) {
@@ -2856,61 +2859,72 @@ function useSelect(userProps) {
2856
2859
  }
2857
2860
  };
2858
2861
 
2859
- var menuHandleMouseLeave = function menuHandleMouseLeave() {
2862
+ const menuHandleMouseLeave = () => {
2860
2863
  dispatch({
2861
2864
  type: MenuMouseLeave$1
2862
2865
  });
2863
2866
  };
2864
2867
 
2865
2868
  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
- }, {
2869
+ return {
2870
+ [refKey]: handleRefs(ref, menuNode => {
2871
+ menuRef.current = menuNode;
2872
+ }),
2873
+ id: elementIds.menuId,
2874
+ role: 'listbox',
2875
+ 'aria-labelledby': elementIds.labelId,
2876
+ tabIndex: -1,
2877
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
2878
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
2879
+ }),
2871
2880
  onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
2872
2881
  onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
2873
- onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
2874
- }, rest);
2882
+ onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
2883
+ ...rest
2884
+ };
2875
2885
  }, [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() {
2886
+ const getToggleButtonProps = useCallback(function (_temp3, _temp4) {
2887
+ let {
2888
+ onClick,
2889
+ onKeyDown,
2890
+ refKey = 'ref',
2891
+ ref,
2892
+ ...rest
2893
+ } = _temp3 === void 0 ? {} : _temp3;
2894
+ let {
2895
+ suppressRefError = false
2896
+ } = _temp4 === void 0 ? {} : _temp4;
2897
+
2898
+ const toggleButtonHandleClick = () => {
2892
2899
  dispatch({
2893
2900
  type: ToggleButtonClick$1
2894
2901
  });
2895
2902
  };
2896
2903
 
2897
- var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
2898
- var key = normalizeArrowKey(event);
2904
+ const toggleButtonHandleKeyDown = event => {
2905
+ const key = normalizeArrowKey(event);
2899
2906
 
2900
2907
  if (key && toggleButtonKeyDownHandlers[key]) {
2901
2908
  toggleButtonKeyDownHandlers[key](event);
2902
2909
  } else if (isAcceptedCharacterKey(key)) {
2903
2910
  dispatch({
2904
2911
  type: ToggleButtonKeyDownCharacter,
2905
- key: key,
2906
- getItemNodeFromIndex: getItemNodeFromIndex
2912
+ key,
2913
+ getItemNodeFromIndex
2907
2914
  });
2908
2915
  }
2909
2916
  };
2910
2917
 
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);
2918
+ const toggleProps = {
2919
+ [refKey]: handleRefs(ref, toggleButtonNode => {
2920
+ toggleButtonRef.current = toggleButtonNode;
2921
+ }),
2922
+ id: elementIds.toggleButtonId,
2923
+ 'aria-haspopup': 'listbox',
2924
+ 'aria-expanded': latest.current.state.isOpen,
2925
+ 'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
2926
+ ...rest
2927
+ };
2914
2928
 
2915
2929
  if (!rest.disabled) {
2916
2930
  toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
@@ -2920,24 +2934,22 @@ function useSelect(userProps) {
2920
2934
  setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
2921
2935
  return toggleProps;
2922
2936
  }, [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() {
2937
+ const getItemProps = useCallback(function (_temp5) {
2938
+ let {
2939
+ item,
2940
+ index,
2941
+ onMouseMove,
2942
+ onClick,
2943
+ refKey = 'ref',
2944
+ ref,
2945
+ ...rest
2946
+ } = _temp5 === void 0 ? {} : _temp5;
2947
+ const {
2948
+ state: latestState,
2949
+ props: latestProps
2950
+ } = latest.current;
2951
+
2952
+ const itemHandleMouseMove = () => {
2941
2953
  if (index === latestState.highlightedIndex) {
2942
2954
  return;
2943
2955
  }
@@ -2945,32 +2957,34 @@ function useSelect(userProps) {
2945
2957
  shouldScrollRef.current = false;
2946
2958
  dispatch({
2947
2959
  type: ItemMouseMove$1,
2948
- index: index
2960
+ index
2949
2961
  });
2950
2962
  };
2951
2963
 
2952
- var itemHandleClick = function itemHandleClick() {
2964
+ const itemHandleClick = () => {
2953
2965
  dispatch({
2954
2966
  type: ItemClick$1,
2955
- index: index
2967
+ index
2956
2968
  });
2957
2969
  };
2958
2970
 
2959
- var itemIndex = getItemIndex(index, item, latestProps.items);
2971
+ const itemIndex = getItemIndex(index, item, latestProps.items);
2960
2972
 
2961
2973
  if (itemIndex < 0) {
2962
2974
  throw new Error('Pass either item or item index in getItemProps!');
2963
2975
  }
2964
2976
 
2965
- var itemProps = _extends((_extends4 = {
2977
+ const itemProps = {
2966
2978
  role: 'option',
2967
2979
  '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);
2980
+ id: elementIds.getItemId(itemIndex),
2981
+ [refKey]: handleRefs(ref, itemNode => {
2982
+ if (itemNode) {
2983
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
2984
+ }
2985
+ }),
2986
+ ...rest
2987
+ };
2974
2988
 
2975
2989
  if (!rest.disabled) {
2976
2990
  itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
@@ -2981,46 +2995,46 @@ function useSelect(userProps) {
2981
2995
  }, [dispatch, latest, shouldScrollRef, elementIds]);
2982
2996
  return {
2983
2997
  // prop getters.
2984
- getToggleButtonProps: getToggleButtonProps,
2985
- getLabelProps: getLabelProps,
2986
- getMenuProps: getMenuProps,
2987
- getItemProps: getItemProps,
2998
+ getToggleButtonProps,
2999
+ getLabelProps,
3000
+ getMenuProps,
3001
+ getItemProps,
2988
3002
  // actions.
2989
- toggleMenu: toggleMenu,
2990
- openMenu: openMenu,
2991
- closeMenu: closeMenu,
2992
- setHighlightedIndex: setHighlightedIndex,
2993
- selectItem: selectItem,
2994
- reset: reset,
2995
- setInputValue: setInputValue,
3003
+ toggleMenu,
3004
+ openMenu,
3005
+ closeMenu,
3006
+ setHighlightedIndex,
3007
+ selectItem,
3008
+ reset,
3009
+ setInputValue,
2996
3010
  // state.
2997
- highlightedIndex: highlightedIndex,
2998
- isOpen: isOpen,
2999
- selectedItem: selectedItem,
3000
- inputValue: inputValue
3011
+ highlightedIndex,
3012
+ isOpen,
3013
+ selectedItem,
3014
+ inputValue
3001
3015
  };
3002
3016
  }
3003
3017
 
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;
3018
+ const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
3019
+ const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
3020
+ const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
3021
+ const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
3022
+ const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
3023
+ const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
3024
+ const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
3025
+ const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
3026
+ const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
3027
+ const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
3028
+ const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
3029
+ const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
3030
+ const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
3031
+ const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
3032
+ const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
3033
+ const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
3034
+ const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
3035
+ const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
3036
+ const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
3037
+ const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
3024
3038
 
3025
3039
  var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3026
3040
  __proto__: null,
@@ -3047,20 +3061,24 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
3047
3061
  });
3048
3062
 
3049
3063
  function getInitialState$1(props) {
3050
- var initialState = getInitialState$2(props);
3051
- var selectedItem = initialState.selectedItem;
3052
- var inputValue = initialState.inputValue;
3064
+ const initialState = getInitialState$2(props);
3065
+ const {
3066
+ selectedItem
3067
+ } = initialState;
3068
+ let {
3069
+ inputValue
3070
+ } = initialState;
3053
3071
 
3054
3072
  if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
3055
3073
  inputValue = props.itemToString(selectedItem);
3056
3074
  }
3057
3075
 
3058
- return _extends({}, initialState, {
3059
- inputValue: inputValue
3060
- });
3076
+ return { ...initialState,
3077
+ inputValue
3078
+ };
3061
3079
  }
3062
3080
 
3063
- var propTypes$1 = {
3081
+ const propTypes$1 = {
3064
3082
  items: PropTypes.array.isRequired,
3065
3083
  itemToString: PropTypes.func,
3066
3084
  getA11yStatusMessage: PropTypes.func,
@@ -3114,14 +3132,10 @@ var propTypes$1 = {
3114
3132
  */
3115
3133
 
3116
3134
  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.
3122
-
3135
+ const previousSelectedItemRef = useRef();
3136
+ const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
3123
3137
 
3124
- useEffect(function () {
3138
+ useEffect(() => {
3125
3139
  if (isControlledProp(props, 'selectedItem')) {
3126
3140
  if (previousSelectedItemRef.current !== props.selectedItem) {
3127
3141
  dispatch({
@@ -3137,27 +3151,29 @@ function useControlledReducer(reducer, initialState, props) {
3137
3151
  } // eslint-disable-next-line import/no-mutable-exports
3138
3152
 
3139
3153
 
3140
- var validatePropTypes$1 = noop;
3154
+ let validatePropTypes$1 = noop;
3141
3155
  /* istanbul ignore next */
3142
3156
 
3143
3157
  if (process.env.NODE_ENV !== 'production') {
3144
- validatePropTypes$1 = function validatePropTypes(options, caller) {
3158
+ validatePropTypes$1 = (options, caller) => {
3145
3159
  PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
3146
3160
  };
3147
3161
  }
3148
3162
 
3149
- var defaultProps$1 = _extends({}, defaultProps$3, {
3163
+ const defaultProps$1 = { ...defaultProps$3,
3150
3164
  getA11yStatusMessage: getA11yStatusMessage$1,
3151
3165
  circularNavigation: true
3152
- });
3166
+ };
3153
3167
 
3154
3168
  /* eslint-disable complexity */
3155
3169
 
3156
3170
  function downshiftUseComboboxReducer(state, action) {
3157
- var type = action.type,
3158
- props = action.props,
3159
- shiftKey = action.shiftKey;
3160
- var changes;
3171
+ const {
3172
+ type,
3173
+ props,
3174
+ shiftKey
3175
+ } = action;
3176
+ let changes;
3161
3177
 
3162
3178
  switch (type) {
3163
3179
  case ItemClick:
@@ -3198,22 +3214,24 @@ function downshiftUseComboboxReducer(state, action) {
3198
3214
  break;
3199
3215
 
3200
3216
  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
- });
3217
+ changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
3218
+ selectedItem: props.items[state.highlightedIndex],
3219
+ isOpen: getDefaultValue$1(props, 'isOpen'),
3220
+ highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
3221
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3222
+ })
3223
+ };
3207
3224
  break;
3208
3225
 
3209
3226
  case InputKeyDownEscape:
3210
- changes = _extends({
3227
+ changes = {
3211
3228
  isOpen: false,
3212
- highlightedIndex: -1
3213
- }, !state.isOpen && {
3214
- selectedItem: null,
3215
- inputValue: ''
3216
- });
3229
+ highlightedIndex: -1,
3230
+ ...(!state.isOpen && {
3231
+ selectedItem: null,
3232
+ inputValue: ''
3233
+ })
3234
+ };
3217
3235
  break;
3218
3236
 
3219
3237
  case InputKeyDownHome:
@@ -3229,13 +3247,14 @@ function downshiftUseComboboxReducer(state, action) {
3229
3247
  break;
3230
3248
 
3231
3249
  case InputBlur:
3232
- changes = _extends({
3250
+ changes = {
3233
3251
  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
- });
3252
+ highlightedIndex: -1,
3253
+ ...(state.highlightedIndex >= 0 && action.selectItem && {
3254
+ selectedItem: props.items[state.highlightedIndex],
3255
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3256
+ })
3257
+ };
3239
3258
  break;
3240
3259
 
3241
3260
  case InputChange:
@@ -3263,15 +3282,13 @@ function downshiftUseComboboxReducer(state, action) {
3263
3282
  return downshiftCommonReducer(state, action, stateChangeTypes$1);
3264
3283
  }
3265
3284
 
3266
- return _extends({}, state, changes);
3285
+ return { ...state,
3286
+ ...changes
3287
+ };
3267
3288
  }
3268
3289
  /* eslint-enable complexity */
3269
3290
 
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"];
3291
+ /* eslint-disable max-statements */
3275
3292
  useCombobox.stateChangeTypes = stateChangeTypes$1;
3276
3293
 
3277
3294
  function useCombobox(userProps) {
@@ -3281,87 +3298,88 @@ function useCombobox(userProps) {
3281
3298
 
3282
3299
  validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
3283
3300
 
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
3301
+ const props = { ...defaultProps$1,
3302
+ ...userProps
3303
+ };
3304
+ const {
3305
+ initialIsOpen,
3306
+ defaultIsOpen,
3307
+ items,
3308
+ scrollIntoView,
3309
+ environment,
3310
+ getA11yStatusMessage,
3311
+ getA11ySelectionMessage,
3312
+ itemToString
3313
+ } = props; // Initial state depending on controlled props.
3314
+
3315
+ const initialState = getInitialState$1(props);
3316
+ const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
3317
+ const {
3318
+ isOpen,
3319
+ highlightedIndex,
3320
+ selectedItem,
3321
+ inputValue
3322
+ } = state; // Element refs.
3323
+
3324
+ const menuRef = useRef(null);
3325
+ const itemRefs = useRef({});
3326
+ const inputRef = useRef(null);
3327
+ const toggleButtonRef = useRef(null);
3328
+ const comboboxRef = useRef(null);
3329
+ const isInitialMountRef = useRef(true); // prevent id re-generation between renders.
3330
+
3331
+ const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
3332
+
3333
+ const previousResultCountRef = useRef(); // utility callback to get item element.
3334
+
3335
+ const latest = useLatestRef({
3336
+ state,
3337
+ props
3320
3338
  });
3321
- var getItemNodeFromIndex = useCallback(function (index) {
3322
- return itemRefs.current[elementIds.getItemId(index)];
3323
- }, [elementIds]); // Effects.
3339
+ const getItemNodeFromIndex = useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
3324
3340
  // Sets a11y status message on changes in state.
3325
3341
 
3326
- useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
3342
+ useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
3327
3343
  isInitialMount: isInitialMountRef.current,
3328
3344
  previousResultCount: previousResultCountRef.current,
3329
- items: items,
3330
- environment: environment,
3331
- itemToString: itemToString
3332
- }, state)); // Sets a11y status message on changes in selectedItem.
3345
+ items,
3346
+ environment,
3347
+ itemToString,
3348
+ ...state
3349
+ }); // Sets a11y status message on changes in selectedItem.
3333
3350
 
3334
- useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
3351
+ useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
3335
3352
  isInitialMount: isInitialMountRef.current,
3336
3353
  previousResultCount: previousResultCountRef.current,
3337
- items: items,
3338
- environment: environment,
3339
- itemToString: itemToString
3340
- }, state)); // Scroll on highlighted item if change comes from keyboard.
3354
+ items,
3355
+ environment,
3356
+ itemToString,
3357
+ ...state
3358
+ }); // Scroll on highlighted item if change comes from keyboard.
3341
3359
 
3342
- var shouldScrollRef = useScrollIntoView({
3360
+ const shouldScrollRef = useScrollIntoView({
3343
3361
  menuElement: menuRef.current,
3344
- highlightedIndex: highlightedIndex,
3345
- isOpen: isOpen,
3346
- itemRefs: itemRefs,
3347
- scrollIntoView: scrollIntoView,
3348
- getItemNodeFromIndex: getItemNodeFromIndex
3362
+ highlightedIndex,
3363
+ isOpen,
3364
+ itemRefs,
3365
+ scrollIntoView,
3366
+ getItemNodeFromIndex
3349
3367
  });
3350
3368
  useControlPropsValidator({
3351
3369
  isInitialMount: isInitialMountRef.current,
3352
- props: props,
3353
- state: state
3370
+ props,
3371
+ state
3354
3372
  }); // Focus the input on first render if required.
3355
3373
 
3356
- useEffect(function () {
3357
- var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3374
+ useEffect(() => {
3375
+ const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
3358
3376
 
3359
3377
  if (focusOnOpen && inputRef.current) {
3360
3378
  inputRef.current.focus();
3361
3379
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3362
3380
 
3363
3381
  }, []);
3364
- useEffect(function () {
3382
+ useEffect(() => {
3365
3383
  if (isInitialMountRef.current) {
3366
3384
  return;
3367
3385
  }
@@ -3369,147 +3387,151 @@ function useCombobox(userProps) {
3369
3387
  previousResultCountRef.current = items.length;
3370
3388
  }); // Add mouse/touch events to document.
3371
3389
 
3372
- var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, function () {
3390
+ const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
3373
3391
  dispatch({
3374
3392
  type: InputBlur,
3375
3393
  selectItem: false
3376
3394
  });
3377
3395
  });
3378
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3396
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
3379
3397
 
3380
- useEffect(function () {
3398
+ useEffect(() => {
3381
3399
  isInitialMountRef.current = false;
3382
3400
  }, []); // Reset itemRefs on close.
3383
3401
 
3384
- useEffect(function () {
3402
+ useEffect(() => {
3385
3403
  if (!isOpen) {
3386
3404
  itemRefs.current = {};
3387
3405
  }
3388
3406
  }, [isOpen]);
3389
3407
  /* Event handler functions */
3390
3408
 
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
- }
3409
+ const inputKeyDownHandlers = useMemo(() => ({
3410
+ ArrowDown(event) {
3411
+ event.preventDefault();
3412
+ dispatch({
3413
+ type: InputKeyDownArrowDown,
3414
+ shiftKey: event.shiftKey,
3415
+ getItemNodeFromIndex
3416
+ });
3417
+ },
3413
3418
 
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
- }
3419
+ ArrowUp(event) {
3420
+ event.preventDefault();
3421
+ dispatch({
3422
+ type: InputKeyDownArrowUp,
3423
+ shiftKey: event.shiftKey,
3424
+ getItemNodeFromIndex
3425
+ });
3426
+ },
3424
3427
 
3425
- event.preventDefault();
3426
- dispatch({
3427
- type: InputKeyDownEnd,
3428
- getItemNodeFromIndex: getItemNodeFromIndex
3429
- });
3430
- },
3431
- Escape: function Escape() {
3432
- var latestState = latest.current.state;
3428
+ Home(event) {
3429
+ if (!latest.current.state.isOpen) {
3430
+ return;
3431
+ }
3433
3432
 
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.
3433
+ event.preventDefault();
3434
+ dispatch({
3435
+ type: InputKeyDownHome,
3436
+ getItemNodeFromIndex
3437
+ });
3438
+ },
3442
3439
 
3443
- if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3444
- ) {
3445
- return;
3446
- }
3440
+ End(event) {
3441
+ if (!latest.current.state.isOpen) {
3442
+ return;
3443
+ }
3447
3444
 
3448
- event.preventDefault();
3445
+ event.preventDefault();
3446
+ dispatch({
3447
+ type: InputKeyDownEnd,
3448
+ getItemNodeFromIndex
3449
+ });
3450
+ },
3451
+
3452
+ Escape() {
3453
+ const latestState = latest.current.state;
3454
+
3455
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3449
3456
  dispatch({
3450
- type: InputKeyDownEnter,
3451
- getItemNodeFromIndex: getItemNodeFromIndex
3457
+ type: InputKeyDownEscape
3452
3458
  });
3453
3459
  }
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;
3460
+ },
3476
3461
 
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 () {
3462
+ Enter(event) {
3463
+ const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3464
+
3465
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3466
+ ) {
3467
+ return;
3468
+ }
3469
+
3470
+ event.preventDefault();
3481
3471
  dispatch({
3482
- type: MenuMouseLeave
3472
+ type: InputKeyDownEnter,
3473
+ getItemNodeFromIndex
3483
3474
  });
3484
- }), _extends2), rest);
3475
+ }
3476
+
3477
+ }), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
3478
+
3479
+ const getLabelProps = useCallback(labelProps => ({
3480
+ id: elementIds.labelId,
3481
+ htmlFor: elementIds.inputId,
3482
+ ...labelProps
3483
+ }), [elementIds]);
3484
+ const getMenuProps = useCallback(function (_temp, _temp2) {
3485
+ let {
3486
+ onMouseLeave,
3487
+ refKey = 'ref',
3488
+ ref,
3489
+ ...rest
3490
+ } = _temp === void 0 ? {} : _temp;
3491
+ let {
3492
+ suppressRefError = false
3493
+ } = _temp2 === void 0 ? {} : _temp2;
3494
+ setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
3495
+ return {
3496
+ [refKey]: handleRefs(ref, menuNode => {
3497
+ menuRef.current = menuNode;
3498
+ }),
3499
+ id: elementIds.menuId,
3500
+ role: 'listbox',
3501
+ 'aria-labelledby': elementIds.labelId,
3502
+ onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
3503
+ dispatch({
3504
+ type: MenuMouseLeave
3505
+ });
3506
+ }),
3507
+ ...rest
3508
+ };
3485
3509
  }, [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);
3510
+ const getItemProps = useCallback(function (_temp3) {
3511
+ let {
3512
+ item,
3513
+ index,
3514
+ refKey = 'ref',
3515
+ ref,
3516
+ onMouseMove,
3517
+ onClick,
3518
+ onPress,
3519
+ ...rest
3520
+ } = _temp3 === void 0 ? {} : _temp3;
3521
+ const {
3522
+ props: latestProps,
3523
+ state: latestState
3524
+ } = latest.current;
3525
+ const itemIndex = getItemIndex(index, item, latestProps.items);
3504
3526
 
3505
3527
  if (itemIndex < 0) {
3506
3528
  throw new Error('Pass either item or item index in getItemProps!');
3507
3529
  }
3508
3530
 
3509
- var onSelectKey = 'onClick';
3510
- var customClickHandler = onClick;
3531
+ const onSelectKey = 'onClick';
3532
+ const customClickHandler = onClick;
3511
3533
 
3512
- var itemHandleMouseMove = function itemHandleMouseMove() {
3534
+ const itemHandleMouseMove = () => {
3513
3535
  if (index === latestState.highlightedIndex) {
3514
3536
  return;
3515
3537
  }
@@ -3517,14 +3539,14 @@ function useCombobox(userProps) {
3517
3539
  shouldScrollRef.current = false;
3518
3540
  dispatch({
3519
3541
  type: ItemMouseMove,
3520
- index: index
3542
+ index
3521
3543
  });
3522
3544
  };
3523
3545
 
3524
- var itemHandleClick = function itemHandleClick() {
3546
+ const itemHandleClick = () => {
3525
3547
  dispatch({
3526
3548
  type: ItemClick,
3527
- index: index
3549
+ index
3528
3550
  });
3529
3551
 
3530
3552
  if (inputRef.current) {
@@ -3532,26 +3554,32 @@ function useCombobox(userProps) {
3532
3554
  }
3533
3555
  };
3534
3556
 
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);
3557
+ return {
3558
+ [refKey]: handleRefs(ref, itemNode => {
3559
+ if (itemNode) {
3560
+ itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
3561
+ }
3562
+ }),
3563
+ role: 'option',
3564
+ 'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
3565
+ id: elementIds.getItemId(itemIndex),
3566
+ ...(!rest.disabled && {
3567
+ onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
3568
+ [onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
3569
+ }),
3570
+ ...rest
3571
+ };
3542
3572
  }, [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() {
3573
+ const getToggleButtonProps = useCallback(function (_temp4) {
3574
+ let {
3575
+ onClick,
3576
+ onPress,
3577
+ refKey = 'ref',
3578
+ ref,
3579
+ ...rest
3580
+ } = _temp4 === void 0 ? {} : _temp4;
3581
+
3582
+ const toggleButtonHandleClick = () => {
3555
3583
  dispatch({
3556
3584
  type: ToggleButtonClick
3557
3585
  });
@@ -3561,49 +3589,52 @@ function useCombobox(userProps) {
3561
3589
  }
3562
3590
  };
3563
3591
 
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);
3592
+ return {
3593
+ [refKey]: handleRefs(ref, toggleButtonNode => {
3594
+ toggleButtonRef.current = toggleButtonNode;
3595
+ }),
3596
+ id: elementIds.toggleButtonId,
3597
+ tabIndex: -1,
3598
+ ...(!rest.disabled && { ...({
3599
+ onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
3600
+ })
3601
+ }),
3602
+ ...rest
3603
+ };
3569
3604
  }, [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
-
3605
+ const getInputProps = useCallback(function (_temp5, _temp6) {
3606
+ let {
3607
+ onKeyDown,
3608
+ onChange,
3609
+ onInput,
3610
+ onBlur,
3611
+ onChangeText,
3612
+ refKey = 'ref',
3613
+ ref,
3614
+ ...rest
3615
+ } = _temp5 === void 0 ? {} : _temp5;
3616
+ let {
3617
+ suppressRefError = false
3618
+ } = _temp6 === void 0 ? {} : _temp6;
3588
3619
  setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
3589
- var latestState = latest.current.state;
3620
+ const latestState = latest.current.state;
3590
3621
 
3591
- var inputHandleKeyDown = function inputHandleKeyDown(event) {
3592
- var key = normalizeArrowKey(event);
3622
+ const inputHandleKeyDown = event => {
3623
+ const key = normalizeArrowKey(event);
3593
3624
 
3594
3625
  if (key && inputKeyDownHandlers[key]) {
3595
3626
  inputKeyDownHandlers[key](event);
3596
3627
  }
3597
3628
  };
3598
3629
 
3599
- var inputHandleChange = function inputHandleChange(event) {
3630
+ const inputHandleChange = event => {
3600
3631
  dispatch({
3601
3632
  type: InputChange,
3602
3633
  inputValue: event.target.value
3603
3634
  });
3604
3635
  };
3605
3636
 
3606
- var inputHandleBlur = function inputHandleBlur() {
3637
+ const inputHandleBlur = () => {
3607
3638
  /* istanbul ignore else */
3608
3639
  if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3609
3640
  dispatch({
@@ -3615,109 +3646,121 @@ function useCombobox(userProps) {
3615
3646
  /* istanbul ignore next (preact) */
3616
3647
 
3617
3648
 
3618
- var onChangeKey = 'onChange';
3619
- var eventHandlers = {};
3649
+ const onChangeKey = 'onChange';
3650
+ let eventHandlers = {};
3620
3651
 
3621
3652
  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);
3653
+ eventHandlers = {
3654
+ [onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
3655
+ onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
3656
+ onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
3657
+ };
3625
3658
  }
3626
3659
 
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
- }, {
3660
+ return {
3661
+ [refKey]: handleRefs(ref, inputNode => {
3662
+ inputRef.current = inputNode;
3663
+ }),
3664
+ id: elementIds.inputId,
3665
+ 'aria-autocomplete': 'list',
3666
+ 'aria-controls': elementIds.menuId,
3667
+ ...(latestState.isOpen && latestState.highlightedIndex > -1 && {
3668
+ 'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
3669
+ }),
3632
3670
  'aria-labelledby': elementIds.labelId,
3633
3671
  // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
3634
3672
  // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
3635
3673
  autoComplete: 'off',
3636
- value: latestState.inputValue
3637
- }, eventHandlers, rest);
3674
+ value: latestState.inputValue,
3675
+ ...eventHandlers,
3676
+ ...rest
3677
+ };
3638
3678
  }, [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
-
3679
+ const getComboboxProps = useCallback(function (_temp7, _temp8) {
3680
+ let {
3681
+ refKey = 'ref',
3682
+ ref,
3683
+ ...rest
3684
+ } = _temp7 === void 0 ? {} : _temp7;
3685
+ let {
3686
+ suppressRefError = false
3687
+ } = _temp8 === void 0 ? {} : _temp8;
3652
3688
  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);
3689
+ return {
3690
+ [refKey]: handleRefs(ref, comboboxNode => {
3691
+ comboboxRef.current = comboboxNode;
3692
+ }),
3693
+ role: 'combobox',
3694
+ 'aria-haspopup': 'listbox',
3695
+ 'aria-owns': elementIds.menuId,
3696
+ 'aria-expanded': latest.current.state.isOpen,
3697
+ ...rest
3698
+ };
3656
3699
  }, [latest, setGetterPropCallInfo, elementIds]); // returns
3657
3700
 
3658
- var toggleMenu = useCallback(function () {
3701
+ const toggleMenu = useCallback(() => {
3659
3702
  dispatch({
3660
3703
  type: FunctionToggleMenu
3661
3704
  });
3662
3705
  }, [dispatch]);
3663
- var closeMenu = useCallback(function () {
3706
+ const closeMenu = useCallback(() => {
3664
3707
  dispatch({
3665
3708
  type: FunctionCloseMenu
3666
3709
  });
3667
3710
  }, [dispatch]);
3668
- var openMenu = useCallback(function () {
3711
+ const openMenu = useCallback(() => {
3669
3712
  dispatch({
3670
3713
  type: FunctionOpenMenu
3671
3714
  });
3672
3715
  }, [dispatch]);
3673
- var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
3716
+ const setHighlightedIndex = useCallback(newHighlightedIndex => {
3674
3717
  dispatch({
3675
3718
  type: FunctionSetHighlightedIndex,
3676
3719
  highlightedIndex: newHighlightedIndex
3677
3720
  });
3678
3721
  }, [dispatch]);
3679
- var selectItem = useCallback(function (newSelectedItem) {
3722
+ const selectItem = useCallback(newSelectedItem => {
3680
3723
  dispatch({
3681
3724
  type: FunctionSelectItem,
3682
3725
  selectedItem: newSelectedItem
3683
3726
  });
3684
3727
  }, [dispatch]);
3685
- var setInputValue = useCallback(function (newInputValue) {
3728
+ const setInputValue = useCallback(newInputValue => {
3686
3729
  dispatch({
3687
3730
  type: FunctionSetInputValue,
3688
3731
  inputValue: newInputValue
3689
3732
  });
3690
3733
  }, [dispatch]);
3691
- var reset = useCallback(function () {
3734
+ const reset = useCallback(() => {
3692
3735
  dispatch({
3693
3736
  type: FunctionReset$1
3694
3737
  });
3695
3738
  }, [dispatch]);
3696
3739
  return {
3697
3740
  // prop getters.
3698
- getItemProps: getItemProps,
3699
- getLabelProps: getLabelProps,
3700
- getMenuProps: getMenuProps,
3701
- getInputProps: getInputProps,
3702
- getComboboxProps: getComboboxProps,
3703
- getToggleButtonProps: getToggleButtonProps,
3741
+ getItemProps,
3742
+ getLabelProps,
3743
+ getMenuProps,
3744
+ getInputProps,
3745
+ getComboboxProps,
3746
+ getToggleButtonProps,
3704
3747
  // actions.
3705
- toggleMenu: toggleMenu,
3706
- openMenu: openMenu,
3707
- closeMenu: closeMenu,
3708
- setHighlightedIndex: setHighlightedIndex,
3709
- setInputValue: setInputValue,
3710
- selectItem: selectItem,
3711
- reset: reset,
3748
+ toggleMenu,
3749
+ openMenu,
3750
+ closeMenu,
3751
+ setHighlightedIndex,
3752
+ setInputValue,
3753
+ selectItem,
3754
+ reset,
3712
3755
  // state.
3713
- highlightedIndex: highlightedIndex,
3714
- isOpen: isOpen,
3715
- selectedItem: selectedItem,
3716
- inputValue: inputValue
3756
+ highlightedIndex,
3757
+ isOpen,
3758
+ selectedItem,
3759
+ inputValue
3717
3760
  };
3718
3761
  }
3719
3762
 
3720
- var defaultStateValues = {
3763
+ const defaultStateValues = {
3721
3764
  activeIndex: -1,
3722
3765
  selectedItems: []
3723
3766
  };
@@ -3757,11 +3800,11 @@ function getDefaultValue(props, propKey) {
3757
3800
 
3758
3801
 
3759
3802
  function getInitialState(props) {
3760
- var activeIndex = getInitialValue(props, 'activeIndex');
3761
- var selectedItems = getInitialValue(props, 'selectedItems');
3803
+ const activeIndex = getInitialValue(props, 'activeIndex');
3804
+ const selectedItems = getInitialValue(props, 'selectedItems');
3762
3805
  return {
3763
- activeIndex: activeIndex,
3764
- selectedItems: selectedItems
3806
+ activeIndex,
3807
+ selectedItems
3765
3808
  };
3766
3809
  }
3767
3810
  /**
@@ -3780,10 +3823,12 @@ function isKeyDownOperationPermitted(event) {
3780
3823
  return false;
3781
3824
  }
3782
3825
 
3783
- var element = event.target;
3826
+ const element = event.target;
3784
3827
 
3785
3828
  if (element instanceof HTMLInputElement && // if element is a text input
3786
- element.value !== '' && (element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3829
+ element.value !== '' && ( // and we have text in it
3830
+ // and cursor is either not at the start or is currently highlighting text.
3831
+ element.selectionStart !== 0 || element.selectionEnd !== 0)) {
3787
3832
  return false;
3788
3833
  }
3789
3834
 
@@ -3798,12 +3843,14 @@ function isKeyDownOperationPermitted(event) {
3798
3843
 
3799
3844
 
3800
3845
  function getA11yRemovalMessage(selectionParameters) {
3801
- var removedSelectedItem = selectionParameters.removedSelectedItem,
3802
- itemToStringLocal = selectionParameters.itemToString;
3846
+ const {
3847
+ removedSelectedItem,
3848
+ itemToString: itemToStringLocal
3849
+ } = selectionParameters;
3803
3850
  return itemToStringLocal(removedSelectedItem) + " has been removed.";
3804
3851
  }
3805
3852
 
3806
- var propTypes = {
3853
+ const propTypes = {
3807
3854
  selectedItems: PropTypes.array,
3808
3855
  initialSelectedItems: PropTypes.array,
3809
3856
  defaultSelectedItems: PropTypes.array,
@@ -3827,37 +3874,37 @@ var propTypes = {
3827
3874
  })
3828
3875
  })
3829
3876
  };
3830
- var defaultProps = {
3877
+ const defaultProps = {
3831
3878
  itemToString: defaultProps$3.itemToString,
3832
3879
  stateReducer: defaultProps$3.stateReducer,
3833
3880
  environment: defaultProps$3.environment,
3834
- getA11yRemovalMessage: getA11yRemovalMessage,
3881
+ getA11yRemovalMessage,
3835
3882
  keyNavigationNext: 'ArrowRight',
3836
3883
  keyNavigationPrevious: 'ArrowLeft'
3837
3884
  }; // eslint-disable-next-line import/no-mutable-exports
3838
3885
 
3839
- var validatePropTypes = noop;
3886
+ let validatePropTypes = noop;
3840
3887
  /* istanbul ignore next */
3841
3888
 
3842
3889
  if (process.env.NODE_ENV !== 'production') {
3843
- validatePropTypes = function validatePropTypes(options, caller) {
3890
+ validatePropTypes = (options, caller) => {
3844
3891
  PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
3845
3892
  };
3846
3893
  }
3847
3894
 
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;
3895
+ const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
3896
+ const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
3897
+ const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
3898
+ const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
3899
+ const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
3900
+ const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
3901
+ const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
3902
+ const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
3903
+ const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
3904
+ const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
3905
+ const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
3906
+ const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
3907
+ const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
3861
3908
 
3862
3909
  var stateChangeTypes = /*#__PURE__*/Object.freeze({
3863
3910
  __proto__: null,
@@ -3879,13 +3926,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
3879
3926
  /* eslint-disable complexity */
3880
3927
 
3881
3928
  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;
3929
+ const {
3930
+ type,
3931
+ index,
3932
+ props,
3933
+ selectedItem
3934
+ } = action;
3935
+ const {
3936
+ activeIndex,
3937
+ selectedItems
3938
+ } = state;
3939
+ let changes;
3889
3940
 
3890
3941
  switch (type) {
3891
3942
  case SelectedItemClick:
@@ -3909,7 +3960,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3909
3960
  case SelectedItemKeyDownBackspace:
3910
3961
  case SelectedItemKeyDownDelete:
3911
3962
  {
3912
- var newActiveIndex = activeIndex;
3963
+ let newActiveIndex = activeIndex;
3913
3964
 
3914
3965
  if (selectedItems.length === 1) {
3915
3966
  newActiveIndex = -1;
@@ -3917,11 +3968,12 @@ function downshiftMultipleSelectionReducer(state, action) {
3917
3968
  newActiveIndex = selectedItems.length - 2;
3918
3969
  }
3919
3970
 
3920
- changes = _extends({
3921
- selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
3922
- }, {
3923
- activeIndex: newActiveIndex
3924
- });
3971
+ changes = {
3972
+ selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
3973
+ ...{
3974
+ activeIndex: newActiveIndex
3975
+ }
3976
+ };
3925
3977
  break;
3926
3978
  }
3927
3979
 
@@ -3939,7 +3991,7 @@ function downshiftMultipleSelectionReducer(state, action) {
3939
3991
 
3940
3992
  case FunctionAddSelectedItem:
3941
3993
  changes = {
3942
- selectedItems: [].concat(selectedItems, [selectedItem])
3994
+ selectedItems: [...selectedItems, selectedItem]
3943
3995
  };
3944
3996
  break;
3945
3997
 
@@ -3951,26 +4003,30 @@ function downshiftMultipleSelectionReducer(state, action) {
3951
4003
 
3952
4004
  case FunctionRemoveSelectedItem:
3953
4005
  {
3954
- var _newActiveIndex = activeIndex;
3955
- var selectedItemIndex = selectedItems.indexOf(selectedItem);
4006
+ let newActiveIndex = activeIndex;
4007
+ const selectedItemIndex = selectedItems.indexOf(selectedItem);
4008
+
4009
+ if (selectedItemIndex >= 0) {
4010
+ if (selectedItems.length === 1) {
4011
+ newActiveIndex = -1;
4012
+ } else if (selectedItemIndex === selectedItems.length - 1) {
4013
+ newActiveIndex = selectedItems.length - 2;
4014
+ }
3956
4015
 
3957
- if (selectedItems.length === 1) {
3958
- _newActiveIndex = -1;
3959
- } else if (selectedItemIndex === selectedItems.length - 1) {
3960
- _newActiveIndex = selectedItems.length - 2;
4016
+ changes = {
4017
+ selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
4018
+ activeIndex: newActiveIndex
4019
+ };
3961
4020
  }
3962
4021
 
3963
- changes = _extends({
3964
- selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
3965
- }, {
3966
- activeIndex: _newActiveIndex
3967
- });
3968
4022
  break;
3969
4023
  }
3970
4024
 
3971
4025
  case FunctionSetSelectedItems:
3972
4026
  {
3973
- var newSelectedItems = action.selectedItems;
4027
+ const {
4028
+ selectedItems: newSelectedItems
4029
+ } = action;
3974
4030
  changes = {
3975
4031
  selectedItems: newSelectedItems
3976
4032
  };
@@ -3979,9 +4035,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3979
4035
 
3980
4036
  case FunctionSetActiveIndex:
3981
4037
  {
3982
- var _newActiveIndex2 = action.activeIndex;
4038
+ const {
4039
+ activeIndex: newActiveIndex
4040
+ } = action;
3983
4041
  changes = {
3984
- activeIndex: _newActiveIndex2
4042
+ activeIndex: newActiveIndex
3985
4043
  };
3986
4044
  break;
3987
4045
  }
@@ -3997,11 +4055,11 @@ function downshiftMultipleSelectionReducer(state, action) {
3997
4055
  throw new Error('Reducer called without proper action type.');
3998
4056
  }
3999
4057
 
4000
- return _extends({}, state, changes);
4058
+ return { ...state,
4059
+ ...changes
4060
+ };
4001
4061
  }
4002
4062
 
4003
- var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
4004
- _excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
4005
4063
  useMultipleSelection.stateChangeTypes = stateChangeTypes;
4006
4064
 
4007
4065
  function useMultipleSelection(userProps) {
@@ -4011,47 +4069,47 @@ function useMultipleSelection(userProps) {
4011
4069
 
4012
4070
  validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
4013
4071
 
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();
4072
+ const props = { ...defaultProps,
4073
+ ...userProps
4074
+ };
4075
+ const {
4076
+ getA11yRemovalMessage,
4077
+ itemToString,
4078
+ environment,
4079
+ keyNavigationNext,
4080
+ keyNavigationPrevious
4081
+ } = props; // Reducer init.
4082
+
4083
+ const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
4084
+ const {
4085
+ activeIndex,
4086
+ selectedItems
4087
+ } = state; // Refs.
4088
+
4089
+ const isInitialMountRef = useRef(true);
4090
+ const dropdownRef = useRef(null);
4091
+ const previousSelectedItemsRef = useRef(selectedItems);
4092
+ const selectedItemRefs = useRef();
4033
4093
  selectedItemRefs.current = [];
4034
- var latest = useLatestRef({
4035
- state: state,
4036
- props: props
4094
+ const latest = useLatestRef({
4095
+ state,
4096
+ props
4037
4097
  }); // Effects.
4038
4098
 
4039
4099
  /* Sets a11y status message on changes in selectedItem. */
4040
4100
 
4041
- useEffect(function () {
4101
+ useEffect(() => {
4042
4102
  if (isInitialMountRef.current) {
4043
4103
  return;
4044
4104
  }
4045
4105
 
4046
4106
  if (selectedItems.length < previousSelectedItemsRef.current.length) {
4047
- var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
4048
- return selectedItems.indexOf(item) < 0;
4049
- });
4107
+ const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
4050
4108
  setStatus(getA11yRemovalMessage({
4051
- itemToString: itemToString,
4109
+ itemToString,
4052
4110
  resultCount: selectedItems.length,
4053
- removedSelectedItem: removedSelectedItem,
4054
- activeIndex: activeIndex,
4111
+ removedSelectedItem,
4112
+ activeIndex,
4055
4113
  activeSelectedItem: selectedItems[activeIndex]
4056
4114
  }), environment.document);
4057
4115
  }
@@ -4059,7 +4117,7 @@ function useMultipleSelection(userProps) {
4059
4117
  previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
4060
4118
  }, [selectedItems.length]); // Sets focus on active item.
4061
4119
 
4062
- useEffect(function () {
4120
+ useEffect(() => {
4063
4121
  if (isInitialMountRef.current) {
4064
4122
  return;
4065
4123
  }
@@ -4072,177 +4130,187 @@ function useMultipleSelection(userProps) {
4072
4130
  }, [activeIndex]);
4073
4131
  useControlPropsValidator({
4074
4132
  isInitialMount: isInitialMountRef.current,
4075
- props: props,
4076
- state: state
4133
+ props,
4134
+ state
4077
4135
  });
4078
- var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4136
+ const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
4079
4137
 
4080
- useEffect(function () {
4138
+ useEffect(() => {
4081
4139
  isInitialMountRef.current = false;
4082
4140
  }, []); // Event handler functions.
4083
4141
 
4084
- var selectedItemKeyDownHandlers = useMemo(function () {
4085
- var _ref;
4086
-
4087
- return _ref = {}, _ref[keyNavigationPrevious] = function () {
4142
+ const selectedItemKeyDownHandlers = useMemo(() => ({
4143
+ [keyNavigationPrevious]() {
4088
4144
  dispatch({
4089
4145
  type: SelectedItemKeyDownNavigationPrevious
4090
4146
  });
4091
- }, _ref[keyNavigationNext] = function () {
4147
+ },
4148
+
4149
+ [keyNavigationNext]() {
4092
4150
  dispatch({
4093
4151
  type: SelectedItemKeyDownNavigationNext
4094
4152
  });
4095
- }, _ref.Delete = function Delete() {
4153
+ },
4154
+
4155
+ Delete() {
4096
4156
  dispatch({
4097
4157
  type: SelectedItemKeyDownDelete
4098
4158
  });
4099
- }, _ref.Backspace = function Backspace() {
4159
+ },
4160
+
4161
+ Backspace() {
4100
4162
  dispatch({
4101
4163
  type: SelectedItemKeyDownBackspace
4102
4164
  });
4103
- }, _ref;
4104
- }, [dispatch, keyNavigationNext, keyNavigationPrevious]);
4105
- var dropdownKeyDownHandlers = useMemo(function () {
4106
- var _ref2;
4165
+ }
4107
4166
 
4108
- return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
4167
+ }), [dispatch, keyNavigationNext, keyNavigationPrevious]);
4168
+ const dropdownKeyDownHandlers = useMemo(() => ({
4169
+ [keyNavigationPrevious](event) {
4109
4170
  if (isKeyDownOperationPermitted(event)) {
4110
4171
  dispatch({
4111
4172
  type: DropdownKeyDownNavigationPrevious
4112
4173
  });
4113
4174
  }
4114
- }, _ref2.Backspace = function Backspace(event) {
4175
+ },
4176
+
4177
+ Backspace(event) {
4115
4178
  if (isKeyDownOperationPermitted(event)) {
4116
4179
  dispatch({
4117
4180
  type: DropdownKeyDownBackspace
4118
4181
  });
4119
4182
  }
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);
4183
+ }
4135
4184
 
4136
- var latestState = latest.current.state;
4137
- var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4185
+ }), [dispatch, keyNavigationPrevious]); // Getter props.
4186
+
4187
+ const getSelectedItemProps = useCallback(function (_temp) {
4188
+ let {
4189
+ refKey = 'ref',
4190
+ ref,
4191
+ onClick,
4192
+ onKeyDown,
4193
+ selectedItem,
4194
+ index,
4195
+ ...rest
4196
+ } = _temp === void 0 ? {} : _temp;
4197
+ const {
4198
+ state: latestState
4199
+ } = latest.current;
4200
+ const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
4138
4201
 
4139
4202
  if (itemIndex < 0) {
4140
4203
  throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
4141
4204
  }
4142
4205
 
4143
- var selectedItemHandleClick = function selectedItemHandleClick() {
4206
+ const selectedItemHandleClick = () => {
4144
4207
  dispatch({
4145
4208
  type: SelectedItemClick,
4146
- index: index
4209
+ index
4147
4210
  });
4148
4211
  };
4149
4212
 
4150
- var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
4151
- var key = normalizeArrowKey(event);
4213
+ const selectedItemHandleKeyDown = event => {
4214
+ const key = normalizeArrowKey(event);
4152
4215
 
4153
4216
  if (key && selectedItemKeyDownHandlers[key]) {
4154
4217
  selectedItemKeyDownHandlers[key](event);
4155
4218
  }
4156
4219
  };
4157
4220
 
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);
4221
+ return {
4222
+ [refKey]: handleRefs(ref, selectedItemNode => {
4223
+ if (selectedItemNode) {
4224
+ selectedItemRefs.current.push(selectedItemNode);
4225
+ }
4226
+ }),
4227
+ tabIndex: index === latestState.activeIndex ? 0 : -1,
4228
+ onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
4229
+ onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
4230
+ ...rest
4231
+ };
4163
4232
  }, [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
-
4233
+ const getDropdownProps = useCallback(function (_temp2, _temp3) {
4234
+ let {
4235
+ refKey = 'ref',
4236
+ ref,
4237
+ onKeyDown,
4238
+ onClick,
4239
+ preventKeyAction = false,
4240
+ ...rest
4241
+ } = _temp2 === void 0 ? {} : _temp2;
4242
+ let {
4243
+ suppressRefError = false
4244
+ } = _temp3 === void 0 ? {} : _temp3;
4181
4245
  setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
4182
4246
 
4183
- var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
4184
- var key = normalizeArrowKey(event);
4247
+ const dropdownHandleKeyDown = event => {
4248
+ const key = normalizeArrowKey(event);
4185
4249
 
4186
4250
  if (key && dropdownKeyDownHandlers[key]) {
4187
4251
  dropdownKeyDownHandlers[key](event);
4188
4252
  }
4189
4253
  };
4190
4254
 
4191
- var dropdownHandleClick = function dropdownHandleClick() {
4255
+ const dropdownHandleClick = () => {
4192
4256
  dispatch({
4193
4257
  type: DropdownClick
4194
4258
  });
4195
4259
  };
4196
4260
 
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);
4261
+ return {
4262
+ [refKey]: handleRefs(ref, dropdownNode => {
4263
+ if (dropdownNode) {
4264
+ dropdownRef.current = dropdownNode;
4265
+ }
4266
+ }),
4267
+ ...(!preventKeyAction && {
4268
+ onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
4269
+ onClick: callAllEventHandlers(onClick, dropdownHandleClick)
4270
+ }),
4271
+ ...rest
4272
+ };
4205
4273
  }, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
4206
4274
 
4207
- var addSelectedItem = useCallback(function (selectedItem) {
4275
+ const addSelectedItem = useCallback(selectedItem => {
4208
4276
  dispatch({
4209
4277
  type: FunctionAddSelectedItem,
4210
- selectedItem: selectedItem
4278
+ selectedItem
4211
4279
  });
4212
4280
  }, [dispatch]);
4213
- var removeSelectedItem = useCallback(function (selectedItem) {
4281
+ const removeSelectedItem = useCallback(selectedItem => {
4214
4282
  dispatch({
4215
4283
  type: FunctionRemoveSelectedItem,
4216
- selectedItem: selectedItem
4284
+ selectedItem
4217
4285
  });
4218
4286
  }, [dispatch]);
4219
- var setSelectedItems = useCallback(function (newSelectedItems) {
4287
+ const setSelectedItems = useCallback(newSelectedItems => {
4220
4288
  dispatch({
4221
4289
  type: FunctionSetSelectedItems,
4222
4290
  selectedItems: newSelectedItems
4223
4291
  });
4224
4292
  }, [dispatch]);
4225
- var setActiveIndex = useCallback(function (newActiveIndex) {
4293
+ const setActiveIndex = useCallback(newActiveIndex => {
4226
4294
  dispatch({
4227
4295
  type: FunctionSetActiveIndex,
4228
4296
  activeIndex: newActiveIndex
4229
4297
  });
4230
4298
  }, [dispatch]);
4231
- var reset = useCallback(function () {
4299
+ const reset = useCallback(() => {
4232
4300
  dispatch({
4233
4301
  type: FunctionReset
4234
4302
  });
4235
4303
  }, [dispatch]);
4236
4304
  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
4305
+ getSelectedItemProps,
4306
+ getDropdownProps,
4307
+ addSelectedItem,
4308
+ removeSelectedItem,
4309
+ setSelectedItems,
4310
+ setActiveIndex,
4311
+ reset,
4312
+ selectedItems,
4313
+ activeIndex
4246
4314
  };
4247
4315
  }
4248
4316