downshift 6.0.16 → 6.1.0

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
@@ -57,7 +57,7 @@ has been around for a while. It established a successful pattern for making
57
57
  components accessible and functional while giving developers complete freedom
58
58
  when building the UI.
59
59
 
60
- The `README` on this page convers only the component while each hook has its own
60
+ The `README` on this page covers only the component while each hook has its own
61
61
  `README` page. You can navigate to the [hooks page][hooks-readme] or go directly
62
62
  to the hook you need by using the links in the list above.
63
63
 
@@ -867,12 +867,16 @@ var Downshift = /*#__PURE__*/function () {
867
867
  Home: function Home(event) {
868
868
  var _this4 = this;
869
869
 
870
- event.preventDefault();
871
- var itemCount = this.getItemCount();
872
-
873
870
  var _this$getState3 = this.getState(),
874
871
  isOpen = _this$getState3.isOpen;
875
872
 
873
+ if (!isOpen) {
874
+ return;
875
+ }
876
+
877
+ event.preventDefault();
878
+ var itemCount = this.getItemCount();
879
+
876
880
  if (itemCount <= 0 || !isOpen) {
877
881
  return;
878
882
  } // get next non-disabled starting downwards from 0 if that's disabled.
@@ -888,12 +892,16 @@ var Downshift = /*#__PURE__*/function () {
888
892
  End: function End(event) {
889
893
  var _this5 = this;
890
894
 
891
- event.preventDefault();
892
- var itemCount = this.getItemCount();
893
-
894
895
  var _this$getState4 = this.getState(),
895
896
  isOpen = _this$getState4.isOpen;
896
897
 
898
+ if (!isOpen) {
899
+ return;
900
+ }
901
+
902
+ event.preventDefault();
903
+ var itemCount = this.getItemCount();
904
+
897
905
  if (itemCount <= 0 || !isOpen) {
898
906
  return;
899
907
  } // get next non-disabled starting upwards from last index if that's disabled.
@@ -3162,7 +3170,7 @@ function downshiftUseComboboxReducer(state, action) {
3162
3170
  } else {
3163
3171
  changes = {
3164
3172
  highlightedIndex: getHighlightedIndexOnOpen(props, state, 1, action.getItemNodeFromIndex),
3165
- isOpen: true
3173
+ isOpen: props.items.length >= 0
3166
3174
  };
3167
3175
  }
3168
3176
 
@@ -3176,7 +3184,7 @@ function downshiftUseComboboxReducer(state, action) {
3176
3184
  } else {
3177
3185
  changes = {
3178
3186
  highlightedIndex: getHighlightedIndexOnOpen(props, state, -1, action.getItemNodeFromIndex),
3179
- isOpen: true
3187
+ isOpen: props.items.length >= 0
3180
3188
  };
3181
3189
  }
3182
3190
 
@@ -3202,28 +3210,25 @@ function downshiftUseComboboxReducer(state, action) {
3202
3210
  break;
3203
3211
 
3204
3212
  case InputKeyDownHome:
3205
- changes = _extends__default['default']({}, state.isOpen && {
3213
+ changes = {
3206
3214
  highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
3207
- });
3215
+ };
3208
3216
  break;
3209
3217
 
3210
3218
  case InputKeyDownEnd:
3211
- changes = _extends__default['default']({}, state.isOpen && {
3219
+ changes = {
3212
3220
  highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
3213
- });
3221
+ };
3214
3222
  break;
3215
3223
 
3216
3224
  case InputBlur:
3217
- if (state.isOpen) {
3218
- changes = _extends__default['default']({
3219
- isOpen: false,
3220
- highlightedIndex: -1
3221
- }, state.highlightedIndex >= 0 && action.selectItem && {
3222
- selectedItem: props.items[state.highlightedIndex],
3223
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3224
- });
3225
- }
3226
-
3225
+ changes = _extends__default['default']({
3226
+ isOpen: false,
3227
+ highlightedIndex: -1
3228
+ }, state.highlightedIndex >= 0 && action.selectItem && {
3229
+ selectedItem: props.items[state.highlightedIndex],
3230
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3231
+ });
3227
3232
  break;
3228
3233
 
3229
3234
  case InputChange:
@@ -3390,6 +3395,10 @@ function useCombobox(userProps) {
3390
3395
  });
3391
3396
  },
3392
3397
  Home: function Home(event) {
3398
+ if (!latest.current.state.isOpen) {
3399
+ return;
3400
+ }
3401
+
3393
3402
  event.preventDefault();
3394
3403
  dispatch({
3395
3404
  type: InputKeyDownHome,
@@ -3397,6 +3406,10 @@ function useCombobox(userProps) {
3397
3406
  });
3398
3407
  },
3399
3408
  End: function End(event) {
3409
+ if (!latest.current.state.isOpen) {
3410
+ return;
3411
+ }
3412
+
3400
3413
  event.preventDefault();
3401
3414
  dispatch({
3402
3415
  type: InputKeyDownEnd,
@@ -3404,22 +3417,23 @@ function useCombobox(userProps) {
3404
3417
  });
3405
3418
  },
3406
3419
  Escape: function Escape() {
3407
- dispatch({
3408
- type: InputKeyDownEscape
3409
- });
3410
- },
3411
- Enter: function Enter(event) {
3412
- // if IME composing, wait for next Enter keydown event.
3413
- if (event.which === 229) {
3414
- return;
3415
- }
3416
-
3417
3420
  var latestState = latest.current.state;
3418
3421
 
3419
- if (latestState.isOpen) {
3420
- event.preventDefault();
3422
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3423
+ dispatch({
3424
+ type: InputKeyDownEscape
3425
+ });
3421
3426
  }
3427
+ },
3428
+ Enter: function Enter(event) {
3429
+ var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3422
3430
 
3431
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3432
+ ) {
3433
+ return;
3434
+ }
3435
+
3436
+ event.preventDefault();
3423
3437
  dispatch({
3424
3438
  type: InputKeyDownEnter,
3425
3439
  getItemNodeFromIndex: getItemNodeFromIndex
@@ -3579,7 +3593,7 @@ function useCombobox(userProps) {
3579
3593
 
3580
3594
  var inputHandleBlur = function inputHandleBlur() {
3581
3595
  /* istanbul ignore else */
3582
- if (!mouseAndTouchTrackersRef.current.isMouseDown) {
3596
+ if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3583
3597
  dispatch({
3584
3598
  type: InputBlur,
3585
3599
  selectItem: true
@@ -854,12 +854,16 @@ var Downshift = /*#__PURE__*/function () {
854
854
  Home: function Home(event) {
855
855
  var _this4 = this;
856
856
 
857
- event.preventDefault();
858
- var itemCount = this.getItemCount();
859
-
860
857
  var _this$getState3 = this.getState(),
861
858
  isOpen = _this$getState3.isOpen;
862
859
 
860
+ if (!isOpen) {
861
+ return;
862
+ }
863
+
864
+ event.preventDefault();
865
+ var itemCount = this.getItemCount();
866
+
863
867
  if (itemCount <= 0 || !isOpen) {
864
868
  return;
865
869
  } // get next non-disabled starting downwards from 0 if that's disabled.
@@ -875,12 +879,16 @@ var Downshift = /*#__PURE__*/function () {
875
879
  End: function End(event) {
876
880
  var _this5 = this;
877
881
 
878
- event.preventDefault();
879
- var itemCount = this.getItemCount();
880
-
881
882
  var _this$getState4 = this.getState(),
882
883
  isOpen = _this$getState4.isOpen;
883
884
 
885
+ if (!isOpen) {
886
+ return;
887
+ }
888
+
889
+ event.preventDefault();
890
+ var itemCount = this.getItemCount();
891
+
884
892
  if (itemCount <= 0 || !isOpen) {
885
893
  return;
886
894
  } // get next non-disabled starting upwards from last index if that's disabled.
@@ -3149,7 +3157,7 @@ function downshiftUseComboboxReducer(state, action) {
3149
3157
  } else {
3150
3158
  changes = {
3151
3159
  highlightedIndex: getHighlightedIndexOnOpen(props, state, 1, action.getItemNodeFromIndex),
3152
- isOpen: true
3160
+ isOpen: props.items.length >= 0
3153
3161
  };
3154
3162
  }
3155
3163
 
@@ -3163,7 +3171,7 @@ function downshiftUseComboboxReducer(state, action) {
3163
3171
  } else {
3164
3172
  changes = {
3165
3173
  highlightedIndex: getHighlightedIndexOnOpen(props, state, -1, action.getItemNodeFromIndex),
3166
- isOpen: true
3174
+ isOpen: props.items.length >= 0
3167
3175
  };
3168
3176
  }
3169
3177
 
@@ -3189,28 +3197,25 @@ function downshiftUseComboboxReducer(state, action) {
3189
3197
  break;
3190
3198
 
3191
3199
  case InputKeyDownHome:
3192
- changes = _extends({}, state.isOpen && {
3200
+ changes = {
3193
3201
  highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
3194
- });
3202
+ };
3195
3203
  break;
3196
3204
 
3197
3205
  case InputKeyDownEnd:
3198
- changes = _extends({}, state.isOpen && {
3206
+ changes = {
3199
3207
  highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
3200
- });
3208
+ };
3201
3209
  break;
3202
3210
 
3203
3211
  case InputBlur:
3204
- if (state.isOpen) {
3205
- changes = _extends({
3206
- isOpen: false,
3207
- highlightedIndex: -1
3208
- }, state.highlightedIndex >= 0 && action.selectItem && {
3209
- selectedItem: props.items[state.highlightedIndex],
3210
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3211
- });
3212
- }
3213
-
3212
+ changes = _extends({
3213
+ isOpen: false,
3214
+ highlightedIndex: -1
3215
+ }, state.highlightedIndex >= 0 && action.selectItem && {
3216
+ selectedItem: props.items[state.highlightedIndex],
3217
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3218
+ });
3214
3219
  break;
3215
3220
 
3216
3221
  case InputChange:
@@ -3377,6 +3382,10 @@ function useCombobox(userProps) {
3377
3382
  });
3378
3383
  },
3379
3384
  Home: function Home(event) {
3385
+ if (!latest.current.state.isOpen) {
3386
+ return;
3387
+ }
3388
+
3380
3389
  event.preventDefault();
3381
3390
  dispatch({
3382
3391
  type: InputKeyDownHome,
@@ -3384,6 +3393,10 @@ function useCombobox(userProps) {
3384
3393
  });
3385
3394
  },
3386
3395
  End: function End(event) {
3396
+ if (!latest.current.state.isOpen) {
3397
+ return;
3398
+ }
3399
+
3387
3400
  event.preventDefault();
3388
3401
  dispatch({
3389
3402
  type: InputKeyDownEnd,
@@ -3391,22 +3404,23 @@ function useCombobox(userProps) {
3391
3404
  });
3392
3405
  },
3393
3406
  Escape: function Escape() {
3394
- dispatch({
3395
- type: InputKeyDownEscape
3396
- });
3397
- },
3398
- Enter: function Enter(event) {
3399
- // if IME composing, wait for next Enter keydown event.
3400
- if (event.which === 229) {
3401
- return;
3402
- }
3403
-
3404
3407
  var latestState = latest.current.state;
3405
3408
 
3406
- if (latestState.isOpen) {
3407
- event.preventDefault();
3409
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3410
+ dispatch({
3411
+ type: InputKeyDownEscape
3412
+ });
3408
3413
  }
3414
+ },
3415
+ Enter: function Enter(event) {
3416
+ var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3409
3417
 
3418
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3419
+ ) {
3420
+ return;
3421
+ }
3422
+
3423
+ event.preventDefault();
3410
3424
  dispatch({
3411
3425
  type: InputKeyDownEnter,
3412
3426
  getItemNodeFromIndex: getItemNodeFromIndex
@@ -3566,7 +3580,7 @@ function useCombobox(userProps) {
3566
3580
 
3567
3581
  var inputHandleBlur = function inputHandleBlur() {
3568
3582
  /* istanbul ignore else */
3569
- if (!mouseAndTouchTrackersRef.current.isMouseDown) {
3583
+ if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3570
3584
  dispatch({
3571
3585
  type: InputBlur,
3572
3586
  selectItem: true
@@ -867,12 +867,16 @@ var Downshift = /*#__PURE__*/function () {
867
867
  Home: function Home(event) {
868
868
  var _this4 = this;
869
869
 
870
- event.preventDefault();
871
- var itemCount = this.getItemCount();
872
-
873
870
  var _this$getState3 = this.getState(),
874
871
  isOpen = _this$getState3.isOpen;
875
872
 
873
+ if (!isOpen) {
874
+ return;
875
+ }
876
+
877
+ event.preventDefault();
878
+ var itemCount = this.getItemCount();
879
+
876
880
  if (itemCount <= 0 || !isOpen) {
877
881
  return;
878
882
  } // get next non-disabled starting downwards from 0 if that's disabled.
@@ -888,12 +892,16 @@ var Downshift = /*#__PURE__*/function () {
888
892
  End: function End(event) {
889
893
  var _this5 = this;
890
894
 
891
- event.preventDefault();
892
- var itemCount = this.getItemCount();
893
-
894
895
  var _this$getState4 = this.getState(),
895
896
  isOpen = _this$getState4.isOpen;
896
897
 
898
+ if (!isOpen) {
899
+ return;
900
+ }
901
+
902
+ event.preventDefault();
903
+ var itemCount = this.getItemCount();
904
+
897
905
  if (itemCount <= 0 || !isOpen) {
898
906
  return;
899
907
  } // get next non-disabled starting upwards from last index if that's disabled.
@@ -3095,7 +3103,7 @@ function downshiftUseComboboxReducer(state, action) {
3095
3103
  } else {
3096
3104
  changes = {
3097
3105
  highlightedIndex: getHighlightedIndexOnOpen(props, state, 1, action.getItemNodeFromIndex),
3098
- isOpen: true
3106
+ isOpen: props.items.length >= 0
3099
3107
  };
3100
3108
  }
3101
3109
 
@@ -3109,7 +3117,7 @@ function downshiftUseComboboxReducer(state, action) {
3109
3117
  } else {
3110
3118
  changes = {
3111
3119
  highlightedIndex: getHighlightedIndexOnOpen(props, state, -1, action.getItemNodeFromIndex),
3112
- isOpen: true
3120
+ isOpen: props.items.length >= 0
3113
3121
  };
3114
3122
  }
3115
3123
 
@@ -3135,28 +3143,25 @@ function downshiftUseComboboxReducer(state, action) {
3135
3143
  break;
3136
3144
 
3137
3145
  case InputKeyDownHome:
3138
- changes = _extends__default['default']({}, state.isOpen && {
3146
+ changes = {
3139
3147
  highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
3140
- });
3148
+ };
3141
3149
  break;
3142
3150
 
3143
3151
  case InputKeyDownEnd:
3144
- changes = _extends__default['default']({}, state.isOpen && {
3152
+ changes = {
3145
3153
  highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
3146
- });
3154
+ };
3147
3155
  break;
3148
3156
 
3149
3157
  case InputBlur:
3150
- if (state.isOpen) {
3151
- changes = _extends__default['default']({
3152
- isOpen: false,
3153
- highlightedIndex: -1
3154
- }, state.highlightedIndex >= 0 && action.selectItem && {
3155
- selectedItem: props.items[state.highlightedIndex],
3156
- inputValue: props.itemToString(props.items[state.highlightedIndex])
3157
- });
3158
- }
3159
-
3158
+ changes = _extends__default['default']({
3159
+ isOpen: false,
3160
+ highlightedIndex: -1
3161
+ }, state.highlightedIndex >= 0 && action.selectItem && {
3162
+ selectedItem: props.items[state.highlightedIndex],
3163
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
3164
+ });
3160
3165
  break;
3161
3166
 
3162
3167
  case InputChange:
@@ -3323,6 +3328,10 @@ function useCombobox(userProps) {
3323
3328
  });
3324
3329
  },
3325
3330
  Home: function Home(event) {
3331
+ if (!latest.current.state.isOpen) {
3332
+ return;
3333
+ }
3334
+
3326
3335
  event.preventDefault();
3327
3336
  dispatch({
3328
3337
  type: InputKeyDownHome,
@@ -3330,6 +3339,10 @@ function useCombobox(userProps) {
3330
3339
  });
3331
3340
  },
3332
3341
  End: function End(event) {
3342
+ if (!latest.current.state.isOpen) {
3343
+ return;
3344
+ }
3345
+
3333
3346
  event.preventDefault();
3334
3347
  dispatch({
3335
3348
  type: InputKeyDownEnd,
@@ -3337,22 +3350,23 @@ function useCombobox(userProps) {
3337
3350
  });
3338
3351
  },
3339
3352
  Escape: function Escape() {
3340
- dispatch({
3341
- type: InputKeyDownEscape
3342
- });
3343
- },
3344
- Enter: function Enter(event) {
3345
- // if IME composing, wait for next Enter keydown event.
3346
- if (event.which === 229) {
3347
- return;
3348
- }
3349
-
3350
3353
  var latestState = latest.current.state;
3351
3354
 
3352
- if (latestState.isOpen) {
3353
- event.preventDefault();
3355
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
3356
+ dispatch({
3357
+ type: InputKeyDownEscape
3358
+ });
3354
3359
  }
3360
+ },
3361
+ Enter: function Enter(event) {
3362
+ var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
3355
3363
 
3364
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
3365
+ ) {
3366
+ return;
3367
+ }
3368
+
3369
+ event.preventDefault();
3356
3370
  dispatch({
3357
3371
  type: InputKeyDownEnter,
3358
3372
  getItemNodeFromIndex: getItemNodeFromIndex
@@ -3520,7 +3534,7 @@ function useCombobox(userProps) {
3520
3534
 
3521
3535
  var inputHandleBlur = function inputHandleBlur() {
3522
3536
  /* istanbul ignore else */
3523
- if (!mouseAndTouchTrackersRef.current.isMouseDown) {
3537
+ if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
3524
3538
  dispatch({
3525
3539
  type: InputBlur,
3526
3540
  selectItem: true
@@ -2308,12 +2308,16 @@
2308
2308
  Home: function Home(event) {
2309
2309
  var _this4 = this;
2310
2310
 
2311
- event.preventDefault();
2312
- var itemCount = this.getItemCount();
2313
-
2314
2311
  var _this$getState3 = this.getState(),
2315
2312
  isOpen = _this$getState3.isOpen;
2316
2313
 
2314
+ if (!isOpen) {
2315
+ return;
2316
+ }
2317
+
2318
+ event.preventDefault();
2319
+ var itemCount = this.getItemCount();
2320
+
2317
2321
  if (itemCount <= 0 || !isOpen) {
2318
2322
  return;
2319
2323
  } // get next non-disabled starting downwards from 0 if that's disabled.
@@ -2329,12 +2333,16 @@
2329
2333
  End: function End(event) {
2330
2334
  var _this5 = this;
2331
2335
 
2332
- event.preventDefault();
2333
- var itemCount = this.getItemCount();
2334
-
2335
2336
  var _this$getState4 = this.getState(),
2336
2337
  isOpen = _this$getState4.isOpen;
2337
2338
 
2339
+ if (!isOpen) {
2340
+ return;
2341
+ }
2342
+
2343
+ event.preventDefault();
2344
+ var itemCount = this.getItemCount();
2345
+
2338
2346
  if (itemCount <= 0 || !isOpen) {
2339
2347
  return;
2340
2348
  } // get next non-disabled starting upwards from last index if that's disabled.
@@ -4593,7 +4601,7 @@
4593
4601
  } else {
4594
4602
  changes = {
4595
4603
  highlightedIndex: getHighlightedIndexOnOpen(props, state, 1, action.getItemNodeFromIndex),
4596
- isOpen: true
4604
+ isOpen: props.items.length >= 0
4597
4605
  };
4598
4606
  }
4599
4607
 
@@ -4607,7 +4615,7 @@
4607
4615
  } else {
4608
4616
  changes = {
4609
4617
  highlightedIndex: getHighlightedIndexOnOpen(props, state, -1, action.getItemNodeFromIndex),
4610
- isOpen: true
4618
+ isOpen: props.items.length >= 0
4611
4619
  };
4612
4620
  }
4613
4621
 
@@ -4633,28 +4641,25 @@
4633
4641
  break;
4634
4642
 
4635
4643
  case InputKeyDownHome:
4636
- changes = _extends({}, state.isOpen && {
4644
+ changes = {
4637
4645
  highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
4638
- });
4646
+ };
4639
4647
  break;
4640
4648
 
4641
4649
  case InputKeyDownEnd:
4642
- changes = _extends({}, state.isOpen && {
4650
+ changes = {
4643
4651
  highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
4644
- });
4652
+ };
4645
4653
  break;
4646
4654
 
4647
4655
  case InputBlur:
4648
- if (state.isOpen) {
4649
- changes = _extends({
4650
- isOpen: false,
4651
- highlightedIndex: -1
4652
- }, state.highlightedIndex >= 0 && action.selectItem && {
4653
- selectedItem: props.items[state.highlightedIndex],
4654
- inputValue: props.itemToString(props.items[state.highlightedIndex])
4655
- });
4656
- }
4657
-
4656
+ changes = _extends({
4657
+ isOpen: false,
4658
+ highlightedIndex: -1
4659
+ }, state.highlightedIndex >= 0 && action.selectItem && {
4660
+ selectedItem: props.items[state.highlightedIndex],
4661
+ inputValue: props.itemToString(props.items[state.highlightedIndex])
4662
+ });
4658
4663
  break;
4659
4664
 
4660
4665
  case InputChange:
@@ -4821,6 +4826,10 @@
4821
4826
  });
4822
4827
  },
4823
4828
  Home: function Home(event) {
4829
+ if (!latest.current.state.isOpen) {
4830
+ return;
4831
+ }
4832
+
4824
4833
  event.preventDefault();
4825
4834
  dispatch({
4826
4835
  type: InputKeyDownHome,
@@ -4828,6 +4837,10 @@
4828
4837
  });
4829
4838
  },
4830
4839
  End: function End(event) {
4840
+ if (!latest.current.state.isOpen) {
4841
+ return;
4842
+ }
4843
+
4831
4844
  event.preventDefault();
4832
4845
  dispatch({
4833
4846
  type: InputKeyDownEnd,
@@ -4835,22 +4848,23 @@
4835
4848
  });
4836
4849
  },
4837
4850
  Escape: function Escape() {
4838
- dispatch({
4839
- type: InputKeyDownEscape
4840
- });
4841
- },
4842
- Enter: function Enter(event) {
4843
- // if IME composing, wait for next Enter keydown event.
4844
- if (event.which === 229) {
4845
- return;
4846
- }
4847
-
4848
4851
  var latestState = latest.current.state;
4849
4852
 
4850
- if (latestState.isOpen) {
4851
- event.preventDefault();
4853
+ if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
4854
+ dispatch({
4855
+ type: InputKeyDownEscape
4856
+ });
4852
4857
  }
4858
+ },
4859
+ Enter: function Enter(event) {
4860
+ var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
4853
4861
 
4862
+ if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
4863
+ ) {
4864
+ return;
4865
+ }
4866
+
4867
+ event.preventDefault();
4854
4868
  dispatch({
4855
4869
  type: InputKeyDownEnter,
4856
4870
  getItemNodeFromIndex: getItemNodeFromIndex
@@ -5010,7 +5024,7 @@
5010
5024
 
5011
5025
  var inputHandleBlur = function inputHandleBlur() {
5012
5026
  /* istanbul ignore else */
5013
- if (!mouseAndTouchTrackersRef.current.isMouseDown) {
5027
+ if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
5014
5028
  dispatch({
5015
5029
  type: InputBlur,
5016
5030
  selectItem: true