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
|
@@ -1541,14 +1541,19 @@ function useElementIds(_ref) {
|
|
|
1541
1541
|
});
|
|
1542
1542
|
return elementIdsRef.current;
|
|
1543
1543
|
}
|
|
1544
|
-
function
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1544
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1545
|
+
var item, index;
|
|
1546
|
+
if (itemProp === undefined) {
|
|
1547
|
+
if (indexProp === undefined) {
|
|
1548
|
+
throw new Error(errorMessage);
|
|
1549
|
+
}
|
|
1550
|
+
item = items[indexProp];
|
|
1551
|
+
index = indexProp;
|
|
1552
|
+
} else {
|
|
1553
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1554
|
+
item = itemProp;
|
|
1550
1555
|
}
|
|
1551
|
-
return
|
|
1556
|
+
return [item, index];
|
|
1552
1557
|
}
|
|
1553
1558
|
function itemToString(item) {
|
|
1554
1559
|
return item ? String(item) : '';
|
|
@@ -1874,6 +1879,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1874
1879
|
};
|
|
1875
1880
|
}
|
|
1876
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
|
+
|
|
1877
1908
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1878
1909
|
var type = action.type,
|
|
1879
1910
|
props = action.props;
|
|
@@ -2065,6 +2096,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2065
2096
|
|
|
2066
2097
|
/* eslint-disable complexity */
|
|
2067
2098
|
function downshiftSelectReducer(state, action) {
|
|
2099
|
+
var _props$items;
|
|
2068
2100
|
var type = action.type,
|
|
2069
2101
|
props = action.props,
|
|
2070
2102
|
altKey = action.altKey;
|
|
@@ -2107,12 +2139,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2107
2139
|
break;
|
|
2108
2140
|
case ToggleButtonKeyDownArrowUp:
|
|
2109
2141
|
if (state.isOpen && altKey) {
|
|
2110
|
-
changes =
|
|
2111
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2112
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2113
|
-
}, state.highlightedIndex >= 0 && {
|
|
2114
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2115
|
-
});
|
|
2142
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2116
2143
|
} else {
|
|
2117
2144
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2118
2145
|
changes = {
|
|
@@ -2124,12 +2151,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2124
2151
|
// only triggered when menu is open.
|
|
2125
2152
|
case ToggleButtonKeyDownEnter:
|
|
2126
2153
|
case ToggleButtonKeyDownSpaceButton:
|
|
2127
|
-
changes =
|
|
2128
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2129
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2130
|
-
}, state.highlightedIndex >= 0 && {
|
|
2131
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2132
|
-
});
|
|
2154
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2133
2155
|
break;
|
|
2134
2156
|
case ToggleButtonKeyDownHome:
|
|
2135
2157
|
changes = {
|
|
@@ -2163,7 +2185,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2163
2185
|
changes = _extends__default["default"]({
|
|
2164
2186
|
isOpen: false,
|
|
2165
2187
|
highlightedIndex: -1
|
|
2166
|
-
}, state.highlightedIndex >= 0 && {
|
|
2188
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2167
2189
|
selectedItem: props.items[state.highlightedIndex]
|
|
2168
2190
|
});
|
|
2169
2191
|
break;
|
|
@@ -2522,8 +2544,9 @@ function useSelect(userProps) {
|
|
|
2522
2544
|
var _latest$current = latest.current,
|
|
2523
2545
|
latestState = _latest$current.state,
|
|
2524
2546
|
latestProps = _latest$current.props;
|
|
2525
|
-
var
|
|
2526
|
-
|
|
2547
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
2548
|
+
item = _getItemAndIndex[0],
|
|
2549
|
+
index = _getItemAndIndex[1];
|
|
2527
2550
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2528
2551
|
if (index === latestState.highlightedIndex) {
|
|
2529
2552
|
return;
|
|
@@ -2541,18 +2564,14 @@ function useSelect(userProps) {
|
|
|
2541
2564
|
index: index
|
|
2542
2565
|
});
|
|
2543
2566
|
};
|
|
2544
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2545
|
-
if (itemIndex < 0) {
|
|
2546
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
2547
|
-
}
|
|
2548
2567
|
var itemProps = _extends__default["default"]((_extends4 = {
|
|
2549
2568
|
disabled: disabled,
|
|
2550
2569
|
role: 'option',
|
|
2551
2570
|
'aria-selected': "" + (item === selectedItem),
|
|
2552
|
-
id: elementIds.getItemId(
|
|
2571
|
+
id: elementIds.getItemId(index)
|
|
2553
2572
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2554
2573
|
if (itemNode) {
|
|
2555
|
-
itemRefs.current[elementIds.getItemId(
|
|
2574
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
2556
2575
|
}
|
|
2557
2576
|
}), _extends4), rest);
|
|
2558
2577
|
if (!disabled) {
|
|
@@ -2563,7 +2582,7 @@ function useSelect(userProps) {
|
|
|
2563
2582
|
}
|
|
2564
2583
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
2565
2584
|
return itemProps;
|
|
2566
|
-
}, [latest,
|
|
2585
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2567
2586
|
return {
|
|
2568
2587
|
// prop getters.
|
|
2569
2588
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2735,6 +2754,7 @@ var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
|
2735
2754
|
|
|
2736
2755
|
/* eslint-disable complexity */
|
|
2737
2756
|
function downshiftUseComboboxReducer(state, action) {
|
|
2757
|
+
var _props$items;
|
|
2738
2758
|
var type = action.type,
|
|
2739
2759
|
props = action.props,
|
|
2740
2760
|
altKey = action.altKey;
|
|
@@ -2763,13 +2783,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2763
2783
|
case InputKeyDownArrowUp:
|
|
2764
2784
|
if (state.isOpen) {
|
|
2765
2785
|
if (altKey) {
|
|
2766
|
-
changes =
|
|
2767
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2768
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2769
|
-
}, state.highlightedIndex >= 0 && {
|
|
2770
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2771
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2772
|
-
});
|
|
2786
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2773
2787
|
} else {
|
|
2774
2788
|
changes = {
|
|
2775
2789
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2783,13 +2797,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2783
2797
|
}
|
|
2784
2798
|
break;
|
|
2785
2799
|
case InputKeyDownEnter:
|
|
2786
|
-
changes =
|
|
2787
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2788
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2789
|
-
}, state.highlightedIndex >= 0 && {
|
|
2790
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2791
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2792
|
-
});
|
|
2800
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2793
2801
|
break;
|
|
2794
2802
|
case InputKeyDownEscape:
|
|
2795
2803
|
changes = _extends__default["default"]({
|
|
@@ -2824,7 +2832,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2824
2832
|
changes = _extends__default["default"]({
|
|
2825
2833
|
isOpen: false,
|
|
2826
2834
|
highlightedIndex: -1
|
|
2827
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2835
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2828
2836
|
selectedItem: props.items[state.highlightedIndex],
|
|
2829
2837
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2830
2838
|
});
|
|
@@ -3092,8 +3100,8 @@ function useCombobox(userProps) {
|
|
|
3092
3100
|
var getItemProps = react.useCallback(function (_temp3) {
|
|
3093
3101
|
var _extends3, _ref4;
|
|
3094
3102
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3095
|
-
|
|
3096
|
-
|
|
3103
|
+
itemProp = _ref3.item,
|
|
3104
|
+
indexProp = _ref3.index,
|
|
3097
3105
|
_ref3$refKey = _ref3.refKey,
|
|
3098
3106
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3099
3107
|
ref = _ref3.ref,
|
|
@@ -3106,10 +3114,8 @@ function useCombobox(userProps) {
|
|
|
3106
3114
|
var _latest$current = latest.current,
|
|
3107
3115
|
latestProps = _latest$current.props,
|
|
3108
3116
|
latestState = _latest$current.state;
|
|
3109
|
-
var
|
|
3110
|
-
|
|
3111
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3112
|
-
}
|
|
3117
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3118
|
+
index = _getItemAndIndex[1];
|
|
3113
3119
|
var onSelectKey = /* istanbul ignore next (react-native) */'onPress' ;
|
|
3114
3120
|
var customClickHandler = /* istanbul ignore next (react-native) */onPress ;
|
|
3115
3121
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -3134,9 +3140,9 @@ function useCombobox(userProps) {
|
|
|
3134
3140
|
};
|
|
3135
3141
|
return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3136
3142
|
if (itemNode) {
|
|
3137
|
-
itemRefs.current[elementIds.getItemId(
|
|
3143
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3138
3144
|
}
|
|
3139
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
3145
|
+
}), _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), {
|
|
3140
3146
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3141
3147
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3142
3148
|
}, rest);
|
|
@@ -3688,14 +3694,13 @@ function useMultipleSelection(userProps) {
|
|
|
3688
3694
|
ref = _ref3.ref,
|
|
3689
3695
|
onClick = _ref3.onClick,
|
|
3690
3696
|
onKeyDown = _ref3.onKeyDown,
|
|
3691
|
-
|
|
3692
|
-
|
|
3697
|
+
selectedItemProp = _ref3.selectedItem,
|
|
3698
|
+
indexProp = _ref3.index,
|
|
3693
3699
|
rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded);
|
|
3694
3700
|
var latestState = latest.current.state;
|
|
3695
|
-
var
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
}
|
|
3701
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3702
|
+
index = _getItemAndIndex[1];
|
|
3703
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
3699
3704
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
3700
3705
|
dispatch({
|
|
3701
3706
|
type: SelectedItemClick,
|
|
@@ -3712,7 +3717,7 @@ function useMultipleSelection(userProps) {
|
|
|
3712
3717
|
if (selectedItemNode) {
|
|
3713
3718
|
selectedItemRefs.current.push(selectedItemNode);
|
|
3714
3719
|
}
|
|
3715
|
-
}), _extends2.tabIndex =
|
|
3720
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
3716
3721
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3717
3722
|
var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
3718
3723
|
var _extends3;
|
package/dist/downshift.umd.js
CHANGED
|
@@ -2889,14 +2889,19 @@
|
|
|
2889
2889
|
});
|
|
2890
2890
|
return elementIdsRef.current;
|
|
2891
2891
|
}
|
|
2892
|
-
function
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2892
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
2893
|
+
var item, index;
|
|
2894
|
+
if (itemProp === undefined) {
|
|
2895
|
+
if (indexProp === undefined) {
|
|
2896
|
+
throw new Error(errorMessage);
|
|
2897
|
+
}
|
|
2898
|
+
item = items[indexProp];
|
|
2899
|
+
index = indexProp;
|
|
2900
|
+
} else {
|
|
2901
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
2902
|
+
item = itemProp;
|
|
2898
2903
|
}
|
|
2899
|
-
return
|
|
2904
|
+
return [item, index];
|
|
2900
2905
|
}
|
|
2901
2906
|
function itemToString(item) {
|
|
2902
2907
|
return item ? String(item) : '';
|
|
@@ -3225,6 +3230,32 @@
|
|
|
3225
3230
|
};
|
|
3226
3231
|
}
|
|
3227
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
|
+
|
|
3228
3259
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
3229
3260
|
var type = action.type,
|
|
3230
3261
|
props = action.props;
|
|
@@ -3442,6 +3473,7 @@
|
|
|
3442
3473
|
|
|
3443
3474
|
/* eslint-disable complexity */
|
|
3444
3475
|
function downshiftSelectReducer(state, action) {
|
|
3476
|
+
var _props$items;
|
|
3445
3477
|
var type = action.type,
|
|
3446
3478
|
props = action.props,
|
|
3447
3479
|
altKey = action.altKey;
|
|
@@ -3484,12 +3516,7 @@
|
|
|
3484
3516
|
break;
|
|
3485
3517
|
case ToggleButtonKeyDownArrowUp:
|
|
3486
3518
|
if (state.isOpen && altKey) {
|
|
3487
|
-
changes =
|
|
3488
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3489
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3490
|
-
}, state.highlightedIndex >= 0 && {
|
|
3491
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
3492
|
-
});
|
|
3519
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
3493
3520
|
} else {
|
|
3494
3521
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
3495
3522
|
changes = {
|
|
@@ -3501,12 +3528,7 @@
|
|
|
3501
3528
|
// only triggered when menu is open.
|
|
3502
3529
|
case ToggleButtonKeyDownEnter:
|
|
3503
3530
|
case ToggleButtonKeyDownSpaceButton:
|
|
3504
|
-
changes =
|
|
3505
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3506
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3507
|
-
}, state.highlightedIndex >= 0 && {
|
|
3508
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
3509
|
-
});
|
|
3531
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
3510
3532
|
break;
|
|
3511
3533
|
case ToggleButtonKeyDownHome:
|
|
3512
3534
|
changes = {
|
|
@@ -3540,7 +3562,7 @@
|
|
|
3540
3562
|
changes = _extends({
|
|
3541
3563
|
isOpen: false,
|
|
3542
3564
|
highlightedIndex: -1
|
|
3543
|
-
}, state.highlightedIndex >= 0 && {
|
|
3565
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
3544
3566
|
selectedItem: props.items[state.highlightedIndex]
|
|
3545
3567
|
});
|
|
3546
3568
|
break;
|
|
@@ -3912,8 +3934,9 @@
|
|
|
3912
3934
|
var _latest$current = latest.current,
|
|
3913
3935
|
latestState = _latest$current.state,
|
|
3914
3936
|
latestProps = _latest$current.props;
|
|
3915
|
-
var
|
|
3916
|
-
|
|
3937
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3938
|
+
item = _getItemAndIndex[0],
|
|
3939
|
+
index = _getItemAndIndex[1];
|
|
3917
3940
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
3918
3941
|
if (index === latestState.highlightedIndex) {
|
|
3919
3942
|
return;
|
|
@@ -3931,18 +3954,14 @@
|
|
|
3931
3954
|
index: index
|
|
3932
3955
|
});
|
|
3933
3956
|
};
|
|
3934
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3935
|
-
if (itemIndex < 0) {
|
|
3936
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3937
|
-
}
|
|
3938
3957
|
var itemProps = _extends((_extends4 = {
|
|
3939
3958
|
disabled: disabled,
|
|
3940
3959
|
role: 'option',
|
|
3941
3960
|
'aria-selected': "" + (item === selectedItem),
|
|
3942
|
-
id: elementIds.getItemId(
|
|
3961
|
+
id: elementIds.getItemId(index)
|
|
3943
3962
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
3944
3963
|
if (itemNode) {
|
|
3945
|
-
itemRefs.current[elementIds.getItemId(
|
|
3964
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3946
3965
|
}
|
|
3947
3966
|
}), _extends4), rest);
|
|
3948
3967
|
if (!disabled) {
|
|
@@ -3953,7 +3972,7 @@
|
|
|
3953
3972
|
}
|
|
3954
3973
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
3955
3974
|
return itemProps;
|
|
3956
|
-
}, [latest,
|
|
3975
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
3957
3976
|
return {
|
|
3958
3977
|
// prop getters.
|
|
3959
3978
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -4125,6 +4144,7 @@
|
|
|
4125
4144
|
|
|
4126
4145
|
/* eslint-disable complexity */
|
|
4127
4146
|
function downshiftUseComboboxReducer(state, action) {
|
|
4147
|
+
var _props$items;
|
|
4128
4148
|
var type = action.type,
|
|
4129
4149
|
props = action.props,
|
|
4130
4150
|
altKey = action.altKey;
|
|
@@ -4153,13 +4173,7 @@
|
|
|
4153
4173
|
case InputKeyDownArrowUp:
|
|
4154
4174
|
if (state.isOpen) {
|
|
4155
4175
|
if (altKey) {
|
|
4156
|
-
changes =
|
|
4157
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4158
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4159
|
-
}, state.highlightedIndex >= 0 && {
|
|
4160
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
4161
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4162
|
-
});
|
|
4176
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
4163
4177
|
} else {
|
|
4164
4178
|
changes = {
|
|
4165
4179
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -4173,13 +4187,7 @@
|
|
|
4173
4187
|
}
|
|
4174
4188
|
break;
|
|
4175
4189
|
case InputKeyDownEnter:
|
|
4176
|
-
changes =
|
|
4177
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4178
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4179
|
-
}, state.highlightedIndex >= 0 && {
|
|
4180
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
4181
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4182
|
-
});
|
|
4190
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
4183
4191
|
break;
|
|
4184
4192
|
case InputKeyDownEscape:
|
|
4185
4193
|
changes = _extends({
|
|
@@ -4214,7 +4222,7 @@
|
|
|
4214
4222
|
changes = _extends({
|
|
4215
4223
|
isOpen: false,
|
|
4216
4224
|
highlightedIndex: -1
|
|
4217
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
4225
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
4218
4226
|
selectedItem: props.items[state.highlightedIndex],
|
|
4219
4227
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4220
4228
|
});
|
|
@@ -4482,8 +4490,8 @@
|
|
|
4482
4490
|
var getItemProps = react.useCallback(function (_temp3) {
|
|
4483
4491
|
var _extends3, _ref4;
|
|
4484
4492
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
4485
|
-
|
|
4486
|
-
|
|
4493
|
+
itemProp = _ref3.item,
|
|
4494
|
+
indexProp = _ref3.index,
|
|
4487
4495
|
_ref3$refKey = _ref3.refKey,
|
|
4488
4496
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4489
4497
|
ref = _ref3.ref,
|
|
@@ -4496,10 +4504,8 @@
|
|
|
4496
4504
|
var _latest$current = latest.current,
|
|
4497
4505
|
latestProps = _latest$current.props,
|
|
4498
4506
|
latestState = _latest$current.state;
|
|
4499
|
-
var
|
|
4500
|
-
|
|
4501
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
4502
|
-
}
|
|
4507
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
4508
|
+
index = _getItemAndIndex[1];
|
|
4503
4509
|
var onSelectKey = 'onClick';
|
|
4504
4510
|
var customClickHandler = onClick;
|
|
4505
4511
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -4524,9 +4530,9 @@
|
|
|
4524
4530
|
};
|
|
4525
4531
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
4526
4532
|
if (itemNode) {
|
|
4527
|
-
itemRefs.current[elementIds.getItemId(
|
|
4533
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
4528
4534
|
}
|
|
4529
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
4535
|
+
}), _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), {
|
|
4530
4536
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
4531
4537
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
4532
4538
|
}, rest);
|
|
@@ -5066,14 +5072,13 @@
|
|
|
5066
5072
|
ref = _ref3.ref,
|
|
5067
5073
|
onClick = _ref3.onClick,
|
|
5068
5074
|
onKeyDown = _ref3.onKeyDown,
|
|
5069
|
-
|
|
5070
|
-
|
|
5075
|
+
selectedItemProp = _ref3.selectedItem,
|
|
5076
|
+
indexProp = _ref3.index,
|
|
5071
5077
|
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
5072
5078
|
var latestState = latest.current.state;
|
|
5073
|
-
var
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
}
|
|
5079
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
5080
|
+
index = _getItemAndIndex[1];
|
|
5081
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
5077
5082
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
5078
5083
|
dispatch({
|
|
5079
5084
|
type: SelectedItemClick,
|
|
@@ -5090,7 +5095,7 @@
|
|
|
5090
5095
|
if (selectedItemNode) {
|
|
5091
5096
|
selectedItemRefs.current.push(selectedItemNode);
|
|
5092
5097
|
}
|
|
5093
|
-
}), _extends2.tabIndex =
|
|
5098
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
5094
5099
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
5095
5100
|
var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
5096
5101
|
var _extends3;
|