downshift 7.3.3 → 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 +34 -28
- package/dist/downshift.esm.js +34 -28
- package/dist/downshift.native.cjs.js +34 -28
- package/dist/downshift.umd.js +34 -28
- 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 +9 -0
- package/package.json +1 -1
- package/preact/dist/downshift.cjs.js +34 -28
- package/preact/dist/downshift.esm.js +34 -28
- package/preact/dist/downshift.umd.js +34 -28
- 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
|
@@ -1944,6 +1944,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1944
1944
|
};
|
|
1945
1945
|
}
|
|
1946
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
|
+
|
|
1947
1973
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1948
1974
|
var type = action.type,
|
|
1949
1975
|
props = action.props;
|
|
@@ -2135,6 +2161,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2135
2161
|
|
|
2136
2162
|
/* eslint-disable complexity */
|
|
2137
2163
|
function downshiftSelectReducer(state, action) {
|
|
2164
|
+
var _props$items;
|
|
2138
2165
|
var type = action.type,
|
|
2139
2166
|
props = action.props,
|
|
2140
2167
|
altKey = action.altKey;
|
|
@@ -2177,12 +2204,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2177
2204
|
break;
|
|
2178
2205
|
case ToggleButtonKeyDownArrowUp:
|
|
2179
2206
|
if (state.isOpen && altKey) {
|
|
2180
|
-
changes =
|
|
2181
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2182
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2183
|
-
}, state.highlightedIndex >= 0 && {
|
|
2184
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2185
|
-
});
|
|
2207
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2186
2208
|
} else {
|
|
2187
2209
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2188
2210
|
changes = {
|
|
@@ -2194,12 +2216,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2194
2216
|
// only triggered when menu is open.
|
|
2195
2217
|
case ToggleButtonKeyDownEnter:
|
|
2196
2218
|
case ToggleButtonKeyDownSpaceButton:
|
|
2197
|
-
changes =
|
|
2198
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2199
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2200
|
-
}, state.highlightedIndex >= 0 && {
|
|
2201
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2202
|
-
});
|
|
2219
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2203
2220
|
break;
|
|
2204
2221
|
case ToggleButtonKeyDownHome:
|
|
2205
2222
|
changes = {
|
|
@@ -2233,7 +2250,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2233
2250
|
changes = _extends__default["default"]({
|
|
2234
2251
|
isOpen: false,
|
|
2235
2252
|
highlightedIndex: -1
|
|
2236
|
-
}, state.highlightedIndex >= 0 && {
|
|
2253
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2237
2254
|
selectedItem: props.items[state.highlightedIndex]
|
|
2238
2255
|
});
|
|
2239
2256
|
break;
|
|
@@ -2815,6 +2832,7 @@ var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
|
2815
2832
|
|
|
2816
2833
|
/* eslint-disable complexity */
|
|
2817
2834
|
function downshiftUseComboboxReducer(state, action) {
|
|
2835
|
+
var _props$items;
|
|
2818
2836
|
var type = action.type,
|
|
2819
2837
|
props = action.props,
|
|
2820
2838
|
altKey = action.altKey;
|
|
@@ -2843,13 +2861,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2843
2861
|
case InputKeyDownArrowUp:
|
|
2844
2862
|
if (state.isOpen) {
|
|
2845
2863
|
if (altKey) {
|
|
2846
|
-
changes =
|
|
2847
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2848
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2849
|
-
}, state.highlightedIndex >= 0 && {
|
|
2850
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2851
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2852
|
-
});
|
|
2864
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2853
2865
|
} else {
|
|
2854
2866
|
changes = {
|
|
2855
2867
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2863,13 +2875,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2863
2875
|
}
|
|
2864
2876
|
break;
|
|
2865
2877
|
case InputKeyDownEnter:
|
|
2866
|
-
changes =
|
|
2867
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2868
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2869
|
-
}, state.highlightedIndex >= 0 && {
|
|
2870
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2871
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2872
|
-
});
|
|
2878
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2873
2879
|
break;
|
|
2874
2880
|
case InputKeyDownEscape:
|
|
2875
2881
|
changes = _extends__default["default"]({
|
|
@@ -2904,7 +2910,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2904
2910
|
changes = _extends__default["default"]({
|
|
2905
2911
|
isOpen: false,
|
|
2906
2912
|
highlightedIndex: -1
|
|
2907
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2913
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2908
2914
|
selectedItem: props.items[state.highlightedIndex],
|
|
2909
2915
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2910
2916
|
});
|
package/dist/downshift.esm.js
CHANGED
|
@@ -1931,6 +1931,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1931
1931
|
};
|
|
1932
1932
|
}
|
|
1933
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
|
+
|
|
1934
1960
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1935
1961
|
var type = action.type,
|
|
1936
1962
|
props = action.props;
|
|
@@ -2122,6 +2148,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2122
2148
|
|
|
2123
2149
|
/* eslint-disable complexity */
|
|
2124
2150
|
function downshiftSelectReducer(state, action) {
|
|
2151
|
+
var _props$items;
|
|
2125
2152
|
var type = action.type,
|
|
2126
2153
|
props = action.props,
|
|
2127
2154
|
altKey = action.altKey;
|
|
@@ -2164,12 +2191,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2164
2191
|
break;
|
|
2165
2192
|
case ToggleButtonKeyDownArrowUp:
|
|
2166
2193
|
if (state.isOpen && altKey) {
|
|
2167
|
-
changes =
|
|
2168
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2169
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2170
|
-
}, state.highlightedIndex >= 0 && {
|
|
2171
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2172
|
-
});
|
|
2194
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2173
2195
|
} else {
|
|
2174
2196
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2175
2197
|
changes = {
|
|
@@ -2181,12 +2203,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2181
2203
|
// only triggered when menu is open.
|
|
2182
2204
|
case ToggleButtonKeyDownEnter:
|
|
2183
2205
|
case ToggleButtonKeyDownSpaceButton:
|
|
2184
|
-
changes =
|
|
2185
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2186
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2187
|
-
}, state.highlightedIndex >= 0 && {
|
|
2188
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2189
|
-
});
|
|
2206
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2190
2207
|
break;
|
|
2191
2208
|
case ToggleButtonKeyDownHome:
|
|
2192
2209
|
changes = {
|
|
@@ -2220,7 +2237,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2220
2237
|
changes = _extends({
|
|
2221
2238
|
isOpen: false,
|
|
2222
2239
|
highlightedIndex: -1
|
|
2223
|
-
}, state.highlightedIndex >= 0 && {
|
|
2240
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2224
2241
|
selectedItem: props.items[state.highlightedIndex]
|
|
2225
2242
|
});
|
|
2226
2243
|
break;
|
|
@@ -2802,6 +2819,7 @@ var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
|
2802
2819
|
|
|
2803
2820
|
/* eslint-disable complexity */
|
|
2804
2821
|
function downshiftUseComboboxReducer(state, action) {
|
|
2822
|
+
var _props$items;
|
|
2805
2823
|
var type = action.type,
|
|
2806
2824
|
props = action.props,
|
|
2807
2825
|
altKey = action.altKey;
|
|
@@ -2830,13 +2848,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2830
2848
|
case InputKeyDownArrowUp:
|
|
2831
2849
|
if (state.isOpen) {
|
|
2832
2850
|
if (altKey) {
|
|
2833
|
-
changes =
|
|
2834
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2835
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2836
|
-
}, state.highlightedIndex >= 0 && {
|
|
2837
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2838
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2839
|
-
});
|
|
2851
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2840
2852
|
} else {
|
|
2841
2853
|
changes = {
|
|
2842
2854
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2850,13 +2862,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2850
2862
|
}
|
|
2851
2863
|
break;
|
|
2852
2864
|
case InputKeyDownEnter:
|
|
2853
|
-
changes =
|
|
2854
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2855
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2856
|
-
}, state.highlightedIndex >= 0 && {
|
|
2857
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2858
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2859
|
-
});
|
|
2865
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2860
2866
|
break;
|
|
2861
2867
|
case InputKeyDownEscape:
|
|
2862
2868
|
changes = _extends({
|
|
@@ -2891,7 +2897,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2891
2897
|
changes = _extends({
|
|
2892
2898
|
isOpen: false,
|
|
2893
2899
|
highlightedIndex: -1
|
|
2894
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2900
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2895
2901
|
selectedItem: props.items[state.highlightedIndex],
|
|
2896
2902
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2897
2903
|
});
|
|
@@ -1879,6 +1879,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1879
1879
|
};
|
|
1880
1880
|
}
|
|
1881
1881
|
|
|
1882
|
+
/**
|
|
1883
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1884
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1885
|
+
* @param {Object} props The useCombobox props.
|
|
1886
|
+
* @param {number} highlightedIndex The index from the state.
|
|
1887
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
1888
|
+
* @returns The changes for the state.
|
|
1889
|
+
*/
|
|
1890
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1891
|
+
var _props$items;
|
|
1892
|
+
if (inputValue === void 0) {
|
|
1893
|
+
inputValue = true;
|
|
1894
|
+
}
|
|
1895
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1896
|
+
return _extends__default["default"]({
|
|
1897
|
+
isOpen: false,
|
|
1898
|
+
highlightedIndex: -1
|
|
1899
|
+
}, shouldSelect && _extends__default["default"]({
|
|
1900
|
+
selectedItem: props.items[highlightedIndex],
|
|
1901
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
1902
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
1903
|
+
}, inputValue && {
|
|
1904
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1905
|
+
}));
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1882
1908
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1883
1909
|
var type = action.type,
|
|
1884
1910
|
props = action.props;
|
|
@@ -2070,6 +2096,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2070
2096
|
|
|
2071
2097
|
/* eslint-disable complexity */
|
|
2072
2098
|
function downshiftSelectReducer(state, action) {
|
|
2099
|
+
var _props$items;
|
|
2073
2100
|
var type = action.type,
|
|
2074
2101
|
props = action.props,
|
|
2075
2102
|
altKey = action.altKey;
|
|
@@ -2112,12 +2139,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2112
2139
|
break;
|
|
2113
2140
|
case ToggleButtonKeyDownArrowUp:
|
|
2114
2141
|
if (state.isOpen && altKey) {
|
|
2115
|
-
changes =
|
|
2116
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2117
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2118
|
-
}, state.highlightedIndex >= 0 && {
|
|
2119
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2120
|
-
});
|
|
2142
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2121
2143
|
} else {
|
|
2122
2144
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2123
2145
|
changes = {
|
|
@@ -2129,12 +2151,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2129
2151
|
// only triggered when menu is open.
|
|
2130
2152
|
case ToggleButtonKeyDownEnter:
|
|
2131
2153
|
case ToggleButtonKeyDownSpaceButton:
|
|
2132
|
-
changes =
|
|
2133
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2134
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2135
|
-
}, state.highlightedIndex >= 0 && {
|
|
2136
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2137
|
-
});
|
|
2154
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2138
2155
|
break;
|
|
2139
2156
|
case ToggleButtonKeyDownHome:
|
|
2140
2157
|
changes = {
|
|
@@ -2168,7 +2185,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2168
2185
|
changes = _extends__default["default"]({
|
|
2169
2186
|
isOpen: false,
|
|
2170
2187
|
highlightedIndex: -1
|
|
2171
|
-
}, state.highlightedIndex >= 0 && {
|
|
2188
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2172
2189
|
selectedItem: props.items[state.highlightedIndex]
|
|
2173
2190
|
});
|
|
2174
2191
|
break;
|
|
@@ -2737,6 +2754,7 @@ var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
|
2737
2754
|
|
|
2738
2755
|
/* eslint-disable complexity */
|
|
2739
2756
|
function downshiftUseComboboxReducer(state, action) {
|
|
2757
|
+
var _props$items;
|
|
2740
2758
|
var type = action.type,
|
|
2741
2759
|
props = action.props,
|
|
2742
2760
|
altKey = action.altKey;
|
|
@@ -2765,13 +2783,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2765
2783
|
case InputKeyDownArrowUp:
|
|
2766
2784
|
if (state.isOpen) {
|
|
2767
2785
|
if (altKey) {
|
|
2768
|
-
changes =
|
|
2769
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2770
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2771
|
-
}, state.highlightedIndex >= 0 && {
|
|
2772
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2773
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2774
|
-
});
|
|
2786
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2775
2787
|
} else {
|
|
2776
2788
|
changes = {
|
|
2777
2789
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2785,13 +2797,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2785
2797
|
}
|
|
2786
2798
|
break;
|
|
2787
2799
|
case InputKeyDownEnter:
|
|
2788
|
-
changes =
|
|
2789
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2790
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2791
|
-
}, state.highlightedIndex >= 0 && {
|
|
2792
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2793
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2794
|
-
});
|
|
2800
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2795
2801
|
break;
|
|
2796
2802
|
case InputKeyDownEscape:
|
|
2797
2803
|
changes = _extends__default["default"]({
|
|
@@ -2826,7 +2832,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2826
2832
|
changes = _extends__default["default"]({
|
|
2827
2833
|
isOpen: false,
|
|
2828
2834
|
highlightedIndex: -1
|
|
2829
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2835
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2830
2836
|
selectedItem: props.items[state.highlightedIndex],
|
|
2831
2837
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2832
2838
|
});
|
package/dist/downshift.umd.js
CHANGED
|
@@ -3230,6 +3230,32 @@
|
|
|
3230
3230
|
};
|
|
3231
3231
|
}
|
|
3232
3232
|
|
|
3233
|
+
/**
|
|
3234
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
3235
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
3236
|
+
* @param {Object} props The useCombobox props.
|
|
3237
|
+
* @param {number} highlightedIndex The index from the state.
|
|
3238
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
3239
|
+
* @returns The changes for the state.
|
|
3240
|
+
*/
|
|
3241
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
3242
|
+
var _props$items;
|
|
3243
|
+
if (inputValue === void 0) {
|
|
3244
|
+
inputValue = true;
|
|
3245
|
+
}
|
|
3246
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
3247
|
+
return _extends({
|
|
3248
|
+
isOpen: false,
|
|
3249
|
+
highlightedIndex: -1
|
|
3250
|
+
}, shouldSelect && _extends({
|
|
3251
|
+
selectedItem: props.items[highlightedIndex],
|
|
3252
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3253
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3254
|
+
}, inputValue && {
|
|
3255
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
3256
|
+
}));
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3233
3259
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
3234
3260
|
var type = action.type,
|
|
3235
3261
|
props = action.props;
|
|
@@ -3447,6 +3473,7 @@
|
|
|
3447
3473
|
|
|
3448
3474
|
/* eslint-disable complexity */
|
|
3449
3475
|
function downshiftSelectReducer(state, action) {
|
|
3476
|
+
var _props$items;
|
|
3450
3477
|
var type = action.type,
|
|
3451
3478
|
props = action.props,
|
|
3452
3479
|
altKey = action.altKey;
|
|
@@ -3489,12 +3516,7 @@
|
|
|
3489
3516
|
break;
|
|
3490
3517
|
case ToggleButtonKeyDownArrowUp:
|
|
3491
3518
|
if (state.isOpen && altKey) {
|
|
3492
|
-
changes =
|
|
3493
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3494
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3495
|
-
}, state.highlightedIndex >= 0 && {
|
|
3496
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
3497
|
-
});
|
|
3519
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
3498
3520
|
} else {
|
|
3499
3521
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
3500
3522
|
changes = {
|
|
@@ -3506,12 +3528,7 @@
|
|
|
3506
3528
|
// only triggered when menu is open.
|
|
3507
3529
|
case ToggleButtonKeyDownEnter:
|
|
3508
3530
|
case ToggleButtonKeyDownSpaceButton:
|
|
3509
|
-
changes =
|
|
3510
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3511
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3512
|
-
}, state.highlightedIndex >= 0 && {
|
|
3513
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
3514
|
-
});
|
|
3531
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
3515
3532
|
break;
|
|
3516
3533
|
case ToggleButtonKeyDownHome:
|
|
3517
3534
|
changes = {
|
|
@@ -3545,7 +3562,7 @@
|
|
|
3545
3562
|
changes = _extends({
|
|
3546
3563
|
isOpen: false,
|
|
3547
3564
|
highlightedIndex: -1
|
|
3548
|
-
}, state.highlightedIndex >= 0 && {
|
|
3565
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
3549
3566
|
selectedItem: props.items[state.highlightedIndex]
|
|
3550
3567
|
});
|
|
3551
3568
|
break;
|
|
@@ -4127,6 +4144,7 @@
|
|
|
4127
4144
|
|
|
4128
4145
|
/* eslint-disable complexity */
|
|
4129
4146
|
function downshiftUseComboboxReducer(state, action) {
|
|
4147
|
+
var _props$items;
|
|
4130
4148
|
var type = action.type,
|
|
4131
4149
|
props = action.props,
|
|
4132
4150
|
altKey = action.altKey;
|
|
@@ -4155,13 +4173,7 @@
|
|
|
4155
4173
|
case InputKeyDownArrowUp:
|
|
4156
4174
|
if (state.isOpen) {
|
|
4157
4175
|
if (altKey) {
|
|
4158
|
-
changes =
|
|
4159
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4160
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4161
|
-
}, state.highlightedIndex >= 0 && {
|
|
4162
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
4163
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4164
|
-
});
|
|
4176
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
4165
4177
|
} else {
|
|
4166
4178
|
changes = {
|
|
4167
4179
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -4175,13 +4187,7 @@
|
|
|
4175
4187
|
}
|
|
4176
4188
|
break;
|
|
4177
4189
|
case InputKeyDownEnter:
|
|
4178
|
-
changes =
|
|
4179
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4180
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4181
|
-
}, state.highlightedIndex >= 0 && {
|
|
4182
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
4183
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4184
|
-
});
|
|
4190
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
4185
4191
|
break;
|
|
4186
4192
|
case InputKeyDownEscape:
|
|
4187
4193
|
changes = _extends({
|
|
@@ -4216,7 +4222,7 @@
|
|
|
4216
4222
|
changes = _extends({
|
|
4217
4223
|
isOpen: false,
|
|
4218
4224
|
highlightedIndex: -1
|
|
4219
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
4225
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
4220
4226
|
selectedItem: props.items[state.highlightedIndex],
|
|
4221
4227
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4222
4228
|
});
|