downshift 6.1.6 → 6.1.9

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