downshift 5.1.0-beta.0 → 5.2.1

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.
@@ -1460,7 +1460,8 @@
1460
1460
 
1461
1461
  function getA11yStatusMessage(_ref2) {
1462
1462
  var isOpen = _ref2.isOpen,
1463
- resultCount = _ref2.resultCount;
1463
+ resultCount = _ref2.resultCount,
1464
+ previousResultCount = _ref2.previousResultCount;
1464
1465
 
1465
1466
  if (!isOpen) {
1466
1467
  return '';
@@ -1470,7 +1471,11 @@
1470
1471
  return 'No results are available.';
1471
1472
  }
1472
1473
 
1473
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
1474
+ if (resultCount !== previousResultCount) {
1475
+ return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
1476
+ }
1477
+
1478
+ return '';
1474
1479
  }
1475
1480
  /**
1476
1481
  * Takes an argument and if it's an array, returns the first item in the array
@@ -1794,8 +1799,12 @@
1794
1799
  touchEnd: touchEnd
1795
1800
  });
1796
1801
 
1797
- var Downshift = /*#__PURE__*/function () {
1798
- var Downshift = /*#__PURE__*/function (_Component) {
1802
+ var Downshift =
1803
+ /*#__PURE__*/
1804
+ function () {
1805
+ var Downshift =
1806
+ /*#__PURE__*/
1807
+ function (_Component) {
1799
1808
  _inheritsLoose(Downshift, _Component);
1800
1809
 
1801
1810
  function Downshift(_props) {
@@ -2069,6 +2078,10 @@
2069
2078
  }
2070
2079
  },
2071
2080
  Enter: function Enter(event) {
2081
+ if (event.which === 229) {
2082
+ return;
2083
+ }
2084
+
2072
2085
  var _this$getState2 = this.getState(),
2073
2086
  isOpen = _this$getState2.isOpen,
2074
2087
  highlightedIndex = _this$getState2.highlightedIndex;
@@ -2946,6 +2959,65 @@
2946
2959
  inputValue: ''
2947
2960
  };
2948
2961
 
2962
+ function callOnChangeProps(action, state, newState) {
2963
+ var props = action.props,
2964
+ type = action.type;
2965
+ var changes = {};
2966
+ Object.keys(state).forEach(function (key) {
2967
+ invokeOnChangeHandler(key, props, state, newState);
2968
+
2969
+ if (newState[key] !== state[key]) {
2970
+ changes[key] = newState[key];
2971
+ }
2972
+ });
2973
+
2974
+ if (props.onStateChange && Object.keys(changes).length) {
2975
+ props.onStateChange(_extends({
2976
+ type: type
2977
+ }, changes));
2978
+ }
2979
+ }
2980
+
2981
+ function invokeOnChangeHandler(key, props, state, newState) {
2982
+ var handler = "on" + capitalizeString(key) + "Change";
2983
+
2984
+ if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
2985
+ props[handler](newState);
2986
+ }
2987
+ }
2988
+ /**
2989
+ * Default state reducer that returns the changes.
2990
+ *
2991
+ * @param {Object} s state.
2992
+ * @param {Object} a action with changes.
2993
+ * @returns {Object} changes.
2994
+ */
2995
+
2996
+
2997
+ function stateReducer(s, a) {
2998
+ return a.changes;
2999
+ }
3000
+ /**
3001
+ * Returns a message to be added to aria-live region when item is selected.
3002
+ *
3003
+ * @param {Object} selectionParameters Parameters required to build the message.
3004
+ * @returns {string} The a11y message.
3005
+ */
3006
+
3007
+
3008
+ function getA11ySelectionMessage(selectionParameters) {
3009
+ var selectedItem = selectionParameters.selectedItem,
3010
+ itemToStringLocal = selectionParameters.itemToString;
3011
+ return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
3012
+ }
3013
+ /**
3014
+ * Debounced call for updating the a11y message.
3015
+ */
3016
+
3017
+
3018
+ var updateA11yStatus = debounce(function (getA11yMessage, document) {
3019
+ setStatus(getA11yMessage(), document);
3020
+ }, 200);
2949
3021
  function getElementIds(_ref) {
2950
3022
  var id = _ref.id,
2951
3023
  labelId = _ref.labelId,
@@ -2962,7 +3034,6 @@
2962
3034
  toggleButtonId: toggleButtonId || uniqueId + "-toggle-button"
2963
3035
  };
2964
3036
  }
2965
-
2966
3037
  function getItemIndex(index, item, items) {
2967
3038
  if (index !== undefined) {
2968
3039
  return index;
@@ -2991,57 +3062,39 @@
2991
3062
  });
2992
3063
  };
