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
|
@@ -75,7 +75,7 @@ export function useEnhancedReducer(reducer: Function, initialState: Object, prop
|
|
|
75
75
|
export function useLatestRef(val: any): import("react").MutableRefObject<any>;
|
|
76
76
|
export function capitalizeString(string: any): string;
|
|
77
77
|
export function isAcceptedCharacterKey(key: any): boolean;
|
|
78
|
-
export function
|
|
78
|
+
export function getItemAndIndex(itemProp: any, indexProp: any, items: any, errorMessage: any): any[];
|
|
79
79
|
export function useElementIds({ id, labelId, menuId, getItemId, toggleButtonId, inputId, }: {
|
|
80
80
|
id?: string | undefined;
|
|
81
81
|
labelId: any;
|
|
@@ -90,6 +90,15 @@ export function useElementIds({ id, labelId, menuId, getItemId, toggleButtonId,
|
|
|
90
90
|
toggleButtonId: any;
|
|
91
91
|
inputId: any;
|
|
92
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
95
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
96
|
+
* @param {Object} props The useCombobox props.
|
|
97
|
+
* @param {number} highlightedIndex The index from the state.
|
|
98
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
99
|
+
* @returns The changes for the state.
|
|
100
|
+
*/
|
|
101
|
+
export function getChangesOnSelection(props: Object, highlightedIndex: number, inputValue?: boolean): any;
|
|
93
102
|
import { noop } from "../utils";
|
|
94
103
|
declare function itemToString(item: any): string;
|
|
95
104
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "downshift",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.4",
|
|
4
4
|
"description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
|
|
5
5
|
"main": "dist/downshift.cjs.js",
|
|
6
6
|
"react-native": "dist/downshift.native.cjs.js",
|
|
@@ -1566,14 +1566,19 @@ function useElementIds(_ref) {
|
|
|
1566
1566
|
});
|
|
1567
1567
|
return elementIdsRef.current;
|
|
1568
1568
|
}
|
|
1569
|
-
function
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1569
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1570
|
+
var item, index;
|
|
1571
|
+
if (itemProp === undefined) {
|
|
1572
|
+
if (indexProp === undefined) {
|
|
1573
|
+
throw new Error(errorMessage);
|
|
1574
|
+
}
|
|
1575
|
+
item = items[indexProp];
|
|
1576
|
+
index = indexProp;
|
|
1577
|
+
} else {
|
|
1578
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1579
|
+
item = itemProp;
|
|
1575
1580
|
}
|
|
1576
|
-
return
|
|
1581
|
+
return [item, index];
|
|
1577
1582
|
}
|
|
1578
1583
|
function itemToString(item) {
|
|
1579
1584
|
return item ? String(item) : '';
|
|
@@ -1902,6 +1907,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1902
1907
|
};
|
|
1903
1908
|
}
|
|
1904
1909
|
|
|
1910
|
+
/**
|
|
1911
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1912
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1913
|
+
* @param {Object} props The useCombobox props.
|
|
1914
|
+
* @param {number} highlightedIndex The index from the state.
|
|
1915
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
1916
|
+
* @returns The changes for the state.
|
|
1917
|
+
*/
|
|
1918
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1919
|
+
var _props$items;
|
|
1920
|
+
if (inputValue === void 0) {
|
|
1921
|
+
inputValue = true;
|
|
1922
|
+
}
|
|
1923
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1924
|
+
return _extends__default["default"]({
|
|
1925
|
+
isOpen: false,
|
|
1926
|
+
highlightedIndex: -1
|
|
1927
|
+
}, shouldSelect && _extends__default["default"]({
|
|
1928
|
+
selectedItem: props.items[highlightedIndex],
|
|
1929
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
1930
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
1931
|
+
}, inputValue && {
|
|
1932
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1933
|
+
}));
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1905
1936
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1906
1937
|
var type = action.type,
|
|
1907
1938
|
props = action.props;
|
|
@@ -2093,6 +2124,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2093
2124
|
|
|
2094
2125
|
/* eslint-disable complexity */
|
|
2095
2126
|
function downshiftSelectReducer(state, action) {
|
|
2127
|
+
var _props$items;
|
|
2096
2128
|
var type = action.type,
|
|
2097
2129
|
props = action.props,
|
|
2098
2130
|
altKey = action.altKey;
|
|
@@ -2135,12 +2167,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2135
2167
|
break;
|
|
2136
2168
|
case ToggleButtonKeyDownArrowUp:
|
|
2137
2169
|
if (state.isOpen && altKey) {
|
|
2138
|
-
changes =
|
|
2139
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2140
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2141
|
-
}, state.highlightedIndex >= 0 && {
|
|
2142
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2143
|
-
});
|
|
2170
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2144
2171
|
} else {
|
|
2145
2172
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2146
2173
|
changes = {
|
|
@@ -2152,12 +2179,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2152
2179
|
// only triggered when menu is open.
|
|
2153
2180
|
case ToggleButtonKeyDownEnter:
|
|
2154
2181
|
case ToggleButtonKeyDownSpaceButton:
|
|
2155
|
-
changes =
|
|
2156
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2157
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2158
|
-
}, state.highlightedIndex >= 0 && {
|
|
2159
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2160
|
-
});
|
|
2182
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2161
2183
|
break;
|
|
2162
2184
|
case ToggleButtonKeyDownHome:
|
|
2163
2185
|
changes = {
|
|
@@ -2191,7 +2213,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2191
2213
|
changes = _extends__default["default"]({
|
|
2192
2214
|
isOpen: false,
|
|
2193
2215
|
highlightedIndex: -1
|
|
2194
|
-
}, state.highlightedIndex >= 0 && {
|
|
2216
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2195
2217
|
selectedItem: props.items[state.highlightedIndex]
|
|
2196
2218
|
});
|
|
2197
2219
|
break;
|
|
@@ -2563,8 +2585,9 @@ function useSelect(userProps) {
|
|
|
2563
2585
|
var _latest$current = latest.current,
|
|
2564
2586
|
latestState = _latest$current.state,
|
|
2565
2587
|
latestProps = _latest$current.props;
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2588
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
2589
|
+
item = _getItemAndIndex[0],
|
|
2590
|
+
index = _getItemAndIndex[1];
|
|
2568
2591
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2569
2592
|
if (index === latestState.highlightedIndex) {
|
|
2570
2593
|
return;
|
|
@@ -2582,18 +2605,14 @@ function useSelect(userProps) {
|
|
|
2582
2605
|
index: index
|
|
2583
2606
|
});
|
|
2584
2607
|
};
|
|
2585
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2586
|
-
if (itemIndex < 0) {
|
|
2587
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
2588
|
-
}
|
|
2589
2608
|
var itemProps = _extends__default["default"]((_extends4 = {
|
|
2590
2609
|
disabled: disabled,
|
|
2591
2610
|
role: 'option',
|
|
2592
2611
|
'aria-selected': "" + (item === selectedItem),
|
|
2593
|
-
id: elementIds.getItemId(
|
|
2612
|
+
id: elementIds.getItemId(index)
|
|
2594
2613
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2595
2614
|
if (itemNode) {
|
|
2596
|
-
itemRefs.current[elementIds.getItemId(
|
|
2615
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
2597
2616
|
}
|
|
2598
2617
|
}), _extends4), rest);
|
|
2599
2618
|
if (!disabled) {
|
|
@@ -2604,7 +2623,7 @@ function useSelect(userProps) {
|
|
|
2604
2623
|
}
|
|
2605
2624
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
2606
2625
|
return itemProps;
|
|
2607
|
-
}, [latest,
|
|
2626
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2608
2627
|
return {
|
|
2609
2628
|
// prop getters.
|
|
2610
2629
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2776,6 +2795,7 @@ var defaultProps$1 = _extends__default["default"]({}, defaultProps$3, {
|
|
|
2776
2795
|
|
|
2777
2796
|
/* eslint-disable complexity */
|
|
2778
2797
|
function downshiftUseComboboxReducer(state, action) {
|
|
2798
|
+
var _props$items;
|
|
2779
2799
|
var type = action.type,
|
|
2780
2800
|
props = action.props,
|
|
2781
2801
|
altKey = action.altKey;
|
|
@@ -2804,13 +2824,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2804
2824
|
case InputKeyDownArrowUp:
|
|
2805
2825
|
if (state.isOpen) {
|
|
2806
2826
|
if (altKey) {
|
|
2807
|
-
changes =
|
|
2808
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2809
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2810
|
-
}, state.highlightedIndex >= 0 && {
|
|
2811
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2812
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2813
|
-
});
|
|
2827
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2814
2828
|
} else {
|
|
2815
2829
|
changes = {
|
|
2816
2830
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2824,13 +2838,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2824
2838
|
}
|
|
2825
2839
|
break;
|
|
2826
2840
|
case InputKeyDownEnter:
|
|
2827
|
-
changes =
|
|
2828
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2829
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2830
|
-
}, state.highlightedIndex >= 0 && {
|
|
2831
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2832
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2833
|
-
});
|
|
2841
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2834
2842
|
break;
|
|
2835
2843
|
case InputKeyDownEscape:
|
|
2836
2844
|
changes = _extends__default["default"]({
|
|
@@ -2865,7 +2873,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2865
2873
|
changes = _extends__default["default"]({
|
|
2866
2874
|
isOpen: false,
|
|
2867
2875
|
highlightedIndex: -1
|
|
2868
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2876
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2869
2877
|
selectedItem: props.items[state.highlightedIndex],
|
|
2870
2878
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2871
2879
|
});
|
|
@@ -3133,8 +3141,8 @@ function useCombobox(userProps) {
|
|
|
3133
3141
|
var getItemProps = preact.useCallback(function (_temp3) {
|
|
3134
3142
|
var _extends3, _ref4;
|
|
3135
3143
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3136
|
-
|
|
3137
|
-
|
|
3144
|
+
itemProp = _ref3.item,
|
|
3145
|
+
indexProp = _ref3.index,
|
|
3138
3146
|
_ref3$refKey = _ref3.refKey,
|
|
3139
3147
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3140
3148
|
ref = _ref3.ref,
|
|
@@ -3147,10 +3155,8 @@ function useCombobox(userProps) {
|
|
|
3147
3155
|
var _latest$current = latest.current,
|
|
3148
3156
|
latestProps = _latest$current.props,
|
|
3149
3157
|
latestState = _latest$current.state;
|
|
3150
|
-
var
|
|
3151
|
-
|
|
3152
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3153
|
-
}
|
|
3158
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3159
|
+
index = _getItemAndIndex[1];
|
|
3154
3160
|
var onSelectKey = 'onClick';
|
|
3155
3161
|
var customClickHandler = onClick;
|
|
3156
3162
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -3175,9 +3181,9 @@ function useCombobox(userProps) {
|
|
|
3175
3181
|
};
|
|
3176
3182
|
return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3177
3183
|
if (itemNode) {
|
|
3178
|
-
itemRefs.current[elementIds.getItemId(
|
|
3184
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3179
3185
|
}
|
|
3180
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
3186
|
+
}), _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), {
|
|
3181
3187
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3182
3188
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3183
3189
|
}, rest);
|
|
@@ -3717,14 +3723,13 @@ function useMultipleSelection(userProps) {
|
|
|
3717
3723
|
ref = _ref3.ref,
|
|
3718
3724
|
onClick = _ref3.onClick,
|
|
3719
3725
|
onKeyDown = _ref3.onKeyDown,
|
|
3720
|
-
|
|
3721
|
-
|
|
3726
|
+
selectedItemProp = _ref3.selectedItem,
|
|
3727
|
+
indexProp = _ref3.index,
|
|
3722
3728
|
rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded);
|
|
3723
3729
|
var latestState = latest.current.state;
|
|
3724
|
-
var
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
}
|
|
3730
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3731
|
+
index = _getItemAndIndex[1];
|
|
3732
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
3728
3733
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
3729
3734
|
dispatch({
|
|
3730
3735
|
type: SelectedItemClick,
|
|
@@ -3741,7 +3746,7 @@ function useMultipleSelection(userProps) {
|
|
|
3741
3746
|
if (selectedItemNode) {
|
|
3742
3747
|
selectedItemRefs.current.push(selectedItemNode);
|
|
3743
3748
|
}
|
|
3744
|
-
}), _extends2.tabIndex =
|
|
3749
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
3745
3750
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3746
3751
|
var getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
|
|
3747
3752
|
var _extends3;
|
|
@@ -1553,14 +1553,19 @@ function useElementIds(_ref) {
|
|
|
1553
1553
|
});
|
|
1554
1554
|
return elementIdsRef.current;
|
|
1555
1555
|
}
|
|
1556
|
-
function
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1556
|
+
function getItemAndIndex(itemProp, indexProp, items, errorMessage) {
|
|
1557
|
+
var item, index;
|
|
1558
|
+
if (itemProp === undefined) {
|
|
1559
|
+
if (indexProp === undefined) {
|
|
1560
|
+
throw new Error(errorMessage);
|
|
1561
|
+
}
|
|
1562
|
+
item = items[indexProp];
|
|
1563
|
+
index = indexProp;
|
|
1564
|
+
} else {
|
|
1565
|
+
index = indexProp === undefined ? items.indexOf(itemProp) : indexProp;
|
|
1566
|
+
item = itemProp;
|
|
1562
1567
|
}
|
|
1563
|
-
return
|
|
1568
|
+
return [item, index];
|
|
1564
1569
|
}
|
|
1565
1570
|
function itemToString(item) {
|
|
1566
1571
|
return item ? String(item) : '';
|
|
@@ -1889,6 +1894,32 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1889
1894
|
};
|
|
1890
1895
|
}
|
|
1891
1896
|
|
|
1897
|
+
/**
|
|
1898
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1899
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1900
|
+
* @param {Object} props The useCombobox props.
|
|
1901
|
+
* @param {number} highlightedIndex The index from the state.
|
|
1902
|
+
* @param {boolean} inputValue Also return the input value for state.
|
|
1903
|
+
* @returns The changes for the state.
|
|
1904
|
+
*/
|
|
1905
|
+
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1906
|
+
var _props$items;
|
|
1907
|
+
if (inputValue === void 0) {
|
|
1908
|
+
inputValue = true;
|
|
1909
|
+
}
|
|
1910
|
+
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1911
|
+
return _extends({
|
|
1912
|
+
isOpen: false,
|
|
1913
|
+
highlightedIndex: -1
|
|
1914
|
+
}, shouldSelect && _extends({
|
|
1915
|
+
selectedItem: props.items[highlightedIndex],
|
|
1916
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
1917
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
1918
|
+
}, inputValue && {
|
|
1919
|
+
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1920
|
+
}));
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1892
1923
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1893
1924
|
var type = action.type,
|
|
1894
1925
|
props = action.props;
|
|
@@ -2080,6 +2111,7 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2080
2111
|
|
|
2081
2112
|
/* eslint-disable complexity */
|
|
2082
2113
|
function downshiftSelectReducer(state, action) {
|
|
2114
|
+
var _props$items;
|
|
2083
2115
|
var type = action.type,
|
|
2084
2116
|
props = action.props,
|
|
2085
2117
|
altKey = action.altKey;
|
|
@@ -2122,12 +2154,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2122
2154
|
break;
|
|
2123
2155
|
case ToggleButtonKeyDownArrowUp:
|
|
2124
2156
|
if (state.isOpen && altKey) {
|
|
2125
|
-
changes =
|
|
2126
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2127
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2128
|
-
}, state.highlightedIndex >= 0 && {
|
|
2129
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2130
|
-
});
|
|
2157
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2131
2158
|
} else {
|
|
2132
2159
|
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2133
2160
|
changes = {
|
|
@@ -2139,12 +2166,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2139
2166
|
// only triggered when menu is open.
|
|
2140
2167
|
case ToggleButtonKeyDownEnter:
|
|
2141
2168
|
case ToggleButtonKeyDownSpaceButton:
|
|
2142
|
-
changes =
|
|
2143
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2144
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2145
|
-
}, state.highlightedIndex >= 0 && {
|
|
2146
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2147
|
-
});
|
|
2169
|
+
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2148
2170
|
break;
|
|
2149
2171
|
case ToggleButtonKeyDownHome:
|
|
2150
2172
|
changes = {
|
|
@@ -2178,7 +2200,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2178
2200
|
changes = _extends({
|
|
2179
2201
|
isOpen: false,
|
|
2180
2202
|
highlightedIndex: -1
|
|
2181
|
-
}, state.highlightedIndex >= 0 && {
|
|
2203
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && {
|
|
2182
2204
|
selectedItem: props.items[state.highlightedIndex]
|
|
2183
2205
|
});
|
|
2184
2206
|
break;
|
|
@@ -2550,8 +2572,9 @@ function useSelect(userProps) {
|
|
|
2550
2572
|
var _latest$current = latest.current,
|
|
2551
2573
|
latestState = _latest$current.state,
|
|
2552
2574
|
latestProps = _latest$current.props;
|
|
2553
|
-
var
|
|
2554
|
-
|
|
2575
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
2576
|
+
item = _getItemAndIndex[0],
|
|
2577
|
+
index = _getItemAndIndex[1];
|
|
2555
2578
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2556
2579
|
if (index === latestState.highlightedIndex) {
|
|
2557
2580
|
return;
|
|
@@ -2569,18 +2592,14 @@ function useSelect(userProps) {
|
|
|
2569
2592
|
index: index
|
|
2570
2593
|
});
|
|
2571
2594
|
};
|
|
2572
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2573
|
-
if (itemIndex < 0) {
|
|
2574
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
2575
|
-
}
|
|
2576
2595
|
var itemProps = _extends((_extends4 = {
|
|
2577
2596
|
disabled: disabled,
|
|
2578
2597
|
role: 'option',
|
|
2579
2598
|
'aria-selected': "" + (item === selectedItem),
|
|
2580
|
-
id: elementIds.getItemId(
|
|
2599
|
+
id: elementIds.getItemId(index)
|
|
2581
2600
|
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2582
2601
|
if (itemNode) {
|
|
2583
|
-
itemRefs.current[elementIds.getItemId(
|
|
2602
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
2584
2603
|
}
|
|
2585
2604
|
}), _extends4), rest);
|
|
2586
2605
|
if (!disabled) {
|
|
@@ -2591,7 +2610,7 @@ function useSelect(userProps) {
|
|
|
2591
2610
|
}
|
|
2592
2611
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
2593
2612
|
return itemProps;
|
|
2594
|
-
}, [latest,
|
|
2613
|
+
}, [latest, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2595
2614
|
return {
|
|
2596
2615
|
// prop getters.
|
|
2597
2616
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2763,6 +2782,7 @@ var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
|
2763
2782
|
|
|
2764
2783
|
/* eslint-disable complexity */
|
|
2765
2784
|
function downshiftUseComboboxReducer(state, action) {
|
|
2785
|
+
var _props$items;
|
|
2766
2786
|
var type = action.type,
|
|
2767
2787
|
props = action.props,
|
|
2768
2788
|
altKey = action.altKey;
|
|
@@ -2791,13 +2811,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2791
2811
|
case InputKeyDownArrowUp:
|
|
2792
2812
|
if (state.isOpen) {
|
|
2793
2813
|
if (altKey) {
|
|
2794
|
-
changes =
|
|
2795
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2796
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2797
|
-
}, state.highlightedIndex >= 0 && {
|
|
2798
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2799
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2800
|
-
});
|
|
2814
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2801
2815
|
} else {
|
|
2802
2816
|
changes = {
|
|
2803
2817
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2811,13 +2825,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2811
2825
|
}
|
|
2812
2826
|
break;
|
|
2813
2827
|
case InputKeyDownEnter:
|
|
2814
|
-
changes =
|
|
2815
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2816
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2817
|
-
}, state.highlightedIndex >= 0 && {
|
|
2818
|
-
selectedItem: props.items[state.highlightedIndex],
|
|
2819
|
-
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2820
|
-
});
|
|
2828
|
+
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2821
2829
|
break;
|
|
2822
2830
|
case InputKeyDownEscape:
|
|
2823
2831
|
changes = _extends({
|
|
@@ -2852,7 +2860,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2852
2860
|
changes = _extends({
|
|
2853
2861
|
isOpen: false,
|
|
2854
2862
|
highlightedIndex: -1
|
|
2855
|
-
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
2863
|
+
}, state.highlightedIndex >= 0 && ((_props$items = props.items) == null ? void 0 : _props$items.length) && action.selectItem && {
|
|
2856
2864
|
selectedItem: props.items[state.highlightedIndex],
|
|
2857
2865
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2858
2866
|
});
|
|
@@ -3120,8 +3128,8 @@ function useCombobox(userProps) {
|
|
|
3120
3128
|
var getItemProps = useCallback(function (_temp3) {
|
|
3121
3129
|
var _extends3, _ref4;
|
|
3122
3130
|
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3123
|
-
|
|
3124
|
-
|
|
3131
|
+
itemProp = _ref3.item,
|
|
3132
|
+
indexProp = _ref3.index,
|
|
3125
3133
|
_ref3$refKey = _ref3.refKey,
|
|
3126
3134
|
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3127
3135
|
ref = _ref3.ref,
|
|
@@ -3134,10 +3142,8 @@ function useCombobox(userProps) {
|
|
|
3134
3142
|
var _latest$current = latest.current,
|
|
3135
3143
|
latestProps = _latest$current.props,
|
|
3136
3144
|
latestState = _latest$current.state;
|
|
3137
|
-
var
|
|
3138
|
-
|
|
3139
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3140
|
-
}
|
|
3145
|
+
var _getItemAndIndex = getItemAndIndex(itemProp, indexProp, latestProps.items, 'Pass either item or index to getItemProps!'),
|
|
3146
|
+
index = _getItemAndIndex[1];
|
|
3141
3147
|
var onSelectKey = 'onClick';
|
|
3142
3148
|
var customClickHandler = onClick;
|
|
3143
3149
|
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
@@ -3162,9 +3168,9 @@ function useCombobox(userProps) {
|
|
|
3162
3168
|
};
|
|
3163
3169
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3164
3170
|
if (itemNode) {
|
|
3165
|
-
itemRefs.current[elementIds.getItemId(
|
|
3171
|
+
itemRefs.current[elementIds.getItemId(index)] = itemNode;
|
|
3166
3172
|
}
|
|
3167
|
-
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (
|
|
3173
|
+
}), _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), {
|
|
3168
3174
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3169
3175
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3170
3176
|
}, rest);
|
|
@@ -3704,14 +3710,13 @@ function useMultipleSelection(userProps) {
|
|
|
3704
3710
|
ref = _ref3.ref,
|
|
3705
3711
|
onClick = _ref3.onClick,
|
|
3706
3712
|
onKeyDown = _ref3.onKeyDown,
|
|
3707
|
-
|
|
3708
|
-
|
|
3713
|
+
selectedItemProp = _ref3.selectedItem,
|
|
3714
|
+
indexProp = _ref3.index,
|
|
3709
3715
|
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
3710
3716
|
var latestState = latest.current.state;
|
|
3711
|
-
var
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
}
|
|
3717
|
+
var _getItemAndIndex = getItemAndIndex(selectedItemProp, indexProp, latestState.selectedItems, 'Pass either item or index to getSelectedItemProps!'),
|
|
3718
|
+
index = _getItemAndIndex[1];
|
|
3719
|
+
var isFocusable = index > -1 && index === latestState.activeIndex;
|
|
3715
3720
|
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
3716
3721
|
dispatch({
|
|
3717
3722
|
type: SelectedItemClick,
|
|
@@ -3728,7 +3733,7 @@ function useMultipleSelection(userProps) {
|
|
|
3728
3733
|
if (selectedItemNode) {
|
|
3729
3734
|
selectedItemRefs.current.push(selectedItemNode);
|
|
3730
3735
|
}
|
|
3731
|
-
}), _extends2.tabIndex =
|
|
3736
|
+
}), _extends2.tabIndex = isFocusable ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
3732
3737
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3733
3738
|
var getDropdownProps = useCallback(function (_temp2, _temp3) {
|
|
3734
3739
|
var _extends3;
|