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.
@@ -399,988 +399,994 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
399
399
 
400
400
  var Downshift =
401
401
  /*#__PURE__*/
402
- function (_Component) {
403
- _inheritsLoose(Downshift, _Component);
402
+ function () {
403
+ var Downshift =
404
+ /*#__PURE__*/
405
+ function (_Component) {
406
+ _inheritsLoose(Downshift, _Component);
407
+
408
+ function Downshift(_props) {
409
+ var _this = _Component.call(this, _props) || this;
410
+
411
+ _this.id = _this.props.id || "downshift-" + generateId();
412
+ _this.menuId = _this.props.menuId || _this.id + "-menu";
413
+ _this.labelId = _this.props.labelId || _this.id + "-label";
414
+ _this.inputId = _this.props.inputId || _this.id + "-input";
415
+
416
+ _this.getItemId = _this.props.getItemId || function (index) {
417
+ return _this.id + "-item-" + index;
418
+ };
404
419
 
405
- function Downshift(_props) {
406
- var _this = _Component.call(this, _props) || this;
420
+ _this.input = null;
421
+ _this.items = [];
422
+ _this.itemCount = null;
423
+ _this.previousResultCount = 0;
424
+ _this.timeoutIds = [];
407
425
 
408
- _this.id = _this.props.id || "downshift-" + generateId();
409
- _this.menuId = _this.props.menuId || _this.id + "-menu";
410
- _this.labelId = _this.props.labelId || _this.id + "-label";
411
- _this.inputId = _this.props.inputId || _this.id + "-input";
426
+ _this.internalSetTimeout = function (fn, time) {
427
+ var id = setTimeout(function () {
428
+ _this.timeoutIds = _this.timeoutIds.filter(function (i) {
429
+ return i !== id;
430
+ });
431
+ fn();
432
+ }, time);
412
433
 
413
- _this.getItemId = _this.props.getItemId || function (index) {
414
- return _this.id + "-item-" + index;
415
- };
434
+ _this.timeoutIds.push(id);
435
+ };
416
436
 
417
- _this.input = null;
418
- _this.items = [];
419
- _this.itemCount = null;
420
- _this.previousResultCount = 0;
421
- _this.timeoutIds = [];
437
+ _this.setItemCount = function (count) {
438
+ _this.itemCount = count;
439
+ };
422
440
 
423
- _this.internalSetTimeout = function (fn, time) {
424
- var id = setTimeout(function () {
425
- _this.timeoutIds = _this.timeoutIds.filter(function (i) {
426
- return i !== id;
427
- });
428
- fn();
429
- }, time);
441
+ _this.unsetItemCount = function () {
442
+ _this.itemCount = null;
443
+ };
430
444
 
431
- _this.timeoutIds.push(id);
432
- };
445
+ _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
446
+ if (highlightedIndex === void 0) {
447
+ highlightedIndex = _this.props.defaultHighlightedIndex;
448
+ }
433
449
 
434
- _this.setItemCount = function (count) {
435
- _this.itemCount = count;
436
- };
450
+ if (otherStateToSet === void 0) {
451
+ otherStateToSet = {};
452
+ }
437
453
 
438
- _this.unsetItemCount = function () {
439
- _this.itemCount = null;
440
- };
454
+ otherStateToSet = pickState(otherStateToSet);
441
455
 
442
- _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
443
- if (highlightedIndex === void 0) {
444
- highlightedIndex = _this.props.defaultHighlightedIndex;
445
- }
456
+ _this.internalSetState(_extends({
457
+ highlightedIndex: highlightedIndex
458
+ }, otherStateToSet));
459
+ };
446
460
 
447
- if (otherStateToSet === void 0) {
448
- otherStateToSet = {};
449
- }
461
+ _this.clearSelection = function (cb) {
462
+ _this.internalSetState({
463
+ selectedItem: null,
464
+ inputValue: '',
465
+ highlightedIndex: _this.props.defaultHighlightedIndex,
466
+ isOpen: _this.props.defaultIsOpen
467
+ }, cb);
468
+ };
450
469
 
451
- otherStateToSet = pickState(otherStateToSet);
470
+ _this.selectItem = function (item, otherStateToSet, cb) {
471
+ otherStateToSet = pickState(otherStateToSet);
452
472
 
453
- _this.internalSetState(_extends({
454
- highlightedIndex: highlightedIndex
455
- }, otherStateToSet));
456
- };
473
+ _this.internalSetState(_extends({
474
+ isOpen: _this.props.defaultIsOpen,
475
+ highlightedIndex: _this.props.defaultHighlightedIndex,
476
+ selectedItem: item,
477
+ inputValue: _this.props.itemToString(item)
478
+ }, otherStateToSet), cb);
479
+ };
457
480
 
458
- _this.clearSelection = function (cb) {
459
- _this.internalSetState({
460
- selectedItem: null,
461
- inputValue: '',
462
- highlightedIndex: _this.props.defaultHighlightedIndex,
463
- isOpen: _this.props.defaultIsOpen
464
- }, cb);
465
- };
481
+ _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
482
+ var item = _this.items[itemIndex];
466
483
 
467
- _this.selectItem = function (item, otherStateToSet, cb) {
468
- otherStateToSet = pickState(otherStateToSet);
484
+ if (item == null) {
485
+ return;
486
+ }
469
487
 
470
- _this.internalSetState(_extends({
471
- isOpen: _this.props.defaultIsOpen,
472
- highlightedIndex: _this.props.defaultHighlightedIndex,
473
- selectedItem: item,
474
- inputValue: _this.props.itemToString(item)
475
- }, otherStateToSet), cb);
476
- };
488
+ _this.selectItem(item, otherStateToSet, cb);
489
+ };
477
490
 
478
- _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
479
- var item = _this.items[itemIndex];
491
+ _this.selectHighlightedItem = function (otherStateToSet, cb) {
492
+ return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
493
+ };
480
494
 
481
- if (item == null) {
482
- return;
483
- }
495
+ _this.internalSetState = function (stateToSet, cb) {
496
+ var isItemSelected, onChangeArg;
497
+ var onStateChangeArg = {};
498
+ var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
499
+ // so someone controlling the `inputValue` state gets notified of
500
+ // the input change as soon as possible. This avoids issues with
501
+ // preserving the cursor position.
502
+ // See https://github.com/downshift-js/downshift/issues/217 for more info.
503
+
504
+ if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
505
+ _this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
506
+ }
484
507
 
485
- _this.selectItem(item, otherStateToSet, cb);
486
- };
508
+ return _this.setState(function (state) {
509
+ state = _this.getState(state);
510
+ var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
487
511
 
488
- _this.selectHighlightedItem = function (otherStateToSet, cb) {
489
- return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
490
- };
512
+ newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
513
+ // what was selected before
514
+ // used to determine if onSelect and onChange callbacks should be called
491
515
 
492
- _this.internalSetState = function (stateToSet, cb) {
493
- var isItemSelected, onChangeArg;
494
- var onStateChangeArg = {};
495
- var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
496
- // so someone controlling the `inputValue` state gets notified of
497
- // the input change as soon as possible. This avoids issues with
498
- // preserving the cursor position.
499
- // See https://github.com/downshift-js/downshift/issues/217 for more info.
500
-
501
- if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
502
- _this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
503
- }
516
+ isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
504
517
 
505
- return _this.setState(function (state) {
506
- state = _this.getState(state);
507
- var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
518
+ var nextState = {}; // this is just used to tell whether the state changed
508
519
 
509
- newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
510
- // what was selected before
511
- // used to determine if onSelect and onChange callbacks should be called
520
+ var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
521
+ // and we're trying to update that state. OR if the selection has changed and we're
522
+ // trying to update the selection
512
523
 
513
- isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
524
+ if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
525
+ onChangeArg = newStateToSet.selectedItem;
526
+ }
514
527
 
515
- var nextState = {}; // this is just used to tell whether the state changed
528
+ newStateToSet.type = newStateToSet.type || unknown;
529
+ Object.keys(newStateToSet).forEach(function (key) {
530
+ // onStateChangeArg should only have the state that is
531
+ // actually changing
532
+ if (state[key] !== newStateToSet[key]) {
533
+ onStateChangeArg[key] = newStateToSet[key];
534
+ } // the type is useful for the onStateChangeArg
535
+ // but we don't actually want to set it in internal state.
536
+ // this is an undocumented feature for now... Not all internalSetState
537
+ // calls support it and I'm not certain we want them to yet.
538
+ // But it enables users controlling the isOpen state to know when
539
+ // the isOpen state changes due to mouseup events which is quite handy.
540
+
541
+
542
+ if (key === 'type') {
543
+ return;
544
+ }
516
545
 
517
- var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
518
- // and we're trying to update that state. OR if the selection has changed and we're
519
- // trying to update the selection
546
+ nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
520
547
 
521
- if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
522
- onChangeArg = newStateToSet.selectedItem;
523
- }
548
+ if (!_this.isControlledProp(key)) {
549
+ nextState[key] = newStateToSet[key];
550
+ }
551
+ }); // if stateToSet is a function, then we weren't able to call onInputValueChange
552
+ // earlier, so we'll call it now that we know what the inputValue state will be.
524
553
 
525
- newStateToSet.type = newStateToSet.type || unknown;
526
- Object.keys(newStateToSet).forEach(function (key) {
527
- // onStateChangeArg should only have the state that is
528
- // actually changing
529
- if (state[key] !== newStateToSet[key]) {
530
- onStateChangeArg[key] = newStateToSet[key];
531
- } // the type is useful for the onStateChangeArg
532
- // but we don't actually want to set it in internal state.
533
- // this is an undocumented feature for now... Not all internalSetState
534
- // calls support it and I'm not certain we want them to yet.
535
- // But it enables users controlling the isOpen state to know when
536
- // the isOpen state changes due to mouseup events which is quite handy.
537
-
538
-
539
- if (key === 'type') {
540
- return;
554
+ if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
555
+ _this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
541
556
  }
542
557
 
543
- nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
558
+ return nextState;
559
+ }, function () {
560
+ // call the provided callback if it's a function
561
+ cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
562
+ // we have relevant information to pass them.
544
563
 
545
- if (!_this.isControlledProp(key)) {
546
- nextState[key] = newStateToSet[key];
547
- }
548
- }); // if stateToSet is a function, then we weren't able to call onInputValueChange
549
- // earlier, so we'll call it now that we know what the inputValue state will be.
564
+ var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
550
565
 
551
- if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
552
- _this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
553
- }
566
+ if (hasMoreStateThanType) {
567
+ _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
568
+ }
554
569
 
555
- return nextState;
556
- }, function () {
557
- // call the provided callback if it's a function
558
- cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
559
- // we have relevant information to pass them.
570
+ if (isItemSelected) {
571
+ _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
572
+ }
560
573
 
561
- var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
574
+ if (onChangeArg !== undefined) {
575
+ _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
576
+ } // this is currently undocumented and therefore subject to change
577
+ // We'll try to not break it, but just be warned.
562
578
 
563
- if (hasMoreStateThanType) {
564
- _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
565
- }
566
579
 
567
- if (isItemSelected) {
568
- _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
569
- }
580
+ _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
581
+ });
582
+ };
570
583
 