2993
3064
  }
2994
-
2995
3065
  function isAcceptedCharacterKey(key) {
2996
3066
  return /^\S{1}$/.test(key);
2997
3067
  }
2998
-
2999
3068
  function capitalizeString(string) {
3000
3069
  return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
3001
3070
  }
3071
+ /**
3072
+ * Computes the controlled state using a the previous state, props,
3073
+ * two reducers, one from downshift and an optional one from the user.
3074
+ * Also calls the onChange handlers for state values that have changed.
3075
+ *
3076
+ * @param {Function} reducer Reducer function from downshift.
3077
+ * @param {Object} initialState Initial state of the hook.
3078
+ * @param {Object} props The hook props.
3079
+ * @returns {Array} An array with the state and an action dispatcher.
3080
+ */
3002
3081
 
3003
- function invokeOnChangeHandler(key, props, state, newState) {
3004
- var handler = "on" + capitalizeString(key) + "Change";
3005
-
3006
- if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
3007
- props[handler](newState);
3008
- }
3009
- }
3010
-
3011
- function callOnChangeProps(action, state, newState) {
3012
- var props = action.props,
3013
- type = action.type;
3014
- var changes = {};
3015
- Object.keys(state).forEach(function (key) {
3016
- invokeOnChangeHandler(key, props, state, newState);
3082
+ function useControlledState(reducer, initialState, props) {
3083
+ var _useState = react.useState(initialState),
3084
+ uncontrolledState = _useState[0],
3085
+ setState = _useState[1];
3017
3086
 
3018
- if (newState[key] !== state[key]) {
3019
- changes[key] = newState[key];
3020
- }
3021
- });
3087
+ var state = getState(uncontrolledState, props);
3022
3088
 
3023
- if (props.onStateChange && Object.keys(changes).length) {
3024
- props.onStateChange(_extends({
3025
- type: type
3026
- }, changes));
3027
- }
3028
- }
3029
-
3030
- function useEnhancedReducer(reducer, initialState, props) {
3031
- var enhancedReducer = react.useCallback(function (state, action) {
3032
- state = getState(state, action.props);
3033
- var stateReduceLocal = action.props.stateReducer;
3089
+ var dispatch = function (action) {
3090
+ var stateReducerFromProps = action.props.stateReducer;
3034
3091
  var changes = reducer(state, action);
3035
- var newState = stateReduceLocal(state, _extends({}, action, {
3092
+ var newState = stateReducerFromProps(state, _extends({}, action, {
3036
3093
  changes: changes
3037
3094
  }));
3038
3095
  callOnChangeProps(action, state, newState);
3039
- return newState;
3040
- }, [reducer]);
3041
-
3042
- var _useReducer = react.useReducer(enhancedReducer, initialState),
3043
- state = _useReducer[0],
3044
- dispatch = _useReducer[1];
3096
+ setState(newState);
3097
+ };
3045
3098
 
3046
3099
  return [getState(state, props), function dispatchWithProps(action) {
3047
3100
  return dispatch(_extends({
@@ -3049,32 +3102,6 @@
3049
3102
  }, action));
3050
3103
  }];
3051
3104
  }
3052
- /**
3053
- * Default state reducer that returns the changes.
3054
- *
3055
- * @param {Object} s state.
3056
- * @param {Object} a action with changes.
3057
- * @returns {Object} changes.
3058
- */
3059
-
3060
-
3061
- function stateReducer(s, a) {
3062
- return a.changes;
3063
- }
3064
- /**
3065
- * Returns a message to be added to aria-live region when item is selected.
3066
- *
3067
- * @param {Object} selectionParameters Parameters required to build the message.
3068
- * @returns {string} The a11y message.
3069
- */
3070
-
3071
-
3072
- function getA11ySelectionMessage(selectionParameters) {
3073
- var selectedItem = selectionParameters.selectedItem,
3074
- itemToStringLocal = selectionParameters.itemToString;
3075
- return itemToStringLocal(selectedItem) + " has been selected.";
3076
- }
3077
-
3078
3105
  var defaultProps = {
3079
3106
  itemToString: itemToString,
3080
3107
  stateReducer: stateReducer,
@@ -3085,7 +3112,6 @@
3085
3112
  /* istanbul ignore next (ssr) */
3086
3113
  ? {} : window
3087
3114
  };
3088
-
3089
3115
  function getDefaultValue(props, propKey, defaultStateValues) {
3090
3116
  if (defaultStateValues === void 0) {
3091
3117
  defaultStateValues = dropdownDefaultStateValues;
@@ -3099,7 +3125,6 @@
3099
3125
 
3100
3126
  return defaultStateValues[propKey];
3101
3127
  }
3102
-
3103
3128
  function getInitialValue(props, propKey, defaultStateValues) {
3104
3129
  if (defaultStateValues === void 0) {
3105
3130
  defaultStateValues = dropdownDefaultStateValues;
@@ -3117,7 +3142,6 @@
3117
3142
 
3118
3143
  return getDefaultValue(props, propKey, defaultStateValues);
3119
3144
  }
3120
-
3121
3145
  function getInitialState(props) {
3122
3146
  var selectedItem = getInitialValue(props, 'selectedItem');
3123
3147
  var isOpen = getInitialValue(props, 'isOpen');
@@ -3130,7 +3154,6 @@
3130
3154
  inputValue: inputValue
3131
3155
  };
3132
3156
  }
3133
-
3134
3157
  function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
3135
3158
  var items = props.items,
3136
3159
  initialHighlightedIndex = props.initialHighlightedIndex,
@@ -3237,7 +3260,8 @@
3237
3260
 
3238
3261
  function getA11yStatusMessage$1(_ref) {
3239
3262
  var isOpen = _ref.isOpen,
3240
- resultCount = _ref.resultCount;
3263
+ resultCount = _ref.resultCount,
3264
+ previousResultCount = _ref.previousResultCount;
3241
3265
 
3242
3266
  if (!isOpen) {
3243
3267
  return '';
@@ -3247,7 +3271,11 @@
3247
3271
  return 'No results are available.';
3248
3272
  }
3249
3273
 
3250
- return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.";
3274
+ if (resultCount !== previousResultCount) {
3275
+ return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.";
3276
+ }
3277
+
3278
+ return '';
3251
3279
  }
3252
3280
 
3253
3281
  var defaultProps$1 = _extends({}, defaultProps, {
@@ -3494,24 +3522,23 @@
3494
3522
  var props = _extends({}, defaultProps$1, {}, userProps);
3495
3523
 
3496
3524
  var items = props.items,
3497
- itemToString = props.itemToString,
3498
- getA11yStatusMessage = props.getA11yStatusMessage,
3499
- getA11ySelectionMessage = props.getA11ySelectionMessage,
3500
3525
  scrollIntoView = props.scrollIntoView,
3501
3526
  environment = props.environment,
3502
3527
  initialIsOpen = props.initialIsOpen,
3503
- defaultIsOpen = props.defaultIsOpen; // Initial state depending on controlled props.
3528
+ defaultIsOpen = props.defaultIsOpen,
3529
+ itemToString = props.itemToString,
3530
+ getA11ySelectionMessage = props.getA11ySelectionMessage,
3531
+ getA11yStatusMessage = props.getA11yStatusMessage; // Initial state depending on controlled props.
3504
3532
 
3505
3533
  var initialState = getInitialState(props); // Reducer init.
3506
3534
 
3507
- var _useEnhancedReducer = useEnhancedReducer(downshiftSelectReducer, initialState, props),
3508
- _useEnhancedReducer$ = _useEnhancedReducer[0],
3509
- isOpen = _useEnhancedReducer$.isOpen,
3510
- highlightedIndex = _useEnhancedReducer$.highlightedIndex,
3511
- selectedItem = _useEnhancedReducer$.selectedItem,
3512
- inputValue = _useEnhancedReducer$.inputValue,
3513
- dispatch = _useEnhancedReducer[1];
3514
- /* Refs */
3535
+ var _useControlledState = useControlledState(downshiftSelectReducer, initialState, props),
3536
+ _useControlledState$ = _useControlledState[0],
3537
+ isOpen = _useControlledState$.isOpen,
3538
+ highlightedIndex = _useControlledState$.highlightedIndex,
3539
+ selectedItem = _useControlledState$.selectedItem,
3540
+ inputValue = _useControlledState$.inputValue,
3541
+ dispatch = _useControlledState[1]; // Refs
3515
3542
 
3516
3543
 
3517
3544
  var toggleButtonRef = react.useRef(null);
@@ -3523,13 +3550,14 @@
3523
3550
  isMouseDown: false,
3524
3551
  isTouchMove: false
3525
3552
  });
3526
- var elementIds = react.useRef(getElementIds(props)); // Some utils.
3553
+ var elementIds = react.useRef(getElementIds(props));
3554
+ var previousResultCountRef = react.useRef(); // Some utils.
3527
3555
 
3528
3556
  var getItemNodeFromIndex = function (index) {
3529
3557
  return environment.document.getElementById(elementIds.current.getItemId(index));
3530
3558
  }; // Effects.
3531
3559
 
3532
- /* Sets a11y status message on changes in isOpen. */
3560
+ /* Sets a11y status message on changes in state. */
3533
3561
 
3534
3562
 
3535
3563
  react.useEffect(function () {
@@ -3537,16 +3565,20 @@
3537
3565
  return;
3538
3566
  }
3539
3567
 
3540
- setStatus(getA11yStatusMessage({
3541
- highlightedIndex: highlightedIndex,
3542
- inputValue: inputValue,
3543
- isOpen: isOpen,
3544
- itemToString: itemToString,
3545
- resultCount: items.length,
3546
- highlightedItem: items[highlightedIndex],
3547
- selectedItem: selectedItem
3548
- }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
3549
- }, [isOpen]);
3568
+ var previousResultCount = previousResultCountRef.current;
3569
+ updateA11yStatus(function () {
3570
+ return getA11yStatusMessage({
3571
+ isOpen: isOpen,
3572
+ highlightedIndex: highlightedIndex,
3573
+ selectedItem: selectedItem,
3574
+ inputValue: inputValue,
3575
+ highlightedItem: items[highlightedIndex],
3576
+ resultCount: items.length,
3577
+ itemToString: itemToString,
3578
+ previousResultCount: previousResultCount
3579
+ });
3580
+ }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
3581
+ }, [isOpen, highlightedIndex, selectedItem, inputValue]);
3550
3582
  /* Sets a11y status message on changes in selectedItem. */
3551
3583
 
3552
3584
  react.useEffect(function () {
@@ -3554,15 +3586,19 @@
3554
3586
  return;
3555
3587
  }
3556
3588
 
3557
- setStatus(getA11ySelectionMessage({
3558
- highlightedIndex: highlightedIndex,
3559
- inputValue: inputValue,
3560
- isOpen: isOpen,
3561
- itemToString: itemToString,
3562
- resultCount: items.length,
3563
- highlightedItem: items[highlightedIndex],
3564
- selectedItem: selectedItem
3565
- }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
3589
+ var previousResultCount = previousResultCountRef.current;
3590
+ updateA11yStatus(function () {
3591
+ return getA11ySelectionMessage({
3592
+ isOpen: isOpen,
3593
+ highlightedIndex: highlightedIndex,
3594
+ selectedItem: selectedItem,
3595
+ inputValue: inputValue,
3596
+ highlightedItem: items[highlightedIndex],
3597
+ resultCount: items.length,
3598
+ itemToString: itemToString,
3599
+ previousResultCount: previousResultCount
3600
+ });
3601
+ }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
3566
3602
  }, [selectedItem]);
3567
3603
  /* Sets cleanup for the keysSoFar after 500ms. */
3568
3604
 
@@ -3619,6 +3655,13 @@
3619
3655
  } // eslint-disable-next-line react-hooks/exhaustive-deps
3620
3656
 
3621
3657
  }, [highlightedIndex]);
3658
+ react.useEffect(function () {
3659
+ if (isInitialMount.current) {
3660
+ return;
3661
+ }
3662
+
3663
+ previousResultCountRef.current = items.length;
3664
+ });
3622
3665
  /* Make initial ref false. */
3623
3666
 
3624
3667
  react.useEffect(function () {
@@ -3942,6 +3985,51 @@
3942
3985
  };
3943
3986
  }
3944
3987
 
3988
+ var InputKeyDownArrowDown = '__input_keydown_arrow_down__';
3989
+ var InputKeyDownArrowUp = '__input_keydown_arrow_up__';
3990
+ var InputKeyDownEscape = '__input_keydown_escape__';
3991
+ var InputKeyDownHome = '__input_keydown_home__';
3992
+ var InputKeyDownEnd = '__input_keydown_end__';
3993
+ var InputKeyDownEnter = '__input_keydown_enter__';
3994
+ var InputChange = '__input_change__';
3995
+ var InputBlur = '__input_blur__';
3996
+ var MenuMouseLeave$1 = '__menu_mouse_leave__';
3997
+ var ItemMouseMove$1 = '__item_mouse_move__';
3998
+ var ItemClick$1 = '__item_click__';
3999
+ var ToggleButtonClick$1 = '__togglebutton_click__';
4000
+ var FunctionToggleMenu$1 = '__function_toggle_menu__';
4001
+ var FunctionOpenMenu$1 = '__function_open_menu__';
4002
+ var FunctionCloseMenu$1 = '__function_close_menu__';
4003
+ var FunctionSetHighlightedIndex$1 = '__function_set_highlighted_index__';
4004
+ var FunctionSelectItem$1 = '__function_select_item__';
4005
+ var FunctionSetInputValue$1 = '__function_set_input_value__';
4006
+ var FunctionReset$1 = '__function_reset__';
4007
+ var ControlledPropUpdatedSelectedItem = '__controlled_prop_updated_selected_item__';
4008
+
4009
+ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
4010
+ __proto__: null,
4011
+ InputKeyDownArrowDown: InputKeyDownArrowDown,
4012
+ InputKeyDownArrowUp: InputKeyDownArrowUp,
4013
+ InputKeyDownEscape: InputKeyDownEscape,
4014
+ InputKeyDownHome: InputKeyDownHome,
4015
+ InputKeyDownEnd: InputKeyDownEnd,
4016
+ InputKeyDownEnter: InputKeyDownEnter,
4017
+ InputChange: InputChange,
4018
+ InputBlur: InputBlur,
4019
+ MenuMouseLeave: MenuMouseLeave$1,
4020
+ ItemMouseMove: ItemMouseMove$1,
4021
+ ItemClick: ItemClick$1,
4022
+ ToggleButtonClick: ToggleButtonClick$1,
4023
+ FunctionToggleMenu: FunctionToggleMenu$1,
4024
+ FunctionOpenMenu: FunctionOpenMenu$1,
4025
+ FunctionCloseMenu: FunctionCloseMenu$1,
4026
+ FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
4027
+ FunctionSelectItem: FunctionSelectItem$1,
4028
+ FunctionSetInputValue: FunctionSetInputValue$1,
4029
+ FunctionReset: FunctionReset$1,
4030
+ ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem
4031
+ });
4032
+
3945
4033
  function getElementIds$1(_ref) {
3946
4034
  var id = _ref.id,
3947
4035
  inputId = _ref.inputId,
@@ -3954,7 +4042,6 @@
3954
4042
  id: id
3955
4043
  }, rest)));
