downshift 3.4.7 → 3.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -414,1066 +414,1071 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
414
414
 
415
415
  var Downshift =
416
416
  /*#__PURE__*/
417
- function (_Component) {
418
- _inheritsLoose(Downshift, _Component);
417
+ function () {
418
+ var Downshift =
419
+ /*#__PURE__*/
420
+ function (_Component) {
421
+ _inheritsLoose(Downshift, _Component);
422
+
423
+ function Downshift(_props) {
424
+ var _this = _Component.call(this, _props) || this;
425
+
426
+ _this.id = _this.props.id || "downshift-" + generateId();
427
+ _this.menuId = _this.props.menuId || _this.id + "-menu";
428
+ _this.labelId = _this.props.labelId || _this.id + "-label";
429
+ _this.inputId = _this.props.inputId || _this.id + "-input";
430
+
431
+ _this.getItemId = _this.props.getItemId || function (index) {
432
+ return _this.id + "-item-" + index;
433
+ };
419
434
 
420
- function Downshift(_props) {
421
- var _this = _Component.call(this, _props) || this;
435
+ _this.input = null;
436
+ _this.items = [];
437
+ _this.itemCount = null;
438
+ _this.previousResultCount = 0;
439
+ _this.timeoutIds = [];
422
440
 
423
- _this.id = _this.props.id || "downshift-" + generateId();
424
- _this.menuId = _this.props.menuId || _this.id + "-menu";
425
- _this.labelId = _this.props.labelId || _this.id + "-label";
426
- _this.inputId = _this.props.inputId || _this.id + "-input";
441
+ _this.internalSetTimeout = function (fn, time) {
442
+ var id = setTimeout(function () {
443
+ _this.timeoutIds = _this.timeoutIds.filter(function (i) {
444
+ return i !== id;
445
+ });
446
+ fn();
447
+ }, time);
427
448
 
428
- _this.getItemId = _this.props.getItemId || function (index) {
429
- return _this.id + "-item-" + index;
430
- };
449
+ _this.timeoutIds.push(id);
450
+ };
431
451
 
432
- _this.input = null;
433
- _this.items = [];
434
- _this.itemCount = null;
435
- _this.previousResultCount = 0;
436
- _this.timeoutIds = [];
452
+ _this.setItemCount = function (count) {
453
+ _this.itemCount = count;
454
+ };
437
455
 
438
- _this.internalSetTimeout = function (fn, time) {
439
- var id = setTimeout(function () {
440
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
441
- return i !== id;
442
- });
443
- fn();
444
- }, time);
456
+ _this.unsetItemCount = function () {
457
+ _this.itemCount = null;
458
+ };
445
459
 
446
- _this.timeoutIds.push(id);
447
- };
460
+ _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
461
+ if (highlightedIndex === void 0) {
462
+ highlightedIndex = _this.props.defaultHighlightedIndex;
463
+ }
448
464
 
449
- _this.setItemCount = function (count) {
450
- _this.itemCount = count;
451
- };
465
+ if (otherStateToSet === void 0) {
466
+ otherStateToSet = {};
467
+ }
452
468
 
453
- _this.unsetItemCount = function () {
454
- _this.itemCount = null;
455
- };
469
+ otherStateToSet = pickState(otherStateToSet);
456
470
 
457
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
458
- if (highlightedIndex === void 0) {
459
- highlightedIndex = _this.props.defaultHighlightedIndex;
460
- }
471
+ _this.internalSetState(_extends({
472
+ highlightedIndex: highlightedIndex
473
+ }, otherStateToSet));
474
+ };
461
475
 
462
- if (otherStateToSet === void 0) {
463
- otherStateToSet = {};
464
- }
476
+ _this.clearSelection = function (cb) {
477
+ _this.internalSetState({
478
+ selectedItem: null,
479
+ inputValue: '',
480
+ highlightedIndex: _this.props.defaultHighlightedIndex,
481
+ isOpen: _this.props.defaultIsOpen
482
+ }, cb);
483
+ };
465
484
 
466
- otherStateToSet = pickState(otherStateToSet);
485
+ _this.selectItem = function (item, otherStateToSet, cb) {
486
+ otherStateToSet = pickState(otherStateToSet);
467
487
 
468
- _this.internalSetState(_extends({
469
- highlightedIndex: highlightedIndex
470
- }, otherStateToSet));
471
- };
488
+ _this.internalSetState(_extends({
489
+ isOpen: _this.props.defaultIsOpen,
490
+ highlightedIndex: _this.props.defaultHighlightedIndex,
491
+ selectedItem: item,
492
+ inputValue: _this.props.itemToString(item)
493
+ }, otherStateToSet), cb);
494
+ };
472
495
 
473
- _this.clearSelection = function (cb) {
474
- _this.internalSetState({
475
- selectedItem: null,
476
- inputValue: '',
477
- highlightedIndex: _this.props.defaultHighlightedIndex,
478
- isOpen: _this.props.defaultIsOpen
479
- }, cb);
480
- };
496
+ _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
497
+ var item = _this.items[itemIndex];
481
498
 
482
- _this.selectItem = function (item, otherStateToSet, cb) {
483
- otherStateToSet = pickState(otherStateToSet);
499
+ if (item == null) {
500
+ return;
501
+ }
484
502
 
485
- _this.internalSetState(_extends({
486
- isOpen: _this.props.defaultIsOpen,
487
- highlightedIndex: _this.props.defaultHighlightedIndex,
488
- selectedItem: item,
489
- inputValue: _this.props.itemToString(item)
490
- }, otherStateToSet), cb);
491
- };
503
+ _this.selectItem(item, otherStateToSet, cb);
504
+ };
492
505
 
493
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
494
- var item = _this.items[itemIndex];
506
+ _this.selectHighlightedItem = function (otherStateToSet, cb) {
507
+ return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
508
+ };
495
509
 
496
- if (item == null) {
497
- return;
498
- }
510
+ _this.internalSetState = function (stateToSet, cb) {
511
+ var isItemSelected, onChangeArg;
512
+ var onStateChangeArg = {};
513
+ var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
514
+ // so someone controlling the `inputValue` state gets notified of
515
+ // the input change as soon as possible. This avoids issues with
516
+ // preserving the cursor position.
517
+ // See https://github.com/downshift-js/downshift/issues/217 for more info.
518
+
519
+ if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
520
+ _this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
521
+ }
499
522
 
500
- _this.selectItem(item, otherStateToSet, cb);
501
- };
523
+ return _this.setState(function (state) {
524
+ state = _this.getState(state);
525
+ var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
502
526
 
503
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
504
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
505
- };
527
+ newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
528
+ // what was selected before
529
+ // used to determine if onSelect and onChange callbacks should be called
506
530
 
507
- _this.internalSetState = function (stateToSet, cb) {
508
- var isItemSelected, onChangeArg;
509
- var onStateChangeArg = {};
510
- var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
511
- // so someone controlling the `inputValue` state gets notified of
512
- // the input change as soon as possible. This avoids issues with
513
- // preserving the cursor position.
514
- // See https://github.com/downshift-js/downshift/issues/217 for more info.
515
-
516
- if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
517
- _this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
518
- }
531
+ isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
519
532
 
520
- return _this.setState(function (state) {
521
- state = _this.getState(state);
522
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
533
+ var nextState = {}; // this is just used to tell whether the state changed
523
534
 
524
- newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
525
- // what was selected before
526
- // used to determine if onSelect and onChange callbacks should be called
535
+ var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
536
+ // and we're trying to update that state. OR if the selection has changed and we're
537
+ // trying to update the selection
527
538
 
528
- isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
539
+ if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
540
+ onChangeArg = newStateToSet.selectedItem;
541
+ }
529
542
 
530
- var nextState = {}; // this is just used to tell whether the state changed
543
+ newStateToSet.type = newStateToSet.type || unknown;
544
+ Object.keys(newStateToSet).forEach(function (key) {
545
+ // onStateChangeArg should only have the state that is
546
+ // actually changing
547
+ if (state[key] !== newStateToSet[key]) {
548
+ onStateChangeArg[key] = newStateToSet[key];
549
+ } // the type is useful for the onStateChangeArg
550
+ // but we don't actually want to set it in internal state.
551
+ // this is an undocumented feature for now... Not all internalSetState
552
+ // calls support it and I'm not certain we want them to yet.
553
+ // But it enables users controlling the isOpen state to know when
554
+ // the isOpen state changes due to mouseup events which is quite handy.
555
+
556
+
557
+ if (key === 'type') {
558
+ return;
559
+ }
531
560
 
532
- var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
533
- // and we're trying to update that state. OR if the selection has changed and we're
534
- // trying to update the selection
561
+ nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
535
562
 
536
- if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
537
- onChangeArg = newStateToSet.selectedItem;
538
- }
563
+ if (!_this.isControlledProp(key)) {
564
+ nextState[key] = newStateToSet[key];
565
+ }
566
+ }); // if stateToSet is a function, then we weren't able to call onInputValueChange
567
+ // earlier, so we'll call it now that we know what the inputValue state will be.
539
568
 
540
- newStateToSet.type = newStateToSet.type || unknown;
541
- Object.keys(newStateToSet).forEach(function (key) {
542
- // onStateChangeArg should only have the state that is
543
- // actually changing
544
- if (state[key] !== newStateToSet[key]) {
545
- onStateChangeArg[key] = newStateToSet[key];
546
- } // the type is useful for the onStateChangeArg
547
- // but we don't actually want to set it in internal state.
548
- // this is an undocumented feature for now... Not all internalSetState
549
- // calls support it and I'm not certain we want them to yet.
550
- // But it enables users controlling the isOpen state to know when
551
- // the isOpen state changes due to mouseup events which is quite handy.
552
-
553
-
554
- if (key === 'type') {
555
- return;
569
+ if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
570
+ _this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
556
571
  }
557
572
 
558
- nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
573
+ return nextState;
574
+ }, function () {
575
+ // call the provided callback if it's a function
576
+ cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
577
+ // we have relevant information to pass them.
559
578
 
560
- if (!_this.isControlledProp(key)) {
561
- nextState[key] = newStateToSet[key];
562
- }
563
- }); // if stateToSet is a function, then we weren't able to call onInputValueChange
564
- // earlier, so we'll call it now that we know what the inputValue state will be.
579
+ var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
565
580
 
566
- if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
567
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
568
- }
581
+ if (hasMoreStateThanType) {
582
+ _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
583
+ }
569
584
 
