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