3956
4044
  }
3957
-
3958
4045
  function getInitialState$1(props) {
3959
4046
  var initialState = getInitialState(props);
3960
4047
  var selectedItem = initialState.selectedItem;
@@ -3968,7 +4055,6 @@
3968
4055
  inputValue: inputValue
3969
4056
  });
3970
4057
  }
3971
-
3972
4058
  var propTypes$2 = {
3973
4059
  items: propTypes.array.isRequired,
3974
4060
  itemToString: propTypes.func,
@@ -4009,55 +4095,43 @@
4009
4095
  })
4010
4096
  })
4011
4097
  };
4098
+ /**
4099
+ * The useCombobox version of useControlledState, which also
4100
+ * checks if the controlled prop selectedItem changed between
4101
+ * renders. If so, it will also update inputValue with its
4102
+ * string equivalent. It uses the common useControlledState to
4103
+ * compute the rest of the state.
4104
+ *
4105
+ * @param {Function} reducer Reducer function from downshift.
4106
+ * @param {Object} initialState Initial state of the hook.
4107
+ * @param {Object} props The hook props.
4108
+ * @returns {Array} An array with the state and an action dispatcher.
4109
+ */
4110
+
4111
+ function useControlledState$1(reducer, initialState, props) {
4112
+ var _useControlledStateCo = useControlledState(reducer, initialState, props),
4113
+ newState = _useControlledStateCo[0],
4114
+ dispatch = _useControlledStateCo[1];
4115
+
4116
+ var previousSelectedItemRef = react.useRef(null);
4117
+ var selectedItem = props.selectedItem,
4118
+ itemToString = props.itemToString; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
4119
+
4120
+ if (isControlledProp(props, 'selectedItem') && previousSelectedItemRef.current !== selectedItem) {
4121
+ dispatch({
4122
+ type: ControlledPropUpdatedSelectedItem,
4123
+ inputValue: itemToString(selectedItem)
4124
+ });
4125
+ }
4012
4126
 
4127
+ previousSelectedItemRef.current = selectedItem;
4128
+ return [newState, dispatch];
4129
+ }
4013
4130
  var defaultProps$2 = _extends({}, defaultProps, {
4014
4131
  getA11yStatusMessage: getA11yStatusMessage,
4015
4132
  circularNavigation: true
4016
4133
  });