570
- return nextState;
571
- }, function () {
572
- // call the provided callback if it's a function
573
- cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
574
- // we have relevant information to pass them.
585
+ if (isItemSelected) {
586
+ _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
587
+ }
575
588
 
576
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
589
+ if (onChangeArg !== undefined) {
590
+ _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
591
+ } // this is currently undocumented and therefore subject to change
592
+ // We'll try to not break it, but just be warned.
577
593
 
578
- if (hasMoreStateThanType) {
579
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
580
- }
581
594
 
582
- if (isItemSelected) {
583
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
584
- }
595
+ _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
596
+ });
597
+ };
585
598
 
586
- if (onChangeArg !== undefined) {
587
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
588
- } // this is currently undocumented and therefore subject to change
589
- // We'll try to not break it, but just be warned.
599
+ _this.rootRef = function (node) {
600
+ return _this._rootNode = node;
601
+ };
590
602
 
603
+ _this.getRootProps = function (_temp, _temp2) {
604
+ var _extends2;
591
605
 
592
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
593
- });
594
- };
606
+ var _ref = _temp === void 0 ? {} : _temp,
607
+ _ref$refKey = _ref.refKey,
608
+ refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
609
+ ref = _ref.ref,
610
+ rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
595
611
 
596
- _this.rootRef = function (node) {
597
- return _this._rootNode = node;
598
- };
612
+ var _ref2 = _temp2 === void 0 ? {} : _temp2,
613
+ _ref2$suppressRefErro = _ref2.suppressRefError,
614
+ suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
599
615
 
600
- _this.getRootProps = function (_temp, _temp2) {
601
- var _extends2;
616
+ // this is used in the render to know whether the user has called getRootProps.
617
+ // It uses that to know whether to apply the props automatically
618
+ _this.getRootProps.called = true;
619
+ _this.getRootProps.refKey = refKey;
620
+ _this.getRootProps.suppressRefError = suppressRefError;
602
621
 
603
- var _ref = _temp === void 0 ? {} : _temp,
604
- _ref$refKey = _ref.refKey,
605
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
606
- ref = _ref.ref,
607
- rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
622
+ var _this$getState = _this.getState(),
623
+ isOpen = _this$getState.isOpen;
608
624
 
609
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
610
- _ref2$suppressRefErro = _ref2.suppressRefError,
611
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
625
+ return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
626
+ };
612
627
 
613
- // this is used in the render to know whether the user has called getRootProps.
614
- // It uses that to know whether to apply the props automatically
615
- _this.getRootProps.called = true;
616
- _this.getRootProps.refKey = refKey;
617
- _this.getRootProps.suppressRefError = suppressRefError;
628
+ _this.keyDownHandlers = {
629
+ ArrowDown: function ArrowDown(event) {
630
+ var _this2 = this;
618
631
 
619
- var _this$getState = _this.getState(),
620
- isOpen = _this$getState.isOpen;
632
+ event.preventDefault();
621
633
 
622
- return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
623
- };
634
+ if (this.getState().isOpen) {
635
+ var amount = event.shiftKey ? 5 : 1;
636
+ this.moveHighlightedIndex(amount, {
637
+ type: keyDownArrowDown
638
+ });
639
+ } else {
640
+ this.internalSetState({
641
+ isOpen: true,
642
+ type: keyDownArrowDown
643
+ }, function () {
644
+ var itemCount = _this2.getItemCount();
645
+
646
+ if (itemCount > 0) {
647
+ _this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
648
+ type: keyDownArrowDown
649
+ });
650
+ }
651
+ });
652
+ }
653
+ },
654
+ ArrowUp: function ArrowUp(event) {
655
+ var _this3 = this;
624
656
 
625
- _this.keyDownHandlers = {
626
- ArrowDown: function ArrowDown(event) {
627
- var _this2 = this;
657
+ event.preventDefault();
628
658
 
629
- event.preventDefault();
659
+ if (this.getState().isOpen) {
660
+ var amount = event.shiftKey ? -5 : -1;
661
+ this.moveHighlightedIndex(amount, {
662
+ type: keyDownArrowUp
663
+ });
664
+ } else {
665
+ this.internalSetState({
666
+ isOpen: true,
667
+ type: keyDownArrowUp
668
+ }, function () {
669
+ var itemCount = _this3.getItemCount();
670
+
671
+ if (itemCount > 0) {
672
+ _this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
673
+ type: keyDownArrowDown
674
+ });
675
+ }
676
+ });
677
+ }
678
+ },
679
+ Enter: function Enter(event) {
680
+ var _this$getState2 = this.getState(),
681
+ isOpen = _this$getState2.isOpen,
682
+ highlightedIndex = _this$getState2.highlightedIndex;
683
+
684
+ if (isOpen && highlightedIndex != null) {
685
+ event.preventDefault();
686
+ var item = this.items[highlightedIndex];
687
+ var itemNode = this.getItemNodeFromIndex(highlightedIndex);
688
+
689
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
690
+ return;
691
+ }
630
692
 
631
- if (this.getState().isOpen) {
632
- var amount = event.shiftKey ? 5 : 1;
633
- this.moveHighlightedIndex(amount, {
634
- type: keyDownArrowDown
693
+ this.selectHighlightedItem({
694
+ type: keyDownEnter
695
+ });
696
+ }
697
+ },
698
+ Escape: function Escape(event) {
699
+ event.preventDefault();
700
+ this.reset({
701
+ type: keyDownEscape,
702
+ selectedItem: null,
703
+ inputValue: ''
635
704
  });
636
- } else {
637
- this.internalSetState({
638
- isOpen: true,
639
- type: keyDownArrowDown
640
- }, function () {
641
- var itemCount = _this2.getItemCount();
642
-
643
- if (itemCount > 0) {
644
- _this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
645
- type: keyDownArrowDown
646
- });
647
- }
705
+ }
706
+ };
707
+ _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
708
+ ' ': function _(event) {
709
+ event.preventDefault();
710
+ this.toggleMenu({
711
+ type: keyDownSpaceButton
648
712
  });
649
713
  }
650
- },
651
- ArrowUp: function ArrowUp(event) {
652
- var _this3 = this;
653
-
654
- event.preventDefault();
655
-
656
- if (this.getState().isOpen) {
657
- var amount = event.shiftKey ? -5 : -1;
658
- this.moveHighlightedIndex(amount, {
659
- type: keyDownArrowUp
714
+ });
715
+ _this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
716
+ Home: function Home(event) {
717
+ this.highlightFirstOrLastIndex(event, true, {
718
+ type: keyDownHome
660
719
  });
661
- } else {
662
- this.internalSetState({
663
- isOpen: true,
664
- type: keyDownArrowUp
665
- }, function () {
666
- var itemCount = _this3.getItemCount();
667
-
668
- if (itemCount > 0) {
669
- _this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
670
- type: keyDownArrowDown
671
- });
672
- }
720
+ },
721
+ End: function End(event) {
722
+ this.highlightFirstOrLastIndex(event, false, {
723
+ type: keyDownEnd
673
724
  });
674
725
  }
675
- },
676
- Enter: function Enter(event) {
677
- var _this$getState2 = this.getState(),
678
- isOpen = _this$getState2.isOpen,
679
- highlightedIndex = _this$getState2.highlightedIndex;
680
-
681
- if (isOpen && highlightedIndex != null) {
682
- event.preventDefault();
683
- var item = this.items[highlightedIndex];
684
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
726
+ });
685
727
 
686
- if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
687
- return;
688
- }
728
+ _this.getToggleButtonProps = function (_temp3) {
729
+ var _ref3 = _temp3 === void 0 ? {} : _temp3,
730
+ onClick = _ref3.onClick,
731
+ onPress = _ref3.onPress,
732
+ onKeyDown = _ref3.onKeyDown,
733
+ onKeyUp = _ref3.onKeyUp,
734
+ onBlur = _ref3.onBlur,
735
+ rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
736
+
737
+ var _this$getState3 = _this.getState(),
738
+ isOpen = _this$getState3.isOpen;
739
+
740
+ var enabledEventHandlers = {
741
+ onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
742
+ onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
743
+ onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
744
+ onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
745
+ };
746
+ var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
747
+ return _extends({
748
+ type: 'button',
749
+ role: 'button',
750
+ 'aria-label': isOpen ? 'close menu' : 'open menu',
751
+ 'aria-haspopup': true,
752
+ 'data-toggle': true
753
+ }, eventHandlers, {}, rest);
754
+ };
689
755
 