571
- if (onChangeArg !== undefined) {
572
- _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
573
- } // this is currently undocumented and therefore subject to change
574
- // We'll try to not break it, but just be warned.
584
+ _this.rootRef = function (node) {
585
+ return _this._rootNode = node;
586
+ };
575
587
 
588
+ _this.getRootProps = function (_temp, _temp2) {
589
+ var _extends2;
576
590
 
577
- _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
578
- });
579
- };
591
+ var _ref = _temp === void 0 ? {} : _temp,
592
+ _ref$refKey = _ref.refKey,
593
+ refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
594
+ ref = _ref.ref,
595
+ rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
580
596
 
581
- _this.rootRef = function (node) {
582
- return _this._rootNode = node;
583
- };
597
+ var _ref2 = _temp2 === void 0 ? {} : _temp2,
598
+ _ref2$suppressRefErro = _ref2.suppressRefError,
599
+ suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
584
600
 
585
- _this.getRootProps = function (_temp, _temp2) {
586
- var _extends2;
601
+ // this is used in the render to know whether the user has called getRootProps.
602
+ // It uses that to know whether to apply the props automatically
603
+ _this.getRootProps.called = true;
604
+ _this.getRootProps.refKey = refKey;
605
+ _this.getRootProps.suppressRefError = suppressRefError;
587
606
 
588
- var _ref = _temp === void 0 ? {} : _temp,
589
- _ref$refKey = _ref.refKey,
590
- refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
591
- ref = _ref.ref,
592
- rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
607
+ var _this$getState = _this.getState(),
608
+ isOpen = _this$getState.isOpen;
593
609
 
594
- var _ref2 = _temp2 === void 0 ? {} : _temp2,
595
- _ref2$suppressRefErro = _ref2.suppressRefError,
596
- suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
610
+ 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);
611
+ };
597
612
 
