downshift 6.1.5 → 6.1.8

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