690
- this.selectHighlightedItem({
691
- type: keyDownEnter
692
- });
693
- }
694
- },
695
- Escape: function Escape(event) {
696
- event.preventDefault();
697
- this.reset({
698
- type: keyDownEscape,
699
- selectedItem: null,
700
- inputValue: ''
701
- });
702
- }
703
- };
704
- _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
705
- ' ': function _(event) {
756
+ _this.buttonHandleKeyUp = function (event) {
757
+ // Prevent click event from emitting in Firefox
706
758
  event.preventDefault();
707
- this.toggleMenu({
708
- type: keyDownSpaceButton
709
- });
710
- }
711
- });
712
- _this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
713
- Home: function Home(event) {
714
- this.highlightFirstOrLastIndex(event, true, {
715
- type: keyDownHome
716
- });
717
- },
718
- End: function End(event) {
719
- this.highlightFirstOrLastIndex(event, false, {
720
- type: keyDownEnd
721
- });
722
- }
723
- });
724
-
725
- _this.getToggleButtonProps = function (_temp3) {
726
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
727
- onClick = _ref3.onClick,
728
- onPress = _ref3.onPress,
729
- onKeyDown = _ref3.onKeyDown,
730
- onKeyUp = _ref3.onKeyUp,
731
- onBlur = _ref3.onBlur,
732
- rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
733
-
734
- var _this$getState3 = _this.getState(),
735
- isOpen = _this$getState3.isOpen;
736
-
737
- var enabledEventHandlers = {
738
- onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
739
- onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
740
- onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
741
- onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
742
759
  };
743
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
744
- return _extends({
745
- type: 'button',
746
- role: 'button',
747
- 'aria-label': isOpen ? 'close menu' : 'open menu',
748
- 'aria-haspopup': true,
749
- 'data-toggle': true
750
- }, eventHandlers, {}, rest);
751
- };
752
760
 
753
- _this.buttonHandleKeyUp = function (event) {
754
- // Prevent click event from emitting in Firefox
755
- event.preventDefault();
756
- };
761
+ _this.buttonHandleKeyDown = function (event) {
762
+ var key = normalizeArrowKey(event);
757
763
 
758
- _this.buttonHandleKeyDown = function (event) {
759
- var key = normalizeArrowKey(event);
760
-
761
- if (_this.buttonKeyDownHandlers[key]) {
762
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
763
- }
764
- };
764
+ if (_this.buttonKeyDownHandlers[key]) {
765
+ _this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
766
+ }
767
+ };
765
768
 
766
- _this.buttonHandleClick = function (event) {
767
- event.preventDefault(); // handle odd case for Safari and Firefox which
768
- // don't give the button the focus properly.
769
+ _this.buttonHandleClick = function (event) {
770
+ event.preventDefault(); // handle odd case for Safari and Firefox which
771
+ // don't give the button the focus properly.
769
772
 
770
- /* istanbul ignore if (can't reasonably test this) */
773
+ /* istanbul ignore if (can't reasonably test this) */
771
774
 
772
- if ( _this.props.environment.document.activeElement === _this.props.environment.document.body) {
773
- event.target.focus();
774
- } // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
775
- // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
776
- // when building for production and should therefore have no impact on production code.
775
+ if ( _this.props.environment.document.activeElement === _this.props.environment.document.body) {
776
+ event.target.focus();
777
+ } // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
778
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
779
+ // when building for production and should therefore have no impact on production code.
777
780
 
778
781
 
779
- if (process.env.NODE_ENV === 'test') {
780
- _this.toggleMenu({
781
- type: clickButton
782
- });
783
- } else {
784
- // Ensure that toggle of menu occurs after the potential blur event in iOS
785
- _this.internalSetTimeout(function () {
786
- return _this.toggleMenu({
782
+ if (process.env.NODE_ENV === 'test') {
783
+ _this.toggleMenu({
787
784
  type: clickButton
788
785
  });
789
- });
790
- }
791
- };
792
-
793
- _this.buttonHandleBlur = function (event) {
794
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
795
- // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
796
-
797
- _this.internalSetTimeout(function () {
798
- 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)
799
- ) {
800
- _this.reset({
801
- type: blurButton
786
+ } else {
787
+ // Ensure that toggle of menu occurs after the potential blur event in iOS
788
+ _this.internalSetTimeout(function () {
789
+ return _this.toggleMenu({
790
+ type: clickButton
802
791
  });
803
- }
804
- });
805
- };
792
+ });
793
+ }
794
+ };
806
795
 
807
- _this.getLabelProps = function (props) {
808
- return _extends({
809
- htmlFor: _this.inputId,
810
- id: _this.labelId
811
- }, props);
812
- };
796
+ _this.buttonHandleBlur = function (event) {
797
+ var blurTarget = event.target; // Save blur target for comparison with activeElement later
798
+ // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
813
799
 
814
- _this.getInputProps = function (_temp4) {
815
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
816
- onKeyDown = _ref4.onKeyDown,
817
- onBlur = _ref4.onBlur,
818
- onChange = _ref4.onChange,
819
- onInput = _ref4.onInput,
820
- onChangeText = _ref4.onChangeText,
821
- rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
800
+ _this.internalSetTimeout(function () {
801
+ 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)
802
+ ) {
803
+ _this.reset({
804
+ type: blurButton
805
+ });
806
+ }
807
+ });
808
+ };
822
809
 
823
- var onChangeKey;
824
- var eventHandlers = {};
825
- /* istanbul ignore next (preact) */
810
+ _this.getLabelProps = function (props) {
811
+ return _extends({
812
+ htmlFor: _this.inputId,
813
+ id: _this.labelId
814
+ }, props);
815
+ };
826
816
 
827
- onChangeKey = 'onInput';
817
+ _this.getInputProps = function (_temp4) {
818
+ var _ref4 = _temp4 === void 0 ? {} : _temp4,
819
+ onKeyDown = _ref4.onKeyDown,
820
+ onBlur = _ref4.onBlur,
821
+ onChange = _ref4.onChange,
822
+ onInput = _ref4.onInput,
823
+ onChangeText = _ref4.onChangeText,
824
+ rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
828
825
 
829
- var _this$getState4 = _this.getState(),
830
- inputValue = _this$getState4.inputValue,
831
- isOpen = _this$getState4.isOpen,
832
- highlightedIndex = _this$getState4.highlightedIndex;
826
+ var onChangeKey;
827
+ var eventHandlers = {};
828
+ /* istanbul ignore next (preact) */
833
829
 
834
- if (!rest.disabled) {
835
- var _eventHandlers;
836
-
837
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
838
- }
839
- /* istanbul ignore if (react-native) */
830
+ onChangeKey = 'onInput';
840
831
 
832
+ var _this$getState4 = _this.getState(),
833
+ inputValue = _this$getState4.inputValue,
834
+ isOpen = _this$getState4.isOpen,
835
+ highlightedIndex = _this$getState4.highlightedIndex;
841
836
 
842
- return _extends({
843
- 'aria-autocomplete': 'list',
844
- 'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
845
- 'aria-controls': isOpen ? _this.menuId : null,
846
- 'aria-labelledby': _this.labelId,
847
- // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
848
- // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
849
- autoComplete: 'off',
850
- value: inputValue,
851
- id: _this.inputId
852
- }, eventHandlers, {}, rest);
853
- };
837
+ if (!rest.disabled) {
838
+ var _eventHandlers;
854
839
 
855
- _this.inputHandleKeyDown = function (event) {
856
- var key = normalizeArrowKey(event);
840
+ eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
841
+ }
842
+ /* istanbul ignore if (react-native) */
857
843
 
858
- if (key && _this.inputKeyDownHandlers[key]) {
859
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
860
- }
861
- };
862
844
 
863
- _this.inputHandleChange = function (event) {
864
- _this.internalSetState({
865
- type: changeInput,
866
- isOpen: true,
867
- inputValue: event.target.value,
868
- highlightedIndex: _this.props.defaultHighlightedIndex
869
- });
870
- };
845
+ return _extends({
846
+ 'aria-autocomplete': 'list',
847
+ 'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
848
+ 'aria-controls': isOpen ? _this.menuId : null,
849
+ 'aria-labelledby': _this.labelId,
850
+ // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
851
+ // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
852
+ autoComplete: 'off',
853
+ value: inputValue,
854
+ id: _this.inputId
855
+ }, eventHandlers, {}, rest);
856
+ };
871
857
 