598
- // this is used in the render to know whether the user has called getRootProps.
599
- // It uses that to know whether to apply the props automatically
600
- _this.getRootProps.called = true;
601
- _this.getRootProps.refKey = refKey;
602
- _this.getRootProps.suppressRefError = suppressRefError;
613
+ _this.keyDownHandlers = {
614
+ ArrowDown: function ArrowDown(event) {
615
+ var _this2 = this;
603
616
 
604
- var _this$getState = _this.getState(),
605
- isOpen = _this$getState.isOpen;
617
+ event.preventDefault();
606
618
 
607
- 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);
608
- };
619
+ if (this.getState().isOpen) {
620
+ var amount = event.shiftKey ? 5 : 1;
621
+ this.moveHighlightedIndex(amount, {
622
+ type: keyDownArrowDown
623
+ });
624
+ } else {
625
+ this.internalSetState({
626
+ isOpen: true,
627
+ type: keyDownArrowDown
628
+ }, function () {
629
+ var itemCount = _this2.getItemCount();
630
+
631
+ if (itemCount > 0) {
632
+ _this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
633
+ type: keyDownArrowDown
634
+ });
635
+ }
636
+ });
637
+ }
638
+ },
639
+ ArrowUp: function ArrowUp(event) {
640
+ var _this3 = this;
609
641
 
610
- _this.keyDownHandlers = {
611
- ArrowDown: function ArrowDown(event) {
612
- var _this2 = this;
642
+ event.preventDefault();
613
643
 
614
- event.preventDefault();
644
+ if (this.getState().isOpen) {
645
+ var amount = event.shiftKey ? -5 : -1;
646
+ this.moveHighlightedIndex(amount, {
647
+ type: keyDownArrowUp
648
+ });
649
+ } else {
650
+ this.internalSetState({
651
+ isOpen: true,
652
+ type: keyDownArrowUp
653
+ }, function () {
654
+ var itemCount = _this3.getItemCount();
655
+
656
+ if (itemCount > 0) {
657
+ _this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
658
+ type: keyDownArrowDown
659
+ });
660
+ }
661
+ });
662
+ }
663
+ },
664
+ Enter: function Enter(event) {
665
+ var _this$getState2 = this.getState(),
666
+ isOpen = _this$getState2.isOpen,
667
+ highlightedIndex = _this$getState2.highlightedIndex;
668
+
669
+ if (isOpen && highlightedIndex != null) {
670
+ event.preventDefault();
671
+ var item = this.items[highlightedIndex];
672
+ var itemNode = this.getItemNodeFromIndex(highlightedIndex);
673
+
674
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
675
+ return;
676
+ }
615
677
 
616
- if (this.getState().isOpen) {
617
- var amount = event.shiftKey ? 5 : 1;
618
- this.moveHighlightedIndex(amount, {
619
- type: keyDownArrowDown
678
+ this.selectHighlightedItem({
679
+ type: keyDownEnter
680
+ });
681
+ }
682
+ },
683
+ Escape: function Escape(event) {
684
+ event.preventDefault();
685
+ this.reset({
686
+ type: keyDownEscape,
687
+ selectedItem: null,
688
+ inputValue: ''
620
689
  });
621
- } else {
622
- this.internalSetState({
623
- isOpen: true,
624
- type: keyDownArrowDown
625
- }, function () {
626
- var itemCount = _this2.getItemCount();
627
-
628
- if (itemCount > 0) {
629
- _this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
630
- type: keyDownArrowDown
631
- });
632
- }
690
+ }
691
+ };
692
+ _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
693
+ ' ': function _(event) {
694
+ event.preventDefault();
695
+ this.toggleMenu({
696
+ type: keyDownSpaceButton
633
697
  });
634
698
  }
635
- },
636
- ArrowUp: function ArrowUp(event) {
637
- var _this3 = this;
638
-
639
- event.preventDefault();
640
-
641
- if (this.getState().isOpen) {
642
- var amount = event.shiftKey ? -5 : -1;
643
- this.moveHighlightedIndex(amount, {
644
- type: keyDownArrowUp
699
+ });
700
+ _this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
701
+ Home: function Home(event) {
702
+ this.highlightFirstOrLastIndex(event, true, {
703
+ type: keyDownHome
645
704
  });
646
- } else {
647
- this.internalSetState({
648
- isOpen: true,
649
- type: keyDownArrowUp
650
- }, function () {
651
- var itemCount = _this3.getItemCount();
652
-
653
- if (itemCount > 0) {
654
- _this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
655
- type: keyDownArrowDown
656
- });
657
- }
705
+ },
706
+ End: function End(event) {
707
+ this.highlightFirstOrLastIndex(event, false, {
708
+ type: keyDownEnd
658
709
  });
659
710
  }
660
- },
661
- Enter: function Enter(event) {
662
- var _this$getState2 = this.getState(),
663
- isOpen = _this$getState2.isOpen,
664
- highlightedIndex = _this$getState2.highlightedIndex;
711
+ });
665
712
 
666
- if (isOpen && highlightedIndex != null) {
667
- event.preventDefault();
668
- var item = this.items[highlightedIndex];
669
- var itemNode = this.getItemNodeFromIndex(highlightedIndex);
713
+ _this.getToggleButtonProps = function (_temp3) {
714
+ var _ref3 = _temp3 === void 0 ? {} : _temp3,
715
+ onClick = _ref3.onClick,
716
+ onPress = _ref3.onPress,
717
+ onKeyDown = _ref3.onKeyDown,
718
+ onKeyUp = _ref3.onKeyUp,
719
+ onBlur = _ref3.onBlur,
720
+ rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
670
721
 
671
- if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
672
- return;
673
- }
722
+ var _this$getState3 = _this.getState(),
723
+ isOpen = _this$getState3.isOpen;
674
724
 
675
- this.selectHighlightedItem({
676
- type: keyDownEnter
677
- });
678
- }
679
- },
680
- Escape: function Escape(event) {
681
- event.preventDefault();
682
- this.reset({
683
- type: keyDownEscape,
684
- selectedItem: null,
685
- inputValue: ''
686
- });
687
- }
688
- };
689
- _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
690
- ' ': function _(event) {
691
- event.preventDefault();
692
- this.toggleMenu({
693
- type: keyDownSpaceButton
694
- });
695
- }
696
- });
697
- _this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
698
- Home: function Home(event) {
699
- this.highlightFirstOrLastIndex(event, true, {
700
- type: keyDownHome
701
- });
702
- },
703
- End: function End(event) {
704
- this.highlightFirstOrLastIndex(event, false, {
705
- type: keyDownEnd
706
- });
707
- }
708
- });
725
+ var enabledEventHandlers =
726
+ /* istanbul ignore next (react-native) */
727
+ {
728
+ onPress: callAllEventHandlers(onPress, _this.buttonHandleClick)
729
+ };
730
+ var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
731
+ return _extends({
732
+ type: 'button',
733
+ role: 'button',
734
+ 'aria-label': isOpen ? 'close menu' : 'open menu',
735
+ 'aria-haspopup': true,
736
+ 'data-toggle': true
737
+ }, eventHandlers, {}, rest);
738
+ };
709
739
 