4017
4134
 
4018
- var InputKeyDownArrowDown = '__input_keydown_arrow_down__';
4019
- var InputKeyDownArrowUp = '__input_keydown_arrow_up__';
4020
- var InputKeyDownEscape = '__input_keydown_escape__';
4021
- var InputKeyDownHome = '__input_keydown_home__';
4022
- var InputKeyDownEnd = '__input_keydown_end__';
4023
- var InputKeyDownEnter = '__input_keydown_enter__';
4024
- var InputChange = '__input_change__';
4025
- var InputBlur = '__input_blur__';
4026
- var MenuMouseLeave$1 = '__menu_mouse_leave__';
4027
- var ItemMouseMove$1 = '__item_mouse_move__';
4028
- var ItemClick$1 = '__item_click__';
4029
- var ToggleButtonClick$1 = '__togglebutton_click__';
4030
- var FunctionToggleMenu$1 = '__function_toggle_menu__';
4031
- var FunctionOpenMenu$1 = '__function_open_menu__';
4032
- var FunctionCloseMenu$1 = '__function_close_menu__';
4033
- var FunctionSetHighlightedIndex$1 = '__function_set_highlighted_index__';
4034
- var FunctionSelectItem$1 = '__function_select_item__';
4035
- var FunctionSetInputValue$1 = '__function_set_input_value__';
4036
- var FunctionReset$1 = '__function_reset__';
4037
-
4038
- var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
4039
- __proto__: null,
4040
- InputKeyDownArrowDown: InputKeyDownArrowDown,
4041
- InputKeyDownArrowUp: InputKeyDownArrowUp,
4042
- InputKeyDownEscape: InputKeyDownEscape,
4043
- InputKeyDownHome: InputKeyDownHome,
4044
- InputKeyDownEnd: InputKeyDownEnd,
4045
- InputKeyDownEnter: InputKeyDownEnter,
4046
- InputChange: InputChange,
4047
- InputBlur: InputBlur,
4048
- MenuMouseLeave: MenuMouseLeave$1,
4049
- ItemMouseMove: ItemMouseMove$1,
4050
- ItemClick: ItemClick$1,
4051
- ToggleButtonClick: ToggleButtonClick$1,
4052
- FunctionToggleMenu: FunctionToggleMenu$1,
4053
- FunctionOpenMenu: FunctionOpenMenu$1,
4054
- FunctionCloseMenu: FunctionCloseMenu$1,
4055
- FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
4056
- FunctionSelectItem: FunctionSelectItem$1,
4057
- FunctionSetInputValue: FunctionSetInputValue$1,
4058
- FunctionReset: FunctionReset$1
4059
- });
4060
-
4061
4135
  /* eslint-disable complexity */