872
- _this.inputHandleBlur = function () {
873
- // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
874
- _this.internalSetTimeout(function () {
875
- 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);
858
+ _this.inputHandleKeyDown = function (event) {
859
+ var key = normalizeArrowKey(event);
876
860
 
877
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
878
- _this.reset({
879
- type: blurInput
880
- });
861
+ if (key && _this.inputKeyDownHandlers[key]) {
862
+ _this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
881
863
  }
882
- });
883
- };
864
+ };
884
865
 
885
- _this.menuRef = function (node) {
886
- _this._menuNode = node;
887
- };
866
+ _this.inputHandleChange = function (event) {
867
+ _this.internalSetState({
868
+ type: changeInput,
869
+ isOpen: true,
870
+ inputValue: event.target.value,
871
+ highlightedIndex: _this.props.defaultHighlightedIndex
872
+ });
873
+ };
888
874
 
889
- _this.getMenuProps = function (_temp5, _temp6) {
890
- var _extends3;
875
+ _this.inputHandleBlur = function () {
876
+ // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
877
+ _this.internalSetTimeout(function () {
878
+ 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);
891
879
 
892
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
893
- _ref5$refKey = _ref5.refKey,
894
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
895
- ref = _ref5.ref,
896
- props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
880
+ if (!_this.isMouseDown && !downshiftButtonIsActive) {
881
+ _this.reset({
882
+ type: blurInput
883
+ });
884
+ }
885
+ });
886
+ };
897
887
 
898
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
899
- _ref6$suppressRefErro = _ref6.suppressRefError,
900
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
888
+ _this.menuRef = function (node) {
889
+ _this._menuNode = node;
890
+ };
901
891
 
902
- _this.getMenuProps.called = true;
903
- _this.getMenuProps.refKey = refKey;
904
- _this.getMenuProps.suppressRefError = suppressRefError;
905
- return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
906
- };
892
+ _this.getMenuProps = function (_temp5, _temp6) {
893
+ var _extends3;
907
894
 
908
- _this.getItemProps = function (_temp7) {
909
- var _enabledEventHandlers;
910
-
911
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
912
- onMouseMove = _ref7.onMouseMove,
913
- onMouseDown = _ref7.onMouseDown,
914
- onClick = _ref7.onClick,
915
- onPress = _ref7.onPress,
916
- index = _ref7.index,
917
- _ref7$item = _ref7.item,
918
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
919
- /* istanbul ignore next */
920
- undefined : requiredProp('getItemProps', 'item') : _ref7$item,
921
- rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
895
+ var _ref5 = _temp5 === void 0 ? {} : _temp5,
896
+ _ref5$refKey = _ref5.refKey,
897
+ refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
898
+ ref = _ref5.ref,
899
+ props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
922
900
 
923
- if (index === undefined) {
924
- _this.items.push(item);
901
+ var _ref6 = _temp6 === void 0 ? {} : _temp6,
902
+ _ref6$suppressRefErro = _ref6.suppressRefError,
903
+ suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
925
904
 
926
- index = _this.items.indexOf(item);
927
- } else {
928
- _this.items[index] = item;
929
- }
905
+ _this.getMenuProps.called = true;
906
+ _this.getMenuProps.refKey = refKey;
907
+ _this.getMenuProps.suppressRefError = suppressRefError;
908
+ return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
909
+ };
930
910
 
931
- var onSelectKey = 'onClick';
932
- var customClickHandler = onClick;
933
- var enabledEventHandlers = (_enabledEventHandlers = {
934
- // onMouseMove is used over onMouseEnter here. onMouseMove
935
- // is only triggered on actual mouse movement while onMouseEnter
936
- // can fire on DOM changes, interrupting keyboard navigation
937
- onMouseMove: callAllEventHandlers(onMouseMove, function () {
938
- if (index === _this.getState().highlightedIndex) {
939
- return;
940
- }
911
+ _this.getItemProps = function (_temp7) {
912
+ var _enabledEventHandlers;
913
+
914
+ var _ref7 = _temp7 === void 0 ? {} : _temp7,
915
+ onMouseMove = _ref7.onMouseMove,
916
+ onMouseDown = _ref7.onMouseDown,
917
+ onClick = _ref7.onClick,
918
+ onPress = _ref7.onPress,
919
+ index = _ref7.index,
920
+ _ref7$item = _ref7.item,
921
+ item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
922
+ /* istanbul ignore next */
923
+ undefined : requiredProp('getItemProps', 'item') : _ref7$item,
924
+ rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
925
+
926
+ if (index === undefined) {
927
+ _this.items.push(item);
928
+
929
+ index = _this.items.indexOf(item);
930
+ } else {
931
+ _this.items[index] = item;
932
+ }
941
933
 
942
- _this.setHighlightedIndex(index, {
943
- type: itemMouseEnter
944
- }); // We never want to manually scroll when changing state based
945
- // on `onMouseMove` because we will be moving the element out
946
- // from under the user which is currently scrolling/moving the
947
- // cursor
934
+ var onSelectKey = 'onClick';
935
+ var customClickHandler = onClick;
936
+ var enabledEventHandlers = (_enabledEventHandlers = {
937
+ // onMouseMove is used over onMouseEnter here. onMouseMove
938
+ // is only triggered on actual mouse movement while onMouseEnter
939
+ // can fire on DOM changes, interrupting keyboard navigation
940
+ onMouseMove: callAllEventHandlers(onMouseMove, function () {
941
+ if (index === _this.getState().highlightedIndex) {
942
+ return;
943
+ }
948
944
 
945
+ _this.setHighlightedIndex(index, {
946
+ type: itemMouseEnter
947
+ }); // We never want to manually scroll when changing state based
948
+ // on `onMouseMove` because we will be moving the element out
949
+ // from under the user which is currently scrolling/moving the
950
+ // cursor
951
+
952
+
953
+ _this.avoidScrolling = true;
954
+
955
+ _this.internalSetTimeout(function () {
956
+ return _this.avoidScrolling = false;
957
+ }, 250);
958
+ }),
959
+ onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
960
+ // This prevents the activeElement from being changed
961
+ // to the item so it can remain with the current activeElement
962
+ // which is a more common use case.
963
+ event.preventDefault();
964
+ })
965
+ }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
966
+ _this.selectItemAtIndex(index, {
967
+ type: clickItem
968
+ });
969
+ }), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
970
+ // of the activeElement if clicking on disabled items
949
971
 
950
- _this.avoidScrolling = true;
972
+ var eventHandlers = rest.disabled ? {
973
+ onMouseDown: enabledEventHandlers.onMouseDown
974
+ } : enabledEventHandlers;
975
+ return _extends({
976
+ id: _this.getItemId(index),
977
+ role: 'option',
978
+ 'aria-selected': _this.getState().highlightedIndex === index
979
+ }, eventHandlers, {}, rest);
980
+ };
951
981
 
952
- _this.internalSetTimeout(function () {
953
- return _this.avoidScrolling = false;
954
- }, 250);
955
- }),
956
- onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
957
- // This prevents the activeElement from being changed
958
- // to the item so it can remain with the current activeElement
959
- // which is a more common use case.
960
- event.preventDefault();
961
- })
962
- }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
963
- _this.selectItemAtIndex(index, {
964
- type: clickItem
965
- });
966
- }), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
967
- // of the activeElement if clicking on disabled items
982
+ _this.clearItems = function () {
983
+ _this.items = [];
984
+ };
968
985
 
969
- var eventHandlers = rest.disabled ? {
970
- onMouseDown: enabledEventHandlers.onMouseDown
971
- } : enabledEventHandlers;
972
- return _extends({
973
- id: _this.getItemId(index),
974
- role: 'option',
975
- 'aria-selected': _this.getState().highlightedIndex === index
976
- }, eventHandlers, {}, rest);
977
- };
986
+ _this.reset = function (otherStateToSet, cb) {
987
+ if (otherStateToSet === void 0) {
988
+ otherStateToSet = {};
989
+ }
978
990
 
979
- _this.clearItems = function () {
980
- _this.items = [];
981
- };
991
+ otherStateToSet = pickState(otherStateToSet);
982
992
 
983
- _this.reset = function (otherStateToSet, cb) {
984
- if (otherStateToSet === void 0) {
985
- otherStateToSet = {};
986
- }
993
+ _this.internalSetState(function (_ref8) {
994
+ var selectedItem = _ref8.selectedItem;
995
+ return _extends({
996
+ isOpen: _this.props.defaultIsOpen,
997
+ highlightedIndex: _this.props.defaultHighlightedIndex,
998
+ inputValue: _this.props.itemToString(selectedItem)
999
+ }, otherStateToSet);
1000
+ }, cb);
1001
+ };
987
1002
 
988
- otherStateToSet = pickState(otherStateToSet);
1003
+ _this.toggleMenu = function (otherStateToSet, cb) {
1004
+ if (otherStateToSet === void 0) {
1005
+ otherStateToSet = {};
1006
+ }
989
1007
 
990
- _this.internalSetState(function (_ref8) {
991
- var selectedItem = _ref8.selectedItem;
992
- return _extends({
993
- isOpen: _this.props.defaultIsOpen,
994
- highlightedIndex: _this.props.defaultHighlightedIndex,
995
- inputValue: _this.props.itemToString(selectedItem)
996
- }, otherStateToSet);
997
- }, cb);
998
- };
1008
+ otherStateToSet = pickState(otherStateToSet);
1009
+
1010
+ _this.internalSetState(function (_ref9) {
1011
+ var isOpen = _ref9.isOpen;
1012
+ return _extends({
1013
+ isOpen: !isOpen
1014
+ }, isOpen && {
1015
+ highlightedIndex: _this.props.defaultHighlightedIndex
1016
+ }, {}, otherStateToSet);
1017
+ }, function () {
1018
+ var _this$getState5 = _this.getState(),
1019
+ isOpen = _this$getState5.isOpen,
1020
+ highlightedIndex = _this$getState5.highlightedIndex;
1021
+
1022
+ if (isOpen) {
1023
+ if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
1024
+ _this.setHighlightedIndex(highlightedIndex, otherStateToSet);
1025
+ }
1026
+ }
999
1027
 
1000
- _this.toggleMenu = function (otherStateToSet, cb) {
1001
- if (otherStateToSet === void 0) {
1002
- otherStateToSet = {};
1003
- }
1028
+ cbToCb(cb)();
1029
+ });
1030
+ };
1004
1031
 