710
- _this.getToggleButtonProps = function (_temp3) {
711
- var _ref3 = _temp3 === void 0 ? {} : _temp3,
712
- onClick = _ref3.onClick,
713
- onPress = _ref3.onPress,
714
- onKeyDown = _ref3.onKeyDown,
715
- onKeyUp = _ref3.onKeyUp,
716
- onBlur = _ref3.onBlur,
717
- rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
740
+ _this.buttonHandleKeyUp = function (event) {
741
+ // Prevent click event from emitting in Firefox
742
+ event.preventDefault();
743
+ };
718
744
 
719
- var _this$getState3 = _this.getState(),
720
- isOpen = _this$getState3.isOpen;
745
+ _this.buttonHandleKeyDown = function (event) {
746
+ var key = normalizeArrowKey(event);
721
747
 
722
- var enabledEventHandlers =
723
- /* istanbul ignore next (react-native) */
724
- {
725
- onPress: callAllEventHandlers(onPress, _this.buttonHandleClick)
748
+ if (_this.buttonKeyDownHandlers[key]) {
749
+ _this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
750
+ }
726
751
  };
727
- var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
728
- return _extends({
729
- type: 'button',
730
- role: 'button',
731
- 'aria-label': isOpen ? 'close menu' : 'open menu',
732
- 'aria-haspopup': true,
733
- 'data-toggle': true
734
- }, eventHandlers, {}, rest);
735
- };
736
-
737
- _this.buttonHandleKeyUp = function (event) {
738
- // Prevent click event from emitting in Firefox
739
- event.preventDefault();
740
- };
741
752
 
742
- _this.buttonHandleKeyDown = function (event) {
743
- var key = normalizeArrowKey(event);
753
+ _this.buttonHandleClick = function (event) {
754
+ event.preventDefault(); // handle odd case for Safari and Firefox which
755
+ // don't give the button the focus properly.
744
756
 
745
- if (_this.buttonKeyDownHandlers[key]) {
746
- _this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
747
- }
748
- };
757
+ /* istanbul ignore if (can't reasonably test this) */
749
758
 
750
- _this.buttonHandleClick = function (event) {
751
- event.preventDefault(); // handle odd case for Safari and Firefox which
752
- // don't give the button the focus properly.
759
+ // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
760
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
761
+ // when building for production and should therefore have no impact on production code.
762
+ if (process.env.NODE_ENV === 'test') {
763
+ _this.toggleMenu({
764
+ type: clickButton
765
+ });
766
+ } else {
767
+ // Ensure that toggle of menu occurs after the potential blur event in iOS
768
+ _this.internalSetTimeout(function () {
769
+ return _this.toggleMenu({
770
+ type: clickButton
771
+ });
772
+ });
773
+ }
774
+ };
753
775
 
754
- /* istanbul ignore if (can't reasonably test this) */
776
+ _this.buttonHandleBlur = function (event) {
777
+ var blurTarget = event.target; // Save blur target for comparison with activeElement later
778
+ // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
755
779
 
756
- // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
757
- // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
758
- // when building for production and should therefore have no impact on production code.
759
- if (process.env.NODE_ENV === 'test') {
760
- _this.toggleMenu({
761
- type: clickButton
762
- });
763
- } else {
764
- // Ensure that toggle of menu occurs after the potential blur event in iOS
765
780
  _this.internalSetTimeout(function () {
766
- return _this.toggleMenu({
767
- type: clickButton
768
- });
781
+ 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)
782
+ ) {
783
+ _this.reset({
784
+ type: blurButton
785
+ });
786
+ }
769
787
  });
770
- }
771
- };
788
+ };
772
789
 