4062
4136
 
4063
4137
  function downshiftUseComboboxReducer(state, action) {
@@ -4197,6 +4271,7 @@
4197
4271
  };
4198
4272
  break;
4199
4273
 
4274
+ case ControlledPropUpdatedSelectedItem:
4200
4275
  case FunctionSetInputValue$1:
4201
4276
  changes = {
4202
4277
  inputValue: action.inputValue
@@ -4237,20 +4312,20 @@
4237
4312
  defaultIsOpen = props.defaultIsOpen,
4238
4313
  items = props.items,
4239
4314
  scrollIntoView = props.scrollIntoView,
4240
- getA11ySelectionMessage = props.getA11ySelectionMessage,
4315
+ environment = props.environment,
4241
4316
  getA11yStatusMessage = props.getA11yStatusMessage,
4242
- itemToString = props.itemToString,
4243
- environment = props.environment; // Initial state depending on controlled props.
4317
+ getA11ySelectionMessage = props.getA11ySelectionMessage,
4318
+ itemToString = props.itemToString; // Initial state depending on controlled props.
4244
4319
 
4245
4320
  var initialState = getInitialState$1(props); // Reducer init.
4246
4321
 
4247
- var _useEnhancedReducer = useEnhancedReducer(downshiftUseComboboxReducer, initialState, props),
4248
- _useEnhancedReducer$ = _useEnhancedReducer[0],
4249
- isOpen = _useEnhancedReducer$.isOpen,
4250
- highlightedIndex = _useEnhancedReducer$.highlightedIndex,
4251
- selectedItem = _useEnhancedReducer$.selectedItem,
4252
- inputValue = _useEnhancedReducer$.inputValue,
4253
- dispatch = _useEnhancedReducer[1];
4322
+ var _useControlledState = useControlledState$1(downshiftUseComboboxReducer, initialState, props),
4323
+ _useControlledState$ = _useControlledState[0],
4324
+ isOpen = _useControlledState$.isOpen,
4325
+ highlightedIndex = _useControlledState$.highlightedIndex,
4326
+ selectedItem = _useControlledState$.selectedItem,
4327
+ inputValue = _useControlledState$.inputValue,
4328
+ dispatch = _useControlledState[1];
4254
4329
  /* Refs */
4255
4330
 
4256
4331
 
@@ -4267,25 +4342,30 @@
4267
4342
  isTouchMove: false
4268
4343
  });