1005
- otherStateToSet = pickState(otherStateToSet);
1032
+ _this.openMenu = function (cb) {
1033
+ _this.internalSetState({
1034
+ isOpen: true
1035
+ }, cb);
1036
+ };
1006
1037
 
1007
- _this.internalSetState(function (_ref9) {
1008
- var isOpen = _ref9.isOpen;
1009
- return _extends({
1010
- isOpen: !isOpen
1011
- }, isOpen && {
1012
- highlightedIndex: _this.props.defaultHighlightedIndex
1013
- }, {}, otherStateToSet);
1014
- }, function () {
1015
- var _this$getState5 = _this.getState(),
1016
- isOpen = _this$getState5.isOpen,
1017
- highlightedIndex = _this$getState5.highlightedIndex;
1018
-
1019
- if (isOpen) {
1020
- if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
1021
- _this.setHighlightedIndex(highlightedIndex, otherStateToSet);
1022
- }
1023
- }
1038
+ _this.closeMenu = function (cb) {
1039
+ _this.internalSetState({
1040
+ isOpen: false
1041
+ }, cb);
1042
+ };
1024
1043
 
1025
- cbToCb(cb)();
1044
+ _this.updateStatus = debounce(function () {
1045
+ var state = _this.getState();
1046
+
1047
+ var item = _this.items[state.highlightedIndex];
1048
+
1049
+ var resultCount = _this.getItemCount();
1050
+
1051
+ var status = _this.props.getA11yStatusMessage(_extends({
1052
+ itemToString: _this.props.itemToString,
1053
+ previousResultCount: _this.previousResultCount,
1054
+ resultCount: resultCount,
1055
+ highlightedItem: item
1056
+ }, state));
1057
+
1058
+ _this.previousResultCount = resultCount;
1059
+ setStatus(status, _this.props.environment.document);
1060
+ }, 200);
1061
+
1062
+ // fancy destructuring + defaults + aliases
1063
+ // this basically says each value of state should either be set to
1064
+ // the initial value or the default value if the initial value is not provided
1065
+ var _this$props = _this.props,
1066
+ defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1067
+ _this$props$initialHi = _this$props.initialHighlightedIndex,
1068
+ _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1069
+ defaultIsOpen = _this$props.defaultIsOpen,
1070
+ _this$props$initialIs = _this$props.initialIsOpen,
1071
+ _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1072
+ _this$props$initialIn = _this$props.initialInputValue,
1073
+ _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1074
+ _this$props$initialSe = _this$props.initialSelectedItem,
1075
+ _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1076
+
1077
+ var _state = _this.getState({
1078
+ highlightedIndex: _highlightedIndex,
1079
+ isOpen: _isOpen,
1080
+ inputValue: _inputValue,
1081
+ selectedItem: _selectedItem
1026
1082
  });
1027
- };
1028
-
1029
- _this.openMenu = function (cb) {
1030
- _this.internalSetState({
1031
- isOpen: true
1032
- }, cb);
1033
- };
1034
1083
 
1035
- _this.closeMenu = function (cb) {
1036
- _this.internalSetState({
1037
- isOpen: false
1038
- }, cb);
1039
- };
1040
-
1041
- _this.updateStatus = debounce(function () {
1042
- var state = _this.getState();
1043
-
1044
- var item = _this.items[state.highlightedIndex];
1045
-
1046
- var resultCount = _this.getItemCount();
1047
-
1048
- var status = _this.props.getA11yStatusMessage(_extends({
1049
- itemToString: _this.props.itemToString,
1050
- previousResultCount: _this.previousResultCount,
1051
- resultCount: resultCount,
1052
- highlightedItem: item
1053
- }, state));
1054
-
1055
- _this.previousResultCount = resultCount;
1056
- setStatus(status, _this.props.environment.document);
1057
- }, 200);
1058
-
1059
- // fancy destructuring + defaults + aliases
1060
- // this basically says each value of state should either be set to
1061
- // the initial value or the default value if the initial value is not provided
1062
- var _this$props = _this.props,
1063
- defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
1064
- _this$props$initialHi = _this$props.initialHighlightedIndex,
1065
- _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
1066
- defaultIsOpen = _this$props.defaultIsOpen,
1067
- _this$props$initialIs = _this$props.initialIsOpen,
1068
- _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
1069
- _this$props$initialIn = _this$props.initialInputValue,
1070
- _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
1071
- _this$props$initialSe = _this$props.initialSelectedItem,
1072
- _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
1073
-
1074
- var _state = _this.getState({
1075
- highlightedIndex: _highlightedIndex,
1076
- isOpen: _isOpen,
1077
- inputValue: _inputValue,
1078
- selectedItem: _selectedItem
1079
- });
1084
+ if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1085
+ _state.inputValue = _this.props.itemToString(_state.selectedItem);
1086
+ }
1080
1087
 
1081
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1082
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1088
+ _this.state = _state;
1089
+ return _this;
1083
1090
  }
1084
1091
 
1085
- _this.state = _state;
1086
- return _this;
1087
- }
1088
-
1089
- var _proto = Downshift.prototype;
1092
+ var _proto = Downshift.prototype;
1090
1093
 
