downshift 9.0.4 → 9.0.5
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 +254 -234
- package/dist/downshift.esm.js +92 -64
- package/dist/downshift.native.cjs.js +254 -234
- package/dist/downshift.nativeweb.cjs.js +254 -234
- package/dist/downshift.umd.js +133 -108
- 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 +7 -0
- package/package.json +37 -37
- package/preact/dist/downshift.cjs.js +216 -196
- package/preact/dist/downshift.esm.js +92 -64
- package/preact/dist/downshift.umd.js +187 -163
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +2 -2
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWith
|
|
|
2
2
|
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
3
3
|
import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
|
-
import React, { cloneElement, Component, useRef, useEffect,
|
|
5
|
+
import React, { cloneElement, Component, useRef, useEffect, useLayoutEffect, useCallback, useReducer, useMemo } from 'react';
|
|
6
6
|
import { isForwardRef } from 'react-is';
|
|
7
7
|
import { compute } from 'compute-scroll-into-view';
|
|
8
8
|
import { __assign } from 'tslib';
|
|
@@ -470,23 +470,23 @@ var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend_
|
|
|
470
470
|
|
|
471
471
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
472
472
|
__proto__: null,
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
blurButton: blurButton,
|
|
474
|
+
blurInput: blurInput,
|
|
475
|
+
changeInput: changeInput,
|
|
476
|
+
clickButton: clickButton,
|
|
477
|
+
clickItem: clickItem,
|
|
478
|
+
controlledPropUpdatedSelectedItem: controlledPropUpdatedSelectedItem,
|
|
475
479
|
itemMouseEnter: itemMouseEnter,
|
|
476
|
-
keyDownArrowUp: keyDownArrowUp,
|
|
477
480
|
keyDownArrowDown: keyDownArrowDown,
|
|
478
|
-
|
|
481
|
+
keyDownArrowUp: keyDownArrowUp,
|
|
482
|
+
keyDownEnd: keyDownEnd,
|
|
479
483
|
keyDownEnter: keyDownEnter,
|
|
484
|
+
keyDownEscape: keyDownEscape,
|
|
480
485
|
keyDownHome: keyDownHome,
|
|
481
|
-
keyDownEnd: keyDownEnd,
|
|
482
|
-
clickItem: clickItem,
|
|
483
|
-
blurInput: blurInput,
|
|
484
|
-
changeInput: changeInput,
|
|
485
486
|
keyDownSpaceButton: keyDownSpaceButton,
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
touchEnd: touchEnd
|
|
487
|
+
mouseUp: mouseUp,
|
|
488
|
+
touchEnd: touchEnd,
|
|
489
|
+
unknown: unknown
|
|
490
490
|
});
|
|
491
491
|
|
|
492
492
|
var _excluded$3 = ["refKey", "ref"],
|
|
@@ -1772,7 +1772,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1772
1772
|
function getInitialState$2(props) {
|
|
1773
1773
|
var selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1774
1774
|
var isOpen = getInitialValue$1(props, 'isOpen');
|
|
1775
|
-
var highlightedIndex =
|
|
1775
|
+
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
1776
1776
|
var inputValue = getInitialValue$1(props, 'inputValue');
|
|
1777
1777
|
return {
|
|
1778
1778
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
@@ -1796,10 +1796,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1796
1796
|
}
|
|
1797
1797
|
|
|
1798
1798
|
// initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
1799
|
-
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex])) {
|
|
1799
|
+
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1800
1800
|
return initialHighlightedIndex;
|
|
1801
1801
|
}
|
|
1802
|
-
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex])) {
|
|
1802
|
+
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1803
1803
|
return defaultHighlightedIndex;
|
|
1804
1804
|
}
|
|
1805
1805
|
if (selectedItem) {
|
|
@@ -1807,10 +1807,10 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1807
1807
|
return itemToKey(selectedItem) === itemToKey(item);
|
|
1808
1808
|
});
|
|
1809
1809
|
}
|
|
1810
|
-
if (offset < 0 && !isItemDisabled(items[items.length - 1])) {
|
|
1810
|
+
if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1811
1811
|
return items.length - 1;
|
|
1812
1812
|
}
|
|
1813
|
-
if (offset > 0 && !isItemDisabled(items[0])) {
|
|
1813
|
+
if (offset > 0 && !isItemDisabled(items[0], 0)) {
|
|
1814
1814
|
return 0;
|
|
1815
1815
|
}
|
|
1816
1816
|
return -1;
|
|
@@ -2058,6 +2058,34 @@ function useIsInitialMount() {
|
|
|
2058
2058
|
return isInitialMountRef.current;
|
|
2059
2059
|
}
|
|
2060
2060
|
|
|
2061
|
+
/**
|
|
2062
|
+
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
2063
|
+
*
|
|
2064
|
+
* @param {Object} props Props from useCombobox or useSelect.
|
|
2065
|
+
* @returns {number} The highlighted index.
|
|
2066
|
+
*/
|
|
2067
|
+
function getDefaultHighlightedIndex(props) {
|
|
2068
|
+
var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex');
|
|
2069
|
+
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2070
|
+
return -1;
|
|
2071
|
+
}
|
|
2072
|
+
return highlightedIndex;
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
/**
|
|
2076
|
+
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
2077
|
+
*
|
|
2078
|
+
* @param {Object} props Props from useCombobox or useSelect.
|
|
2079
|
+
* @returns {number} The highlighted index.
|
|
2080
|
+
*/
|
|
2081
|
+
function getInitialHighlightedIndex(props) {
|
|
2082
|
+
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
2083
|
+
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2084
|
+
return -1;
|
|
2085
|
+
}
|
|
2086
|
+
return highlightedIndex;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2061
2089
|
// Shared between all exports.
|
|
2062
2090
|
var commonPropTypes = {
|
|
2063
2091
|
environment: PropTypes.shape({
|
|
@@ -2135,7 +2163,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2135
2163
|
break;
|
|
2136
2164
|
case stateChangeTypes.FunctionSetHighlightedIndex:
|
|
2137
2165
|
changes = {
|
|
2138
|
-
highlightedIndex: action.highlightedIndex
|
|
2166
|
+
highlightedIndex: props.isItemDisabled(props.items[action.highlightedIndex], action.highlightedIndex) ? -1 : action.highlightedIndex
|
|
2139
2167
|
};
|
|
2140
2168
|
break;
|
|
2141
2169
|
case stateChangeTypes.FunctionSetInputValue:
|
|
@@ -2145,7 +2173,7 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2145
2173
|
break;
|
|
2146
2174
|
case stateChangeTypes.FunctionReset:
|
|
2147
2175
|
changes = {
|
|
2148
|
-
highlightedIndex:
|
|
2176
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2149
2177
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2150
2178
|
selectedItem: getDefaultValue$1(props, 'selectedItem'),
|
|
2151
2179
|
inputValue: getDefaultValue$1(props, 'inputValue')
|
|
@@ -2211,28 +2239,28 @@ var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset_
|
|
|
2211
2239
|
|
|
2212
2240
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2213
2241
|
__proto__: null,
|
|
2242
|
+
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2243
|
+
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2244
|
+
FunctionReset: FunctionReset$2,
|
|
2245
|
+
FunctionSelectItem: FunctionSelectItem$1,
|
|
2246
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
|
|
2247
|
+
FunctionSetInputValue: FunctionSetInputValue$1,
|
|
2248
|
+
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2249
|
+
ItemClick: ItemClick$1,
|
|
2250
|
+
ItemMouseMove: ItemMouseMove$1,
|
|
2251
|
+
MenuMouseLeave: MenuMouseLeave$1,
|
|
2252
|
+
ToggleButtonBlur: ToggleButtonBlur,
|
|
2214
2253
|
ToggleButtonClick: ToggleButtonClick$1,
|
|
2215
2254
|
ToggleButtonKeyDownArrowDown: ToggleButtonKeyDownArrowDown,
|
|
2216
2255
|
ToggleButtonKeyDownArrowUp: ToggleButtonKeyDownArrowUp,
|
|
2217
2256
|
ToggleButtonKeyDownCharacter: ToggleButtonKeyDownCharacter,
|
|
2218
|
-
ToggleButtonKeyDownEscape: ToggleButtonKeyDownEscape,
|
|
2219
|
-
ToggleButtonKeyDownHome: ToggleButtonKeyDownHome,
|
|
2220
2257
|
ToggleButtonKeyDownEnd: ToggleButtonKeyDownEnd,
|
|
2221
2258
|
ToggleButtonKeyDownEnter: ToggleButtonKeyDownEnter,
|
|
2222
|
-
|
|
2223
|
-
|
|
2259
|
+
ToggleButtonKeyDownEscape: ToggleButtonKeyDownEscape,
|
|
2260
|
+
ToggleButtonKeyDownHome: ToggleButtonKeyDownHome,
|
|
2224
2261
|
ToggleButtonKeyDownPageDown: ToggleButtonKeyDownPageDown,
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
ItemMouseMove: ItemMouseMove$1,
|
|
2228
|
-
ItemClick: ItemClick$1,
|
|
2229
|
-
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2230
|
-
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2231
|
-
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
2232
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex$1,
|
|
2233
|
-
FunctionSelectItem: FunctionSelectItem$1,
|
|
2234
|
-
FunctionSetInputValue: FunctionSetInputValue$1,
|
|
2235
|
-
FunctionReset: FunctionReset$2
|
|
2262
|
+
ToggleButtonKeyDownPageUp: ToggleButtonKeyDownPageUp,
|
|
2263
|
+
ToggleButtonKeyDownSpaceButton: ToggleButtonKeyDownSpaceButton
|
|
2236
2264
|
});
|
|
2237
2265
|
|
|
2238
2266
|
/* eslint-disable complexity */
|
|
@@ -2246,7 +2274,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2246
2274
|
case ItemClick$1:
|
|
2247
2275
|
changes = {
|
|
2248
2276
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2249
|
-
highlightedIndex:
|
|
2277
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2250
2278
|
selectedItem: props.items[action.index]
|
|
2251
2279
|
};
|
|
2252
2280
|
break;
|
|
@@ -2762,29 +2790,29 @@ var ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ?
|
|
|
2762
2790
|
|
|
2763
2791
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2764
2792
|
__proto__: null,
|
|
2793
|
+
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem,
|
|
2794
|
+
FunctionCloseMenu: FunctionCloseMenu,
|
|
2795
|
+
FunctionOpenMenu: FunctionOpenMenu,
|
|
2796
|
+
FunctionReset: FunctionReset$1,
|
|
2797
|
+
FunctionSelectItem: FunctionSelectItem,
|
|
2798
|
+
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2799
|
+
FunctionSetInputValue: FunctionSetInputValue,
|
|
2800
|
+
FunctionToggleMenu: FunctionToggleMenu,
|
|
2801
|
+
InputBlur: InputBlur,
|
|
2802
|
+
InputChange: InputChange,
|
|
2803
|
+
InputClick: InputClick,
|
|
2765
2804
|
InputKeyDownArrowDown: InputKeyDownArrowDown,
|
|
2766
2805
|
InputKeyDownArrowUp: InputKeyDownArrowUp,
|
|
2806
|
+
InputKeyDownEnd: InputKeyDownEnd,
|
|
2807
|
+
InputKeyDownEnter: InputKeyDownEnter,
|
|
2767
2808
|
InputKeyDownEscape: InputKeyDownEscape,
|
|
2768
2809
|
InputKeyDownHome: InputKeyDownHome,
|
|
2769
|
-
InputKeyDownEnd: InputKeyDownEnd,
|
|
2770
|
-
InputKeyDownPageUp: InputKeyDownPageUp,
|
|
2771
2810
|
InputKeyDownPageDown: InputKeyDownPageDown,
|
|
2772
|
-
|
|
2773
|
-
InputChange: InputChange,
|
|
2774
|
-
InputBlur: InputBlur,
|
|
2775
|
-
InputClick: InputClick,
|
|
2776
|
-
MenuMouseLeave: MenuMouseLeave,
|
|
2777
|
-
ItemMouseMove: ItemMouseMove,
|
|
2811
|
+
InputKeyDownPageUp: InputKeyDownPageUp,
|
|
2778
2812
|
ItemClick: ItemClick,
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
FunctionCloseMenu: FunctionCloseMenu,
|
|
2783
|
-
FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
|
2784
|
-
FunctionSelectItem: FunctionSelectItem,
|
|
2785
|
-
FunctionSetInputValue: FunctionSetInputValue,
|
|
2786
|
-
FunctionReset: FunctionReset$1,
|
|
2787
|
-
ControlledPropUpdatedSelectedItem: ControlledPropUpdatedSelectedItem
|
|
2813
|
+
ItemMouseMove: ItemMouseMove,
|
|
2814
|
+
MenuMouseLeave: MenuMouseLeave,
|
|
2815
|
+
ToggleButtonClick: ToggleButtonClick
|
|
2788
2816
|
});
|
|
2789
2817
|
|
|
2790
2818
|
function getInitialState$1(props) {
|
|
@@ -2872,7 +2900,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2872
2900
|
case ItemClick:
|
|
2873
2901
|
changes = {
|
|
2874
2902
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2875
|
-
highlightedIndex:
|
|
2903
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2876
2904
|
selectedItem: props.items[action.index],
|
|
2877
2905
|
inputValue: props.itemToString(props.items[action.index])
|
|
2878
2906
|
};
|
|
@@ -2949,7 +2977,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2949
2977
|
case InputChange:
|
|
2950
2978
|
changes = {
|
|
2951
2979
|
isOpen: true,
|
|
2952
|
-
highlightedIndex:
|
|
2980
|
+
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2953
2981
|
inputValue: action.inputValue
|
|
2954
2982
|
};
|
|
2955
2983
|
break;
|
|
@@ -3507,19 +3535,19 @@ var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__'
|
|
|
3507
3535
|
|
|
3508
3536
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3509
3537
|
__proto__: null,
|
|
3510
|
-
SelectedItemClick: SelectedItemClick,
|
|
3511
|
-
SelectedItemKeyDownDelete: SelectedItemKeyDownDelete,
|
|
3512
|
-
SelectedItemKeyDownBackspace: SelectedItemKeyDownBackspace,
|
|
3513
|
-
SelectedItemKeyDownNavigationNext: SelectedItemKeyDownNavigationNext,
|
|
3514
|
-
SelectedItemKeyDownNavigationPrevious: SelectedItemKeyDownNavigationPrevious,
|
|
3515
|
-
DropdownKeyDownNavigationPrevious: DropdownKeyDownNavigationPrevious,
|
|
3516
|
-
DropdownKeyDownBackspace: DropdownKeyDownBackspace,
|
|
3517
3538
|
DropdownClick: DropdownClick,
|
|
3539
|
+
DropdownKeyDownBackspace: DropdownKeyDownBackspace,
|
|
3540
|
+
DropdownKeyDownNavigationPrevious: DropdownKeyDownNavigationPrevious,
|
|
3518
3541
|
FunctionAddSelectedItem: FunctionAddSelectedItem,
|
|
3519
3542
|
FunctionRemoveSelectedItem: FunctionRemoveSelectedItem,
|
|
3520
|
-
|
|
3543
|
+
FunctionReset: FunctionReset,
|
|
3521
3544
|
FunctionSetActiveIndex: FunctionSetActiveIndex,
|
|
3522
|
-
|
|
3545
|
+
FunctionSetSelectedItems: FunctionSetSelectedItems,
|
|
3546
|
+
SelectedItemClick: SelectedItemClick,
|
|
3547
|
+
SelectedItemKeyDownBackspace: SelectedItemKeyDownBackspace,
|
|
3548
|
+
SelectedItemKeyDownDelete: SelectedItemKeyDownDelete,
|
|
3549
|
+
SelectedItemKeyDownNavigationNext: SelectedItemKeyDownNavigationNext,
|
|
3550
|
+
SelectedItemKeyDownNavigationPrevious: SelectedItemKeyDownNavigationPrevious
|
|
3523
3551
|
});
|
|
3524
3552
|
|
|
3525
3553
|
/* eslint-disable complexity */
|