4269
4344
  var elementIds = react.useRef(getElementIds$1(props));
4345
+ var previousResultCountRef = react.useRef();
4270
4346
  /* Effects */
4271
4347
 
4272
- /* Sets a11y status message on changes in isOpen. */
4348
+ /* Sets a11y status message on changes in state. */
4273
4349
 
4274
4350
  react.useEffect(function () {
4275
4351
  if (isInitialMount.current) {
4276
4352
  return;
4277
4353
  }
4278
4354
 
4279
- setStatus(getA11yStatusMessage({
4280
- highlightedIndex: highlightedIndex,
4281
- inputValue: inputValue,
4282
- isOpen: isOpen,
4283
- itemToString: itemToString,
4284
- resultCount: items.length,
4285
- highlightedItem: items[highlightedIndex],
4286
- selectedItem: selectedItem
4287
- }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
4288
- }, [isOpen]);
4355
+ var previousResultCount = previousResultCountRef.current;
4356
+ updateA11yStatus(function () {
4357
+ return getA11yStatusMessage({
4358
+ isOpen: isOpen,
4359
+ highlightedIndex: highlightedIndex,
4360
+ selectedItem: selectedItem,
4361
+ inputValue: inputValue,
4362
+ highlightedItem: items[highlightedIndex],
4363
+ resultCount: items.length,
4364
+ itemToString: itemToString,
4365
+ previousResultCount: previousResultCount
4366
+ });
4367
+ }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
4368
+ }, [isOpen, highlightedIndex, selectedItem, inputValue]);
4289
4369
  /* Sets a11y status message on changes in selectedItem. */
4290
4370
 
4291
4371
  react.useEffect(function () {
@@ -4293,15 +4373,19 @@
4293
4373
  return;
4294
4374
  }
4295
4375
 
4296
- setStatus(getA11ySelectionMessage({
4297
- highlightedIndex: highlightedIndex,
4298
- inputValue: inputValue,
4299
- isOpen: isOpen,
4300
- itemToString: itemToString,
4301
- resultCount: items.length,
4302
- highlightedItem: items[highlightedIndex],
4303
- selectedItem: selectedItem
4304
- }), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
4376
+ var previousResultCount = previousResultCountRef.current;
4377
+ updateA11yStatus(function () {
4378
+ return getA11ySelectionMessage({
4379
+ isOpen: isOpen,
4380
+ highlightedIndex: highlightedIndex,
4381
+ selectedItem: selectedItem,
4382
+ inputValue: inputValue,
4383
+ highlightedItem: items[highlightedIndex],
4384
+ resultCount: items.length,
4385
+ itemToString: itemToString,
4386
+ previousResultCount: previousResultCount
4387
+ });
4388
+ }, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
4305
4389
  }, [selectedItem]);
4306
4390
  /* Scroll on highlighted item if change comes from keyboard. */
4307
4391
 
@@ -4331,8 +4415,13 @@
4331
4415
  } // eslint-disable-next-line react-hooks/exhaustive-deps
4332
4416
 
4333
4417
  }, [isOpen]);
