downshift 7.3.2 → 7.3.4
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/dist/downshift.cjs.js +64 -59
- package/dist/downshift.esm.js +64 -59
- package/dist/downshift.native.cjs.js +64 -59
- package/dist/downshift.umd.js +64 -59
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/dist/src/hooks/utils.d.ts +10 -1
- package/package.json +1 -1
- package/preact/dist/downshift.cjs.js +64 -59
- package/preact/dist/downshift.esm.js +64 -59
- package/preact/dist/downshift.umd.js +64 -59
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -1
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.cjs.js
CHANGED
|
@@ -1603,14 +1603,19 @@ function useElementIds(_ref) {
|
|
|
1603
1603
|
});
|
|
1604
1604
|
return elementIdsRef.current;
|
|
1605
1605
|
}
|
|
1606
|
-
function
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1606
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1607
|
+
var item, index;
|
|
1608
|
+
if (itemProp === undefined) {
|
|
1609
|
+
if (indexProp === undefined) {
|
|
1610
|
+
throw new Error(errorMessage);
|
|
1611
|
+
}
|
|
1612
|
+
item = items[indexProp];
|
|
1613
|
+
index = indexProp;
|
|
1614
|
+
} else {
|
|
1615
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1616
|
+
item = itemProp;
|
|
1612
1617
|
}
|
|
1613
|
-
return
|
|
1618
|
+
return [item, index];
|
|
1614
1619
|
}
|
|
1615
1620
|
function itemToString(item) {
|
|
1616
1621
|
return item ? String(item) : '';
|
|
@@ -1939,6 +1944,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1939
1944
|
};
|
|
1940
1945
|
}
|
|
1941
1946
|
|
|
1947
|
+
/**
|
|
1948
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1949
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1950
|
+
* @param {Object} props The useCombobox props.
|
|
1951
|
+
* @param {number} highlightedIndex The index from the state.
|
|
1952
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
1953
|
+
* @returns The changes for the state.
|
|
1954
|
+
*/
|
|
1955
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1956
|
+
var _props$items;
|
|
1957
|
+
if (inputValue === void 0) {
|
|
1958
|
+
inputValue = true;
|
|
1959
|
+
}
|
|
1960
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1961
|
+
return _extends__default["default"]({
|
|
1962
|
+
isOpen: false,
|
|
1963
|
+
highlightedIndex: -1
|
|
1964
|
+
}, shouldSelect && _extends__default["default"]({
|
|
1965
|
+
selectedItem: props.items[highlightedIndex],
|
|
1966
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
1967
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
1968
|
+
}, inputValue && {
|
|
1969
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1970
|
+
}));
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1942
1973
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1943
1974
|
var type = action.type,
|
|
1944
1975
|
props = action.props;
|
|
@@ -2130,6 +2161,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2130
2161
|
|
|
2131
2162
|
/* eslint-disable complexity */
|
|
2132
2163
|
function downshiftSelectReducer(state, action) {
|
|
2164
|
+
var _props$items;
|
|
2133
2165
|
var type = action.type,
|
|
2134
2166
|
props = action.props,
|
|
2135
2167
|
altKey = action.altKey;
|
|
@@ -2172,12 +2204,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2172
2204
|
break;
|
|
2173
2205
|
case ToggleButtonKeyDownArrowUp:
|
|
2174
2206
|
if (state.isOpen && altKey) {
|
|
2175
|
-
changes =
|
|
2176
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2177
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2178
|
-
}, state.highlightedIndex >= 0 && {
|
|
2179
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2180
|
-
});
|
|
2207
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2181
2208
|
} else {
|
|
2182
2209
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2183
2210
|
changes = {
|
|
@@ -2189,12 +2216,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2189
2216
|
// only triggered when menu is open.
|
|
2190
2217
|
case ToggleButtonKeyDownEnter:
|
|
2191
2218
|
case ToggleButtonKeyDownSpaceButton:
|
|
2192
|
-
changes =
|
|
2193
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2194
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2195
|
-
}, state.highlightedIndex >= 0 && {
|
|
2196
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2197
|
-
});
|
|
2219
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2198
2220
|
break;
|
|
2199
2221
|
case ToggleButtonKeyDownHome:
|
|
2200
2222
|
changes = {
|
|
@@ -2228,7 +2250,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2228
2250
|
changes = _extends__default["default"]({
|
|
2229
2251
|
isOpen: false,
|
|
2230
2252
|
highlightedIndex: -1
|
|
2231
|
-
}, state.highlightedIndex >= 0 && {
|
|
2253
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2232
2254
|
selectedItem: props.items[state.highlightedIndex]
|
|
2233
2255
|
});
|
|
2234
2256
|
break;
|
|
@@ -2600,8 +2622,9 @@ function useSelect(userProps) {
|
|
|
2600
2622
|
var _latest$current = latest.current,
|
|
2601
2623
|
latestState = _latest$current.state,
|
|
2602
2624
|
latestProps = _latest$current.props;
|
|
2603
|
-
var
|
|
2604
|
-
|
|
2625
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
2626
|
+
item = _getItemAndIndex[0],
|
|
2627
|
+
index = _getItemAndIndex[1];
|
|
2605
2628
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2606
2629
|
if (index === latestState.highlightedIndex) {
|
|
2607
2630
|
return;
|
|
@@ -2619,18 +2642,14 @@ function useSelect(userProps) {
|
|
|
2619
2642
|
index: index
|
|
2620
2643
|
});
|
|
2621
2644
|
};
|
|
2622
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2623
|
-
if (itemIndex < 0) {
|
|
2624
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
2625
|
-
}
|
|
2626
2645
|
var itemProps = _extends__default["default"]((_extends4 = {
|
|
2627
2646
|
disabled: disabled,
|
|
2628
2647
|
role: 'option',
|
|
2629
2648
|
'aria-selected': "" + (item === selectedItem),
|
|
2630
|
-
id: elementIds.getItemId(
|
|
2649
|
+
id: elementIds.getItemId(index)
|
|
2631
2650
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2632
2651
|
if (itemNode) {
|
|
2633
|
-
itemRefs.current[elementIds.getItemId(
|
|
2652
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
2634
2653
|
}
|
|
2635
2654
|
}), _extends4), rest);
|
|
2636
2655
|
if (!disabled) {
|
|
@@ -2641,7 +2660,7 @@ function useSelect(userProps) {
|
|
|
2641
2660
|
}
|
|
2642
2661
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
2643
2662
|
return itemProps;
|
|
2644
|
-
}, [latest,
|
|
2663
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2645
2664
|
return {
|
|
2646
2665
|
// prop getters.
|
|
2647
2666
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2813,6 +2832,7 @@ var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
|
2813
2832
|
|
|
2814
2833
|
/* eslint-disable complexity */
|
|
2815
2834
|
function downshiftUseComboboxReducer(state, action) {
|
|
2835
|
+
var _props$items;
|
|
2816
2836
|
var type = action.type,
|
|
2817
2837
|
props = action.props,
|
|
2818
2838
|
altKey = action.altKey;
|
|
@@ -2841,13 +2861,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2841
2861
|
case InputKeyDownArrowUp:
|
|
2842
2862
|
if (state.isOpen) {
|
|
2843
2863
|
if (altKey) {
|
|
2844
|
-
changes =
|
|
2845
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2846
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2847
|
-
}, state.highlightedIndex >= 0 && {
|
|
2848
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2849
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2850
|
-
});
|
|
2864
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2851
2865
|
} else {
|
|
2852
2866
|
changes = {
|
|
2853
2867
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2861,13 +2875,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2861
2875
|
}
|
|
2862
2876
|
break;
|
|
2863
2877
|
case InputKeyDownEnter:
|
|
2864
|
-
changes =
|
|
2865
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2866
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2867
|
-
}, state.highlightedIndex >= 0 && {
|
|
2868
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2869
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2870
|
-
});
|
|
2878
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2871
2879
|
break;
|
|
2872
2880
|
case InputKeyDownEscape:
|
|
2873
2881
|
changes = _extends__default["default"]({
|
|
@@ -2902,7 +2910,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2902
2910
|
changes = _extends__default["default"]({
|
|
2903
2911
|
isOpen: false,
|
|
2904
2912
|
highlightedIndex: -1
|
|
2905
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2913
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2906
2914
|
selectedItem: props.items[state.highlightedIndex],
|
|
2907
2915
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2908
2916
|
});
|
|
@@ -3170,8 +3178,8 @@ function useCombobox(userProps) {
|
|
|
3170
3178
|
var getItemProps = react.useCallback(function (_temp3) {
|
|
3171
3179
|
var _extends3, _ref4;
|
|
3172
3180
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3173
|
-
|
|
3174
|
-
|
|
3181
|
+
itemProp = _ref3.item,
|
|
3182
|
+
indexProp = _ref3.index,
|
|
3175
3183
|
_ref3$refKey = _ref3.refKey,
|
|
3176
3184
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3177
3185
|
ref = _ref3.ref,
|
|
@@ -3184,10 +3192,8 @@ function useCombobox(userProps) {
|
|
|
3184
3192
|
var _latest$current = latest.current,
|
|
3185
3193
|
latestProps = _latest$current.props,
|
|
3186
3194
|
latestState = _latest$current.state;
|
|
3187
|
-
var
|
|
3188
|
-
|
|
3189
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3190
|
-
}
|
|
3195
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3196
|
+
index = _getItemAndIndex[1];
|
|
3191
3197
|
var onSelectKey = 'onClick';
|
|
3192
3198
|
var customClickHandler = onClick;
|
|
3193
3199
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -3212,9 +3218,9 @@ function useCombobox(userProps) {
|
|
|
3212
3218
|
};
|
|
3213
3219
|
return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3214
3220
|
if (itemNode) {
|
|
3215
|
-
itemRefs.current[elementIds.getItemId(
|
|
3221
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3216
3222
|
}
|
|
3217
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
3223
|
+
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (index === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(index), _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
|
|
3218
3224
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3219
3225
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3220
3226
|
}, rest);
|
|
@@ -3754,14 +3760,13 @@ function useMultipleSelection(userProps) {
|
|
|
3754
3760
|
ref = _ref3.ref,
|
|
3755
3761
|
onClick = _ref3.onClick,
|
|
3756
3762
|
onKeyDown = _ref3.onKeyDown,
|
|
3757
|
-
|
|
3758
|
-
|
|
3763
|
+
selectedItemProp = _ref3.selectedItem,
|
|
3764
|
+
indexProp = _ref3.index,
|
|
3759
3765
|
rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded);
|
|
3760
3766
|
var latestState = latest.current.state;
|
|
3761
|
-
var
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
}
|
|
3767
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3768
|
+
index = _getItemAndIndex[1];
|
|
3769
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
3765
3770
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
3766
3771
|
dispatch({
|
|
3767
3772
|
type: SelectedItemClick,
|
|
@@ -3778,7 +3783,7 @@ function useMultipleSelection(userProps) {
|
|
|
3778
3783
|
if (selectedItemNode) {
|
|
3779
3784
|
selectedItemRefs.current.push(selectedItemNode);
|
|
3780
3785
|
}
|
|
3781
|
-
}), _extends2.tabIndex =
|
|
3786
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
3782
3787
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3783
3788
|
var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
3784
3789
|
var _extends3;
|
package/dist/downshift.esm.js
CHANGED
|
@@ -1590,14 +1590,19 @@ function useElementIds(_ref) {
|
|
|
1590
1590
|
});
|
|
1591
1591
|
return elementIdsRef.current;
|
|
1592
1592
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1593
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1594
|
+
var item, index;
|
|
1595
|
+
if (itemProp === undefined) {
|
|
1596
|
+
if (indexProp === undefined) {
|
|
1597
|
+
throw new Error(errorMessage);
|
|
1598
|
+
}
|
|
1599
|
+
item = items[indexProp];
|
|
1600
|
+
index = indexProp;
|
|
1601
|
+
} else {
|
|
1602
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1603
|
+
item = itemProp;
|
|
1599
1604
|
}
|
|
1600
|
-
return
|
|
1605
|
+
return [item, index];
|
|
1601
1606
|
}
|
|
1602
1607
|
function itemToString(item) {
|
|
1603
1608
|
return item ? String(item) : '';
|
|
@@ -1926,6 +1931,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1926
1931
|
};
|
|
1927
1932
|
}
|
|
1928
1933
|
|
|
1934
|
+
/**
|
|
1935
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1936
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1937
|
+
* @param {Object} props The useCombobox props.
|
|
1938
|
+
* @param {number} highlightedIndex The index from the state.
|
|
1939
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
1940
|
+
* @returns The changes for the state.
|
|
1941
|
+
*/
|
|
1942
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1943
|
+
var _props$items;
|
|
1944
|
+
if (inputValue === void 0) {
|
|
1945
|
+
inputValue = true;
|
|
1946
|
+
}
|
|
1947
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1948
|
+
return _extends({
|
|
1949
|
+
isOpen: false,
|
|
1950
|
+
highlightedIndex: -1
|
|
1951
|
+
}, shouldSelect && _extends({
|
|
1952
|
+
selectedItem: props.items[highlightedIndex],
|
|
1953
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
1954
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
1955
|
+
}, inputValue && {
|
|
1956
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1957
|
+
}));
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1929
1960
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1930
1961
|
var type = action.type,
|
|
1931
1962
|
props = action.props;
|
|
@@ -2117,6 +2148,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2117
2148
|
|
|
2118
2149
|
/* eslint-disable complexity */
|
|
2119
2150
|
function downshiftSelectReducer(state, action) {
|
|
2151
|
+
var _props$items;
|
|
2120
2152
|
var type = action.type,
|
|
2121
2153
|
props = action.props,
|
|
2122
2154
|
altKey = action.altKey;
|
|
@@ -2159,12 +2191,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2159
2191
|
break;
|
|
2160
2192
|
case ToggleButtonKeyDownArrowUp:
|
|
2161
2193
|
if (state.isOpen && altKey) {
|
|
2162
|
-
changes =
|
|
2163
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2164
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2165
|
-
}, state.highlightedIndex >= 0 && {
|
|
2166
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2167
|
-
});
|
|
2194
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2168
2195
|
} else {
|
|
2169
2196
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2170
2197
|
changes = {
|
|
@@ -2176,12 +2203,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2176
2203
|
// only triggered when menu is open.
|
|
2177
2204
|
case ToggleButtonKeyDownEnter:
|
|
2178
2205
|
case ToggleButtonKeyDownSpaceButton:
|
|
2179
|
-
changes =
|
|
2180
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2181
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2182
|
-
}, state.highlightedIndex >= 0 && {
|
|
2183
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2184
|
-
});
|
|
2206
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2185
2207
|
break;
|
|
2186
2208
|
case ToggleButtonKeyDownHome:
|
|
2187
2209
|
changes = {
|
|
@@ -2215,7 +2237,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2215
2237
|
changes = _extends({
|
|
2216
2238
|
isOpen: false,
|
|
2217
2239
|
highlightedIndex: -1
|
|
2218
|
-
}, state.highlightedIndex >= 0 && {
|
|
2240
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2219
2241
|
selectedItem: props.items[state.highlightedIndex]
|
|
2220
2242
|
});
|
|
2221
2243
|
break;
|
|
@@ -2587,8 +2609,9 @@ function useSelect(userProps) {
|
|
|
2587
2609
|
var _latest$current = latest.current,
|
|
2588
2610
|
latestState = _latest$current.state,
|
|
2589
2611
|
latestProps = _latest$current.props;
|
|
2590
|
-
var
|
|
2591
|
-
|
|
2612
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
2613
|
+
item = _getItemAndIndex[0],
|
|
2614
|
+
index = _getItemAndIndex[1];
|
|
2592
2615
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2593
2616
|
if (index === latestState.highlightedIndex) {
|
|
2594
2617
|
return;
|
|
@@ -2606,18 +2629,14 @@ function useSelect(userProps) {
|
|
|
2606
2629
|
index: index
|
|
2607
2630
|
});
|
|
2608
2631
|
};
|
|
2609
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2610
|
-
if (itemIndex < 0) {
|
|
2611
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
2612
|
-
}
|
|
2613
2632
|
var itemProps = _extends((_extends4 = {
|
|
2614
2633
|
disabled: disabled,
|
|
2615
2634
|
role: 'option',
|
|
2616
2635
|
'aria-selected': "" + (item === selectedItem),
|
|
2617
|
-
id: elementIds.getItemId(
|
|
2636
|
+
id: elementIds.getItemId(index)
|
|
2618
2637
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2619
2638
|
if (itemNode) {
|
|
2620
|
-
itemRefs.current[elementIds.getItemId(
|
|
2639
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
2621
2640
|
}
|
|
2622
2641
|
}), _extends4), rest);
|
|
2623
2642
|
if (!disabled) {
|
|
@@ -2628,7 +2647,7 @@ function useSelect(userProps) {
|
|
|
2628
2647
|
}
|
|
2629
2648
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
2630
2649
|
return itemProps;
|
|
2631
|
-
}, [latest,
|
|
2650
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2632
2651
|
return {
|
|
2633
2652
|
// prop getters.
|
|
2634
2653
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2800,6 +2819,7 @@ var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
|
2800
2819
|
|
|
2801
2820
|
/* eslint-disable complexity */
|
|
2802
2821
|
function downshiftUseComboboxReducer(state, action) {
|
|
2822
|
+
var _props$items;
|
|
2803
2823
|
var type = action.type,
|
|
2804
2824
|
props = action.props,
|
|
2805
2825
|
altKey = action.altKey;
|
|
@@ -2828,13 +2848,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2828
2848
|
case InputKeyDownArrowUp:
|
|
2829
2849
|
if (state.isOpen) {
|
|
2830
2850
|
if (altKey) {
|
|
2831
|
-
changes =
|
|
2832
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2833
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2834
|
-
}, state.highlightedIndex >= 0 && {
|
|
2835
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2836
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2837
|
-
});
|
|
2851
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2838
2852
|
} else {
|
|
2839
2853
|
changes = {
|
|
2840
2854
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2848,13 +2862,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2848
2862
|
}
|
|
2849
2863
|
break;
|
|
2850
2864
|
case InputKeyDownEnter:
|
|
2851
|
-
changes =
|
|
2852
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2853
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2854
|
-
}, state.highlightedIndex >= 0 && {
|
|
2855
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2856
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2857
|
-
});
|
|
2865
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2858
2866
|
break;
|
|
2859
2867
|
case InputKeyDownEscape:
|
|
2860
2868
|
changes = _extends({
|
|
@@ -2889,7 +2897,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2889
2897
|
changes = _extends({
|
|
2890
2898
|
isOpen: false,
|
|
2891
2899
|
highlightedIndex: -1
|
|
2892
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2900
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2893
2901
|
selectedItem: props.items[state.highlightedIndex],
|
|
2894
2902
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2895
2903
|
});
|
|
@@ -3157,8 +3165,8 @@ function useCombobox(userProps) {
|
|
|
3157
3165
|
var getItemProps = useCallback(function (_temp3) {
|
|
3158
3166
|
var _extends3, _ref4;
|
|
3159
3167
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3160
|
-
|
|
3161
|
-
|
|
3168
|
+
itemProp = _ref3.item,
|
|
3169
|
+
indexProp = _ref3.index,
|
|
3162
3170
|
_ref3$refKey = _ref3.refKey,
|
|
3163
3171
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3164
3172
|
ref = _ref3.ref,
|
|
@@ -3171,10 +3179,8 @@ function useCombobox(userProps) {
|
|
|
3171
3179
|
var _latest$current = latest.current,
|
|
3172
3180
|
latestProps = _latest$current.props,
|
|
3173
3181
|
latestState = _latest$current.state;
|
|
3174
|
-
var
|
|
3175
|
-
|
|
3176
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3177
|
-
}
|
|
3182
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3183
|
+
index = _getItemAndIndex[1];
|
|
3178
3184
|
var onSelectKey = 'onClick';
|
|
3179
3185
|
var customClickHandler = onClick;
|
|
3180
3186
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -3199,9 +3205,9 @@ function useCombobox(userProps) {
|
|
|
3199
3205
|
};
|
|
3200
3206
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3201
3207
|
if (itemNode) {
|
|
3202
|
-
itemRefs.current[elementIds.getItemId(
|
|
3208
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3203
3209
|
}
|
|
3204
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
3210
|
+
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (index === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(index), _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
|
|
3205
3211
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3206
3212
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3207
3213
|
}, rest);
|
|
@@ -3741,14 +3747,13 @@ function useMultipleSelection(userProps) {
|
|
|
3741
3747
|
ref = _ref3.ref,
|
|
3742
3748
|
onClick = _ref3.onClick,
|
|
3743
3749
|
onKeyDown = _ref3.onKeyDown,
|
|
3744
|
-
|
|
3745
|
-
|
|
3750
|
+
selectedItemProp = _ref3.selectedItem,
|
|
3751
|
+
indexProp = _ref3.index,
|
|
3746
3752
|
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
3747
3753
|
var latestState = latest.current.state;
|
|
3748
|
-
var
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
}
|
|
3754
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3755
|
+
index = _getItemAndIndex[1];
|
|
3756
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
3752
3757
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
3753
3758
|
dispatch({
|
|
3754
3759
|
type: SelectedItemClick,
|
|
@@ -3765,7 +3770,7 @@ function useMultipleSelection(userProps) {
|
|
|
3765
3770
|
if (selectedItemNode) {
|
|
3766
3771
|
selectedItemRefs.current.push(selectedItemNode);
|
|
3767
3772
|
}
|
|
3768
|
-
}), _extends2.tabIndex =
|
|
3773
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
3769
3774
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3770
3775
|
var getDropdownProps = useCallback(function (_temp2, _temp3) {
|
|
3771
3776
|
var _extends3;
|