downshift 6.0.16 → 6.1.2
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 +1 -1
- package/dist/downshift.cjs.js +234 -216
- package/dist/downshift.esm.js +234 -216
- package/dist/downshift.native.cjs.js +230 -220
- package/dist/downshift.umd.js +475 -448
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +26 -2
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +24 -24
- package/preact/dist/downshift.cjs.js +234 -216
- package/preact/dist/downshift.esm.js +234 -216
- package/preact/dist/downshift.umd.js +318 -291
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +12 -3
- package/preact/dist/downshift.umd.min.js.map +1 -1
|
@@ -162,7 +162,7 @@ function resetIdCounter() {
|
|
|
162
162
|
*/
|
|
163
163
|
|
|
164
164
|
|
|
165
|
-
function getA11yStatusMessage(_ref2) {
|
|
165
|
+
function getA11yStatusMessage$1(_ref2) {
|
|
166
166
|
var isOpen = _ref2.isOpen,
|
|
167
167
|
resultCount = _ref2.resultCount,
|
|
168
168
|
previousResultCount = _ref2.previousResultCount;
|
|
@@ -518,7 +518,7 @@ var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_bu
|
|
|
518
518
|
var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
|
519
519
|
var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
|
520
520
|
|
|
521
|
-
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
521
|
+
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
522
522
|
__proto__: null,
|
|
523
523
|
unknown: unknown,
|
|
524
524
|
mouseUp: mouseUp,
|
|
@@ -860,12 +860,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
860
860
|
Home: function Home(event) {
|
|
861
861
|
var _this4 = this;
|
|
862
862
|
|
|
863
|
-
event.preventDefault();
|
|
864
|
-
var itemCount = this.getItemCount();
|
|
865
|
-
|
|
866
863
|
var _this$getState3 = this.getState(),
|
|
867
864
|
isOpen = _this$getState3.isOpen;
|
|
868
865
|
|
|
866
|
+
if (!isOpen) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
event.preventDefault();
|
|
871
|
+
var itemCount = this.getItemCount();
|
|
872
|
+
|
|
869
873
|
if (itemCount <= 0 || !isOpen) {
|
|
870
874
|
return;
|
|
871
875
|
} // get next non-disabled starting downwards from 0 if that's disabled.
|
|
@@ -881,12 +885,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
881
885
|
End: function End(event) {
|
|
882
886
|
var _this5 = this;
|
|
883
887
|
|
|
884
|
-
event.preventDefault();
|
|
885
|
-
var itemCount = this.getItemCount();
|
|
886
|
-
|
|
887
888
|
var _this$getState4 = this.getState(),
|
|
888
889
|
isOpen = _this$getState4.isOpen;
|
|
889
890
|
|
|
891
|
+
if (!isOpen) {
|
|
892
|
+
return;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
event.preventDefault();
|
|
896
|
+
var itemCount = this.getItemCount();
|
|
897
|
+
|
|
890
898
|
if (itemCount <= 0 || !isOpen) {
|
|
891
899
|
return;
|
|
892
900
|
} // get next non-disabled starting upwards from last index if that's disabled.
|
|
@@ -903,9 +911,9 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
903
911
|
|
|
904
912
|
_this.getToggleButtonProps = function (_temp3) {
|
|
905
913
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
906
|
-
onClick = _ref3.onClick
|
|
907
|
-
|
|
908
|
-
onKeyDown = _ref3.onKeyDown,
|
|
914
|
+
onClick = _ref3.onClick;
|
|
915
|
+
_ref3.onPress;
|
|
916
|
+
var onKeyDown = _ref3.onKeyDown,
|
|
909
917
|
onKeyUp = _ref3.onKeyUp,
|
|
910
918
|
onBlur = _ref3.onBlur,
|
|
911
919
|
rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
|
|
@@ -913,7 +921,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
913
921
|
var _this$getState5 = _this.getState(),
|
|
914
922
|
isOpen = _this$getState5.isOpen;
|
|
915
923
|
|
|
916
|
-
var enabledEventHandlers =
|
|
924
|
+
var enabledEventHandlers = {
|
|
917
925
|
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
918
926
|
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
919
927
|
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
@@ -948,7 +956,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
948
956
|
|
|
949
957
|
/* istanbul ignore if (can't reasonably test this) */
|
|
950
958
|
|
|
951
|
-
if (
|
|
959
|
+
if (_this.props.environment.document.activeElement === _this.props.environment.document.body) {
|
|
952
960
|
event.target.focus();
|
|
953
961
|
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
954
962
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -995,9 +1003,9 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
995
1003
|
onKeyDown = _ref4.onKeyDown,
|
|
996
1004
|
onBlur = _ref4.onBlur,
|
|
997
1005
|
onChange = _ref4.onChange,
|
|
998
|
-
onInput = _ref4.onInput
|
|
999
|
-
|
|
1000
|
-
rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
|
|
1006
|
+
onInput = _ref4.onInput;
|
|
1007
|
+
_ref4.onChangeText;
|
|
1008
|
+
var rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
|
|
1001
1009
|
|
|
1002
1010
|
var onChangeKey;
|
|
1003
1011
|
var eventHandlers = {};
|
|
@@ -1043,7 +1051,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1043
1051
|
_this.internalSetState({
|
|
1044
1052
|
type: changeInput,
|
|
1045
1053
|
isOpen: true,
|
|
1046
|
-
inputValue:
|
|
1054
|
+
inputValue: event.target.value,
|
|
1047
1055
|
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
1048
1056
|
});
|
|
1049
1057
|
};
|
|
@@ -1090,9 +1098,9 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1090
1098
|
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
1091
1099
|
onMouseMove = _ref7.onMouseMove,
|
|
1092
1100
|
onMouseDown = _ref7.onMouseDown,
|
|
1093
|
-
onClick = _ref7.onClick
|
|
1094
|
-
|
|
1095
|
-
index = _ref7.index,
|
|
1101
|
+
onClick = _ref7.onClick;
|
|
1102
|
+
_ref7.onPress;
|
|
1103
|
+
var index = _ref7.index,
|
|
1096
1104
|
_ref7$item = _ref7.item,
|
|
1097
1105
|
item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
|
|
1098
1106
|
/* istanbul ignore next */
|
|
@@ -1107,8 +1115,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1107
1115
|
_this.items[index] = item;
|
|
1108
1116
|
}
|
|
1109
1117
|
|
|
1110
|
-
var onSelectKey =
|
|
1111
|
-
var customClickHandler =
|
|
1118
|
+
var onSelectKey = 'onClick';
|
|
1119
|
+
var customClickHandler = onClick;
|
|
1112
1120
|
var enabledEventHandlers = (_enabledEventHandlers = {
|
|
1113
1121
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
1114
1122
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
@@ -1498,7 +1506,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1498
1506
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
1499
1507
|
/* istanbul ignore if (react-native) */
|
|
1500
1508
|
|
|
1501
|
-
if (
|
|
1509
|
+
if (this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
1502
1510
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
1503
1511
|
}
|
|
1504
1512
|
}
|
|
@@ -1583,7 +1591,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1583
1591
|
Downshift.defaultProps = {
|
|
1584
1592
|
defaultHighlightedIndex: null,
|
|
1585
1593
|
defaultIsOpen: false,
|
|
1586
|
-
getA11yStatusMessage: getA11yStatusMessage,
|
|
1594
|
+
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
1587
1595
|
itemToString: function itemToString(i) {
|
|
1588
1596
|
if (i == null) {
|
|
1589
1597
|
return '';
|
|
@@ -1614,7 +1622,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1614
1622
|
suppressRefError: false,
|
|
1615
1623
|
scrollIntoView: scrollIntoView
|
|
1616
1624
|
};
|
|
1617
|
-
Downshift.stateChangeTypes = stateChangeTypes;
|
|
1625
|
+
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
1618
1626
|
return Downshift;
|
|
1619
1627
|
}();
|
|
1620
1628
|
|
|
@@ -1829,7 +1837,7 @@ function useEnhancedReducer(reducer, initialState, props) {
|
|
|
1829
1837
|
*/
|
|
1830
1838
|
|
|
1831
1839
|
|
|
1832
|
-
function useControlledReducer(reducer, initialState, props) {
|
|
1840
|
+
function useControlledReducer$1(reducer, initialState, props) {
|
|
1833
1841
|
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
1834
1842
|
state = _useEnhancedReducer[0],
|
|
1835
1843
|
dispatch = _useEnhancedReducer[1];
|
|
@@ -1837,7 +1845,7 @@ function useControlledReducer(reducer, initialState, props) {
|
|
|
1837
1845
|
return [getState(state, props), dispatch];
|
|
1838
1846
|
}
|
|
1839
1847
|
|
|
1840
|
-
var defaultProps = {
|
|
1848
|
+
var defaultProps$3 = {
|
|
1841
1849
|
itemToString: itemToString,
|
|
1842
1850
|
stateReducer: stateReducer,
|
|
1843
1851
|
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
@@ -1848,7 +1856,7 @@ var defaultProps = {
|
|
|
1848
1856
|
? {} : window
|
|
1849
1857
|
};
|
|
1850
1858
|
|
|
1851
|
-
function getDefaultValue(props, propKey, defaultStateValues) {
|
|
1859
|
+
function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
1852
1860
|
if (defaultStateValues === void 0) {
|
|
1853
1861
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1854
1862
|
}
|
|
@@ -1862,7 +1870,7 @@ function getDefaultValue(props, propKey, defaultStateValues) {
|
|
|
1862
1870
|
return defaultStateValues[propKey];
|
|
1863
1871
|
}
|
|
1864
1872
|
|
|
1865
|
-
function getInitialValue(props, propKey, defaultStateValues) {
|
|
1873
|
+
function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
1866
1874
|
if (defaultStateValues === void 0) {
|
|
1867
1875
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1868
1876
|
}
|
|
@@ -1877,14 +1885,14 @@ function getInitialValue(props, propKey, defaultStateValues) {
|
|
|
1877
1885
|
return props[initialPropKey];
|
|
1878
1886
|
}
|
|
1879
1887
|
|
|
1880
|
-
return getDefaultValue(props, propKey, defaultStateValues);
|
|
1888
|
+
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1881
1889
|
}
|
|
1882
1890
|
|
|
1883
|
-
function getInitialState(props) {
|
|
1884
|
-
var selectedItem = getInitialValue(props, 'selectedItem');
|
|
1885
|
-
var isOpen = getInitialValue(props, 'isOpen');
|
|
1886
|
-
var highlightedIndex = getInitialValue(props, 'highlightedIndex');
|
|
1887
|
-
var inputValue = getInitialValue(props, 'inputValue');
|
|
1891
|
+
function getInitialState$2(props) {
|
|
1892
|
+
var selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1893
|
+
var isOpen = getInitialValue$1(props, 'isOpen');
|
|
1894
|
+
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
1895
|
+
var inputValue = getInitialValue$1(props, 'inputValue');
|
|
1888
1896
|
return {
|
|
1889
1897
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
1890
1898
|
isOpen: isOpen,
|
|
@@ -2179,10 +2187,10 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2179
2187
|
|
|
2180
2188
|
case stateChangeTypes.FunctionReset:
|
|
2181
2189
|
changes = {
|
|
2182
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
2183
|
-
isOpen: getDefaultValue(props, 'isOpen'),
|
|
2184
|
-
selectedItem: getDefaultValue(props, 'selectedItem'),
|
|
2185
|
-
inputValue: getDefaultValue(props, 'inputValue')
|
|
2190
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2191
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2192
|
+
selectedItem: getDefaultValue$1(props, 'selectedItem'),
|
|
2193
|
+
inputValue: getDefaultValue$1(props, 'inputValue')
|
|
2186
2194
|
};
|
|
2187
2195
|
break;
|
|
2188
2196
|
|
|
@@ -2212,7 +2220,7 @@ function getItemIndexByCharacterKey(keysSoFar, highlightedIndex, items, itemToSt
|
|
|
2212
2220
|
return highlightedIndex;
|
|
2213
2221
|
}
|
|
2214
2222
|
|
|
2215
|
-
var propTypes = {
|
|
2223
|
+
var propTypes$2 = {
|
|
2216
2224
|
items: PropTypes.array.isRequired,
|
|
2217
2225
|
itemToString: PropTypes.func,
|
|
2218
2226
|
getA11yStatusMessage: PropTypes.func,
|
|
@@ -2256,7 +2264,7 @@ var propTypes = {
|
|
|
2256
2264
|
* @return {String} the a11y status message
|
|
2257
2265
|
*/
|
|
2258
2266
|
|
|
2259
|
-
function getA11yStatusMessage
|
|
2267
|
+
function getA11yStatusMessage(_ref) {
|
|
2260
2268
|
var isOpen = _ref.isOpen,
|
|
2261
2269
|
resultCount = _ref.resultCount,
|
|
2262
2270
|
previousResultCount = _ref.previousResultCount;
|
|
@@ -2276,17 +2284,17 @@ function getA11yStatusMessage$1(_ref) {
|
|
|
2276
2284
|
return '';
|
|
2277
2285
|
}
|
|
2278
2286
|
|
|
2279
|
-
var defaultProps$
|
|
2280
|
-
getA11yStatusMessage: getA11yStatusMessage
|
|
2287
|
+
var defaultProps$2 = _extends({}, defaultProps$3, {
|
|
2288
|
+
getA11yStatusMessage: getA11yStatusMessage
|
|
2281
2289
|
}); // eslint-disable-next-line import/no-mutable-exports
|
|
2282
2290
|
|
|
2283
2291
|
|
|
2284
|
-
var validatePropTypes = noop;
|
|
2292
|
+
var validatePropTypes$2 = noop;
|
|
2285
2293
|
/* istanbul ignore next */
|
|
2286
2294
|
|
|
2287
2295
|
if (process.env.NODE_ENV !== 'production') {
|
|
2288
|
-
validatePropTypes = function validatePropTypes(options, caller) {
|
|
2289
|
-
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
2296
|
+
validatePropTypes$2 = function validatePropTypes(options, caller) {
|
|
2297
|
+
PropTypes.checkPropTypes(propTypes$2, options, 'prop', caller.name);
|
|
2290
2298
|
};
|
|
2291
2299
|
}
|
|
2292
2300
|
|
|
@@ -2299,22 +2307,22 @@ var MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_e
|
|
|
2299
2307
|
var MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
|
|
2300
2308
|
var MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
|
|
2301
2309
|
var MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
|
|
2302
|
-
var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
|
|
2303
|
-
var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
|
|
2304
|
-
var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
|
|
2305
|
-
var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
|
|
2310
|
+
var MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
|
|
2311
|
+
var ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
|
|
2312
|
+
var ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
|
|
2313
|
+
var ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
|
|
2306
2314
|
var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
|
|
2307
2315
|
var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
|
|
2308
2316
|
var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
|
|
2309
|
-
var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
|
|
2310
|
-
var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
|
|
2311
|
-
var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
|
|
2312
|
-
var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
|
|
2313
|
-
var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
|
|
2314
|
-
var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
|
|
2315
|
-
var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
|
|
2317
|
+
var FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
|
|
2318
|
+
var FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
|
|
2319
|
+
var FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
|
|
2320
|
+
var FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
|
|
2321
|
+
var FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
|
|
2322
|
+
var FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
|
|
2323
|
+
var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
|
|
2316
2324
|
|
|
2317
|
-
var stateChangeTypes$
|
|
2325
|
+
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2318
2326
|
__proto__: null,
|
|
2319
2327
|
MenuKeyDownArrowDown: MenuKeyDownArrowDown,
|
|
2320
2328
|
MenuKeyDownArrowUp: MenuKeyDownArrowUp,
|
|
@@ -2325,20 +2333,20 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
2325
2333
|
MenuKeyDownSpaceButton: MenuKeyDownSpaceButton,
|
|
2326
2334
|
MenuKeyDownCharacter: MenuKeyDownCharacter,
|
|
2327
2335
|
MenuBlur: MenuBlur,
|
|
2328
|
-
MenuMouseLeave: MenuMouseLeave,
|
|
2329
|
-
ItemMouseMove: ItemMouseMove,
|
|
2330
|
-
ItemClick: ItemClick,
|
|
2331
|
-
ToggleButtonClick: ToggleButtonClick,
|
|
2336
|
+
MenuMouseLeave: MenuMouseLeave$1,
|
|
2337
|
+
ItemMouseMove: ItemMouseMove$1,
|
|
2338
|
+
ItemClick: ItemClick$1,
|
|
2339
|
+
ToggleButtonClick: ToggleButtonClick$1,
|
|
2332
2340
|
ToggleButtonKeyDownArrowDown: ToggleButtonKeyDownArrowDown,
|
|
2333
2341
|
ToggleButtonKeyDownArrowUp: ToggleButtonKeyDownArrowUp,
|
|
2334
2342
|
ToggleButtonKeyDownCharacter: ToggleButtonKeyDownCharacter,
|
|
2335
|
-
FunctionToggleMenu: FunctionToggleMenu,
|
|
2336
|
-
FunctionOpenMenu: FunctionOpenMenu,
|
|
2337
|
-
FunctionCloseMenu: FunctionCloseMenu,
|
|
2338
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2339
|
-
FunctionSelectItem: FunctionSelectItem,
|
|
2340
|
-
FunctionSetInputValue: FunctionSetInputValue,
|
|
2341
|
-
FunctionReset: FunctionReset
|
|
2343
|
+
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2344
|
+
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2345
|
+
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2346
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
|
|
2347
|
+
FunctionSelectItem: FunctionSelectItem$1,
|
|
2348
|
+
FunctionSetInputValue: FunctionSetInputValue$1,
|
|
2349
|
+
FunctionReset: FunctionReset$2
|
|
2342
2350
|
});
|
|
2343
2351
|
|
|
2344
2352
|
/* eslint-disable complexity */
|
|
@@ -2350,10 +2358,10 @@ function downshiftSelectReducer(state, action) {
|
|
|
2350
2358
|
var changes;
|
|
2351
2359
|
|
|
2352
2360
|
switch (type) {
|
|
2353
|
-
case ItemClick:
|
|
2361
|
+
case ItemClick$1:
|
|
2354
2362
|
changes = {
|
|
2355
|
-
isOpen: getDefaultValue(props, 'isOpen'),
|
|
2356
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
2363
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2364
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2357
2365
|
selectedItem: props.items[action.index]
|
|
2358
2366
|
};
|
|
2359
2367
|
break;
|
|
@@ -2388,8 +2396,8 @@ function downshiftSelectReducer(state, action) {
|
|
|
2388
2396
|
case MenuKeyDownEnter:
|
|
2389
2397
|
case MenuKeyDownSpaceButton:
|
|
2390
2398
|
changes = _extends({
|
|
2391
|
-
isOpen: getDefaultValue(props, 'isOpen'),
|
|
2392
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex')
|
|
2399
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2400
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2393
2401
|
}, state.highlightedIndex >= 0 && {
|
|
2394
2402
|
selectedItem: props.items[state.highlightedIndex]
|
|
2395
2403
|
});
|
|
@@ -2448,30 +2456,30 @@ function downshiftSelectReducer(state, action) {
|
|
|
2448
2456
|
};
|
|
2449
2457
|
break;
|
|
2450
2458
|
|
|
2451
|
-
case FunctionSelectItem:
|
|
2459
|
+
case FunctionSelectItem$1:
|
|
2452
2460
|
changes = {
|
|
2453
2461
|
selectedItem: action.selectedItem
|
|
2454
2462
|
};
|
|
2455
2463
|
break;
|
|
2456
2464
|
|
|
2457
2465
|
default:
|
|
2458
|
-
return downshiftCommonReducer(state, action, stateChangeTypes$
|
|
2466
|
+
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2459
2467
|
}
|
|
2460
2468
|
|
|
2461
2469
|
return _extends({}, state, changes);
|
|
2462
2470
|
}
|
|
2463
2471
|
/* eslint-enable complexity */
|
|
2464
2472
|
|
|
2465
|
-
useSelect.stateChangeTypes = stateChangeTypes$
|
|
2473
|
+
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2466
2474
|
|
|
2467
2475
|
function useSelect(userProps) {
|
|
2468
2476
|
if (userProps === void 0) {
|
|
2469
2477
|
userProps = {};
|
|
2470
2478
|
}
|
|
2471
2479
|
|
|
2472
|
-
validatePropTypes(userProps, useSelect); // Props defaults and destructuring.
|
|
2480
|
+
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
2473
2481
|
|
|
2474
|
-
var props = _extends({}, defaultProps$
|
|
2482
|
+
var props = _extends({}, defaultProps$2, userProps);
|
|
2475
2483
|
|
|
2476
2484
|
var items = props.items,
|
|
2477
2485
|
scrollIntoView = props.scrollIntoView,
|
|
@@ -2482,9 +2490,9 @@ function useSelect(userProps) {
|
|
|
2482
2490
|
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
2483
2491
|
getA11yStatusMessage = props.getA11yStatusMessage; // Initial state depending on controlled props.
|
|
2484
2492
|
|
|
2485
|
-
var initialState = getInitialState(props);
|
|
2493
|
+
var initialState = getInitialState$2(props);
|
|
2486
2494
|
|
|
2487
|
-
var _useControlledReducer = useControlledReducer(downshiftSelectReducer, initialState, props),
|
|
2495
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
|
|
2488
2496
|
state = _useControlledReducer[0],
|
|
2489
2497
|
dispatch = _useControlledReducer[1];
|
|
2490
2498
|
|
|
@@ -2539,19 +2547,23 @@ function useSelect(userProps) {
|
|
|
2539
2547
|
itemRefs: itemRefs,
|
|
2540
2548
|
scrollIntoView: scrollIntoView,
|
|
2541
2549
|
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2542
|
-
}); // Sets cleanup for the keysSoFar after 500ms.
|
|
2550
|
+
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2543
2551
|
|
|
2544
2552
|
useEffect(function () {
|
|
2545
2553
|
// init the clean function here as we need access to dispatch.
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
+
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
2555
|
+
outerDispatch({
|
|
2556
|
+
type: FunctionSetInputValue$1,
|
|
2557
|
+
inputValue: ''
|
|
2558
|
+
});
|
|
2559
|
+
}, 500); // Cancel any pending debounced calls on mount
|
|
2560
|
+
|
|
2561
|
+
return function () {
|
|
2562
|
+
clearTimeoutRef.current.cancel();
|
|
2563
|
+
};
|
|
2564
|
+
}, []); // Invokes the keysSoFar callback set up above.
|
|
2554
2565
|
|
|
2566
|
+
useEffect(function () {
|
|
2555
2567
|
if (!inputValue) {
|
|
2556
2568
|
return;
|
|
2557
2569
|
}
|
|
@@ -2695,39 +2707,39 @@ function useSelect(userProps) {
|
|
|
2695
2707
|
|
|
2696
2708
|
var toggleMenu = useCallback(function () {
|
|
2697
2709
|
dispatch({
|
|
2698
|
-
type: FunctionToggleMenu
|
|
2710
|
+
type: FunctionToggleMenu$1
|
|
2699
2711
|
});
|
|
2700
2712
|
}, [dispatch]);
|
|
2701
2713
|
var closeMenu = useCallback(function () {
|
|
2702
2714
|
dispatch({
|
|
2703
|
-
type: FunctionCloseMenu
|
|
2715
|
+
type: FunctionCloseMenu$1
|
|
2704
2716
|
});
|
|
2705
2717
|
}, [dispatch]);
|
|
2706
2718
|
var openMenu = useCallback(function () {
|
|
2707
2719
|
dispatch({
|
|
2708
|
-
type: FunctionOpenMenu
|
|
2720
|
+
type: FunctionOpenMenu$1
|
|
2709
2721
|
});
|
|
2710
2722
|
}, [dispatch]);
|
|
2711
2723
|
var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
|
|
2712
2724
|
dispatch({
|
|
2713
|
-
type: FunctionSetHighlightedIndex,
|
|
2725
|
+
type: FunctionSetHighlightedIndex$1,
|
|
2714
2726
|
highlightedIndex: newHighlightedIndex
|
|
2715
2727
|
});
|
|
2716
2728
|
}, [dispatch]);
|
|
2717
2729
|
var selectItem = useCallback(function (newSelectedItem) {
|
|
2718
2730
|
dispatch({
|
|
2719
|
-
type: FunctionSelectItem,
|
|
2731
|
+
type: FunctionSelectItem$1,
|
|
2720
2732
|
selectedItem: newSelectedItem
|
|
2721
2733
|
});
|
|
2722
2734
|
}, [dispatch]);
|
|
2723
2735
|
var reset = useCallback(function () {
|
|
2724
2736
|
dispatch({
|
|
2725
|
-
type: FunctionReset
|
|
2737
|
+
type: FunctionReset$2
|
|
2726
2738
|
});
|
|
2727
2739
|
}, [dispatch]);
|
|
2728
2740
|
var setInputValue = useCallback(function (newInputValue) {
|
|
2729
2741
|
dispatch({
|
|
2730
|
-
type: FunctionSetInputValue,
|
|
2742
|
+
type: FunctionSetInputValue$1,
|
|
2731
2743
|
inputValue: newInputValue
|
|
2732
2744
|
});
|
|
2733
2745
|
}, [dispatch]); // Getter functions.
|
|
@@ -2789,7 +2801,7 @@ function useSelect(userProps) {
|
|
|
2789
2801
|
|
|
2790
2802
|
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
2791
2803
|
dispatch({
|
|
2792
|
-
type: MenuMouseLeave
|
|
2804
|
+
type: MenuMouseLeave$1
|
|
2793
2805
|
});
|
|
2794
2806
|
};
|
|
2795
2807
|
|
|
@@ -2821,7 +2833,7 @@ function useSelect(userProps) {
|
|
|
2821
2833
|
|
|
2822
2834
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
2823
2835
|
dispatch({
|
|
2824
|
-
type: ToggleButtonClick
|
|
2836
|
+
type: ToggleButtonClick$1
|
|
2825
2837
|
});
|
|
2826
2838
|
};
|
|
2827
2839
|
|
|
@@ -2875,14 +2887,14 @@ function useSelect(userProps) {
|
|
|
2875
2887
|
|
|
2876
2888
|
shouldScrollRef.current = false;
|
|
2877
2889
|
dispatch({
|
|
2878
|
-
type: ItemMouseMove,
|
|
2890
|
+
type: ItemMouseMove$1,
|
|
2879
2891
|
index: index
|
|
2880
2892
|
});
|
|
2881
2893
|
};
|
|
2882
2894
|
|
|
2883
2895
|
var itemHandleClick = function itemHandleClick() {
|
|
2884
2896
|
dispatch({
|
|
2885
|
-
type: ItemClick,
|
|
2897
|
+
type: ItemClick$1,
|
|
2886
2898
|
index: index
|
|
2887
2899
|
});
|
|
2888
2900
|
};
|
|
@@ -2940,20 +2952,20 @@ var InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_e
|
|
|
2940
2952
|
var InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
|
|
2941
2953
|
var InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
|
|
2942
2954
|
var InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
|
|
2943
|
-
var MenuMouseLeave
|
|
2944
|
-
var ItemMouseMove
|
|
2945
|
-
var ItemClick
|
|
2946
|
-
var ToggleButtonClick
|
|
2947
|
-
var FunctionToggleMenu
|
|
2948
|
-
var FunctionOpenMenu
|
|
2949
|
-
var FunctionCloseMenu
|
|
2950
|
-
var FunctionSetHighlightedIndex
|
|
2951
|
-
var FunctionSelectItem
|
|
2952
|
-
var FunctionSetInputValue
|
|
2955
|
+
var MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
|
|
2956
|
+
var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
|
|
2957
|
+
var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
|
|
2958
|
+
var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
|
|
2959
|
+
var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
|
|
2960
|
+
var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
|
|
2961
|
+
var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
|
|
2962
|
+
var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
|
|
2963
|
+
var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
|
|
2964
|
+
var FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
|
|
2953
2965
|
var FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
|
|
2954
2966
|
var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
|
|
2955
2967
|
|
|
2956
|
-
var stateChangeTypes$
|
|
2968
|
+
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2957
2969
|
__proto__: null,
|
|
2958
2970
|
InputKeyDownArrowDown: InputKeyDownArrowDown,
|
|
2959
2971
|
InputKeyDownArrowUp: InputKeyDownArrowUp,
|
|
@@ -2963,22 +2975,22 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2963
2975
|
InputKeyDownEnter: InputKeyDownEnter,
|
|
2964
2976
|
InputChange: InputChange,
|
|
2965
2977
|
InputBlur: InputBlur,
|
|
2966
|
-
MenuMouseLeave: MenuMouseLeave
|
|
2967
|
-
ItemMouseMove: ItemMouseMove
|
|
2968
|
-
ItemClick: ItemClick
|
|
2969
|
-
ToggleButtonClick: ToggleButtonClick
|
|
2970
|
-
FunctionToggleMenu: FunctionToggleMenu
|
|
2971
|
-
FunctionOpenMenu: FunctionOpenMenu
|
|
2972
|
-
FunctionCloseMenu: FunctionCloseMenu
|
|
2973
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex
|
|
2974
|
-
FunctionSelectItem: FunctionSelectItem
|
|
2975
|
-
FunctionSetInputValue: FunctionSetInputValue
|
|
2978
|
+
MenuMouseLeave: MenuMouseLeave,
|
|
2979
|
+
ItemMouseMove: ItemMouseMove,
|
|
2980
|
+
ItemClick: ItemClick,
|
|
2981
|
+
ToggleButtonClick: ToggleButtonClick,
|
|
2982
|
+
FunctionToggleMenu: FunctionToggleMenu,
|
|
2983
|
+
FunctionOpenMenu: FunctionOpenMenu,
|
|
2984
|
+
FunctionCloseMenu: FunctionCloseMenu,
|
|
2985
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2986
|
+
FunctionSelectItem: FunctionSelectItem,
|
|
2987
|
+
FunctionSetInputValue: FunctionSetInputValue,
|
|
2976
2988
|
FunctionReset: FunctionReset$1,
|
|
2977
2989
|
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem
|
|
2978
2990
|
});
|
|
2979
2991
|
|
|
2980
2992
|
function getInitialState$1(props) {
|
|
2981
|
-
var initialState = getInitialState(props);
|
|
2993
|
+
var initialState = getInitialState$2(props);
|
|
2982
2994
|
var selectedItem = initialState.selectedItem;
|
|
2983
2995
|
var inputValue = initialState.inputValue;
|
|
2984
2996
|
|
|
@@ -3044,7 +3056,7 @@ var propTypes$1 = {
|
|
|
3044
3056
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
3045
3057
|
*/
|
|
3046
3058
|
|
|
3047
|
-
function useControlledReducer
|
|
3059
|
+
function useControlledReducer(reducer, initialState, props) {
|
|
3048
3060
|
var previousSelectedItemRef = useRef();
|
|
3049
3061
|
|
|
3050
3062
|
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
@@ -3077,8 +3089,8 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
3077
3089
|
};
|
|
3078
3090
|
}
|
|
3079
3091
|
|
|
3080
|
-
var defaultProps$
|
|
3081
|
-
getA11yStatusMessage: getA11yStatusMessage,
|
|
3092
|
+
var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
3093
|
+
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
3082
3094
|
circularNavigation: true
|
|
3083
3095
|
});
|
|
3084
3096
|
|
|
@@ -3091,10 +3103,10 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3091
3103
|
var changes;
|
|
3092
3104
|
|
|
3093
3105
|
switch (type) {
|
|
3094
|
-
case ItemClick
|
|
3106
|
+
case ItemClick:
|
|
3095
3107
|
changes = {
|
|
3096
|
-
isOpen: getDefaultValue(props, 'isOpen'),
|
|
3097
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
3108
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3109
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3098
3110
|
selectedItem: props.items[action.index],
|
|
3099
3111
|
inputValue: props.itemToString(props.items[action.index])
|
|
3100
3112
|
};
|
|
@@ -3108,7 +3120,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3108
3120
|
} else {
|
|
3109
3121
|
changes = {
|
|
3110
3122
|
highlightedIndex: getHighlightedIndexOnOpen(props, state, 1, action.getItemNodeFromIndex),
|
|
3111
|
-
isOpen:
|
|
3123
|
+
isOpen: props.items.length >= 0
|
|
3112
3124
|
};
|
|
3113
3125
|
}
|
|
3114
3126
|
|
|
@@ -3122,7 +3134,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3122
3134
|
} else {
|
|
3123
3135
|
changes = {
|
|
3124
3136
|
highlightedIndex: getHighlightedIndexOnOpen(props, state, -1, action.getItemNodeFromIndex),
|
|
3125
|
-
isOpen:
|
|
3137
|
+
isOpen: props.items.length >= 0
|
|
3126
3138
|
};
|
|
3127
3139
|
}
|
|
3128
3140
|
|
|
@@ -3131,8 +3143,8 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3131
3143
|
case InputKeyDownEnter:
|
|
3132
3144
|
changes = _extends({}, state.isOpen && state.highlightedIndex >= 0 && {
|
|
3133
3145
|
selectedItem: props.items[state.highlightedIndex],
|
|
3134
|
-
isOpen: getDefaultValue(props, 'isOpen'),
|
|
3135
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
3146
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3147
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3136
3148
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3137
3149
|
});
|
|
3138
3150
|
break;
|
|
@@ -3148,39 +3160,36 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3148
3160
|
break;
|
|
3149
3161
|
|
|
3150
3162
|
case InputKeyDownHome:
|
|
3151
|
-
changes =
|
|
3163
|
+
changes = {
|
|
3152
3164
|
highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
|
|
3153
|
-
}
|
|
3165
|
+
};
|
|
3154
3166
|
break;
|
|
3155
3167
|
|
|
3156
3168
|
case InputKeyDownEnd:
|
|
3157
|
-
changes =
|
|
3169
|
+
changes = {
|
|
3158
3170
|
highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
|
|
3159
|
-
}
|
|
3171
|
+
};
|
|
3160
3172
|
break;
|
|
3161
3173
|
|
|
3162
3174
|
case InputBlur:
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
});
|
|
3171
|
-
}
|
|
3172
|
-
|
|
3175
|
+
changes = _extends({
|
|
3176
|
+
isOpen: false,
|
|
3177
|
+
highlightedIndex: -1
|
|
3178
|
+
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
3179
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3180
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3181
|
+
});
|
|
3173
3182
|
break;
|
|
3174
3183
|
|
|
3175
3184
|
case InputChange:
|
|
3176
3185
|
changes = {
|
|
3177
3186
|
isOpen: true,
|
|
3178
|
-
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
3187
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3179
3188
|
inputValue: action.inputValue
|
|
3180
3189
|
};
|
|
3181
3190
|
break;
|
|
3182
3191
|
|
|
3183
|
-
case FunctionSelectItem
|
|
3192
|
+
case FunctionSelectItem:
|
|
3184
3193
|
changes = {
|
|
3185
3194
|
selectedItem: action.selectedItem,
|
|
3186
3195
|
inputValue: props.itemToString(action.selectedItem)
|
|
@@ -3194,14 +3203,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3194
3203
|
break;
|
|
3195
3204
|
|
|
3196
3205
|
default:
|
|
3197
|
-
return downshiftCommonReducer(state, action, stateChangeTypes$
|
|
3206
|
+
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
3198
3207
|
}
|
|
3199
3208
|
|
|
3200
3209
|
return _extends({}, state, changes);
|
|
3201
3210
|
}
|
|
3202
3211
|
/* eslint-enable complexity */
|
|
3203
3212
|
|
|
3204
|
-
useCombobox.stateChangeTypes = stateChangeTypes$
|
|
3213
|
+
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
3205
3214
|
|
|
3206
3215
|
function useCombobox(userProps) {
|
|
3207
3216
|
if (userProps === void 0) {
|
|
@@ -3210,7 +3219,7 @@ function useCombobox(userProps) {
|
|
|
3210
3219
|
|
|
3211
3220
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
3212
3221
|
|
|
3213
|
-
var props = _extends({}, defaultProps$
|
|
3222
|
+
var props = _extends({}, defaultProps$1, userProps);
|
|
3214
3223
|
|
|
3215
3224
|
var initialIsOpen = props.initialIsOpen,
|
|
3216
3225
|
defaultIsOpen = props.defaultIsOpen,
|
|
@@ -3223,7 +3232,7 @@ function useCombobox(userProps) {
|
|
|
3223
3232
|
|
|
3224
3233
|
var initialState = getInitialState$1(props);
|
|
3225
3234
|
|
|
3226
|
-
var _useControlledReducer = useControlledReducer
|
|
3235
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
|
|
3227
3236
|
state = _useControlledReducer[0],
|
|
3228
3237
|
dispatch = _useControlledReducer[1];
|
|
3229
3238
|
|
|
@@ -3336,6 +3345,10 @@ function useCombobox(userProps) {
|
|
|
3336
3345
|
});
|
|
3337
3346
|
},
|
|
3338
3347
|
Home: function Home(event) {
|
|
3348
|
+
if (!latest.current.state.isOpen) {
|
|
3349
|
+
return;
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3339
3352
|
event.preventDefault();
|
|
3340
3353
|
dispatch({
|
|
3341
3354
|
type: InputKeyDownHome,
|
|
@@ -3343,6 +3356,10 @@ function useCombobox(userProps) {
|
|
|
3343
3356
|
});
|
|
3344
3357
|
},
|
|
3345
3358
|
End: function End(event) {
|
|
3359
|
+
if (!latest.current.state.isOpen) {
|
|
3360
|
+
return;
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3346
3363
|
event.preventDefault();
|
|
3347
3364
|
dispatch({
|
|
3348
3365
|
type: InputKeyDownEnd,
|
|
@@ -3350,22 +3367,23 @@ function useCombobox(userProps) {
|
|
|
3350
3367
|
});
|
|
3351
3368
|
},
|
|
3352
3369
|
Escape: function Escape() {
|
|
3353
|
-
dispatch({
|
|
3354
|
-
type: InputKeyDownEscape
|
|
3355
|
-
});
|
|
3356
|
-
},
|
|
3357
|
-
Enter: function Enter(event) {
|
|
3358
|
-
// if IME composing, wait for next Enter keydown event.
|
|
3359
|
-
if (event.which === 229) {
|
|
3360
|
-
return;
|
|
3361
|
-
}
|
|
3362
|
-
|
|
3363
3370
|
var latestState = latest.current.state;
|
|
3364
3371
|
|
|
3365
|
-
if (latestState.isOpen) {
|
|
3366
|
-
|
|
3372
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
3373
|
+
dispatch({
|
|
3374
|
+
type: InputKeyDownEscape
|
|
3375
|
+
});
|
|
3367
3376
|
}
|
|
3377
|
+
},
|
|
3378
|
+
Enter: function Enter(event) {
|
|
3379
|
+
var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3368
3380
|
|
|
3381
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3382
|
+
) {
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
event.preventDefault();
|
|
3369
3387
|
dispatch({
|
|
3370
3388
|
type: InputKeyDownEnter,
|
|
3371
3389
|
getItemNodeFromIndex: getItemNodeFromIndex
|
|
@@ -3399,7 +3417,7 @@ function useCombobox(userProps) {
|
|
|
3399
3417
|
menuRef.current = menuNode;
|
|
3400
3418
|
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
3401
3419
|
dispatch({
|
|
3402
|
-
type: MenuMouseLeave
|
|
3420
|
+
type: MenuMouseLeave
|
|
3403
3421
|
});
|
|
3404
3422
|
}), _extends2), rest);
|
|
3405
3423
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
@@ -3413,9 +3431,9 @@ function useCombobox(userProps) {
|
|
|
3413
3431
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3414
3432
|
ref = _ref3.ref,
|
|
3415
3433
|
onMouseMove = _ref3.onMouseMove,
|
|
3416
|
-
onClick = _ref3.onClick
|
|
3417
|
-
|
|
3418
|
-
rest = _objectWithoutPropertiesLoose(_ref3, ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"]);
|
|
3434
|
+
onClick = _ref3.onClick;
|
|
3435
|
+
_ref3.onPress;
|
|
3436
|
+
var rest = _objectWithoutPropertiesLoose(_ref3, ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"]);
|
|
3419
3437
|
|
|
3420
3438
|
var _latest$current = latest.current,
|
|
3421
3439
|
latestProps = _latest$current.props,
|
|
@@ -3426,8 +3444,8 @@ function useCombobox(userProps) {
|
|
|
3426
3444
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3427
3445
|
}
|
|
3428
3446
|
|
|
3429
|
-
var onSelectKey =
|
|
3430
|
-
var customClickHandler =
|
|
3447
|
+
var onSelectKey = 'onClick';
|
|
3448
|
+
var customClickHandler = onClick;
|
|
3431
3449
|
|
|
3432
3450
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
3433
3451
|
if (index === latestState.highlightedIndex) {
|
|
@@ -3436,14 +3454,14 @@ function useCombobox(userProps) {
|
|
|
3436
3454
|
|
|
3437
3455
|
shouldScrollRef.current = false;
|
|
3438
3456
|
dispatch({
|
|
3439
|
-
type: ItemMouseMove
|
|
3457
|
+
type: ItemMouseMove,
|
|
3440
3458
|
index: index
|
|
3441
3459
|
});
|
|
3442
3460
|
};
|
|
3443
3461
|
|
|
3444
3462
|
var itemHandleClick = function itemHandleClick() {
|
|
3445
3463
|
dispatch({
|
|
3446
|
-
type: ItemClick
|
|
3464
|
+
type: ItemClick,
|
|
3447
3465
|
index: index
|
|
3448
3466
|
});
|
|
3449
3467
|
|
|
@@ -3464,16 +3482,16 @@ function useCombobox(userProps) {
|
|
|
3464
3482
|
var _extends4;
|
|
3465
3483
|
|
|
3466
3484
|
var _ref5 = _temp4 === void 0 ? {} : _temp4,
|
|
3467
|
-
onClick = _ref5.onClick
|
|
3468
|
-
|
|
3469
|
-
_ref5$refKey = _ref5.refKey,
|
|
3485
|
+
onClick = _ref5.onClick;
|
|
3486
|
+
_ref5.onPress;
|
|
3487
|
+
var _ref5$refKey = _ref5.refKey,
|
|
3470
3488
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3471
3489
|
ref = _ref5.ref,
|
|
3472
3490
|
rest = _objectWithoutPropertiesLoose(_ref5, ["onClick", "onPress", "refKey", "ref"]);
|
|
3473
3491
|
|
|
3474
3492
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3475
3493
|
dispatch({
|
|
3476
|
-
type: ToggleButtonClick
|
|
3494
|
+
type: ToggleButtonClick
|
|
3477
3495
|
});
|
|
3478
3496
|
|
|
3479
3497
|
if (!latest.current.state.isOpen && inputRef.current) {
|
|
@@ -3483,7 +3501,7 @@ function useCombobox(userProps) {
|
|
|
3483
3501
|
|
|
3484
3502
|
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3485
3503
|
toggleButtonRef.current = toggleButtonNode;
|
|
3486
|
-
}), _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({},
|
|
3504
|
+
}), _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
|
|
3487
3505
|
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3488
3506
|
}), rest);
|
|
3489
3507
|
}, [dispatch, latest, elementIds]);
|
|
@@ -3494,9 +3512,9 @@ function useCombobox(userProps) {
|
|
|
3494
3512
|
onKeyDown = _ref6.onKeyDown,
|
|
3495
3513
|
onChange = _ref6.onChange,
|
|
3496
3514
|
onInput = _ref6.onInput,
|
|
3497
|
-
onBlur = _ref6.onBlur
|
|
3498
|
-
|
|
3499
|
-
_ref6$refKey = _ref6.refKey,
|
|
3515
|
+
onBlur = _ref6.onBlur;
|
|
3516
|
+
_ref6.onChangeText;
|
|
3517
|
+
var _ref6$refKey = _ref6.refKey,
|
|
3500
3518
|
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
3501
3519
|
ref = _ref6.ref,
|
|
3502
3520
|
rest = _objectWithoutPropertiesLoose(_ref6, ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"]);
|
|
@@ -3519,13 +3537,13 @@ function useCombobox(userProps) {
|
|
|
3519
3537
|
var inputHandleChange = function inputHandleChange(event) {
|
|
3520
3538
|
dispatch({
|
|
3521
3539
|
type: InputChange,
|
|
3522
|
-
inputValue:
|
|
3540
|
+
inputValue: event.target.value
|
|
3523
3541
|
});
|
|
3524
3542
|
};
|
|
3525
3543
|
|
|
3526
3544
|
var inputHandleBlur = function inputHandleBlur() {
|
|
3527
3545
|
/* istanbul ignore else */
|
|
3528
|
-
if (!mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3546
|
+
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3529
3547
|
dispatch({
|
|
3530
3548
|
type: InputBlur,
|
|
3531
3549
|
selectItem: true
|
|
@@ -3535,7 +3553,7 @@ function useCombobox(userProps) {
|
|
|
3535
3553
|
/* istanbul ignore next (preact) */
|
|
3536
3554
|
|
|
3537
3555
|
|
|
3538
|
-
var onChangeKey =
|
|
3556
|
+
var onChangeKey = 'onInput' ;
|
|
3539
3557
|
var eventHandlers = {};
|
|
3540
3558
|
|
|
3541
3559
|
if (!rest.disabled) {
|
|
@@ -3577,34 +3595,34 @@ function useCombobox(userProps) {
|
|
|
3577
3595
|
|
|
3578
3596
|
var toggleMenu = useCallback(function () {
|
|
3579
3597
|
dispatch({
|
|
3580
|
-
type: FunctionToggleMenu
|
|
3598
|
+
type: FunctionToggleMenu
|
|
3581
3599
|
});
|
|
3582
3600
|
}, [dispatch]);
|
|
3583
3601
|
var closeMenu = useCallback(function () {
|
|
3584
3602
|
dispatch({
|
|
3585
|
-
type: FunctionCloseMenu
|
|
3603
|
+
type: FunctionCloseMenu
|
|
3586
3604
|
});
|
|
3587
3605
|
}, [dispatch]);
|
|
3588
3606
|
var openMenu = useCallback(function () {
|
|
3589
3607
|
dispatch({
|
|
3590
|
-
type: FunctionOpenMenu
|
|
3608
|
+
type: FunctionOpenMenu
|
|
3591
3609
|
});
|
|
3592
3610
|
}, [dispatch]);
|
|
3593
3611
|
var setHighlightedIndex = useCallback(function (newHighlightedIndex) {
|
|
3594
3612
|
dispatch({
|
|
3595
|
-
type: FunctionSetHighlightedIndex
|
|
3613
|
+
type: FunctionSetHighlightedIndex,
|
|
3596
3614
|
highlightedIndex: newHighlightedIndex
|
|
3597
3615
|
});
|
|
3598
3616
|
}, [dispatch]);
|
|
3599
3617
|
var selectItem = useCallback(function (newSelectedItem) {
|
|
3600
3618
|
dispatch({
|
|
3601
|
-
type: FunctionSelectItem
|
|
3619
|
+
type: FunctionSelectItem,
|
|
3602
3620
|
selectedItem: newSelectedItem
|
|
3603
3621
|
});
|
|
3604
3622
|
}, [dispatch]);
|
|
3605
3623
|
var setInputValue = useCallback(function (newInputValue) {
|
|
3606
3624
|
dispatch({
|
|
3607
|
-
type: FunctionSetInputValue
|
|
3625
|
+
type: FunctionSetInputValue,
|
|
3608
3626
|
inputValue: newInputValue
|
|
3609
3627
|
});
|
|
3610
3628
|
}, [dispatch]);
|
|
@@ -3651,8 +3669,8 @@ var defaultStateValues = {
|
|
|
3651
3669
|
* @returns {any} The initial value for that prop.
|
|
3652
3670
|
*/
|
|
3653
3671
|
|
|
3654
|
-
function getInitialValue
|
|
3655
|
-
return getInitialValue(props, propKey, defaultStateValues);
|
|
3672
|
+
function getInitialValue(props, propKey) {
|
|
3673
|
+
return getInitialValue$1(props, propKey, defaultStateValues);
|
|
3656
3674
|
}
|
|
3657
3675
|
/**
|
|
3658
3676
|
* Returns the default value for a state key in the following order:
|
|
@@ -3664,8 +3682,8 @@ function getInitialValue$1(props, propKey) {
|
|
|
3664
3682
|
*/
|
|
3665
3683
|
|
|
3666
3684
|
|
|
3667
|
-
function getDefaultValue
|
|
3668
|
-
return getDefaultValue(props, propKey, defaultStateValues);
|
|
3685
|
+
function getDefaultValue(props, propKey) {
|
|
3686
|
+
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
3669
3687
|
}
|
|
3670
3688
|
/**
|
|
3671
3689
|
* Gets the initial state based on the provided props. It uses initial, default
|
|
@@ -3676,9 +3694,9 @@ function getDefaultValue$1(props, propKey) {
|
|
|
3676
3694
|
*/
|
|
3677
3695
|
|
|
3678
3696
|
|
|
3679
|
-
function getInitialState
|
|
3680
|
-
var activeIndex = getInitialValue
|
|
3681
|
-
var selectedItems = getInitialValue
|
|
3697
|
+
function getInitialState(props) {
|
|
3698
|
+
var activeIndex = getInitialValue(props, 'activeIndex');
|
|
3699
|
+
var selectedItems = getInitialValue(props, 'selectedItems');
|
|
3682
3700
|
return {
|
|
3683
3701
|
activeIndex: activeIndex,
|
|
3684
3702
|
selectedItems: selectedItems
|
|
@@ -3725,7 +3743,7 @@ function getA11yRemovalMessage(selectionParameters) {
|
|
|
3725
3743
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3726
3744
|
}
|
|
3727
3745
|
|
|
3728
|
-
var propTypes
|
|
3746
|
+
var propTypes = {
|
|
3729
3747
|
selectedItems: PropTypes.array,
|
|
3730
3748
|
initialSelectedItems: PropTypes.array,
|
|
3731
3749
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3749,21 +3767,21 @@ var propTypes$2 = {
|
|
|
3749
3767
|
})
|
|
3750
3768
|
})
|
|
3751
3769
|
};
|
|
3752
|
-
var defaultProps
|
|
3753
|
-
itemToString: defaultProps.itemToString,
|
|
3754
|
-
stateReducer: defaultProps.stateReducer,
|
|
3755
|
-
environment: defaultProps.environment,
|
|
3770
|
+
var defaultProps = {
|
|
3771
|
+
itemToString: defaultProps$3.itemToString,
|
|
3772
|
+
stateReducer: defaultProps$3.stateReducer,
|
|
3773
|
+
environment: defaultProps$3.environment,
|
|
3756
3774
|
getA11yRemovalMessage: getA11yRemovalMessage,
|
|
3757
3775
|
keyNavigationNext: 'ArrowRight',
|
|
3758
3776
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3759
3777
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
3760
3778
|
|
|
3761
|
-
var validatePropTypes
|
|
3779
|
+
var validatePropTypes = noop;
|
|
3762
3780
|
/* istanbul ignore next */
|
|
3763
3781
|
|
|
3764
3782
|
if (process.env.NODE_ENV !== 'production') {
|
|
3765
|
-
validatePropTypes
|
|
3766
|
-
PropTypes.checkPropTypes(propTypes
|
|
3783
|
+
validatePropTypes = function validatePropTypes(options, caller) {
|
|
3784
|
+
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3767
3785
|
};
|
|
3768
3786
|
}
|
|
3769
3787
|
|
|
@@ -3779,9 +3797,9 @@ var FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__functio
|
|
|
3779
3797
|
var FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
|
|
3780
3798
|
var FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
|
|
3781
3799
|
var FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3782
|
-
var FunctionReset
|
|
3800
|
+
var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3783
3801
|
|
|
3784
|
-
var stateChangeTypes
|
|
3802
|
+
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3785
3803
|
__proto__: null,
|
|
3786
3804
|
SelectedItemClick: SelectedItemClick,
|
|
3787
3805
|
SelectedItemKeyDownDelete: SelectedItemKeyDownDelete,
|
|
@@ -3795,7 +3813,7 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
3795
3813
|
FunctionRemoveSelectedItem: FunctionRemoveSelectedItem,
|
|
3796
3814
|
FunctionSetSelectedItems: FunctionSetSelectedItems,
|
|
3797
3815
|
FunctionSetActiveIndex: FunctionSetActiveIndex,
|
|
3798
|
-
FunctionReset: FunctionReset
|
|
3816
|
+
FunctionReset: FunctionReset
|
|
3799
3817
|
});
|
|
3800
3818
|
|
|
3801
3819
|
/* eslint-disable complexity */
|
|
@@ -3908,10 +3926,10 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3908
3926
|
break;
|
|
3909
3927
|
}
|
|
3910
3928
|
|
|
3911
|
-
case FunctionReset
|
|
3929
|
+
case FunctionReset:
|
|
3912
3930
|
changes = {
|
|
3913
|
-
activeIndex: getDefaultValue
|
|
3914
|
-
selectedItems: getDefaultValue
|
|
3931
|
+
activeIndex: getDefaultValue(props, 'activeIndex'),
|
|
3932
|
+
selectedItems: getDefaultValue(props, 'selectedItems')
|
|
3915
3933
|
};
|
|
3916
3934
|
break;
|
|
3917
3935
|
|
|
@@ -3922,16 +3940,16 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3922
3940
|
return _extends({}, state, changes);
|
|
3923
3941
|
}
|
|
3924
3942
|
|
|
3925
|
-
useMultipleSelection.stateChangeTypes = stateChangeTypes
|
|
3943
|
+
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
3926
3944
|
|
|
3927
3945
|
function useMultipleSelection(userProps) {
|
|
3928
3946
|
if (userProps === void 0) {
|
|
3929
3947
|
userProps = {};
|
|
3930
3948
|
}
|
|
3931
3949
|
|
|
3932
|
-
validatePropTypes
|
|
3950
|
+
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
3933
3951
|
|
|
3934
|
-
var props = _extends({}, defaultProps
|
|
3952
|
+
var props = _extends({}, defaultProps, userProps);
|
|
3935
3953
|
|
|
3936
3954
|
var getA11yRemovalMessage = props.getA11yRemovalMessage,
|
|
3937
3955
|
itemToString = props.itemToString,
|
|
@@ -3939,7 +3957,7 @@ function useMultipleSelection(userProps) {
|
|
|
3939
3957
|
keyNavigationNext = props.keyNavigationNext,
|
|
3940
3958
|
keyNavigationPrevious = props.keyNavigationPrevious; // Reducer init.
|
|
3941
3959
|
|
|
3942
|
-
var _useControlledReducer = useControlledReducer(downshiftMultipleSelectionReducer, getInitialState
|
|
3960
|
+
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
|
|
3943
3961
|
state = _useControlledReducer[0],
|
|
3944
3962
|
dispatch = _useControlledReducer[1];
|
|
3945
3963
|
|
|
@@ -4150,7 +4168,7 @@ function useMultipleSelection(userProps) {
|
|
|
4150
4168
|
}, [dispatch]);
|
|
4151
4169
|
var reset = useCallback(function () {
|
|
4152
4170
|
dispatch({
|
|
4153
|
-
type: FunctionReset
|
|
4171
|
+
type: FunctionReset
|
|
4154
4172
|
});
|
|
4155
4173
|
}, [dispatch]);
|
|
4156
4174
|
return {
|