773
- _this.buttonHandleBlur = function (event) {
774
- var blurTarget = event.target; // Save blur target for comparison with activeElement later
775
- // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
790
+ _this.getLabelProps = function (props) {
791
+ return _extends({
792
+ htmlFor: _this.inputId,
793
+ id: _this.labelId
794
+ }, props);
795
+ };
776
796
 
777
- _this.internalSetTimeout(function () {
778
- 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)
779
- ) {
780
- _this.reset({
781
- type: blurButton
782
- });
783
- }
784
- });
785
- };
797
+ _this.getInputProps = function (_temp4) {
798
+ var _ref4 = _temp4 === void 0 ? {} : _temp4,
799
+ onKeyDown = _ref4.onKeyDown,
800
+ onBlur = _ref4.onBlur,
801
+ onChange = _ref4.onChange,
802
+ onInput = _ref4.onInput,
803
+ onChangeText = _ref4.onChangeText,
804
+ rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
786
805
 
787
- _this.getLabelProps = function (props) {
788
- return _extends({
789
- htmlFor: _this.inputId,
790
- id: _this.labelId
791
- }, props);
792
- };
806
+ var onChangeKey;
807
+ var eventHandlers = {};
808
+ /* istanbul ignore next (preact) */
793
809
 
794
- _this.getInputProps = function (_temp4) {
795
- var _ref4 = _temp4 === void 0 ? {} : _temp4,
796
- onKeyDown = _ref4.onKeyDown,
797
- onBlur = _ref4.onBlur,
798
- onChange = _ref4.onChange,
799
- onInput = _ref4.onInput,
800
- onChangeText = _ref4.onChangeText,
801
- rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
810
+ onChangeKey = 'onChange';
802
811
 
803
- var onChangeKey;
804
- var eventHandlers = {};
805
- /* istanbul ignore next (preact) */
812
+ var _this$getState4 = _this.getState(),
813
+ inputValue = _this$getState4.inputValue,
814
+ isOpen = _this$getState4.isOpen,
815
+ highlightedIndex = _this$getState4.highlightedIndex;
806
816
 
807
- onChangeKey = 'onChange';
817
+ if (!rest.disabled) {
818
+ var _eventHandlers;
808
819
 
809
- var _this$getState4 = _this.getState(),
810
- inputValue = _this$getState4.inputValue,
811
- isOpen = _this$getState4.isOpen,
812
- highlightedIndex = _this$getState4.highlightedIndex;
820
+ eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
821
+ }
822
+ /* istanbul ignore if (react-native) */
813
823
 
814
- if (!rest.disabled) {
815
- var _eventHandlers;
816
824
 
817
- eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
818
- }
819
- /* istanbul ignore if (react-native) */
825
+ eventHandlers = {
826
+ onChange: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
827
+ onChangeText: callAllEventHandlers(onChangeText, onInput, function (text) {
828
+ return _this.inputHandleChange({
829
+ nativeEvent: {
830
+ text: text
831
+ }
832
+ });
833
+ }, _this.inputHandleTextChange),
834
+ onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
835
+ };
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
+ };
820
848
 
849
+ _this.inputHandleKeyDown = function (event) {
850
+ var key = normalizeArrowKey(event);
821
851
 
822
- eventHandlers = {
823
- onChange: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
824
- onChangeText: callAllEventHandlers(onChangeText, onInput, function (text) {
825
- return _this.inputHandleChange({
826
- nativeEvent: {
827
- text: text
828
- }
829
- });
830
- }, _this.inputHandleTextChange),
831
- onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
852
+ if (key && _this.inputKeyDownHandlers[key]) {
853
+ _this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
854
+ }
832
855
  };
833
- return _extends({
834
- 'aria-autocomplete': 'list',
835
- 'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
836
- 'aria-controls': isOpen ? _this.menuId : null,
837
- 'aria-labelledby': _this.labelId,
838
- // https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
839
- // revert back since autocomplete="nope" is ignored on latest Chrome and Opera
840
- autoComplete: 'off',
841
- value: inputValue,
842
- id: _this.inputId
843
- }, eventHandlers, {}, rest);
844
- };
845
-
846
- _this.inputHandleKeyDown = function (event) {
847
- var key = normalizeArrowKey(event);
848
856
 
849
- if (key && _this.inputKeyDownHandlers[key]) {
850
- _this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
851
- }
852
- };
857
+ _this.inputHandleChange = function (event) {
858
+ _this.internalSetState({
859
+ type: changeInput,
860
+ isOpen: true,
861
+ inputValue:
862
+ /* istanbul ignore next (react-native) */
863
+ event.nativeEvent.text,
864
+ highlightedIndex: _this.props.defaultHighlightedIndex
865
+ });
866
+ };
853
867
 
854
- _this.inputHandleChange = function (event) {
855
- _this.internalSetState({
856
- type: changeInput,
857
- isOpen: true,
858
- inputValue:
859
- /* istanbul ignore next (react-native) */
860
- event.nativeEvent.text,
861
- highlightedIndex: _this.props.defaultHighlightedIndex
862
- });
863
- };
868
+ _this.inputHandleBlur = function () {
869
+ // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
870
+ _this.internalSetTimeout(function () {
871
+ 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);
864
872
 
865
- _this.inputHandleBlur = function () {
866
- // Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
867
- _this.internalSetTimeout(function () {
868
- 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);
873
+ if (!_this.isMouseDown && !downshiftButtonIsActive) {
874
+ _this.reset({
875
+ type: blurInput
876
+ });
877
+ }
878
+ });
879
+ };
869
880
 
870
- if (!_this.isMouseDown && !downshiftButtonIsActive) {
871
- _this.reset({
872
- type: blurInput
873
- });
874
- }
875
- });
876
- };
881
+ _this.menuRef = function (node) {
882
+ _this._menuNode = node;
883
+ };
877
884
 
878
- _this.menuRef = function (node) {
879
- _this._menuNode = node;
880
- };
885
+ _this.getMenuProps = function (_temp5, _temp6) {
886
+ var _extends3;
881
887
 
882
- _this.getMenuProps = function (_temp5, _temp6) {
883
- var _extends3;
888
+ var _ref5 = _temp5 === void 0 ? {} : _temp5,
889
+ _ref5$refKey = _ref5.refKey,
890
+ refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
891
+ ref = _ref5.ref,
892
+ props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
884
893
 
885
- var _ref5 = _temp5 === void 0 ? {} : _temp5,
886
- _ref5$refKey = _ref5.refKey,
887
- refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
888
- ref = _ref5.ref,
889
- props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
894
+ var _ref6 = _temp6 === void 0 ? {} : _temp6,
895
+ _ref6$suppressRefErro = _ref6.suppressRefError,
896
+ suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
890
897
 
891
- var _ref6 = _temp6 === void 0 ? {} : _temp6,
892
- _ref6$suppressRefErro = _ref6.suppressRefError,
893
- suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
898
+ _this.getMenuProps.called = true;
899
+ _this.getMenuProps.refKey = refKey;
900
+ _this.getMenuProps.suppressRefError = suppressRefError;
901
+ 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);
902
+ };
894
903
 
895
- _this.getMenuProps.called = true;
896
- _this.getMenuProps.refKey = refKey;
897
- _this.getMenuProps.suppressRefError = suppressRefError;
898
- 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);
899
- };
904
+ _this.getItemProps = function (_temp7) {
905
+ var _enabledEventHandlers;
906
+
907
+ var _ref7 = _temp7 === void 0 ? {} : _temp7,
908
+ onMouseMove = _ref7.onMouseMove,
909
+ onMouseDown = _ref7.onMouseDown,
910
+ onClick = _ref7.onClick,
911
+ onPress = _ref7.onPress,
912
+ index = _ref7.index,
913
+ _ref7$item = _ref7.item,
914
+ item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
915
+ /* istanbul ignore next */
916
+ undefined : requiredProp('getItemProps', 'item') : _ref7$item,
917
+ rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
918
+
919
+ if (index === undefined) {
920
+ _this.items.push(item);
921
+
922
+ index = _this.items.indexOf(item);
923
+ } else {
924
+ _this.items[index] = item;
925
+ }
900
926
 
901
- _this.getItemProps = function (_temp7) {
902
- var _enabledEventHandlers;
903
-
904
- var _ref7 = _temp7 === void 0 ? {} : _temp7,
905
- onMouseMove = _ref7.onMouseMove,
906
- onMouseDown = _ref7.onMouseDown,
907
- onClick = _ref7.onClick,
908
- onPress = _ref7.onPress,
909
- index = _ref7.index,
910
- _ref7$item = _ref7.item,
911
- item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
912
- /* istanbul ignore next */
913
- undefined : requiredProp('getItemProps', 'item') : _ref7$item,
914
- rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
927
+ var onSelectKey =
928
+ /* istanbul ignore next (react-native) */
929
+ 'onPress';
930
+ var customClickHandler =
931
+ /* istanbul ignore next (react-native) */
932
+ onPress;
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
+ }
915
941
 
916
- if (index === undefined) {
917
- _this.items.push(item);
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
948
+
949
+
950
+ _this.avoidScrolling = true;
951
+
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
918
968
 
919
- index = _this.items.indexOf(item);
920
- } else {
921
- _this.items[index] = item;
922
- }
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
+ };
923
978
 