1091
- /**
1092
- * Clear all running timeouts
1093
- */
1094
- _proto.internalClearTimeouts = function internalClearTimeouts() {
1095
- this.timeoutIds.forEach(function (id) {
1096
- clearTimeout(id);
1097
- });
1098
- this.timeoutIds = [];
1099
- }
1100
- /**
1101
- * Gets the state based on internal state or props
1102
- * If a state value is passed via props, then that
1103
- * is the value given, otherwise it's retrieved from
1104
- * stateToMerge
1105
- *
1106
- * This will perform a shallow merge of the given state object
1107
- * with the state coming from props
1108
- * (for the controlled component scenario)
1109
- * This is used in state updater functions so they're referencing
1110
- * the right state regardless of where it comes from.
1111
- *
1112
- * @param {Object} stateToMerge defaults to this.state
1113
- * @return {Object} the state
1114
- */
1115
- ;
1116
-
1117
- _proto.getState = function getState(stateToMerge) {
1118
- var _this4 = this;
1119
-
1120
- if (stateToMerge === void 0) {
1121
- stateToMerge = this.state;
1094
+ /**
1095
+ * Clear all running timeouts
1096
+ */
1097
+ _proto.internalClearTimeouts = function internalClearTimeouts() {
1098
+ this.timeoutIds.forEach(function (id) {
1099
+ clearTimeout(id);
1100
+ });
1101
+ this.timeoutIds = [];
1122
1102
  }
1103
+ /**
1104
+ * Gets the state based on internal state or props
1105
+ * If a state value is passed via props, then that
1106
+ * is the value given, otherwise it's retrieved from
1107
+ * stateToMerge
1108
+ *
1109
+ * This will perform a shallow merge of the given state object
1110
+ * with the state coming from props
1111
+ * (for the controlled component scenario)
1112
+ * This is used in state updater functions so they're referencing
1113
+ * the right state regardless of where it comes from.
1114
+ *
1115
+ * @param {Object} stateToMerge defaults to this.state
1116
+ * @return {Object} the state
1117
+ */
1118
+ ;
1119
+
1120
+ _proto.getState = function getState(stateToMerge) {
1121
+ var _this4 = this;
1122
+
1123
+ if (stateToMerge === void 0) {
1124
+ stateToMerge = this.state;
1125
+ }
1123
1126
 
1124
- return Object.keys(stateToMerge).reduce(function (state, key) {
1125
- state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
1126
- return state;
1127
- }, {});
1128
- }
1129
- /**
1130
- * This determines whether a prop is a "controlled prop" meaning it is
1131
- * state which is controlled by the outside of this component rather
1132
- * than within this component.
1133
- * @param {String} key the key to check
1134
- * @return {Boolean} whether it is a controlled controlled prop
1135
- */
1136
- ;
1137
-
1138
- _proto.isControlledProp = function isControlledProp(key) {
1139
- return this.props[key] !== undefined;
1140
- };
1141
-
1142
- _proto.getItemCount = function getItemCount() {
1143
- // things read better this way. They're in priority order:
1144
- // 1. `this.itemCount`
1145
- // 2. `this.props.itemCount`
1146
- // 3. `this.items.length`
1147
- var itemCount = this.items.length;
1148
-
1149
- if (this.itemCount != null) {
1150
- itemCount = this.itemCount;
1151
- } else if (this.props.itemCount !== undefined) {
1152
- itemCount = this.props.itemCount;
1127
+ return Object.keys(stateToMerge).reduce(function (state, key) {
1128
+ state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
1129
+ return state;
1130
+ }, {});
1153
1131
  }
1132
+ /**
1133
+ * This determines whether a prop is a "controlled prop" meaning it is
1134
+ * state which is controlled by the outside of this component rather
1135
+ * than within this component.
1136
+ * @param {String} key the key to check
1137
+ * @return {Boolean} whether it is a controlled controlled prop
1138
+ */
1139
+ ;
1140
+
1141
+ _proto.isControlledProp = function isControlledProp(key) {
1142
+ return this.props[key] !== undefined;
1143
+ };
1154
1144
 
1155
- return itemCount;
1156
- };
1145
+ _proto.getItemCount = function getItemCount() {
1146
+ // things read better this way. They're in priority order:
1147
+ // 1. `this.itemCount`
1148
+ // 2. `this.props.itemCount`
1149
+ // 3. `this.items.length`
1150
+ var itemCount = this.items.length;
1151
+
1152
+ if (this.itemCount != null) {
1153
+ itemCount = this.itemCount;
1154
+ } else if (this.props.itemCount !== undefined) {
1155
+ itemCount = this.props.itemCount;
1156
+ }
1157
1157
 
1158
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1159
- return this.props.environment.document.getElementById(this.getItemId(index));
1160
- };
1158
+ return itemCount;
1159
+ };
1161
1160
 
1162
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1163
- /* istanbul ignore else (react-native) */
1164
- {
1165
- var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1166
- this.props.scrollIntoView(node, this._menuNode);
1167
- }
1168
- };
1161
+ _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1162
+ return this.props.environment.document.getElementById(this.getItemId(index));
1163
+ };
1169
1164
 
1170
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1171
- var itemCount = this.getItemCount();
1165
+ _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
1166
+ /* istanbul ignore else (react-native) */
1167
+ {
1168
+ var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
1169
+ this.props.scrollIntoView(node, this._menuNode);
1170
+ }
1171
+ };
1172
1172
 
1173
- if (itemCount > 0) {
1174
- var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
1175
- this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1176
- }
1177
- };
1173
+ _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1174
+ var itemCount = this.getItemCount();
1178
1175
 
1179
- _proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
1180
- var itemsLastIndex = this.getItemCount() - 1;
1176
+ if (itemCount > 0) {
1177
+ var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
1178
+ this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1179
+ }
1180
+ };
1181
1181
 
1182
- if (itemsLastIndex < 0 || !this.getState().isOpen) {
1183
- return;
1184
- }
1182
+ _proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
1183
+ var itemsLastIndex = this.getItemCount() - 1;
1185
1184
 
1186
- event.preventDefault();
1187
- this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
1188
- };
1185
+ if (itemsLastIndex < 0 || !this.getState().isOpen) {
1186
+ return;
1187
+ }
1189
1188
 
1190
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1191
- var _this$getState6 = this.getState(),
1192
- highlightedIndex = _this$getState6.highlightedIndex,
1193
- inputValue = _this$getState6.inputValue,
1194
- selectedItem = _this$getState6.selectedItem,
1195
- isOpen = _this$getState6.isOpen;
1196
-
1197
- var itemToString = this.props.itemToString;
1198
- var id = this.id;
1199
- var getRootProps = this.getRootProps,
1200
- getToggleButtonProps = this.getToggleButtonProps,
1201
- getLabelProps = this.getLabelProps,
1202
- getMenuProps = this.getMenuProps,
1203
- getInputProps = this.getInputProps,
1204
- getItemProps = this.getItemProps,
1205
- openMenu = this.openMenu,
1206
- closeMenu = this.closeMenu,
1207
- toggleMenu = this.toggleMenu,
1208
- selectItem = this.selectItem,
1209
- selectItemAtIndex = this.selectItemAtIndex,
1210
- selectHighlightedItem = this.selectHighlightedItem,
1211
- setHighlightedIndex = this.setHighlightedIndex,
1212
- clearSelection = this.clearSelection,
1213
- clearItems = this.clearItems,
1214
- reset = this.reset,
1215
- setItemCount = this.setItemCount,
1216
- unsetItemCount = this.unsetItemCount,
1217
- setState = this.internalSetState;
1218
- return {
1219
- // prop getters
1220
- getRootProps: getRootProps,
1221
- getToggleButtonProps: getToggleButtonProps,
1222
- getLabelProps: getLabelProps,
1223
- getMenuProps: getMenuProps,
1224
- getInputProps: getInputProps,
1225
- getItemProps: getItemProps,
1226
- // actions
1227
- reset: reset,
1228
- openMenu: openMenu,
1229
- closeMenu: closeMenu,
1230
- toggleMenu: toggleMenu,
1231
- selectItem: selectItem,
1232
- selectItemAtIndex: selectItemAtIndex,
1233
- selectHighlightedItem: selectHighlightedItem,
1234
- setHighlightedIndex: setHighlightedIndex,
1235
- clearSelection: clearSelection,
1236
- clearItems: clearItems,
1237
- setItemCount: setItemCount,
1238
- unsetItemCount: unsetItemCount,
1239
- setState: setState,
1240
- // props
1241
- itemToString: itemToString,
1242
- // derived
1243
- id: id,
1244
- // state
1245
- highlightedIndex: highlightedIndex,
1246
- inputValue: inputValue,
1247
- isOpen: isOpen,
1248
- selectedItem: selectedItem
1189
+ event.preventDefault();
1190
+ this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
1249
1191
  };
1250
- } //////////////////////////// ROOT
1251
- ;
1252
1192
 
1253
- _proto.componentDidMount = function componentDidMount() {
1254
- var _this5 = this;
1193
+ _proto.getStateAndHelpers = function getStateAndHelpers() {
1194
+ var _this$getState6 = this.getState(),
1195
+ highlightedIndex = _this$getState6.highlightedIndex,
1196
+ inputValue = _this$getState6.inputValue,
1197
+ selectedItem = _this$getState6.selectedItem,
1198
+ isOpen = _this$getState6.isOpen;
1199
+
1200
+ var itemToString = this.props.itemToString;
1201
+ var id = this.id;
1202
+ var getRootProps = this.getRootProps,
1203
+ getToggleButtonProps = this.getToggleButtonProps,
1204
+ getLabelProps = this.getLabelProps,
1205
+ getMenuProps = this.getMenuProps,
1206
+ getInputProps = this.getInputProps,
1207
+ getItemProps = this.getItemProps,
1208
+ openMenu = this.openMenu,
1209
+ closeMenu = this.closeMenu,
1210
+ toggleMenu = this.toggleMenu,
1211
+ selectItem = this.selectItem,
1212
+ selectItemAtIndex = this.selectItemAtIndex,
1213
+ selectHighlightedItem = this.selectHighlightedItem,
1214
+ setHighlightedIndex = this.setHighlightedIndex,
1215
+ clearSelection = this.clearSelection,
1216
+ clearItems = this.clearItems,
1217
+ reset = this.reset,
1218
+ setItemCount = this.setItemCount,
1219
+ unsetItemCount = this.unsetItemCount,
1220
+ setState = this.internalSetState;
1221
+ return {
1222
+ // prop getters
1223
+ getRootProps: getRootProps,
1224
+ getToggleButtonProps: getToggleButtonProps,
1225
+ getLabelProps: getLabelProps,
1226
+ getMenuProps: getMenuProps,
1227
+ getInputProps: getInputProps,
1228
+ getItemProps: getItemProps,
1229
+ // actions
1230
+ reset: reset,
1231
+ openMenu: openMenu,
1232
+ closeMenu: closeMenu,
1233
+ toggleMenu: toggleMenu,
1234
+ selectItem: selectItem,
1235
+ selectItemAtIndex: selectItemAtIndex,
1236
+ selectHighlightedItem: selectHighlightedItem,
1237
+ setHighlightedIndex: setHighlightedIndex,
1238
+ clearSelection: clearSelection,
1239
+ clearItems: clearItems,
1240
+ setItemCount: setItemCount,
1241
+ unsetItemCount: unsetItemCount,
1242
+ setState: setState,
1243
+ // props
1244
+ itemToString: itemToString,
1245
+ // derived
1246
+ id: id,
1247
+ // state
1248
+ highlightedIndex: highlightedIndex,
1249
+ inputValue: inputValue,
1250
+ isOpen: isOpen,
1251
+ selectedItem: selectedItem
1252
+ };
1253
+ } //////////////////////////// ROOT
1254
+ ;
1255
1255
 
1256
- /* istanbul ignore if (react-native) */
1257
- if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1258
- validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1259
- }
1260
- /* istanbul ignore if (react-native) */
1256
+ _proto.componentDidMount = function componentDidMount() {
1257
+ var _this5 = this;
1261
1258
 
1259
+ /* istanbul ignore if (react-native) */
1260
+ if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1261
+ validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1262
+ }
1263
+ /* istanbul ignore if (react-native) */
1262
1264
 
