downshift 6.1.7 → 7.0.0-alpha.0

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