4334
- /* Make initial ref false. */
4418
+ react.useEffect(function () {
4419
+ if (isInitialMount.current) {
4420
+ return;
4421
+ }
4335
4422
 
4423
+ previousResultCountRef.current = items.length;
4424
+ });
4336
4425
  react.useEffect(function () {
4337
4426
  isInitialMount.current = false;
4338
4427
  }, []);
@@ -4428,6 +4517,11 @@
4428
4517
  });
4429
4518
  },
4430
4519
  Enter: function Enter(event) {
4520
+ // if IME composing, wait for next Enter keydown event.
4521
+ if (event.which === 229) {
4522
+ return;
4523
+ }
4524
+
4431
4525
  event.preventDefault();
4432
4526
  dispatch({
4433
4527
  type: InputKeyDownEnter,
@@ -4958,11 +5052,11 @@
4958
5052
  keyNavigationNext = props.keyNavigationNext,
4959
5053
  keyNavigationPrevious = props.keyNavigationPrevious; // Reducer init.
4960
5054
 
4961
- var _useEnhancedReducer = useEnhancedReducer(downshiftMultipleSelectionReducer, getInitialState$2(props), props),
4962
- _useEnhancedReducer$ = _useEnhancedReducer[0],
4963
- activeIndex = _useEnhancedReducer$.activeIndex,
4964
- selectedItems = _useEnhancedReducer$.selectedItems,
4965
- dispatch = _useEnhancedReducer[1]; // Refs.
5055
+ var _useControlledState = useControlledState(downshiftMultipleSelectionReducer, getInitialState$2(props), props),
5056
+ _useControlledState$ = _useControlledState[0],
5057
+ activeIndex = _useControlledState$.activeIndex,
5058
+ selectedItems = _useControlledState$.selectedItems,
5059
+ dispatch = _useControlledState[1]; // Refs.
4966
5060
 
4967
5061
 
4968
5062
  var isInitialMount = react.useRef(true);