1263
- {
1264
- var targetWithinDownshift = function (target, checkActiveElement) {
1265
- if (checkActiveElement === void 0) {
1266
- checkActiveElement = true;
1267
- }
1268
1265
 
1269
- var document = _this5.props.environment.document;
1270
- return [_this5._rootNode, _this5._menuNode].some(function (contextNode) {
1271
- return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
1272
- });
1273
- }; // this.isMouseDown helps us track whether the mouse is currently held down.
1274
- // This is useful when the user clicks on an item in the list, but holds the mouse
1275
- // down long enough for the list to disappear (because the blur event fires on the input)
1276
- // this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
1277
- // trigger hiding the menu.
1266
+ {
1267
+ var targetWithinDownshift = function (target, checkActiveElement) {
1268
+ if (checkActiveElement === void 0) {
1269
+ checkActiveElement = true;
1270
+ }
1278
1271
 
1272
+ var document = _this5.props.environment.document;
1273
+ return [_this5._rootNode, _this5._menuNode].some(function (contextNode) {
1274
+ return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
1275
+ });
1276
+ }; // this.isMouseDown helps us track whether the mouse is currently held down.
1277
+ // This is useful when the user clicks on an item in the list, but holds the mouse
1278
+ // down long enough for the list to disappear (because the blur event fires on the input)
1279
+ // this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
1280
+ // trigger hiding the menu.
1279
1281
 
1280
- var onMouseDown = function () {
1281
- _this5.isMouseDown = true;
1282
- };
1283
1282
 
1284
- var onMouseUp = function (event) {
1285
- _this5.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1286
- // then we don't want to reset downshift
1283
+ var onMouseDown = function () {
1284
+ _this5.isMouseDown = true;
1285
+ };
1287
1286
 
1288
- var contextWithinDownshift = targetWithinDownshift(event.target);
1287
+ var onMouseUp = function (event) {
1288
+ _this5.isMouseDown = false; // if the target element or the activeElement is within a downshift node
1289
+ // then we don't want to reset downshift
1289
1290
 
1290
- if (!contextWithinDownshift && _this5.getState().isOpen) {
1291
- _this5.reset({
1292
- type: mouseUp
1293
- }, function () {
1294
- return _this5.props.onOuterClick(_this5.getStateAndHelpers());
1295
- });
1296
- }
1297
- }; // Touching an element in iOS gives focus and hover states, but touching out of
1298
- // the element will remove hover, and persist the focus state, resulting in the
1299
- // blur event not being triggered.
1300
- // this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
1301
- // If the user taps outside of Downshift, the component should be reset,
1302
- // but not if the user is swiping
1291
+ var contextWithinDownshift = targetWithinDownshift(event.target);
1303
1292
 
1293
+ if (!contextWithinDownshift && _this5.getState().isOpen) {
1294
+ _this5.reset({
1295
+ type: mouseUp
1296
+ }, function () {
1297
+ return _this5.props.onOuterClick(_this5.getStateAndHelpers());
1298
+ });
1299
+ }
1300
+ }; // Touching an element in iOS gives focus and hover states, but touching out of
1301
+ // the element will remove hover, and persist the focus state, resulting in the
1302
+ // blur event not being triggered.
1303
+ // this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
1304
+ // If the user taps outside of Downshift, the component should be reset,
1305
+ // but not if the user is swiping
1304
1306
 
1305
- var onTouchStart = function () {
1306
- _this5.isTouchMove = false;
1307
- };
1308
1307
 
1309
- var onTouchMove = function () {
1310
- _this5.isTouchMove = true;
1311
- };
1308
+ var onTouchStart = function () {
1309
+ _this5.isTouchMove = false;
1310
+ };
1312
1311
 
1313
- var onTouchEnd = function (event) {
1314
- var contextWithinDownshift = targetWithinDownshift(event.target, false);
1312
+ var onTouchMove = function () {
1313
+ _this5.isTouchMove = true;
1314
+ };
1315
1315
 
1316
- if (!_this5.isTouchMove && !contextWithinDownshift && _this5.getState().isOpen) {
1317
- _this5.reset({
1318
- type: touchEnd
1319
- }, function () {
1320
- return _this5.props.onOuterClick(_this5.getStateAndHelpers());
1321
- });
1322
- }
1323
- };
1316
+ var onTouchEnd = function (event) {
1317
+ var contextWithinDownshift = targetWithinDownshift(event.target, false);
1324
1318
 
1325
- var environment = this.props.environment;
1326
- environment.addEventListener('mousedown', onMouseDown);
1327
- environment.addEventListener('mouseup', onMouseUp);
1328
- environment.addEventListener('touchstart', onTouchStart);
1329
- environment.addEventListener('touchmove', onTouchMove);
1330
- environment.addEventListener('touchend', onTouchEnd);
1319
+ if (!_this5.isTouchMove && !contextWithinDownshift && _this5.getState().isOpen) {
1320
+ _this5.reset({
1321
+ type: touchEnd
1322
+ }, function () {
1323
+ return _this5.props.onOuterClick(_this5.getStateAndHelpers());
1324
+ });
1325
+ }
1326
+ };
1331
1327
 
1332
- this.cleanup = function () {
1333
- _this5.internalClearTimeouts();
1328
+ var environment = this.props.environment;
1329
+ environment.addEventListener('mousedown', onMouseDown);
1330
+ environment.addEventListener('mouseup', onMouseUp);
1331
+ environment.addEventListener('touchstart', onTouchStart);
1332
+ environment.addEventListener('touchmove', onTouchMove);
1333
+ environment.addEventListener('touchend', onTouchEnd);
1334
1334
 
1335
- _this5.updateStatus.cancel();
1335
+ this.cleanup = function () {
1336
+ _this5.internalClearTimeouts();
1336
1337
 
1337
- environment.removeEventListener('mousedown', onMouseDown);
1338
- environment.removeEventListener('mouseup', onMouseUp);
1339
- environment.removeEventListener('touchstart', onTouchStart);
1340
- environment.removeEventListener('touchmove', onTouchMove);
1341
- environment.removeEventListener('touchend', onTouchEnd);
1342
- };
1343
- }
1344
- };
1338
+ _this5.updateStatus.cancel();
1345
1339
 
1346
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1347
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1348
- currentHighlightedIndex = _ref10.highlightedIndex;
1340
+ environment.removeEventListener('mousedown', onMouseDown);
1341
+ environment.removeEventListener('mouseup', onMouseUp);
1342
+ environment.removeEventListener('touchstart', onTouchStart);
1343
+ environment.removeEventListener('touchmove', onTouchMove);
1344
+ environment.removeEventListener('touchend', onTouchEnd);
1345
+ };
1346
+ }
1347
+ };
1349
1348
 
1350
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1351
- prevHighlightedIndex = _ref11.highlightedIndex;
1349
+ _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1350
+ var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1351
+ currentHighlightedIndex = _ref10.highlightedIndex;
1352
1352
 
1353
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1354
- return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
1355
- };
1353
+ var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1354
+ prevHighlightedIndex = _ref11.highlightedIndex;
1356
1355
 
1357
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1358
- if (process.env.NODE_ENV !== 'production') {
1359
- validateControlledUnchanged(prevProps, this.props);
1360
- /* istanbul ignore if (react-native) */
1356
+ var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1357
+ return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
1358
+ };
1361
1359
 
1362
- if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1363
- validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1360
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1361
+ if (process.env.NODE_ENV !== 'production') {
1362
+ validateControlledUnchanged(prevProps, this.props);
1363
+ /* istanbul ignore if (react-native) */
1364
+
1365
+ if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1366
+ validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1367
+ }
1364
1368
  }
1365
- }
1366
1369
 
1367
- if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1368
- this.internalSetState({
1369
- type: controlledPropUpdatedSelectedItem,
1370
- inputValue: this.props.itemToString(this.props.selectedItem)
1371
- });
1372
- }
1370
+ if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1371
+ this.internalSetState({
1372
+ type: controlledPropUpdatedSelectedItem,
1373
+ inputValue: this.props.itemToString(this.props.selectedItem)
1374
+ });
1375
+ }
1373
1376
 
1374
- if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
1375
- this.scrollHighlightedItemIntoView();
1376
- }
1377
- /* istanbul ignore else (react-native) */
1377
+ if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
1378
+ this.scrollHighlightedItemIntoView();
1379
+ }
1380
+ /* istanbul ignore else (react-native) */
1378
1381
 
