@algolia/autocomplete-core 1.19.9 → 1.19.11

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.
@@ -93,9 +93,11 @@ export function onKeyDown(_ref) {
93
93
  // result in an unsolicited UI behavior.
94
94
  store.pendingRequests.cancelAll();
95
95
  } else if (event.key === 'Enter') {
96
+ var activeItem = store.getState().activeItemId !== null ? getActiveItem(store.getState()) : null;
97
+
96
98
  // No active item, so we let the browser handle the native `onSubmit` form
97
99
  // event.
98
- if (store.getState().activeItemId === null || store.getState().collections.every(function (collection) {
100
+ if (!activeItem || store.getState().collections.every(function (collection) {
99
101
  return collection.items.length === 0;
100
102
  })) {
101
103
  var waitForSubmit = getPluginSubmitPromise(props.plugins, store.pendingRequests);
@@ -114,11 +116,10 @@ export function onKeyDown(_ref) {
114
116
  // This prevents the `onSubmit` event to be sent because an item is
115
117
  // highlighted.
116
118
  event.preventDefault();
117
- var _ref2 = getActiveItem(store.getState()),
118
- item = _ref2.item,
119
- itemInputValue = _ref2.itemInputValue,
120
- itemUrl = _ref2.itemUrl,
121
- source = _ref2.source;
119
+ var item = activeItem.item,
120
+ itemInputValue = activeItem.itemInputValue,
121
+ itemUrl = activeItem.itemUrl,
122
+ source = activeItem.source;
122
123
  if (event.metaKey || event.ctrlKey) {
123
124
  if (itemUrl !== undefined) {
124
125
  source.onSelect(_objectSpread({
@@ -24,9 +24,13 @@ export var stateReducer = function stateReducer(state, action) {
24
24
  }
25
25
  case 'setCollections':
26
26
  {
27
- return _objectSpread(_objectSpread({}, state), {}, {
27
+ var newItemsCount = getItemsCount({
28
28
  collections: action.payload
29
29
  });
30
+ return _objectSpread(_objectSpread({}, state), {}, {
31
+ collections: action.payload,
32
+ activeItemId: state.activeItemId !== null && state.activeItemId >= newItemsCount ? action.props.defaultActiveItemId : state.activeItemId
33
+ });
30
34
  }
31
35
  case 'setIsOpen':
32
36
  {
@@ -1,4 +1,4 @@
1
- /*! @algolia/autocomplete-core 1.19.9 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
1
+ /*! @algolia/autocomplete-core 1.19.11 | MIT License | © Algolia, Inc. and contributors | https://github.com/algolia/autocomplete */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
4
4
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -324,7 +324,7 @@
324
324
  return undefined;
325
325
  }
326
326
 
327
- var version = '1.19.9';
327
+ var version = '1.19.11';
328
328
 
329
329
  var userAgents = [{
330
330
  segment: 'autocomplete-core',
@@ -1951,9 +1951,11 @@
1951
1951
  // result in an unsolicited UI behavior.
1952
1952
  store.pendingRequests.cancelAll();
1953
1953
  } else if (event.key === 'Enter') {
1954
+ var activeItem = store.getState().activeItemId !== null ? getActiveItem(store.getState()) : null;
1955
+
1954
1956
  // No active item, so we let the browser handle the native `onSubmit` form
1955
1957
  // event.
1956
- if (store.getState().activeItemId === null || store.getState().collections.every(function (collection) {
1958
+ if (!activeItem || store.getState().collections.every(function (collection) {
1957
1959
  return collection.items.length === 0;
1958
1960
  })) {
1959
1961
  var waitForSubmit = getPluginSubmitPromise(props.plugins, store.pendingRequests);
@@ -1972,11 +1974,10 @@
1972
1974
  // This prevents the `onSubmit` event to be sent because an item is
1973
1975
  // highlighted.
1974
1976
  event.preventDefault();
1975
- var _ref2 = getActiveItem(store.getState()),
1976
- item = _ref2.item,
1977
- itemInputValue = _ref2.itemInputValue,
1978
- itemUrl = _ref2.itemUrl,
1979
- source = _ref2.source;
1977
+ var item = activeItem.item,
1978
+ itemInputValue = activeItem.itemInputValue,
1979
+ itemUrl = activeItem.itemUrl,
1980
+ source = activeItem.source;
1980
1981
  if (event.metaKey || event.ctrlKey) {
1981
1982
  if (itemUrl !== undefined) {
1982
1983
  source.onSelect(_objectSpread2({
@@ -2450,9 +2451,13 @@
2450
2451
  }
2451
2452
  case 'setCollections':
2452
2453
  {
2453
- return _objectSpread2(_objectSpread2({}, state), {}, {
2454
+ var newItemsCount = getItemsCount({
2454
2455
  collections: action.payload
2455
2456
  });
2457
+ return _objectSpread2(_objectSpread2({}, state), {}, {
2458
+ collections: action.payload,
2459
+ activeItemId: state.activeItemId !== null && state.activeItemId >= newItemsCount ? action.props.defaultActiveItemId : state.activeItemId
2460
+ });
2456
2461
  }
2457
2462
  case 'setIsOpen':
2458
2463
  {