924
- var onSelectKey =
925
- /* istanbul ignore next (react-native) */
926
- 'onPress';
927
- var customClickHandler =
928
- /* istanbul ignore next (react-native) */
929
- onPress;
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
- }
979
+ _this.clearItems = function () {
980
+ _this.items = [];
981
+ };
938
982
 
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
983
+ _this.reset = function (otherStateToSet, cb) {
984
+ if (otherStateToSet === void 0) {
985
+ otherStateToSet = {};
986
+ }
945
987
 
988
+ otherStateToSet = pickState(otherStateToSet);
946
989
 
947
- _this.avoidScrolling = true;
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
+ };
948
999
 
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
1000
+ _this.toggleMenu = function (otherStateToSet, cb) {
1001
+ if (otherStateToSet === void 0) {
1002
+ otherStateToSet = {};
1003
+ }
965
1004
 
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
- };
1005
+ otherStateToSet = pickState(otherStateToSet);
1006
+
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
+ }
975
1024
 
976
- _this.clearItems = function () {
977
- _this.items = [];
978
- };
1025
+ cbToCb(cb)();
1026
+ });
1027
+ };
979
1028
 
980
- _this.reset = function (otherStateToSet, cb) {
981
- if (otherStateToSet === void 0) {
982
- otherStateToSet = {};
983
- }
1029
+ _this.openMenu = function (cb) {
1030
+ _this.internalSetState({
1031
+ isOpen: true
1032
+ }, cb);
1033
+ };
984
1034
 
985
- otherStateToSet = pickState(otherStateToSet);
1035
+ _this.closeMenu = function (cb) {
1036
+ _this.internalSetState({
1037
+ isOpen: false
1038
+ }, cb);
1039
+ };
986
1040
 
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
- };
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
+ });
996
1080
 
997
- _this.toggleMenu = function (otherStateToSet, cb) {
998
- if (otherStateToSet === void 0) {
999
- otherStateToSet = {};
1081
+ if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1082
+ _state.inputValue = _this.props.itemToString(_state.selectedItem);
1000
1083
  }
1001
1084
 
1002
- otherStateToSet = pickState(otherStateToSet);
1085
+ _this.state = _state;
1086
+ return _this;
1087
+ }
1003
1088
 
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
- }
1089
+ var _proto = Downshift.prototype;
1021
1090
 
1022
- cbToCb(cb)();
1091
+ /**
1092
+ * Clear all running timeouts
1093
+ */
1094
+ _proto.internalClearTimeouts = function internalClearTimeouts() {
1095
+ this.timeoutIds.forEach(function (id) {
1096
+ clearTimeout(id);
1023
1097
  });
1024
- };
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;
1122
+ }
1025
1123
 
1026
- _this.openMenu = function (cb) {
1027
- _this.internalSetState({
1028
- isOpen: true
1029
- }, cb);
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;
1030
1140
  };
1031
1141
 
1032
- _this.closeMenu = function (cb) {
1033
- _this.internalSetState({
1034
- isOpen: false
1035
- }, cb);
1036
- };
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;
1153
+ }
1037
1154
 
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
1076
- });
1155
+ return itemCount;
1156
+ };
1077
1157
 
1078
- if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
1079
- _state.inputValue = _this.props.itemToString(_state.selectedItem);
1080
- }
1158
+ _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1159
+ return this.props.environment.document.getElementById(this.getItemId(index));
1160
+ };
1081
1161
 
1082
- _this.state = _state;
1083
- return _this;
1084
- }
1162
+ _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {};
1085
1163
 
1086
- var _proto = Downshift.prototype;
1164
+ _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1165
+ var itemCount = this.getItemCount();
1087
1166
 
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 = [];
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
- }
1167
+ if (itemCount > 0) {
1168
+ var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
1169
+ this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1170
+ }
1171
+ };
1120
1172
 
1121
- return Object.keys(stateToMerge).reduce(function (state, key) {
1122
- state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
1123
- return state;
1124
- }, {});
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
- };
1173
+ _proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
1174
+ var itemsLastIndex = this.getItemCount() - 1;
1138
1175
 
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
- }
1176
+ if (itemsLastIndex < 0 || !this.getState().isOpen) {
1177
+ return;
1178
+ }
1151
1179
 
1152
- return itemCount;
1153
- };
1180
+ event.preventDefault();
1181
+ this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
1182
+ };
1154
1183
 
1155
- _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
1156
- return this.props.environment.document.getElementById(this.getItemId(index));
1157
- };
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
1243
+ };
1244
+ } //////////////////////////// ROOT
1245
+ ;
1158
1246
 
1159
- _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {};
1247
+ _proto.componentDidMount = function componentDidMount() {
1248
+ var _this5 = this;
1160
1249
 
1161
- _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
1162
- var itemCount = this.getItemCount();
1250
+ /* istanbul ignore if (react-native) */
1251
+ if (process.env.NODE_ENV !== 'production' && !true && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1252
+ validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1253
+ }
1254
+ /* istanbul ignore if (react-native) */
1163
1255
 
1164
- if (itemCount > 0) {
1165
- var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
1166
- this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
1167
- }
1168
- };
1169
1256
 
1170
- _proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
1171
- var itemsLastIndex = this.getItemCount() - 1;
1257
+ this.cleanup = function () {
1258
+ _this5.internalClearTimeouts();
1259
+ };
1260
+ };
1172
1261
 
1173
- if (itemsLastIndex < 0 || !this.getState().isOpen) {
1174
- return;
1175
- }
1262
+ _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1263
+ var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1264
+ currentHighlightedIndex = _ref10.highlightedIndex;
1176
1265
 
1177
- event.preventDefault();
1178
- this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
1179
- };
1266
+ var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1267
+ prevHighlightedIndex = _ref11.highlightedIndex;
1180
1268
 