1379
1382
 
1380
- this.updateStatus();
1381
- };
1383
+ this.updateStatus();
1384
+ };
1382
1385
 
1383
- _proto.componentWillUnmount = function componentWillUnmount() {
1384
- this.cleanup(); // avoids memory leak
1385
- };
1386
+ _proto.componentWillUnmount = function componentWillUnmount() {
1387
+ this.cleanup(); // avoids memory leak
1388
+ };
1386
1389
 
1387
- _proto.render = function render() {
1388
- var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1389
- // we clear this out each render and it will be populated again as
1390
- // getItemProps is called.
1390
+ _proto.render = function render() {
1391
+ var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1392
+ // we clear this out each render and it will be populated again as
1393
+ // getItemProps is called.
1391
1394
 
1392
- this.clearItems(); // we reset this so we know whether the user calls getRootProps during
1393
- // this render. If they do then we don't need to do anything,
1394
- // if they don't then we need to clone the element they return and
1395
- // apply the props for them.
1395
+ this.clearItems(); // we reset this so we know whether the user calls getRootProps during
1396
+ // this render. If they do then we don't need to do anything,
1397
+ // if they don't then we need to clone the element they return and
1398
+ // apply the props for them.
1396
1399
 
1397
- this.getRootProps.called = false;
1398
- this.getRootProps.refKey = undefined;
1399
- this.getRootProps.suppressRefError = undefined; // we do something similar for getMenuProps
1400
+ this.getRootProps.called = false;
1401
+ this.getRootProps.refKey = undefined;
1402
+ this.getRootProps.suppressRefError = undefined; // we do something similar for getMenuProps
1400
1403
 
1401
- this.getMenuProps.called = false;
1402
- this.getMenuProps.refKey = undefined;
1403
- this.getMenuProps.suppressRefError = undefined; // we do something similar for getLabelProps
1404
+ this.getMenuProps.called = false;
1405
+ this.getMenuProps.refKey = undefined;
1406
+ this.getMenuProps.suppressRefError = undefined; // we do something similar for getLabelProps
1404
1407
 
1405
- this.getLabelProps.called = false; // and something similar for getInputProps
1408
+ this.getLabelProps.called = false; // and something similar for getInputProps
1406
1409
 
1407
- this.getInputProps.called = false;
1408
- var element = unwrapArray(children(this.getStateAndHelpers()));
1410
+ this.getInputProps.called = false;
1411
+ var element = unwrapArray(children(this.getStateAndHelpers()));
1409
1412
 
1410
- if (!element) {
1411
- return null;
1412
- }
1413
+ if (!element) {
1414
+ return null;
1415
+ }
1416
+
1417
+ if (this.getRootProps.called || this.props.suppressRefError) {
1418
+ if (process.env.NODE_ENV !== 'production' && !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
1419
+ validateGetRootPropsCalledCorrectly(element, this.getRootProps);
1420
+ }
1413
1421
 
1414
- if (this.getRootProps.called || this.props.suppressRefError) {
1415
- if (process.env.NODE_ENV !== 'production' && !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
1416
- validateGetRootPropsCalledCorrectly(element, this.getRootProps);
1422
+ return element;
1423
+ } else if (isDOMElement(element)) {
1424
+ // they didn't apply the root props, but we can clone
1425
+ // this and apply the props ourselves
1426
+ return preact.cloneElement(element, this.getRootProps(getElementProps(element)));
1417
1427
  }
1428
+ /* istanbul ignore else */
1418
1429
 
1419
- return element;
1420
- } else if (isDOMElement(element)) {
1421
- // they didn't apply the root props, but we can clone
1422
- // this and apply the props ourselves
1423
- return preact.cloneElement(element, this.getRootProps(getElementProps(element)));
1424
- }
1425
- /* istanbul ignore else */
1426
1430
 
1431
+ if (process.env.NODE_ENV !== 'production') {
1432
+ // they didn't apply the root props, but they need to
1433
+ // otherwise we can't query around the autocomplete
1434
+ throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
1435
+ }
1436
+ /* istanbul ignore next */
1427
1437
 
1428
- if (process.env.NODE_ENV !== 'production') {
1429
- // they didn't apply the root props, but they need to
1430
- // otherwise we can't query around the autocomplete
1431
- throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
1432
- }
1433
- /* istanbul ignore next */
1434
1438
 
1439
+ return undefined;
1440
+ };
1435
1441
 
1436
- return undefined;
1437
- };
1442
+ return Downshift;
1443
+ }(preact.Component);
1438
1444
 
1439
- return Downshift;
1440
- }(preact.Component);
1441
-
1442
- Downshift.defaultProps = {
1443
- defaultHighlightedIndex: null,
1444
- defaultIsOpen: false,
1445
- getA11yStatusMessage: getA11yStatusMessage,
1446
- itemToString: function itemToString(i) {
1447
- if (i == null) {
1448
- return '';
1449
- }
1445
+ Downshift.defaultProps = {
1446
+ defaultHighlightedIndex: null,
1447
+ defaultIsOpen: false,
1448
+ getA11yStatusMessage: getA11yStatusMessage,
1449
+ itemToString: function itemToString(i) {
1450
+ if (i == null) {
1451
+ return '';
1452
+ }
1450
1453
 
1451
- if (process.env.NODE_ENV !== 'production' && isPlainObject(i) && !i.hasOwnProperty('toString')) {
1452
- // eslint-disable-next-line no-console
1453
- console.warn('downshift: An object was passed to the default implementation of `itemToString`. You should probably provide your own `itemToString` implementation. Please refer to the `itemToString` API documentation.', 'The object that was passed:', i);
1454
- }
1454
+ if (process.env.NODE_ENV !== 'production' && isPlainObject(i) && !i.hasOwnProperty('toString')) {
1455
+ // eslint-disable-next-line no-console
1456
+ console.warn('downshift: An object was passed to the default implementation of `itemToString`. You should probably provide your own `itemToString` implementation. Please refer to the `itemToString` API documentation.', 'The object that was passed:', i);
1457
+ }
1455
1458
 
1456
- return String(i);
1457
- },
1458
- onStateChange: noop,
1459
- onInputValueChange: noop,
1460
- onUserAction: noop,
1461
- onChange: noop,
1462
- onSelect: noop,
1463
- onOuterClick: noop,
1464
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1465
- return prevItem !== item;
1466
- },
1467
- environment: typeof window === 'undefined'
1468
- /* istanbul ignore next (ssr) */
1469
- ? {} : window,
1470
- stateReducer: function stateReducer(state, stateToSet) {
1471
- return stateToSet;
1472
- },
1473
- suppressRefError: false,
1474
- scrollIntoView: scrollIntoView
1475
- };
1476
- Downshift.stateChangeTypes = stateChangeTypes;
1459
+ return String(i);
1460
+ },
1461
+ onStateChange: noop,
1462
+ onInputValueChange: noop,
1463
+ onUserAction: noop,
1464
+ onChange: noop,
1465
+ onSelect: noop,
1466
+ onOuterClick: noop,
1467
+ selectedItemChanged: function selectedItemChanged(prevItem, item) {
1468
+ return prevItem !== item;
1469
+ },
1470
+ environment: typeof window === 'undefined'
1471
+ /* istanbul ignore next (ssr) */
1472
+ ? {} : window,
1473
+ stateReducer: function stateReducer(state, stateToSet) {
1474
+ return stateToSet;
1475
+ },
1476
+ suppressRefError: false,
1477
+ scrollIntoView: scrollIntoView
1478
+ };
1479
+ Downshift.stateChangeTypes = stateChangeTypes;
1480
+ return Downshift;
1481
+ }();
1477
1482
 
1478
1483
  function validateGetMenuPropsCalledCorrectly(node, _ref12) {
1479
1484
  var refKey = _ref12.refKey;
@@ -2051,7 +2056,9 @@ function downshiftSelectReducer(state, action) {
2051
2056
  }
2052
2057
  /* eslint-enable complexity */
2053
2058
 
2054
- var validatePropTypes = getPropTypesValidator(useSelect, propTypes);
2059
+ var validatePropTypes = process.env.NODE_ENV === 'production' ?
2060
+ /* istanbul ignore next */
2061
+ null : getPropTypesValidator(useSelect, propTypes);
2055
2062
  var defaultProps = {
2056
2063
  itemToString: itemToString,
2057
2064
  stateReducer: function stateReducer(s, a) {
@@ -2071,7 +2078,11 @@ function useSelect(userProps) {
2071
2078
  userProps = {};
2072
2079
  }
2073
2080
 
2074
- validatePropTypes(userProps); // Props defaults and destructuring.
2081
+ /* istanbul ignore else */
2082
+ if (process.env.NODE_ENV !== 'production') {
2083
+ validatePropTypes(userProps);
2084
+ } // Props defaults and destructuring.
2085
+
2075
2086
 
2076
2087
  var props = _extends({}, defaultProps, {}, userProps);
2077
2088