downshift 1.31.10 β†’ 1.31.14

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.
package/README.md CHANGED
@@ -19,7 +19,7 @@ autocomplete/dropdown/select/combobox components</p>
19
19
  [![downloads][downloads-badge]][npmcharts] [![version][version-badge]][package]
20
20
  [![MIT License][license-badge]][license]
21
21
 
22
- [![All Contributors](https://img.shields.io/badge/all_contributors-76-orange.svg?style=flat-square)](#contributors)
22
+ [![All Contributors](https://img.shields.io/badge/all_contributors-77-orange.svg?style=flat-square)](#contributors)
23
23
  [![PRs Welcome][prs-badge]][prs] [![Chat][chat-badge]][chat]
24
24
  [![Code of Conduct][coc-badge]][coc]
25
25
 
@@ -132,8 +132,8 @@ import Downshift from 'downshift'
132
132
  function BasicAutocomplete({items, onChange}) {
133
133
  return (
134
134
  <Downshift
135
- onChange={onChange}
136
- render={({
135
+ onChange={onChange}>
136
+ {({
137
137
  getInputProps,
138
138
  getItemProps,
139
139
  isOpen,
@@ -168,7 +168,7 @@ function BasicAutocomplete({items, onChange}) {
168
168
  ) : null}
169
169
  </div>
170
170
  )}
171
- />
171
+ </Downshift>
172
172
  )
173
173
  }
174
174
 
@@ -943,7 +943,6 @@ If you're developing some React in ReasonML, check out the [`Downshift` bindings
943
943
  Thanks goes to these people ([emoji key][emojis]):
944
944
 
945
945
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
946
-
947
946
  <!-- prettier-ignore -->
948
947
  | [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/paypal/downshift/commits?author=kentcdodds "Tests") [πŸ‘€](#review-kentcdodds "Reviewed Pull Requests") [πŸ“](#blog-kentcdodds "Blogposts") [πŸ›](https://github.com/paypal/downshift/issues?q=author%3Akentcdodds "Bug reports") [πŸ’‘](#example-kentcdodds "Examples") [πŸ€”](#ideas-kentcdodds "Ideas, Planning, & Feedback") [πŸ“’](#talk-kentcdodds "Talks") | [<img src="https://avatars0.githubusercontent.com/u/100200?v=4" width="100px;"/><br /><sub><b>Ryan Florence</b></sub>](http://twitter.com/ryanflorence)<br />[πŸ€”](#ideas-ryanflorence "Ideas, Planning, & Feedback") | [<img src="https://avatars3.githubusercontent.com/u/112170?v=4" width="100px;"/><br /><sub><b>Jared Forsyth</b></sub>](http://jaredforsyth.com)<br />[πŸ€”](#ideas-jaredly "Ideas, Planning, & Feedback") [πŸ“–](https://github.com/paypal/downshift/commits?author=jaredly "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/8162598?v=4" width="100px;"/><br /><sub><b>Jack Moore</b></sub>](https://github.com/jtmthf)<br />[πŸ’‘](#example-jtmthf "Examples") | [<img src="https://avatars1.githubusercontent.com/u/2762082?v=4" width="100px;"/><br /><sub><b>Travis Arnold</b></sub>](http://travisrayarnold.com)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=souporserious "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=souporserious "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1045233?v=4" width="100px;"/><br /><sub><b>Marcy Sutton</b></sub>](http://marcysutton.com)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Amarcysutton "Bug reports") [πŸ€”](#ideas-marcysutton "Ideas, Planning, & Feedback") | [<img src="https://avatars2.githubusercontent.com/u/244704?v=4" width="100px;"/><br /><sub><b>Jeremy Gayed</b></sub>](http://www.jeremygayed.com)<br />[πŸ’‘](#example-tizmagik "Examples") |
949
948
  | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
@@ -956,8 +955,7 @@ Thanks goes to these people ([emoji key][emojis]):
956
955
  | [<img src="https://avatars2.githubusercontent.com/u/1556430?v=4" width="100px;"/><br /><sub><b>Pete Redmond</b></sub>](https://httpete.com)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ahttpete-ire "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/1706342?v=4" width="100px;"/><br /><sub><b>Nick Lavin</b></sub>](https://github.com/Zashy)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3AZashy "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=Zashy "Code") [⚠️](https://github.com/paypal/downshift/commits?author=Zashy "Tests") | [<img src="https://avatars2.githubusercontent.com/u/17031?v=4" width="100px;"/><br /><sub><b>James Long</b></sub>](http://jlongster.com)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ajlongster "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=jlongster "Code") | [<img src="https://avatars0.githubusercontent.com/u/1505907?v=4" width="100px;"/><br /><sub><b>Michael Ball</b></sub>](http://michaelball.co)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Acycomachead "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=cycomachead "Code") | [<img src="https://avatars0.githubusercontent.com/u/8990614?v=4" width="100px;"/><br /><sub><b>CAVALEIRO Julien</b></sub>](https://github.com/Julienng)<br />[πŸ’‘](#example-Julienng "Examples") | [<img src="https://avatars1.githubusercontent.com/u/3421067?v=4" width="100px;"/><br /><sub><b>Kim GrΓΆnqvist</b></sub>](http://www.kimgronqvist.se)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=kimgronqvist "Code") [⚠️](https://github.com/paypal/downshift/commits?author=kimgronqvist "Tests") | [<img src="https://avatars2.githubusercontent.com/u/3675602?v=4" width="100px;"/><br /><sub><b>Sijie</b></sub>](http://sijietian.com)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Atiansijie "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=tiansijie "Code") |
957
956
  | [<img src="https://avatars0.githubusercontent.com/u/410792?v=4" width="100px;"/><br /><sub><b>Dony Sukardi</b></sub>](http://dsds.io)<br />[πŸ’‘](#example-donysukardi "Examples") [πŸ’¬](#question-donysukardi "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=donysukardi "Code") [⚠️](https://github.com/paypal/downshift/commits?author=donysukardi "Tests") | [<img src="https://avatars1.githubusercontent.com/u/2755722?v=4" width="100px;"/><br /><sub><b>Dillon Mulroy</b></sub>](https://dillonmulroy.com)<br />[πŸ“–](https://github.com/paypal/downshift/commits?author=dmmulroy "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/12440573?v=4" width="100px;"/><br /><sub><b>Curtis Tate Wilkinson</b></sub>](https://twitter.com/curtytate)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=curtiswilkinson "Code") | [<img src="https://avatars3.githubusercontent.com/u/383212?v=4" width="100px;"/><br /><sub><b>Brice BERNARD</b></sub>](https://github.com/brikou)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Abrikou "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=brikou "Code") | [<img src="https://avatars3.githubusercontent.com/u/14304503?v=4" width="100px;"/><br /><sub><b>Tony Xu</b></sub>](https://github.com/xutopia)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=xutopia "Code") | [<img src="https://avatars1.githubusercontent.com/u/14035529?v=4" width="100px;"/><br /><sub><b>Anthony Ng</b></sub>](http://anthonyng.me)<br />[πŸ“–](https://github.com/paypal/downshift/commits?author=newyork-anthonyng "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/11996139?v=4" width="100px;"/><br /><sub><b>S S</b></sub>](https://github.com/notruth)<br />[πŸ’¬](#question-notruth "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=notruth "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=notruth "Documentation") [πŸ€”](#ideas-notruth "Ideas, Planning, & Feedback") [⚠️](https://github.com/paypal/downshift/commits?author=notruth "Tests") |
958
957
  | [<img src="https://avatars0.githubusercontent.com/u/29493001?v=4" width="100px;"/><br /><sub><b>Austin Tackaberry</b></sub>](http://austintackaberry.co)<br />[πŸ’¬](#question-austintackaberry "Answering Questions") [πŸ’»](https://github.com/paypal/downshift/commits?author=austintackaberry "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=austintackaberry "Documentation") [πŸ›](https://github.com/paypal/downshift/issues?q=author%3Aaustintackaberry "Bug reports") [πŸ’‘](#example-austintackaberry "Examples") [πŸ€”](#ideas-austintackaberry "Ideas, Planning, & Feedback") [πŸ‘€](#review-austintackaberry "Reviewed Pull Requests") [⚠️](https://github.com/paypal/downshift/commits?author=austintackaberry "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4168055?v=4" width="100px;"/><br /><sub><b>Jean Duthon</b></sub>](https://github.com/jduthon)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ajduthon "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=jduthon "Code") | [<img src="https://avatars3.githubusercontent.com/u/3889580?v=4" width="100px;"/><br /><sub><b>Anton Telesh</b></sub>](http://antontelesh.github.io)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3AAntontelesh "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=Antontelesh "Code") | [<img src="https://avatars3.githubusercontent.com/u/1060669?v=4" width="100px;"/><br /><sub><b>Eric Edem</b></sub>](https://github.com/ericedem)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=ericedem "Code") [πŸ“–](https://github.com/paypal/downshift/commits?author=ericedem "Documentation") [πŸ€”](#ideas-ericedem "Ideas, Planning, & Feedback") [⚠️](https://github.com/paypal/downshift/commits?author=ericedem "Tests") | [<img src="https://avatars3.githubusercontent.com/u/3409645?v=4" width="100px;"/><br /><sub><b>Austin Wood</b></sub>](https://github.com/indiesquidge)<br />[πŸ’¬](#question-indiesquidge "Answering Questions") [πŸ“–](https://github.com/paypal/downshift/commits?author=indiesquidge "Documentation") [πŸ‘€](#review-indiesquidge "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/14275790?v=4" width="100px;"/><br /><sub><b>Mark Murray</b></sub>](https://github.com/mmmurray)<br />[πŸš‡](#infra-mmmurray "Infrastructure (Hosting, Build-Tools, etc)") | [<img src="https://avatars0.githubusercontent.com/u/1862172?v=4" width="100px;"/><br /><sub><b>Gianmarco</b></sub>](https://github.com/gsimone)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Agsimone "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=gsimone "Code") |
959
- | [<img src="https://avatars2.githubusercontent.com/u/6838136?v=4" width="100px;"/><br /><sub><b>Emmanuel Pastor</b></sub>](https://github.com/pastr)<br />[πŸ’‘](#example-pastr "Examples") | [<img src="https://avatars2.githubusercontent.com/u/10345034?v=4" width="100px;"/><br /><sub><b>dalehurwitz</b></sub>](https://github.com/dalehurwitz)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=dalehurwitz "Code") | [<img src="https://avatars1.githubusercontent.com/u/4813007?v=4" width="100px;"/><br /><sub><b>Bogdan Lobor</b></sub>](https://github.com/blobor)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ablobor "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=blobor "Code") | [<img src="https://avatars0.githubusercontent.com/u/1127238?v=4" width="100px;"/><br /><sub><b>Luke Herrington</b></sub>](https://github.com/infiniteluke)<br />[πŸ’‘](#example-infiniteluke "Examples") | [<img src="https://avatars2.githubusercontent.com/u/6361167?v=4" width="100px;"/><br /><sub><b>Brandon Clemons</b></sub>](https://github.com/drobannx)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=drobannx "Code") | [<img src="https://avatars0.githubusercontent.com/u/10591587?v=4" width="100px;"/><br /><sub><b>Kieran</b></sub>](https://github.com/aMollusk)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=aMollusk "Code") |
960
-
958
+ | [<img src="https://avatars2.githubusercontent.com/u/6838136?v=4" width="100px;"/><br /><sub><b>Emmanuel Pastor</b></sub>](https://github.com/pastr)<br />[πŸ’‘](#example-pastr "Examples") | [<img src="https://avatars2.githubusercontent.com/u/10345034?v=4" width="100px;"/><br /><sub><b>dalehurwitz</b></sub>](https://github.com/dalehurwitz)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=dalehurwitz "Code") | [<img src="https://avatars1.githubusercontent.com/u/4813007?v=4" width="100px;"/><br /><sub><b>Bogdan Lobor</b></sub>](https://github.com/blobor)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3Ablobor "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=blobor "Code") | [<img src="https://avatars0.githubusercontent.com/u/1127238?v=4" width="100px;"/><br /><sub><b>Luke Herrington</b></sub>](https://github.com/infiniteluke)<br />[πŸ’‘](#example-infiniteluke "Examples") | [<img src="https://avatars2.githubusercontent.com/u/6361167?v=4" width="100px;"/><br /><sub><b>Brandon Clemons</b></sub>](https://github.com/drobannx)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=drobannx "Code") | [<img src="https://avatars0.githubusercontent.com/u/10591587?v=4" width="100px;"/><br /><sub><b>Kieran</b></sub>](https://github.com/aMollusk)<br />[πŸ’»](https://github.com/paypal/downshift/commits?author=aMollusk "Code") | [<img src="https://avatars3.githubusercontent.com/u/11570627?v=4" width="100px;"/><br /><sub><b>Brushedoctopus</b></sub>](https://github.com/Brushedoctopus)<br />[πŸ›](https://github.com/paypal/downshift/issues?q=author%3ABrushedoctopus "Bug reports") [πŸ’»](https://github.com/paypal/downshift/commits?author=Brushedoctopus "Code") |
961
959
  <!-- ALL-CONTRIBUTORS-LIST:END -->
962
960
 
963
961
  This project follows the [all-contributors][all-contributors] specification.
@@ -441,7 +441,7 @@ var Downshift = function (_Component) {
441
441
  inputValue: _this.props.defaultInputValue,
442
442
  selectedItem: _this.props.defaultSelectedItem
443
443
  });
444
- if (state.selectedItem) {
444
+ if (state.selectedItem != null) {
445
445
  state.inputValue = _this.props.itemToString(state.selectedItem);
446
446
  }
447
447
  _this.state = state;
@@ -685,13 +685,27 @@ var Downshift = function (_Component) {
685
685
  });
686
686
  }
687
687
  };
688
+ // Touching an element in iOS gives focus and hover states, but touching out of
689
+ // the element will remove hover, and persist the focus state, resulting in the
690
+ // blur event not being triggered.
691
+ var onTouchStart = function (event) {
692
+ var targetInDownshift = _this3._rootNode && isOrContainsNode(_this3._rootNode, event.target);
693
+ if (!targetInDownshift && _this3.getState().isOpen) {
694
+ _this3.reset({ type: Downshift.stateChangeTypes.touchStart }, function () {
695
+ return _this3.props.onOuterClick(_this3.getStateAndHelpers());
696
+ });
697
+ }
698
+ };
699
+
688
700
  this.props.environment.addEventListener('mousedown', onMouseDown);
689
701
  this.props.environment.addEventListener('mouseup', onMouseUp);
702
+ this.props.environment.addEventListener('touchstart', onTouchStart);
690
703
 
691
704
  this.cleanup = function () {
692
705
  _this3._isMounted = false;
693
706
  _this3.props.environment.removeEventListener('mousedown', onMouseDown);
694
707
  _this3.props.environment.removeEventListener('mouseup', onMouseUp);
708
+ _this3.props.environment.removeEventListener('touchstart', onTouchStart);
695
709
  };
696
710
  }
697
711
  };
@@ -806,7 +820,8 @@ Downshift.stateChangeTypes = {
806
820
  keyDownSpaceButton: '__autocomplete_keydown_space_button__',
807
821
  clickButton: '__autocomplete_click_button__',
808
822
  blurButton: '__autocomplete_blur_button__',
809
- controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__'
823
+ controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__',
824
+ touchStart: '__autocomplete_touchstart__'
810
825
  };
811
826
 
812
827
  var _initialiseProps = function () {
@@ -997,6 +1012,12 @@ var _initialiseProps = function () {
997
1012
  Enter: function Enter(event) {
998
1013
  if (this.getState().isOpen) {
999
1014
  event.preventDefault();
1015
+ var itemIndex = this.getState().highlightedIndex;
1016
+ var item = this.items[itemIndex];
1017
+ var itemNode = this.getItemNodeFromIndex(itemIndex);
1018
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
1019
+ return;
1020
+ }
1000
1021
  this.selectHighlightedItem({
1001
1022
  type: Downshift.stateChangeTypes.keyDownEnter
1002
1023
  });
@@ -1058,10 +1079,17 @@ var _initialiseProps = function () {
1058
1079
  if (_this4.props.environment.document.activeElement === _this4.props.environment.document.body) {
1059
1080
  event.target.focus();
1060
1081
  }
1061
- // Ensure that toggle of menu occurs after the potential blur event in iOS
1062
- setTimeout(function () {
1063
- return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1064
- });
1082
+ // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
1083
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
1084
+ // when building for production and should therefore have no impact on production code.
1085
+ if (process.env.NODE_ENV === 'test') {
1086
+ _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1087
+ } else {
1088
+ // Ensure that toggle of menu occurs after the potential blur event in iOS
1089
+ setTimeout(function () {
1090
+ return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1091
+ });
1092
+ }
1065
1093
  };
1066
1094
 
1067
1095
  this.button_handleBlur = function () {
@@ -436,7 +436,7 @@ var Downshift = function (_Component) {
436
436
  inputValue: _this.props.defaultInputValue,
437
437
  selectedItem: _this.props.defaultSelectedItem
438
438
  });
439
- if (state.selectedItem) {
439
+ if (state.selectedItem != null) {
440
440
  state.inputValue = _this.props.itemToString(state.selectedItem);
441
441
  }
442
442
  _this.state = state;
@@ -680,13 +680,27 @@ var Downshift = function (_Component) {
680
680
  });
681
681
  }
682
682
  };
683
+ // Touching an element in iOS gives focus and hover states, but touching out of
684
+ // the element will remove hover, and persist the focus state, resulting in the
685
+ // blur event not being triggered.
686
+ var onTouchStart = function (event) {
687
+ var targetInDownshift = _this3._rootNode && isOrContainsNode(_this3._rootNode, event.target);
688
+ if (!targetInDownshift && _this3.getState().isOpen) {
689
+ _this3.reset({ type: Downshift.stateChangeTypes.touchStart }, function () {
690
+ return _this3.props.onOuterClick(_this3.getStateAndHelpers());
691
+ });
692
+ }
693
+ };
694
+
683
695
  this.props.environment.addEventListener('mousedown', onMouseDown);
684
696
  this.props.environment.addEventListener('mouseup', onMouseUp);
697
+ this.props.environment.addEventListener('touchstart', onTouchStart);
685
698
 
686
699
  this.cleanup = function () {
687
700
  _this3._isMounted = false;
688
701
  _this3.props.environment.removeEventListener('mousedown', onMouseDown);
689
702
  _this3.props.environment.removeEventListener('mouseup', onMouseUp);
703
+ _this3.props.environment.removeEventListener('touchstart', onTouchStart);
690
704
  };
691
705
  }
692
706
  };
@@ -801,7 +815,8 @@ Downshift.stateChangeTypes = {
801
815
  keyDownSpaceButton: '__autocomplete_keydown_space_button__',
802
816
  clickButton: '__autocomplete_click_button__',
803
817
  blurButton: '__autocomplete_blur_button__',
804
- controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__'
818
+ controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__',
819
+ touchStart: '__autocomplete_touchstart__'
805
820
  };
806
821
 
807
822
  var _initialiseProps = function () {
@@ -992,6 +1007,12 @@ var _initialiseProps = function () {
992
1007
  Enter: function Enter(event) {
993
1008
  if (this.getState().isOpen) {
994
1009
  event.preventDefault();
1010
+ var itemIndex = this.getState().highlightedIndex;
1011
+ var item = this.items[itemIndex];
1012
+ var itemNode = this.getItemNodeFromIndex(itemIndex);
1013
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
1014
+ return;
1015
+ }
995
1016
  this.selectHighlightedItem({
996
1017
  type: Downshift.stateChangeTypes.keyDownEnter
997
1018
  });
@@ -1053,10 +1074,17 @@ var _initialiseProps = function () {
1053
1074
  if (_this4.props.environment.document.activeElement === _this4.props.environment.document.body) {
1054
1075
  event.target.focus();
1055
1076
  }
1056
- // Ensure that toggle of menu occurs after the potential blur event in iOS
1057
- setTimeout(function () {
1058
- return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1059
- });
1077
+ // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
1078
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
1079
+ // when building for production and should therefore have no impact on production code.
1080
+ if (process.env.NODE_ENV === 'test') {
1081
+ _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1082
+ } else {
1083
+ // Ensure that toggle of menu occurs after the potential blur event in iOS
1084
+ setTimeout(function () {
1085
+ return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
1086
+ });
1087
+ }
1060
1088
  };
1061
1089
 
1062
1090
  this.button_handleBlur = function () {
@@ -326,7 +326,7 @@ var Downshift = function (_Component) {
326
326
  inputValue: _this.props.defaultInputValue,
327
327
  selectedItem: _this.props.defaultSelectedItem
328
328
  });
329
- if (state.selectedItem) {
329
+ if (state.selectedItem != null) {
330
330
  state.inputValue = _this.props.itemToString(state.selectedItem);
331
331
  }
332
332
  _this.state = state;
@@ -658,7 +658,8 @@ Downshift.stateChangeTypes = {
658
658
  keyDownSpaceButton: '__autocomplete_keydown_space_button__',
659
659
  clickButton: '__autocomplete_click_button__',
660
660
  blurButton: '__autocomplete_blur_button__',
661
- controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__'
661
+ controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__',
662
+ touchStart: '__autocomplete_touchstart__'
662
663
  };
663
664
 
664
665
  var _initialiseProps = function () {
@@ -849,6 +850,12 @@ var _initialiseProps = function () {
849
850
  Enter: function Enter(event) {
850
851
  if (this.getState().isOpen) {
851
852
  event.preventDefault();
853
+ var itemIndex = this.getState().highlightedIndex;
854
+ var item = this.items[itemIndex];
855
+ var itemNode = this.getItemNodeFromIndex(itemIndex);
856
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
857
+ return;
858
+ }
852
859
  this.selectHighlightedItem({
853
860
  type: Downshift.stateChangeTypes.keyDownEnter
854
861
  });
@@ -909,10 +916,17 @@ var _initialiseProps = function () {
909
916
  if (_this4.props.environment.document.activeElement === _this4.props.environment.document.body) {
910
917
  event.target.focus();
911
918
  }
912
- // Ensure that toggle of menu occurs after the potential blur event in iOS
913
- setTimeout(function () {
914
- return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
915
- });
919
+ // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
920
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
921
+ // when building for production and should therefore have no impact on production code.
922
+ if (process.env.NODE_ENV === 'test') {
923
+ _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
924
+ } else {
925
+ // Ensure that toggle of menu occurs after the potential blur event in iOS
926
+ setTimeout(function () {
927
+ return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });
928
+ });
929
+ }
916
930
  };
917
931
 
918
932
  this.button_handleBlur = function () {
@@ -442,7 +442,7 @@
442
442
  inputValue: _this.props.defaultInputValue,
443
443
  selectedItem: _this.props.defaultSelectedItem
444
444
  });
445
- if (state.selectedItem) {
445
+ if (state.selectedItem != null) {
446
446
  state.inputValue = _this.props.itemToString(state.selectedItem);
447
447
  }
448
448
  _this.state = state;
@@ -686,13 +686,27 @@
686
686
  });
687
687
  }
688
688
  };
689
+ // Touching an element in iOS gives focus and hover states, but touching out of
690
+ // the element will remove hover, and persist the focus state, resulting in the
691
+ // blur event not being triggered.
692
+ var onTouchStart = function (event) {
693
+ var targetInDownshift = _this3._rootNode && isOrContainsNode(_this3._rootNode, event.target);
694
+ if (!targetInDownshift && _this3.getState().isOpen) {
695
+ _this3.reset({ type: Downshift.stateChangeTypes.touchStart }, function () {
696
+ return _this3.props.onOuterClick(_this3.getStateAndHelpers());
697
+ });
698
+ }
699
+ };
700
+
689
701
  this.props.environment.addEventListener('mousedown', onMouseDown);
690
702
  this.props.environment.addEventListener('mouseup', onMouseUp);
703
+ this.props.environment.addEventListener('touchstart', onTouchStart);
691
704
 
692
705
  this.cleanup = function () {
693
706
  _this3._isMounted = false;
694
707
  _this3.props.environment.removeEventListener('mousedown', onMouseDown);
695
708
  _this3.props.environment.removeEventListener('mouseup', onMouseUp);
709
+ _this3.props.environment.removeEventListener('touchstart', onTouchStart);
696
710
  };
697
711
  }
698
712
  };
@@ -807,7 +821,8 @@
807
821
  keyDownSpaceButton: '__autocomplete_keydown_space_button__',
808
822
  clickButton: '__autocomplete_click_button__',
809
823
  blurButton: '__autocomplete_blur_button__',
810
- controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__'
824
+ controlledPropUpdatedSelectedItem: '__autocomplete_controlled_prop_updated_selected_item__',
825
+ touchStart: '__autocomplete_touchstart__'
811
826
  };
812
827
 
813
828
  var _initialiseProps = function () {
@@ -998,6 +1013,12 @@
998
1013
  Enter: function Enter(event) {
999
1014
  if (this.getState().isOpen) {
1000
1015
  event.preventDefault();
1016
+ var itemIndex = this.getState().highlightedIndex;
1017
+ var item = this.items[itemIndex];
1018
+ var itemNode = this.getItemNodeFromIndex(itemIndex);
1019
+ if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
1020
+ return;
1021
+ }
1001
1022
  this.selectHighlightedItem({
1002
1023
  type: Downshift.stateChangeTypes.keyDownEnter
1003
1024
  });
@@ -1059,6 +1080,10 @@
1059
1080
  if (_this4.props.environment.document.activeElement === _this4.props.environment.document.body) {
1060
1081
  event.target.focus();
1061
1082
  }
1083
+ // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
1084
+ // if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
1085
+ // when building for production and should therefore have no impact on production code.
1086
+
1062
1087
  // Ensure that toggle of menu occurs after the potential blur event in iOS
1063
1088
  setTimeout(function () {
1064
1089
  return _this4.toggleMenu({ type: Downshift.stateChangeTypes.clickButton });