1181
- _proto.getStateAndHelpers = function getStateAndHelpers() {
1182
- var _this$getState6 = this.getState(),
1183
- highlightedIndex = _this$getState6.highlightedIndex,
1184
- inputValue = _this$getState6.inputValue,
1185
- selectedItem = _this$getState6.selectedItem,
1186
- isOpen = _this$getState6.isOpen;
1187
-
1188
- var itemToString = this.props.itemToString;
1189
- var id = this.id;
1190
- var getRootProps = this.getRootProps,
1191
- getToggleButtonProps = this.getToggleButtonProps,
1192
- getLabelProps = this.getLabelProps,
1193
- getMenuProps = this.getMenuProps,
1194
- getInputProps = this.getInputProps,
1195
- getItemProps = this.getItemProps,
1196
- openMenu = this.openMenu,
1197
- closeMenu = this.closeMenu,
1198
- toggleMenu = this.toggleMenu,
1199
- selectItem = this.selectItem,
1200
- selectItemAtIndex = this.selectItemAtIndex,
1201
- selectHighlightedItem = this.selectHighlightedItem,
1202
- setHighlightedIndex = this.setHighlightedIndex,
1203
- clearSelection = this.clearSelection,
1204
- clearItems = this.clearItems,
1205
- reset = this.reset,
1206
- setItemCount = this.setItemCount,
1207
- unsetItemCount = this.unsetItemCount,
1208
- setState = this.internalSetState;
1209
- return {
1210
- // prop getters
1211
- getRootProps: getRootProps,
1212
- getToggleButtonProps: getToggleButtonProps,
1213
- getLabelProps: getLabelProps,
1214
- getMenuProps: getMenuProps,
1215
- getInputProps: getInputProps,
1216
- getItemProps: getItemProps,
1217
- // actions
1218
- reset: reset,
1219
- openMenu: openMenu,
1220
- closeMenu: closeMenu,
1221
- toggleMenu: toggleMenu,
1222
- selectItem: selectItem,
1223
- selectItemAtIndex: selectItemAtIndex,
1224
- selectHighlightedItem: selectHighlightedItem,
1225
- setHighlightedIndex: setHighlightedIndex,
1226
- clearSelection: clearSelection,
1227
- clearItems: clearItems,
1228
- setItemCount: setItemCount,
1229
- unsetItemCount: unsetItemCount,
1230
- setState: setState,
1231
- // props
1232
- itemToString: itemToString,
1233
- // derived
1234
- id: id,
1235
- // state
1236
- highlightedIndex: highlightedIndex,
1237
- inputValue: inputValue,
1238
- isOpen: isOpen,
1239
- selectedItem: selectedItem
1269
+ var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1270
+ return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
1240
1271
  };
1241
- } //////////////////////////// ROOT
1242
- ;
1243
1272
 
1244
- _proto.componentDidMount = function componentDidMount() {
1245
- var _this5 = this;
1273
+ _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1274
+ if (process.env.NODE_ENV !== 'production') {
1275
+ validateControlledUnchanged(prevProps, this.props);
1276
+ /* istanbul ignore if (react-native) */
1277
+ }
1246
1278
 
1247
- /* istanbul ignore if (react-native) */
1248
- if (process.env.NODE_ENV !== 'production' && !true && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
1249
- validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
1250
- }
1251
- /* istanbul ignore if (react-native) */
1279
+ if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1280
+ this.internalSetState({
1281
+ type: controlledPropUpdatedSelectedItem,
1282
+ inputValue: this.props.itemToString(this.props.selectedItem)
1283
+ });
1284
+ }
1252
1285
 
1286
+ if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
1287
+ this.scrollHighlightedItemIntoView();
1288
+ }
1289
+ /* istanbul ignore else (react-native) */
1253
1290
 
1254
- this.cleanup = function () {
1255
- _this5.internalClearTimeouts();
1256
1291
  };
1257
- };
1258
1292
 
1259
- _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
1260
- var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
1261
- currentHighlightedIndex = _ref10.highlightedIndex;
1293
+ _proto.componentWillUnmount = function componentWillUnmount() {
1294
+ this.cleanup(); // avoids memory leak
1295
+ };
1262
1296
 
1263
- var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
1264
- prevHighlightedIndex = _ref11.highlightedIndex;
1297
+ _proto.render = function render() {
1298
+ var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1299
+ // we clear this out each render and it will be populated again as
1300
+ // getItemProps is called.
1265
1301
 
1266
- var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
1267
- return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
1268
- };
1302
+ this.clearItems(); // we reset this so we know whether the user calls getRootProps during
1303
+ // this render. If they do then we don't need to do anything,
1304
+ // if they don't then we need to clone the element they return and
1305
+ // apply the props for them.
1269
1306
 
1270
- _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
1271
- if (process.env.NODE_ENV !== 'production') {
1272
- validateControlledUnchanged(prevProps, this.props);
1273
- /* istanbul ignore if (react-native) */
1274
- }
1307
+ this.getRootProps.called = false;
1308
+ this.getRootProps.refKey = undefined;
1309
+ this.getRootProps.suppressRefError = undefined; // we do something similar for getMenuProps
1275
1310
 
1276
- if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
1277
- this.internalSetState({
1278
- type: controlledPropUpdatedSelectedItem,
1279
- inputValue: this.props.itemToString(this.props.selectedItem)
1280
- });
1281
- }
1311
+ this.getMenuProps.called = false;
1312
+ this.getMenuProps.refKey = undefined;
1313
+ this.getMenuProps.suppressRefError = undefined; // we do something similar for getLabelProps
1282
1314
 
1283
- if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
1284
- this.scrollHighlightedItemIntoView();
1285
- }
1286
- /* istanbul ignore else (react-native) */
1315
+ this.getLabelProps.called = false; // and something similar for getInputProps
1287
1316
 
1288
- };
1317
+ this.getInputProps.called = false;
1318
+ var element = unwrapArray(children(this.getStateAndHelpers()));
1289
1319
 
1290
- _proto.componentWillUnmount = function componentWillUnmount() {
1291
- this.cleanup(); // avoids memory leak
1292
- };
1320
+ if (!element) {
1321
+ return null;
1322
+ }
1293
1323
 
1294
- _proto.render = function render() {
1295
- var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
1296
- // we clear this out each render and it will be populated again as
1297
- // getItemProps is called.
1324
+ if (this.getRootProps.called || this.props.suppressRefError) {
1325
+ if (process.env.NODE_ENV !== 'production' && !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
1326
+ validateGetRootPropsCalledCorrectly(element, this.getRootProps);
1327
+ }
1298
1328
 
1299
- this.clearItems(); // we reset this so we know whether the user calls getRootProps during
1300
- // this render. If they do then we don't need to do anything,
1301
- // if they don't then we need to clone the element they return and
1302
- // apply the props for them.
1329
+ return element;
1330
+ } else if (isDOMElement(element)) {
1331
+ // they didn't apply the root props, but we can clone
1332
+ // this and apply the props ourselves
1333
+ return react.cloneElement(element, this.getRootProps(getElementProps(element)));
1334
+ }
1335
+ /* istanbul ignore else */
1303
1336
 
1304
- this.getRootProps.called = false;
1305
- this.getRootProps.refKey = undefined;
1306
- this.getRootProps.suppressRefError = undefined; // we do something similar for getMenuProps
1307
1337
 
1308
- this.getMenuProps.called = false;
1309
- this.getMenuProps.refKey = undefined;
1310
- this.getMenuProps.suppressRefError = undefined; // we do something similar for getLabelProps
1338
+ if (process.env.NODE_ENV !== 'production') {
1339
+ // they didn't apply the root props, but they need to
1340
+ // otherwise we can't query around the autocomplete
1341
+ throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
1342
+ }
1343
+ /* istanbul ignore next */
1311
1344
 
1312
- this.getLabelProps.called = false; // and something similar for getInputProps
1313
1345
 
1314
- this.getInputProps.called = false;
1315
- var element = unwrapArray(children(this.getStateAndHelpers()));
1346
+ return undefined;
1347
+ };
1316
1348
 
1317
- if (!element) {
1318
- return null;
1319
- }
1349
+ return Downshift;
1350
+ }(react.Component);
1320
1351
 
1321
- if (this.getRootProps.called || this.props.suppressRefError) {
1322
- if (process.env.NODE_ENV !== 'production' && !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
1323
- validateGetRootPropsCalledCorrectly(element, this.getRootProps);
1352
+ Downshift.defaultProps = {
1353
+ defaultHighlightedIndex: null,
1354
+ defaultIsOpen: false,
1355
+ getA11yStatusMessage: getA11yStatusMessage,
1356
+ itemToString: function itemToString(i) {
1357
+ if (i == null) {
1358
+ return '';
1324
1359
  }
1325
1360
 
1326
- return element;
1327
- } else if (isDOMElement(element)) {
1328
- // they didn't apply the root props, but we can clone
1329
- // this and apply the props ourselves
1330
- return react.cloneElement(element, this.getRootProps(getElementProps(element)));
1331
- }
1332
- /* istanbul ignore else */
1333
-
1334
-
1335
- if (process.env.NODE_ENV !== 'production') {
1336
- // they didn't apply the root props, but they need to
1337
- // otherwise we can't query around the autocomplete
1338
- throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
1339
- }
1340
- /* istanbul ignore next */
1341
-
1361
+ if (process.env.NODE_ENV !== 'production' && isPlainObject(i) && !i.hasOwnProperty('toString')) {
1362
+ // eslint-disable-next-line no-console
1363
+ 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);
1364
+ }
1342
1365
 
1343
- return undefined;
1366
+ return String(i);
1367
+ },
1368
+ onStateChange: noop,
1369
+ onInputValueChange: noop,
1370
+ onUserAction: noop,
1371
+ onChange: noop,
1372
+ onSelect: noop,
1373
+ onOuterClick: noop,
1374
+ selectedItemChanged: function selectedItemChanged(prevItem, item) {
1375
+ return prevItem !== item;
1376
+ },
1377
+ environment: typeof window === 'undefined'
1378
+ /* istanbul ignore next (ssr) */
1379
+ ? {} : window,
1380
+ stateReducer: function stateReducer(state, stateToSet) {
1381
+ return stateToSet;
1382
+ },
1383
+ suppressRefError: false,
1384
+ scrollIntoView: scrollIntoView
1344
1385
  };
1345
-
1386
+ Downshift.stateChangeTypes = stateChangeTypes;
1346
1387
  return Downshift;
1347
- }(react.Component);
1348
-
1349
- Downshift.defaultProps = {
1350
- defaultHighlightedIndex: null,
1351
- defaultIsOpen: false,
1352
- getA11yStatusMessage: getA11yStatusMessage,
1353
- itemToString: function itemToString(i) {
1354
- if (i == null) {
1355
- return '';
1356
- }
1388
+ }();
1357
1389
 
1358
- if (process.env.NODE_ENV !== 'production' && isPlainObject(i) && !i.hasOwnProperty('toString')) {
1359
- // eslint-disable-next-line no-console
1360
- 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);
1361
- }
1362
-
1363
- return String(i);
1364
- },
1365
- onStateChange: noop,
1366
- onInputValueChange: noop,
1367
- onUserAction: noop,
1368
- onChange: noop,
1369
- onSelect: noop,
1370
- onOuterClick: noop,
1371
- selectedItemChanged: function selectedItemChanged(prevItem, item) {
1372
- return prevItem !== item;
1373
- },
1374
- environment: typeof window === 'undefined'
1375
- /* istanbul ignore next (ssr) */
1376
- ? {} : window,
1377
- stateReducer: function stateReducer(state, stateToSet) {
1378
- return stateToSet;
1379
- },
1380
- suppressRefError: false,
1381
- scrollIntoView: scrollIntoView
1382
- };
1383
- Downshift.stateChangeTypes = stateChangeTypes;
1384
1390
  process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
1385
1391
  children: PropTypes.func,
1386
1392
  defaultHighlightedIndex: PropTypes.number,
@@ -2004,7 +2010,9 @@ function downshiftSelectReducer(state, action) {
2004
2010
  }
2005
2011
  /* eslint-enable complexity */
2006
2012
 
2007
- var validatePropTypes = getPropTypesValidator(useSelect, propTypes);
2013
+ var validatePropTypes = process.env.NODE_ENV === 'production' ?
2014
+ /* istanbul ignore next */
2015
+ null : getPropTypesValidator(useSelect, propTypes);
2008
2016
  var defaultProps = {
2009
2017
  itemToString: itemToString,
2010
2018
  stateReducer: function stateReducer(s, a) {
@@ -2024,7 +2032,11 @@ function useSelect(userProps) {
2024
2032
  userProps = {};
2025
2033
  }
2026
2034
 
2027
- validatePropTypes(userProps); // Props defaults and destructuring.
2035
+ /* istanbul ignore else */
2036
+ if (process.env.NODE_ENV !== 'production') {
2037
+ validatePropTypes(userProps);
2038
+ } // Props defaults and destructuring.
2039
+
2028
2040
 
2029
2041
  var props = _extends({}, defaultProps, {}, userProps);
2030
2042