downshift 5.3.0-alpha → 5.4.2
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/README.md +1 -1
- package/dist/downshift.cjs.js +941 -738
- package/dist/downshift.esm.js +942 -739
- package/dist/downshift.native.cjs.js +956 -753
- package/dist/downshift.umd.js +929 -738
- 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/package.json +1 -1
- package/preact/dist/downshift.cjs.js +941 -738
- package/preact/dist/downshift.esm.js +942 -739
- package/preact/dist/downshift.umd.js +929 -738
- 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.umd.js
CHANGED
|
@@ -1326,7 +1326,7 @@
|
|
|
1326
1326
|
|
|
1327
1327
|
|
|
1328
1328
|
function scrollIntoView(node, menuNode) {
|
|
1329
|
-
if (node
|
|
1329
|
+
if (!node) {
|
|
1330
1330
|
return;
|
|
1331
1331
|
}
|
|
1332
1332
|
|
|
@@ -1627,6 +1627,10 @@
|
|
|
1627
1627
|
circular = true;
|
|
1628
1628
|
}
|
|
1629
1629
|
|
|
1630
|
+
if (itemCount === 0) {
|
|
1631
|
+
return -1;
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1630
1634
|
var itemsLastIndex = itemCount - 1;
|
|
1631
1635
|
|
|
1632
1636
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
@@ -1705,6 +1709,19 @@
|
|
|
1705
1709
|
});
|
|
1706
1710
|
}
|
|
1707
1711
|
|
|
1712
|
+
function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
1713
|
+
var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
|
|
1714
|
+
Object.keys(state).forEach(function (propKey) {
|
|
1715
|
+
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
1716
|
+
// eslint-disable-next-line no-console
|
|
1717
|
+
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
1718
|
+
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
1719
|
+
// eslint-disable-next-line no-console
|
|
1720
|
+
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
1721
|
+
}
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1708
1725
|
var cleanupStatus = debounce(function () {
|
|
1709
1726
|
getStatusDiv().textContent = '';
|
|
1710
1727
|
}, 500);
|
|
@@ -1799,8 +1816,12 @@
|
|
|
1799
1816
|
touchEnd: touchEnd
|
|
1800
1817
|
});
|
|
1801
1818
|
|
|
1802
|
-
var Downshift =
|
|
1803
|
-
|
|
1819
|
+
var Downshift =
|
|
1820
|
+
/*#__PURE__*/
|
|
1821
|
+
function () {
|
|
1822
|
+
var Downshift =
|
|
1823
|
+
/*#__PURE__*/
|
|
1824
|
+
function (_Component) {
|
|
1804
1825
|
_inheritsLoose(Downshift, _Component);
|
|
1805
1826
|
|
|
1806
1827
|
function Downshift(_props) {
|
|
@@ -1900,7 +1921,7 @@
|
|
|
1900
1921
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
1901
1922
|
|
|
1902
1923
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
1903
|
-
_this.props.onInputValueChange(stateToSet.inputValue, _extends(
|
|
1924
|
+
_this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
|
|
1904
1925
|
}
|
|
1905
1926
|
|
|
1906
1927
|
return _this.setState(function (state) {
|
|
@@ -1950,7 +1971,7 @@
|
|
|
1950
1971
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
1951
1972
|
|
|
1952
1973
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
1953
|
-
_this.props.onInputValueChange(newStateToSet.inputValue, _extends(
|
|
1974
|
+
_this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
|
|
1954
1975
|
}
|
|
1955
1976
|
|
|
1956
1977
|
return nextState;
|
|
@@ -2105,7 +2126,7 @@
|
|
|
2105
2126
|
});
|
|
2106
2127
|
}
|
|
2107
2128
|
};
|
|
2108
|
-
_this.buttonKeyDownHandlers = _extends(
|
|
2129
|
+
_this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2109
2130
|
' ': function _(event) {
|
|
2110
2131
|
event.preventDefault();
|
|
2111
2132
|
this.toggleMenu({
|
|
@@ -2113,7 +2134,7 @@
|
|
|
2113
2134
|
});
|
|
2114
2135
|
}
|
|
2115
2136
|
});
|
|
2116
|
-
_this.inputKeyDownHandlers = _extends(
|
|
2137
|
+
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2117
2138
|
Home: function Home(event) {
|
|
2118
2139
|
var _this4 = this;
|
|
2119
2140
|
|
|
@@ -2177,13 +2198,13 @@
|
|
|
2177
2198
|
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
2178
2199
|
};
|
|
2179
2200
|
var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
2180
|
-
return _extends(
|
|
2201
|
+
return _extends({
|
|
2181
2202
|
type: 'button',
|
|
2182
2203
|
role: 'button',
|
|
2183
2204
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
2184
2205
|
'aria-haspopup': true,
|
|
2185
2206
|
'data-toggle': true
|
|
2186
|
-
}, eventHandlers
|
|
2207
|
+
}, eventHandlers, {}, rest);
|
|
2187
2208
|
};
|
|
2188
2209
|
|
|
2189
2210
|
_this.buttonHandleKeyUp = function (event) {
|
|
@@ -2269,7 +2290,7 @@
|
|
|
2269
2290
|
/* istanbul ignore if (react-native) */
|
|
2270
2291
|
|
|
2271
2292
|
|
|
2272
|
-
return _extends(
|
|
2293
|
+
return _extends({
|
|
2273
2294
|
'aria-autocomplete': 'list',
|
|
2274
2295
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
2275
2296
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -2279,7 +2300,7 @@
|
|
|
2279
2300
|
autoComplete: 'off',
|
|
2280
2301
|
value: inputValue,
|
|
2281
2302
|
id: _this.inputId
|
|
2282
|
-
}, eventHandlers
|
|
2303
|
+
}, eventHandlers, {}, rest);
|
|
2283
2304
|
};
|
|
2284
2305
|
|
|
2285
2306
|
_this.inputHandleKeyDown = function (event) {
|
|
@@ -2397,11 +2418,11 @@
|
|
|
2397
2418
|
var eventHandlers = rest.disabled ? {
|
|
2398
2419
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
2399
2420
|
} : enabledEventHandlers;
|
|
2400
|
-
return _extends(
|
|
2421
|
+
return _extends({
|
|
2401
2422
|
id: _this.getItemId(index),
|
|
2402
2423
|
role: 'option',
|
|
2403
2424
|
'aria-selected': _this.getState().highlightedIndex === index
|
|
2404
|
-
}, eventHandlers
|
|
2425
|
+
}, eventHandlers, {}, rest);
|
|
2405
2426
|
};
|
|
2406
2427
|
|
|
2407
2428
|
_this.clearItems = function () {
|
|
@@ -2434,11 +2455,11 @@
|
|
|
2434
2455
|
|
|
2435
2456
|
_this.internalSetState(function (_ref9) {
|
|
2436
2457
|
var isOpen = _ref9.isOpen;
|
|
2437
|
-
return _extends(
|
|
2458
|
+
return _extends({
|
|
2438
2459
|
isOpen: !isOpen
|
|
2439
2460
|
}, isOpen && {
|
|
2440
2461
|
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2441
|
-
}
|
|
2462
|
+
}, {}, otherStateToSet);
|
|
2442
2463
|
}, function () {
|
|
2443
2464
|
var _this$getState7 = _this.getState(),
|
|
2444
2465
|
isOpen = _this$getState7.isOpen,
|
|
@@ -2745,7 +2766,7 @@
|
|
|
2745
2766
|
};
|
|
2746
2767
|
|
|
2747
2768
|
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
2748
|
-
validateControlledUnchanged(prevProps, this.props);
|
|
2769
|
+
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
2749
2770
|
/* istanbul ignore if (react-native) */
|
|
2750
2771
|
|
|
2751
2772
|
if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
@@ -2935,19 +2956,6 @@
|
|
|
2935
2956
|
}
|
|
2936
2957
|
}
|
|
2937
2958
|
|
|
2938
|
-
function validateControlledUnchanged(prevProps, nextProps) {
|
|
2939
|
-
var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
|
|
2940
|
-
['selectedItem', 'isOpen', 'inputValue', 'highlightedIndex'].forEach(function (propKey) {
|
|
2941
|
-
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
2942
|
-
// eslint-disable-next-line no-console
|
|
2943
|
-
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
2944
|
-
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
2945
|
-
// eslint-disable-next-line no-console
|
|
2946
|
-
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
2947
|
-
}
|
|
2948
|
-
});
|
|
2949
|
-
}
|
|
2950
|
-
|
|
2951
2959
|
var dropdownDefaultStateValues = {
|
|
2952
2960
|
highlightedIndex: -1,
|
|
2953
2961
|
isOpen: false,
|
|
@@ -3064,6 +3072,16 @@
|
|
|
3064
3072
|
function capitalizeString(string) {
|
|
3065
3073
|
return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
|
|
3066
3074
|
}
|
|
3075
|
+
function useLatestRef(val) {
|
|
3076
|
+
var ref = react.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
|
|
3077
|
+
// the value during render (so it's not idempotent). However, the places this
|
|
3078
|
+
// hook is used is to support memoizing callbacks which will be called
|
|
3079
|
+
// *during* render, so we need the latest values *during* render.
|
|
3080
|
+
// If not for this, then we'd probably want to use useLayoutEffect instead.
|
|
3081
|
+
|
|
3082
|
+
ref.current = val;
|
|
3083
|
+
return ref;
|
|
3084
|
+
}
|
|
3067
3085
|
/**
|
|
3068
3086
|
* Computes the controlled state using a the previous state, props,
|
|
3069
3087
|
* two reducers, one from downshift and an optional one from the user.
|
|
@@ -3082,7 +3100,7 @@
|
|
|
3082
3100
|
actionRef.current = action;
|
|
3083
3101
|
state = getState(state, action.props);
|
|
3084
3102
|
var changes = reducer(state, action);
|
|
3085
|
-
var newState = action.props.stateReducer(state, _extends(
|
|
3103
|
+
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
3086
3104
|
changes: changes
|
|
3087
3105
|
}));
|
|
3088
3106
|
return newState;
|
|
@@ -3092,6 +3110,12 @@
|
|
|
3092
3110
|
state = _useReducer[0],
|
|
3093
3111
|
dispatch = _useReducer[1];
|
|
3094
3112
|
|
|
3113
|
+
var propsRef = useLatestRef(props);
|
|
3114
|
+
var dispatchWithProps = react.useCallback(function (action) {
|
|
3115
|
+
return dispatch(_extends({
|
|
3116
|
+
props: propsRef.current
|
|
3117
|
+
}, action));
|
|
3118
|
+
}, [propsRef]);
|
|
3095
3119
|
var action = actionRef.current;
|
|
3096
3120
|
react.useEffect(function () {
|
|
3097
3121
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
@@ -3100,11 +3124,7 @@
|
|
|
3100
3124
|
|
|
3101
3125
|
prevStateRef.current = state;
|
|
3102
3126
|
}, [state, props, action]);
|
|
3103
|
-
return [state,
|
|
3104
|
-
return dispatch(_extends({
|
|
3105
|
-
props: props
|
|
3106
|
-
}, action));
|
|
3107
|
-
}];
|
|
3127
|
+
return [state, dispatchWithProps];
|
|
3108
3128
|
}
|
|
3109
3129
|
/**
|
|
3110
3130
|
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
@@ -3180,7 +3200,12 @@
|
|
|
3180
3200
|
initialHighlightedIndex = props.initialHighlightedIndex,
|
|
3181
3201
|
defaultHighlightedIndex = props.defaultHighlightedIndex;
|
|
3182
3202
|
var selectedItem = state.selectedItem,
|
|
3183
|
-
highlightedIndex = state.highlightedIndex;
|
|
3203
|
+
highlightedIndex = state.highlightedIndex;
|
|
3204
|
+
|
|
3205
|
+
if (items.length === 0) {
|
|
3206
|
+
return -1;
|
|
3207
|
+
} // initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
3208
|
+
|
|
3184
3209
|
|
|
3185
3210
|
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex) {
|
|
3186
3211
|
return initialHighlightedIndex;
|
|
@@ -3267,6 +3292,53 @@
|
|
|
3267
3292
|
}, [isOpen, environment]);
|
|
3268
3293
|
return mouseAndTouchTrackersRef;
|
|
3269
3294
|
}
|
|
3295
|
+
/**
|
|
3296
|
+
* Custom hook that checks if getter props are called correctly.
|
|
3297
|
+
*
|
|
3298
|
+
* @param {...any} propKeys Getter prop names to be handled.
|
|
3299
|
+
* @returns {Function} Setter function called inside getter props to set call information.
|
|
3300
|
+
*/
|
|
3301
|
+
|
|
3302
|
+
function useGetterPropsCalledChecker() {
|
|
3303
|
+
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3304
|
+
propKeys[_key] = arguments[_key];
|
|
3305
|
+
}
|
|
3306
|
+
|
|
3307
|
+
var getterPropsCalledRef = react.useRef(propKeys.reduce(function (acc, propKey) {
|
|
3308
|
+
acc[propKey] = {};
|
|
3309
|
+
return acc;
|
|
3310
|
+
}, {}));
|
|
3311
|
+
Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
|
|
3312
|
+
getterPropsCalledRef.current[propKey] = null;
|
|
3313
|
+
});
|
|
3314
|
+
react.useEffect(function () {
|
|
3315
|
+
Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
|
|
3316
|
+
if (!getterPropsCalledRef.current[propKey]) {
|
|
3317
|
+
// eslint-disable-next-line no-console
|
|
3318
|
+
console.error("downshift: You forgot to call the " + propKey + " getter function on your component / element.");
|
|
3319
|
+
return;
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3322
|
+
var _getterPropsCalledRef = getterPropsCalledRef.current[propKey],
|
|
3323
|
+
suppressRefError = _getterPropsCalledRef.suppressRefError,
|
|
3324
|
+
refKey = _getterPropsCalledRef.refKey,
|
|
3325
|
+
elementRef = _getterPropsCalledRef.elementRef;
|
|
3326
|
+
|
|
3327
|
+
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
3328
|
+
// eslint-disable-next-line no-console
|
|
3329
|
+
console.error("downshift: The ref prop \"" + refKey + "\" from " + propKey + " was not applied correctly on your element.");
|
|
3330
|
+
}
|
|
3331
|
+
});
|
|
3332
|
+
});
|
|
3333
|
+
var setGetterPropCallInfo = react.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
|
|
3334
|
+
getterPropsCalledRef.current[propKey] = {
|
|
3335
|
+
suppressRefError: suppressRefError,
|
|
3336
|
+
refKey: refKey,
|
|
3337
|
+
elementRef: elementRef
|
|
3338
|
+
};
|
|
3339
|
+
}, []);
|
|
3340
|
+
return setGetterPropCallInfo;
|
|
3341
|
+
}
|
|
3270
3342
|
|
|
3271
3343
|
function getItemIndexByCharacterKey(keysSoFar, highlightedIndex, items, itemToStringParam, getItemNodeFromIndex) {
|
|
3272
3344
|
var lowerCasedItemStrings = items.map(function (item) {
|
|
@@ -3362,7 +3434,7 @@
|
|
|
3362
3434
|
return '';
|
|
3363
3435
|
}
|
|
3364
3436
|
|
|
3365
|
-
var defaultProps$1 = _extends(
|
|
3437
|
+
var defaultProps$1 = _extends({}, defaultProps, {
|
|
3366
3438
|
getA11yStatusMessage: getA11yStatusMessage$1
|
|
3367
3439
|
});
|
|
3368
3440
|
|
|
@@ -3588,7 +3660,7 @@
|
|
|
3588
3660
|
throw new Error('Reducer called without proper action type.');
|
|
3589
3661
|
}
|
|
3590
3662
|
|
|
3591
|
-
return _extends(
|
|
3663
|
+
return _extends({}, state, {}, changes);
|
|
3592
3664
|
}
|
|
3593
3665
|
/* eslint-enable complexity */
|
|
3594
3666
|
|
|
@@ -3603,7 +3675,7 @@
|
|
|
3603
3675
|
/* istanbul ignore else */
|
|
3604
3676
|
validatePropTypes(userProps); // Props defaults and destructuring.
|
|
3605
3677
|
|
|
3606
|
-
var props = _extends(
|
|
3678
|
+
var props = _extends({}, defaultProps$1, {}, userProps);
|
|
3607
3679
|
|
|
3608
3680
|
var items = props.items,
|
|
3609
3681
|
scrollIntoView = props.scrollIntoView,
|
|
@@ -3614,31 +3686,44 @@
|
|
|
3614
3686
|
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
3615
3687
|
getA11yStatusMessage = props.getA11yStatusMessage; // Initial state depending on controlled props.
|
|
3616
3688
|
|
|
3617
|
-
var initialState = getInitialState(props);
|
|
3689
|
+
var initialState = getInitialState(props);
|
|
3618
3690
|
|
|
3619
3691
|
var _useControlledReducer = useControlledReducer(downshiftSelectReducer, initialState, props),
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
highlightedIndex = _useControlledReducer2.highlightedIndex,
|
|
3623
|
-
selectedItem = _useControlledReducer2.selectedItem,
|
|
3624
|
-
inputValue = _useControlledReducer2.inputValue,
|
|
3625
|
-
dispatch = _useControlledReducer[1]; // Refs
|
|
3692
|
+
state = _useControlledReducer[0],
|
|
3693
|
+
dispatch = _useControlledReducer[1];
|
|
3626
3694
|
|
|
3695
|
+
var isOpen = state.isOpen,
|
|
3696
|
+
highlightedIndex = state.highlightedIndex,
|
|
3697
|
+
selectedItem = state.selectedItem,
|
|
3698
|
+
inputValue = state.inputValue; // Element efs.
|
|
3627
3699
|
|
|
3628
3700
|
var toggleButtonRef = react.useRef(null);
|
|
3629
3701
|
var menuRef = react.useRef(null);
|
|
3630
|
-
var
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
var
|
|
3634
|
-
|
|
3635
|
-
var
|
|
3702
|
+
var itemRefs = react.useRef();
|
|
3703
|
+
itemRefs.current = {}; // used not to scroll when highlight by mouse.
|
|
3704
|
+
|
|
3705
|
+
var shouldScrollRef = react.useRef(true); // used not to trigger menu blur action in some scenarios.
|
|
3706
|
+
|
|
3707
|
+
var shouldBlurRef = react.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
3708
|
+
|
|
3709
|
+
var clearTimeoutRef = react.useRef(null); // prevent id re-generation between renders.
|
|
3710
|
+
|
|
3711
|
+
var elementIdsRef = react.useRef(getElementIds(props)); // used to keep track of how many items we had on previous cycle.
|
|
3712
|
+
|
|
3713
|
+
var previousResultCountRef = react.useRef();
|
|
3714
|
+
var isInitialMountRef = react.useRef(true); // used for checking when props are moving from controlled to uncontrolled.
|
|
3715
|
+
|
|
3716
|
+
var prevPropsRef = react.useRef(props); // utility callback to get item element.
|
|
3717
|
+
|
|
3718
|
+
var latest = useLatestRef({
|
|
3719
|
+
state: state,
|
|
3720
|
+
props: props
|
|
3721
|
+
}); // Some utils.
|
|
3636
3722
|
|
|
3637
3723
|
var getItemNodeFromIndex = function (index) {
|
|
3638
|
-
return
|
|
3724
|
+
return itemRefs.current[elementIdsRef.current.getItemId(index)];
|
|
3639
3725
|
}; // Effects.
|
|
3640
|
-
|
|
3641
|
-
/* Sets a11y status message on changes in state. */
|
|
3726
|
+
// Sets a11y status message on changes in state.
|
|
3642
3727
|
|
|
3643
3728
|
|
|
3644
3729
|
react.useEffect(function () {
|
|
@@ -3659,8 +3744,7 @@
|
|
|
3659
3744
|
previousResultCount: previousResultCount
|
|
3660
3745
|
});
|
|
3661
3746
|
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3662
|
-
}, [isOpen, highlightedIndex, selectedItem, inputValue]);
|
|
3663
|
-
/* Sets a11y status message on changes in selectedItem. */
|
|
3747
|
+
}, [isOpen, highlightedIndex, selectedItem, inputValue]); // Sets a11y status message on changes in selectedItem.
|
|
3664
3748
|
|
|
3665
3749
|
react.useEffect(function () {
|
|
3666
3750
|
if (isInitialMountRef.current) {
|
|
@@ -3680,8 +3764,7 @@
|
|
|
3680
3764
|
previousResultCount: previousResultCount
|
|
3681
3765
|
});
|
|
3682
3766
|
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3683
|
-
}, [selectedItem]);
|
|
3684
|
-
/* Sets cleanup for the keysSoFar after 500ms. */
|
|
3767
|
+
}, [selectedItem]); // Sets cleanup for the keysSoFar after 500ms.
|
|
3685
3768
|
|
|
3686
3769
|
react.useEffect(function () {
|
|
3687
3770
|
// init the clean function here as we need access to dispatch.
|
|
@@ -3718,9 +3801,10 @@
|
|
|
3718
3801
|
// istanbul ignore else
|
|
3719
3802
|
if (menuRef.current) {
|
|
3720
3803
|
menuRef.current.focus();
|
|
3721
|
-
return;
|
|
3722
3804
|
}
|
|
3723
|
-
|
|
3805
|
+
|
|
3806
|
+
return;
|
|
3807
|
+
} // Focus toggleButton on close, but not if it was closed with (Shift+)Tab.
|
|
3724
3808
|
|
|
3725
3809
|
|
|
3726
3810
|
if (environment.document.activeElement === menuRef.current) {
|
|
@@ -3731,11 +3815,10 @@
|
|
|
3731
3815
|
}
|
|
3732
3816
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3733
3817
|
|
|
3734
|
-
}, [isOpen]);
|
|
3735
|
-
/* Scroll on highlighted item if change comes from keyboard. */
|
|
3818
|
+
}, [isOpen]); // Scroll on highlighted item if change comes from keyboard.
|
|
3736
3819
|
|
|
3737
3820
|
react.useEffect(function () {
|
|
3738
|
-
if (highlightedIndex < 0 || !isOpen || !
|
|
3821
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
3739
3822
|
return;
|
|
3740
3823
|
}
|
|
3741
3824
|
|
|
@@ -3753,286 +3836,322 @@
|
|
|
3753
3836
|
|
|
3754
3837
|
previousResultCountRef.current = items.length;
|
|
3755
3838
|
});
|
|
3756
|
-
/* Make initial ref false. */
|
|
3757
|
-
|
|
3758
3839
|
react.useEffect(function () {
|
|
3759
|
-
isInitialMountRef.current
|
|
3760
|
-
|
|
3761
|
-
|
|
3840
|
+
if (isInitialMountRef.current) {
|
|
3841
|
+
return;
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3844
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
3845
|
+
prevPropsRef.current = props;
|
|
3846
|
+
}, [state, props]); // Add mouse/touch events to document.
|
|
3762
3847
|
|
|
3763
3848
|
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
|
|
3764
3849
|
dispatch({
|
|
3765
3850
|
type: MenuBlur
|
|
3766
3851
|
});
|
|
3767
|
-
});
|
|
3768
|
-
|
|
3769
|
-
var toggleButtonKeyDownHandlers = {
|
|
3770
|
-
ArrowDown: function ArrowDown(event) {
|
|
3771
|
-
event.preventDefault();
|
|
3772
|
-
dispatch({
|
|
3773
|
-
type: ToggleButtonKeyDownArrowDown,
|
|
3774
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3775
|
-
shiftKey: event.shiftKey
|
|
3776
|
-
});
|
|
3777
|
-
},
|
|
3778
|
-
ArrowUp: function ArrowUp(event) {
|
|
3779
|
-
event.preventDefault();
|
|
3780
|
-
dispatch({
|
|
3781
|
-
type: ToggleButtonKeyDownArrowUp,
|
|
3782
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3783
|
-
shiftKey: event.shiftKey
|
|
3784
|
-
});
|
|
3785
|
-
}
|
|
3786
|
-
};
|
|
3787
|
-
var menuKeyDownHandlers = {
|
|
3788
|
-
ArrowDown: function ArrowDown(event) {
|
|
3789
|
-
event.preventDefault();
|
|
3790
|
-
dispatch({
|
|
3791
|
-
type: MenuKeyDownArrowDown,
|
|
3792
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3793
|
-
shiftKey: event.shiftKey
|
|
3794
|
-
});
|
|
3795
|
-
},
|
|
3796
|
-
ArrowUp: function ArrowUp(event) {
|
|
3797
|
-
event.preventDefault();
|
|
3798
|
-
dispatch({
|
|
3799
|
-
type: MenuKeyDownArrowUp,
|
|
3800
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3801
|
-
shiftKey: event.shiftKey
|
|
3802
|
-
});
|
|
3803
|
-
},
|
|
3804
|
-
Home: function Home(event) {
|
|
3805
|
-
event.preventDefault();
|
|
3806
|
-
dispatch({
|
|
3807
|
-
type: MenuKeyDownHome,
|
|
3808
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3809
|
-
});
|
|
3810
|
-
},
|
|
3811
|
-
End: function End(event) {
|
|
3812
|
-
event.preventDefault();
|
|
3813
|
-
dispatch({
|
|
3814
|
-
type: MenuKeyDownEnd,
|
|
3815
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3816
|
-
});
|
|
3817
|
-
},
|
|
3818
|
-
Escape: function Escape() {
|
|
3819
|
-
dispatch({
|
|
3820
|
-
type: MenuKeyDownEscape
|
|
3821
|
-
});
|
|
3822
|
-
},
|
|
3823
|
-
Enter: function Enter(event) {
|
|
3824
|
-
event.preventDefault();
|
|
3825
|
-
dispatch({
|
|
3826
|
-
type: MenuKeyDownEnter
|
|
3827
|
-
});
|
|
3828
|
-
},
|
|
3829
|
-
' ': function _(event) {
|
|
3830
|
-
event.preventDefault();
|
|
3831
|
-
dispatch({
|
|
3832
|
-
type: MenuKeyDownSpaceButton
|
|
3833
|
-
});
|
|
3834
|
-
}
|
|
3835
|
-
}; // Event handlers.
|
|
3836
|
-
|
|
3837
|
-
var menuHandleKeyDown = function (event) {
|
|
3838
|
-
var key = normalizeArrowKey(event);
|
|
3839
|
-
|
|
3840
|
-
if (key && menuKeyDownHandlers[key]) {
|
|
3841
|
-
menuKeyDownHandlers[key](event);
|
|
3842
|
-
} else if (isAcceptedCharacterKey(key)) {
|
|
3843
|
-
dispatch({
|
|
3844
|
-
type: MenuKeyDownCharacter,
|
|
3845
|
-
key: key,
|
|
3846
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3847
|
-
});
|
|
3848
|
-
}
|
|
3849
|
-
};
|
|
3850
|
-
|
|
3851
|
-
var menuHandleBlur = function () {
|
|
3852
|
-
// if the blur was a result of selection, we don't trigger this action.
|
|
3853
|
-
if (shouldBlurRef.current === false) {
|
|
3854
|
-
shouldBlurRef.current = true;
|
|
3855
|
-
return;
|
|
3856
|
-
}
|
|
3852
|
+
});
|
|
3853
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
3857
3854
|
|
|
3858
|
-
|
|
3859
|
-
|
|
3855
|
+
react.useEffect(function () {
|
|
3856
|
+
isInitialMountRef.current = false;
|
|
3857
|
+
}, []); // Event handler functions.
|
|
3860
3858
|
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3859
|
+
var toggleButtonKeyDownHandlers = react.useMemo(function () {
|
|
3860
|
+
return {
|
|
3861
|
+
ArrowDown: function ArrowDown(event) {
|
|
3862
|
+
event.preventDefault();
|
|
3863
|
+
dispatch({
|
|
3864
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
3865
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3866
|
+
shiftKey: event.shiftKey
|
|
3867
|
+
});
|
|
3868
|
+
},
|
|
3869
|
+
ArrowUp: function ArrowUp(event) {
|
|
3870
|
+
event.preventDefault();
|
|
3871
|
+
dispatch({
|
|
3872
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
3873
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3874
|
+
shiftKey: event.shiftKey
|
|
3875
|
+
});
|
|
3876
|
+
}
|
|
3877
|
+
};
|
|
3878
|
+
}, [dispatch]);
|
|
3879
|
+
var menuKeyDownHandlers = react.useMemo(function () {
|
|
3880
|
+
return {
|
|
3881
|
+
ArrowDown: function ArrowDown(event) {
|
|
3882
|
+
event.preventDefault();
|
|
3883
|
+
dispatch({
|
|
3884
|
+
type: MenuKeyDownArrowDown,
|
|
3885
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3886
|
+
shiftKey: event.shiftKey
|
|
3887
|
+
});
|
|
3888
|
+
},
|
|
3889
|
+
ArrowUp: function ArrowUp(event) {
|
|
3890
|
+
event.preventDefault();
|
|
3891
|
+
dispatch({
|
|
3892
|
+
type: MenuKeyDownArrowUp,
|
|
3893
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3894
|
+
shiftKey: event.shiftKey
|
|
3895
|
+
});
|
|
3896
|
+
},
|
|
3897
|
+
Home: function Home(event) {
|
|
3898
|
+
event.preventDefault();
|
|
3899
|
+
dispatch({
|
|
3900
|
+
type: MenuKeyDownHome,
|
|
3901
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3902
|
+
});
|
|
3903
|
+
},
|
|
3904
|
+
End: function End(event) {
|
|
3905
|
+
event.preventDefault();
|
|
3906
|
+
dispatch({
|
|
3907
|
+
type: MenuKeyDownEnd,
|
|
3908
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3909
|
+
});
|
|
3910
|
+
},
|
|
3911
|
+
Escape: function Escape() {
|
|
3912
|
+
dispatch({
|
|
3913
|
+
type: MenuKeyDownEscape
|
|
3914
|
+
});
|
|
3915
|
+
},
|
|
3916
|
+
Enter: function Enter(event) {
|
|
3917
|
+
event.preventDefault();
|
|
3918
|
+
dispatch({
|
|
3919
|
+
type: MenuKeyDownEnter
|
|
3920
|
+
});
|
|
3921
|
+
},
|
|
3922
|
+
' ': function _(event) {
|
|
3923
|
+
event.preventDefault();
|
|
3924
|
+
dispatch({
|
|
3925
|
+
type: MenuKeyDownSpaceButton
|
|
3926
|
+
});
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
}, [dispatch]); // Action functions.
|
|
3867
3930
|
|
|
3868
|
-
var
|
|
3931
|
+
var toggleMenu = react.useCallback(function () {
|
|
3869
3932
|
dispatch({
|
|
3870
|
-
type:
|
|
3933
|
+
type: FunctionToggleMenu
|
|
3871
3934
|
});
|
|
3872
|
-
};
|
|
3873
|
-
|
|
3874
|
-
var toggleButtonHandleClick = function () {
|
|
3935
|
+
}, [dispatch]);
|
|
3936
|
+
var closeMenu = react.useCallback(function () {
|
|
3875
3937
|
dispatch({
|
|
3876
|
-
type:
|
|
3938
|
+
type: FunctionCloseMenu
|
|
3877
3939
|
});
|
|
3878
|
-
};
|
|
3879
|
-
|
|
3880
|
-
var toggleButtonHandleKeyDown = function (event) {
|
|
3881
|
-
var key = normalizeArrowKey(event);
|
|
3882
|
-
|
|
3883
|
-
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
3884
|
-
toggleButtonKeyDownHandlers[key](event);
|
|
3885
|
-
} else if (isAcceptedCharacterKey(key)) {
|
|
3886
|
-
dispatch({
|
|
3887
|
-
type: ToggleButtonKeyDownCharacter,
|
|
3888
|
-
key: key,
|
|
3889
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3890
|
-
});
|
|
3891
|
-
}
|
|
3892
|
-
};
|
|
3893
|
-
|
|
3894
|
-
var itemHandleMouseMove = function (index) {
|
|
3895
|
-
if (index === highlightedIndex) {
|
|
3896
|
-
return;
|
|
3897
|
-
}
|
|
3898
|
-
|
|
3899
|
-
shouldScrollRef.current = false;
|
|
3940
|
+
}, [dispatch]);
|
|
3941
|
+
var openMenu = react.useCallback(function () {
|
|
3900
3942
|
dispatch({
|
|
3901
|
-
type:
|
|
3902
|
-
index: index
|
|
3943
|
+
type: FunctionOpenMenu
|
|
3903
3944
|
});
|
|
3904
|
-
};
|
|
3905
|
-
|
|
3906
|
-
|
|
3945
|
+
}, [dispatch]);
|
|
3946
|
+
var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
|
|
3947
|
+
dispatch({
|
|
3948
|
+
type: FunctionSetHighlightedIndex,
|
|
3949
|
+
highlightedIndex: newHighlightedIndex
|
|
3950
|
+
});
|
|
3951
|
+
}, [dispatch]);
|
|
3952
|
+
var selectItem = react.useCallback(function (newSelectedItem) {
|
|
3953
|
+
dispatch({
|
|
3954
|
+
type: FunctionSelectItem,
|
|
3955
|
+
selectedItem: newSelectedItem
|
|
3956
|
+
});
|
|
3957
|
+
}, [dispatch]);
|
|
3958
|
+
var reset = react.useCallback(function () {
|
|
3959
|
+
dispatch({
|
|
3960
|
+
type: FunctionReset
|
|
3961
|
+
});
|
|
3962
|
+
}, [dispatch]);
|
|
3963
|
+
var setInputValue = react.useCallback(function (newInputValue) {
|
|
3907
3964
|
dispatch({
|
|
3908
|
-
type:
|
|
3909
|
-
|
|
3965
|
+
type: FunctionSetInputValue,
|
|
3966
|
+
inputValue: newInputValue
|
|
3910
3967
|
});
|
|
3911
|
-
}; //
|
|
3968
|
+
}, [dispatch]); // Getter functions.
|
|
3912
3969
|
|
|
3970
|
+
var getLabelProps = react.useCallback(function (labelProps) {
|
|
3971
|
+
return _extends({
|
|
3972
|
+
id: elementIdsRef.current.labelId,
|
|
3973
|
+
htmlFor: elementIdsRef.current.toggleButtonId
|
|
3974
|
+
}, labelProps);
|
|
3975
|
+
}, []);
|
|
3976
|
+
var getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
3977
|
+
var _extends2;
|
|
3978
|
+
|
|
3979
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
3980
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
3981
|
+
_ref$refKey = _ref.refKey,
|
|
3982
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3983
|
+
onKeyDown = _ref.onKeyDown,
|
|
3984
|
+
onBlur = _ref.onBlur,
|
|
3985
|
+
ref = _ref.ref,
|
|
3986
|
+
rest = _objectWithoutPropertiesLoose(_ref, ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"]);
|
|
3987
|
+
|
|
3988
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
3989
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3990
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3991
|
+
|
|
3992
|
+
var latestState = latest.current.state;
|
|
3993
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3994
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3995
|
+
menuRef.current = menuNode;
|
|
3996
|
+
}), _extends2.id = elementIdsRef.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIdsRef.current.labelId, _extends2.tabIndex = -1, _extends2), latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3997
|
+
'aria-activedescendant': elementIdsRef.current.getItemId(latestState.highlightedIndex)
|
|
3998
|
+
}, {
|
|
3999
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, function menuHandleMouseLeave() {
|
|
4000
|
+
dispatch({
|
|
4001
|
+
type: MenuMouseLeave
|
|
4002
|
+
});
|
|
4003
|
+
}),
|
|
4004
|
+
onKeyDown: callAllEventHandlers(onKeyDown, function menuHandleKeyDown(event) {
|
|
4005
|
+
var key = normalizeArrowKey(event);
|
|
3913
4006
|
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
if (!rest.disabled) {
|
|
3932
|
-
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
3933
|
-
toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
|
|
3934
|
-
}
|
|
4007
|
+
if (key && menuKeyDownHandlers[key]) {
|
|
4008
|
+
menuKeyDownHandlers[key](event);
|
|
4009
|
+
} else if (isAcceptedCharacterKey(key)) {
|
|
4010
|
+
dispatch({
|
|
4011
|
+
type: MenuKeyDownCharacter,
|
|
4012
|
+
key: key,
|
|
4013
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4014
|
+
});
|
|
4015
|
+
}
|
|
4016
|
+
}),
|
|
4017
|
+
onBlur: callAllEventHandlers(onBlur, function menuHandleBlur() {
|
|
4018
|
+
// if the blur was a result of selection, we don't trigger this action.
|
|
4019
|
+
if (shouldBlurRef.current === false) {
|
|
4020
|
+
shouldBlurRef.current = true;
|
|
4021
|
+
return;
|
|
4022
|
+
}
|
|
3935
4023
|
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
getLabelProps: function getLabelProps(labelProps) {
|
|
3939
|
-
return _extends({
|
|
3940
|
-
id: elementIdsRef.current.labelId,
|
|
3941
|
-
htmlFor: elementIdsRef.current.toggleButtonId
|
|
3942
|
-
}, labelProps);
|
|
3943
|
-
},
|
|
3944
|
-
getMenuProps: function getMenuProps(_temp) {
|
|
3945
|
-
var _extends2;
|
|
3946
|
-
|
|
3947
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
3948
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
3949
|
-
_ref$refKey = _ref.refKey,
|
|
3950
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3951
|
-
onKeyDown = _ref.onKeyDown,
|
|
3952
|
-
onBlur = _ref.onBlur,
|
|
3953
|
-
ref = _ref.ref,
|
|
3954
|
-
rest = _objectWithoutPropertiesLoose(_ref, ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"]);
|
|
3955
|
-
|
|
3956
|
-
return _extends(_extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3957
|
-
menuRef.current = menuNode;
|
|
3958
|
-
}), _extends2.id = elementIdsRef.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIdsRef.current.labelId, _extends2.tabIndex = -1, _extends2), isOpen && highlightedIndex > -1 && {
|
|
3959
|
-
'aria-activedescendant': elementIdsRef.current.getItemId(highlightedIndex)
|
|
3960
|
-
}), {}, {
|
|
3961
|
-
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
3962
|
-
onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
|
3963
|
-
onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
|
3964
|
-
}, rest);
|
|
3965
|
-
},
|
|
3966
|
-
getItemProps: function getItemProps(_temp3) {
|
|
3967
|
-
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3968
|
-
item = _ref3.item,
|
|
3969
|
-
index = _ref3.index,
|
|
3970
|
-
onMouseMove = _ref3.onMouseMove,
|
|
3971
|
-
onClick = _ref3.onClick,
|
|
3972
|
-
rest = _objectWithoutPropertiesLoose(_ref3, ["item", "index", "onMouseMove", "onClick"]);
|
|
3973
|
-
|
|
3974
|
-
var itemIndex = getItemIndex(index, item, items);
|
|
3975
|
-
|
|
3976
|
-
if (itemIndex < 0) {
|
|
3977
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
3978
|
-
}
|
|
4024
|
+
var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
4025
|
+
/* istanbul ignore else */
|
|
3979
4026
|
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
4027
|
+
if (shouldBlur) {
|
|
4028
|
+
dispatch({
|
|
4029
|
+
type: MenuBlur
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
})
|
|
4033
|
+
}, rest);
|
|
4034
|
+
}, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo]);
|
|
4035
|
+
var getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
|
|
4036
|
+
var _extends3;
|
|
4037
|
+
|
|
4038
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
4039
|
+
onClick = _ref3.onClick,
|
|
4040
|
+
onKeyDown = _ref3.onKeyDown,
|
|
4041
|
+
_ref3$refKey = _ref3.refKey,
|
|
4042
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4043
|
+
ref = _ref3.ref,
|
|
4044
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onKeyDown", "refKey", "ref"]);
|
|
4045
|
+
|
|
4046
|
+
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
4047
|
+
_ref4$suppressRefErro = _ref4.suppressRefError,
|
|
4048
|
+
suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
|
|
4049
|
+
|
|
4050
|
+
var toggleButtonHandleClick = function () {
|
|
4051
|
+
dispatch({
|
|
4052
|
+
type: ToggleButtonClick
|
|
4053
|
+
});
|
|
4054
|
+
};
|
|
3985
4055
|
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
4056
|
+
var toggleButtonHandleKeyDown = function (event) {
|
|
4057
|
+
var key = normalizeArrowKey(event);
|
|
4058
|
+
|
|
4059
|
+
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
4060
|
+
toggleButtonKeyDownHandlers[key](event);
|
|
4061
|
+
} else if (isAcceptedCharacterKey(key)) {
|
|
4062
|
+
dispatch({
|
|
4063
|
+
type: ToggleButtonKeyDownCharacter,
|
|
4064
|
+
key: key,
|
|
4065
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3992
4066
|
});
|
|
3993
4067
|
}
|
|
4068
|
+
};
|
|
3994
4069
|
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
}
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4070
|
+
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
4071
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
4072
|
+
}), _extends3.id = elementIdsRef.current.toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-labelledby'] = elementIdsRef.current.labelId + " " + elementIdsRef.current.toggleButtonId, _extends3), rest);
|
|
4073
|
+
|
|
4074
|
+
if (!rest.disabled) {
|
|
4075
|
+
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
4076
|
+
toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
|
|
4077
|
+
}
|
|
4078
|
+
|
|
4079
|
+
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
4080
|
+
return toggleProps;
|
|
4081
|
+
}, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo]);
|
|
4082
|
+
var getItemProps = react.useCallback(function (_temp5) {
|
|
4083
|
+
var _extends4;
|
|
4084
|
+
|
|
4085
|
+
var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
|
4086
|
+
item = _ref5.item,
|
|
4087
|
+
index = _ref5.index,
|
|
4088
|
+
onMouseMove = _ref5.onMouseMove,
|
|
4089
|
+
onClick = _ref5.onClick,
|
|
4090
|
+
_ref5$refKey = _ref5.refKey,
|
|
4091
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
4092
|
+
ref = _ref5.ref,
|
|
4093
|
+
rest = _objectWithoutPropertiesLoose(_ref5, ["item", "index", "onMouseMove", "onClick", "refKey", "ref"]);
|
|
4094
|
+
|
|
4095
|
+
var _latest$current = latest.current,
|
|
4096
|
+
latestState = _latest$current.state,
|
|
4097
|
+
latestProps = _latest$current.props;
|
|
4098
|
+
|
|
4099
|
+
var itemHandleMouseMove = function () {
|
|
4100
|
+
if (index === latestState.highlightedIndex) {
|
|
4101
|
+
return;
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
shouldScrollRef.current = false;
|
|
4026
4105
|
dispatch({
|
|
4027
|
-
type:
|
|
4106
|
+
type: ItemMouseMove,
|
|
4107
|
+
index: index
|
|
4028
4108
|
});
|
|
4029
|
-
}
|
|
4030
|
-
|
|
4109
|
+
};
|
|
4110
|
+
|
|
4111
|
+
var itemHandleClick = function () {
|
|
4031
4112
|
dispatch({
|
|
4032
|
-
type:
|
|
4033
|
-
|
|
4113
|
+
type: ItemClick,
|
|
4114
|
+
index: index
|
|
4034
4115
|
});
|
|
4035
|
-
}
|
|
4116
|
+
};
|
|
4117
|
+
|
|
4118
|
+
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4119
|
+
|
|
4120
|
+
if (itemIndex < 0) {
|
|
4121
|
+
throw new Error('Pass either item or item index in getItemProps!');
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4124
|
+
var itemProps = _extends((_extends4 = {
|
|
4125
|
+
role: 'option',
|
|
4126
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
4127
|
+
id: elementIdsRef.current.getItemId(itemIndex)
|
|
4128
|
+
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
4129
|
+
if (itemNode) {
|
|
4130
|
+
itemRefs.current[elementIdsRef.current.getItemId(itemIndex)] = itemNode;
|
|
4131
|
+
}
|
|
4132
|
+
}), _extends4), rest);
|
|
4133
|
+
|
|
4134
|
+
if (!rest.disabled) {
|
|
4135
|
+
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
4136
|
+
itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
return itemProps;
|
|
4140
|
+
}, [dispatch, latest]);
|
|
4141
|
+
return {
|
|
4142
|
+
// prop getters.
|
|
4143
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
4144
|
+
getLabelProps: getLabelProps,
|
|
4145
|
+
getMenuProps: getMenuProps,
|
|
4146
|
+
getItemProps: getItemProps,
|
|
4147
|
+
// actions.
|
|
4148
|
+
toggleMenu: toggleMenu,
|
|
4149
|
+
openMenu: openMenu,
|
|
4150
|
+
closeMenu: closeMenu,
|
|
4151
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
4152
|
+
selectItem: selectItem,
|
|
4153
|
+
reset: reset,
|
|
4154
|
+
setInputValue: setInputValue,
|
|
4036
4155
|
// state.
|
|
4037
4156
|
highlightedIndex: highlightedIndex,
|
|
4038
4157
|
isOpen: isOpen,
|
|
@@ -4107,7 +4226,7 @@
|
|
|
4107
4226
|
inputValue = props.itemToString(selectedItem);
|
|
4108
4227
|
}
|
|
4109
4228
|
|
|
4110
|
-
return _extends(
|
|
4229
|
+
return _extends({}, initialState, {
|
|
4111
4230
|
inputValue: inputValue
|
|
4112
4231
|
});
|
|
4113
4232
|
}
|
|
@@ -4185,7 +4304,7 @@
|
|
|
4185
4304
|
|
|
4186
4305
|
return [getState(state, props), dispatch];
|
|
4187
4306
|
}
|
|
4188
|
-
var defaultProps$2 = _extends(
|
|
4307
|
+
var defaultProps$2 = _extends({}, defaultProps, {
|
|
4189
4308
|
getA11yStatusMessage: getA11yStatusMessage,
|
|
4190
4309
|
circularNavigation: true
|
|
4191
4310
|
});
|
|
@@ -4325,7 +4444,8 @@
|
|
|
4325
4444
|
|
|
4326
4445
|
case FunctionSelectItem$1:
|
|
4327
4446
|
changes = {
|
|
4328
|
-
selectedItem: action.selectedItem
|
|
4447
|
+
selectedItem: action.selectedItem,
|
|
4448
|
+
inputValue: props.itemToString(action.selectedItem)
|
|
4329
4449
|
};
|
|
4330
4450
|
break;
|
|
4331
4451
|
|
|
@@ -4349,7 +4469,7 @@
|
|
|
4349
4469
|
throw new Error('Reducer called without proper action type.');
|
|
4350
4470
|
}
|
|
4351
4471
|
|
|
4352
|
-
return _extends(
|
|
4472
|
+
return _extends({}, state, {}, changes);
|
|
4353
4473
|
}
|
|
4354
4474
|
/* eslint-enable complexity */
|
|
4355
4475
|
|
|
@@ -4364,7 +4484,7 @@
|
|
|
4364
4484
|
/* istanbul ignore else */
|
|
4365
4485
|
validatePropTypes$1(userProps); // Props defaults and destructuring.
|
|
4366
4486
|
|
|
4367
|
-
var props = _extends(
|
|
4487
|
+
var props = _extends({}, defaultProps$2, {}, userProps);
|
|
4368
4488
|
|
|
4369
4489
|
var initialIsOpen = props.initialIsOpen,
|
|
4370
4490
|
defaultIsOpen = props.defaultIsOpen,
|
|
@@ -4375,37 +4495,47 @@
|
|
|
4375
4495
|
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
4376
4496
|
itemToString = props.itemToString; // Initial state depending on controlled props.
|
|
4377
4497
|
|
|
4378
|
-
var initialState = getInitialState$1(props);
|
|
4498
|
+
var initialState = getInitialState$1(props);
|
|
4379
4499
|
|
|
4380
4500
|
var _useControlledReducer = useControlledReducer$1(downshiftUseComboboxReducer, initialState, props),
|
|
4381
|
-
|
|
4382
|
-
isOpen = _useControlledReducer2.isOpen,
|
|
4383
|
-
highlightedIndex = _useControlledReducer2.highlightedIndex,
|
|
4384
|
-
selectedItem = _useControlledReducer2.selectedItem,
|
|
4385
|
-
inputValue = _useControlledReducer2.inputValue,
|
|
4501
|
+
state = _useControlledReducer[0],
|
|
4386
4502
|
dispatch = _useControlledReducer[1];
|
|
4387
|
-
/* Refs */
|
|
4388
4503
|
|
|
4504
|
+
var isOpen = state.isOpen,
|
|
4505
|
+
highlightedIndex = state.highlightedIndex,
|
|
4506
|
+
selectedItem = state.selectedItem,
|
|
4507
|
+
inputValue = state.inputValue; // Element refs.
|
|
4389
4508
|
|
|
4390
4509
|
var menuRef = react.useRef(null);
|
|
4510
|
+
var itemRefs = react.useRef();
|
|
4391
4511
|
var inputRef = react.useRef(null);
|
|
4392
4512
|
var toggleButtonRef = react.useRef(null);
|
|
4393
4513
|
var comboboxRef = react.useRef(null);
|
|
4394
|
-
|
|
4395
|
-
var isInitialMount = react.useRef(true);
|
|
4396
|
-
var elementIds = react.useRef(getElementIds$1(props));
|
|
4397
|
-
var previousResultCountRef = react.useRef();
|
|
4514
|
+
itemRefs.current = {}; // used not to scroll on highlight by mouse.
|
|
4398
4515
|
|
|
4399
|
-
var
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4516
|
+
var shouldScrollRef = react.useRef(true);
|
|
4517
|
+
var isInitialMountRef = react.useRef(true); // prevent id re-generation between renders.
|
|
4518
|
+
|
|
4519
|
+
var elementIdsRef = react.useRef(getElementIds$1(props)); // used to keep track of how many items we had on previous cycle.
|
|
4520
|
+
|
|
4521
|
+
var previousResultCountRef = react.useRef(); // used for checking when props are moving from controlled to uncontrolled.
|
|
4522
|
+
|
|
4523
|
+
var prevPropsRef = react.useRef(props); // used to store information about getter props being called on render.
|
|
4524
|
+
// utility callback to get item element.
|
|
4403
4525
|
|
|
4404
|
-
|
|
4526
|
+
var latest = useLatestRef({
|
|
4527
|
+
state: state,
|
|
4528
|
+
props: props
|
|
4529
|
+
});
|
|
4530
|
+
|
|
4531
|
+
var getItemNodeFromIndex = function (index) {
|
|
4532
|
+
return itemRefs.current[elementIdsRef.current.getItemId(index)];
|
|
4533
|
+
}; // Effects.
|
|
4534
|
+
// Sets a11y status message on changes in state.
|
|
4405
4535
|
|
|
4406
4536
|
|
|
4407
4537
|
react.useEffect(function () {
|
|
4408
|
-
if (
|
|
4538
|
+
if (isInitialMountRef.current) {
|
|
4409
4539
|
return;
|
|
4410
4540
|
}
|
|
4411
4541
|
|
|
@@ -4422,11 +4552,10 @@
|
|
|
4422
4552
|
previousResultCount: previousResultCount
|
|
4423
4553
|
});
|
|
4424
4554
|
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4425
|
-
}, [isOpen, highlightedIndex, selectedItem, inputValue]);
|
|
4426
|
-
/* Sets a11y status message on changes in selectedItem. */
|
|
4555
|
+
}, [isOpen, highlightedIndex, selectedItem, inputValue]); // Sets a11y status message on changes in selectedItem.
|
|
4427
4556
|
|
|
4428
4557
|
react.useEffect(function () {
|
|
4429
|
-
if (
|
|
4558
|
+
if (isInitialMountRef.current) {
|
|
4430
4559
|
return;
|
|
4431
4560
|
}
|
|
4432
4561
|
|
|
@@ -4443,26 +4572,24 @@
|
|
|
4443
4572
|
previousResultCount: previousResultCount
|
|
4444
4573
|
});
|
|
4445
4574
|
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4446
|
-
}, [selectedItem]);
|
|
4447
|
-
/* Scroll on highlighted item if change comes from keyboard. */
|
|
4575
|
+
}, [selectedItem]); // Scroll on highlighted item if change comes from keyboard.
|
|
4448
4576
|
|
|
4449
4577
|
react.useEffect(function () {
|
|
4450
|
-
if (highlightedIndex < 0 || !isOpen || !
|
|
4578
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
4451
4579
|
return;
|
|
4452
4580
|
}
|
|
4453
4581
|
|
|
4454
|
-
if (
|
|
4455
|
-
|
|
4582
|
+
if (shouldScrollRef.current === false) {
|
|
4583
|
+
shouldScrollRef.current = true;
|
|
4456
4584
|
} else {
|
|
4457
4585
|
scrollIntoView(getItemNodeFromIndex(highlightedIndex), menuRef.current);
|
|
4458
4586
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4459
4587
|
|
|
4460
|
-
}, [highlightedIndex]);
|
|
4461
|
-
/* Controls the focus on the menu or the toggle button. */
|
|
4588
|
+
}, [highlightedIndex]); // Controls the focus on the menu or the toggle button.
|
|
4462
4589
|
|
|
4463
4590
|
react.useEffect(function () {
|
|
4464
4591
|
// Don't focus menu on first render.
|
|
4465
|
-
if (
|
|
4592
|
+
if (isInitialMountRef.current) {
|
|
4466
4593
|
// Unless it was initialised as open.
|
|
4467
4594
|
if (initialIsOpen || defaultIsOpen || isOpen) {
|
|
4468
4595
|
if (inputRef.current) {
|
|
@@ -4473,296 +4600,336 @@
|
|
|
4473
4600
|
|
|
4474
4601
|
}, [isOpen]);
|
|
4475
4602
|
react.useEffect(function () {
|
|
4476
|
-
if (
|
|
4603
|
+
if (isInitialMountRef.current) {
|
|
4477
4604
|
return;
|
|
4478
4605
|
}
|
|
4479
4606
|
|
|
4480
4607
|
previousResultCountRef.current = items.length;
|
|
4481
4608
|
});
|
|
4482
4609
|
react.useEffect(function () {
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4610
|
+
if (isInitialMountRef.current) {
|
|
4611
|
+
return;
|
|
4612
|
+
}
|
|
4613
|
+
|
|
4614
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
4615
|
+
prevPropsRef.current = props;
|
|
4616
|
+
}, [state, props]); // Add mouse/touch events to document.
|
|
4486
4617
|
|
|
4487
4618
|
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, function () {
|
|
4488
4619
|
dispatch({
|
|
4489
4620
|
type: InputBlur
|
|
4490
4621
|
});
|
|
4491
4622
|
});
|
|
4623
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
4624
|
+
|
|
4625
|
+
react.useEffect(function () {
|
|
4626
|
+
isInitialMountRef.current = false;
|
|
4627
|
+
}, []);
|
|
4492
4628
|
/* Event handler functions */
|
|
4493
4629
|
|
|
4494
|
-
var inputKeyDownHandlers = {
|
|
4495
|
-
|
|
4496
|
-
event
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
event
|
|
4630
|
+
var inputKeyDownHandlers = react.useMemo(function () {
|
|
4631
|
+
return {
|
|
4632
|
+
ArrowDown: function ArrowDown(event) {
|
|
4633
|
+
event.preventDefault();
|
|
4634
|
+
dispatch({
|
|
4635
|
+
type: InputKeyDownArrowDown,
|
|
4636
|
+
shiftKey: event.shiftKey,
|
|
4637
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4638
|
+
});
|
|
4639
|
+
},
|
|
4640
|
+
ArrowUp: function ArrowUp(event) {
|
|
4641
|
+
event.preventDefault();
|
|
4642
|
+
dispatch({
|
|
4643
|
+
type: InputKeyDownArrowUp,
|
|
4644
|
+
shiftKey: event.shiftKey,
|
|
4645
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4646
|
+
});
|
|
4647
|
+
},
|
|
4648
|
+
Home: function Home(event) {
|
|
4649
|
+
event.preventDefault();
|
|
4650
|
+
dispatch({
|
|
4651
|
+
type: InputKeyDownHome,
|
|
4652
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4653
|
+
});
|
|
4654
|
+
},
|
|
4655
|
+
End: function End(event) {
|
|
4656
|
+
event.preventDefault();
|
|
4657
|
+
dispatch({
|
|
4658
|
+
type: InputKeyDownEnd,
|
|
4659
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4660
|
+
});
|
|
4661
|
+
},
|
|
4662
|
+
Escape: function Escape() {
|
|
4663
|
+
dispatch({
|
|
4664
|
+
type: InputKeyDownEscape
|
|
4665
|
+
});
|
|
4666
|
+
},
|
|
4667
|
+
Enter: function Enter(event) {
|
|
4668
|
+
// if IME composing, wait for next Enter keydown event.
|
|
4669
|
+
if (event.which === 229) {
|
|
4670
|
+
return;
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4673
|
+
var latestState = latest.current.state;
|
|
4674
|
+
|
|
4675
|
+
if (latestState.isOpen && latestState.highlightedIndex > -1) {
|
|
4676
|
+
event.preventDefault();
|
|
4677
|
+
dispatch({
|
|
4678
|
+
type: InputKeyDownEnter,
|
|
4679
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4680
|
+
});
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4683
|
+
};
|
|
4684
|
+
}, [dispatch, latest]); // Getter props.
|
|
4685
|
+
|
|
4686
|
+
var getLabelProps = react.useCallback(function (labelProps) {
|
|
4687
|
+
return _extends({
|
|
4688
|
+
id: elementIdsRef.current.labelId,
|
|
4689
|
+
htmlFor: elementIdsRef.current.inputId
|
|
4690
|
+
}, labelProps);
|
|
4691
|
+
}, []);
|
|
4692
|
+
var getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
4693
|
+
var _extends2;
|
|
4694
|
+
|
|
4695
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
4696
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
4697
|
+
_ref$refKey = _ref.refKey,
|
|
4698
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
4699
|
+
ref = _ref.ref,
|
|
4700
|
+
rest = _objectWithoutPropertiesLoose(_ref, ["onMouseLeave", "refKey", "ref"]);
|
|
4701
|
+
|
|
4702
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
4703
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
4704
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
4705
|
+
|
|
4706
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
4707
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
4708
|
+
menuRef.current = menuNode;
|
|
4709
|
+
}), _extends2.id = elementIdsRef.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIdsRef.current.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
4505
4710
|
dispatch({
|
|
4506
|
-
type:
|
|
4507
|
-
shiftKey: event.shiftKey,
|
|
4508
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4711
|
+
type: MenuMouseLeave$1
|
|
4509
4712
|
});
|
|
4510
|
-
},
|
|
4511
|
-
|
|
4512
|
-
|
|
4713
|
+
}), _extends2), rest);
|
|
4714
|
+
}, [dispatch, setGetterPropCallInfo]);
|
|
4715
|
+
var getItemProps = react.useCallback(function (_temp3) {
|
|
4716
|
+
var _extends3, _ref4;
|
|
4717
|
+
|
|
4718
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
4719
|
+
item = _ref3.item,
|
|
4720
|
+
index = _ref3.index,
|
|
4721
|
+
_ref3$refKey = _ref3.refKey,
|
|
4722
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4723
|
+
ref = _ref3.ref,
|
|
4724
|
+
onMouseMove = _ref3.onMouseMove,
|
|
4725
|
+
onClick = _ref3.onClick,
|
|
4726
|
+
onPress = _ref3.onPress,
|
|
4727
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"]);
|
|
4728
|
+
|
|
4729
|
+
var _latest$current = latest.current,
|
|
4730
|
+
latestProps = _latest$current.props,
|
|
4731
|
+
latestState = _latest$current.state;
|
|
4732
|
+
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4733
|
+
|
|
4734
|
+
if (itemIndex < 0) {
|
|
4735
|
+
throw new Error('Pass either item or item index in getItemProps!');
|
|
4736
|
+
}
|
|
4737
|
+
|
|
4738
|
+
var onSelectKey = 'onClick';
|
|
4739
|
+
var customClickHandler = onClick;
|
|
4740
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
4741
|
+
if (itemNode) {
|
|
4742
|
+
itemRefs.current[elementIdsRef.current.getItemId(itemIndex)] = itemNode;
|
|
4743
|
+
}
|
|
4744
|
+
}), _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIdsRef.current.getItemId(itemIndex), _extends3), !rest.disabled && (_ref4 = {
|
|
4745
|
+
onMouseMove: callAllEventHandlers(onMouseMove, function itemHandleMouseMove() {
|
|
4746
|
+
if (index === latestState.highlightedIndex) {
|
|
4747
|
+
return;
|
|
4748
|
+
}
|
|
4749
|
+
|
|
4750
|
+
shouldScrollRef.current = false;
|
|
4751
|
+
dispatch({
|
|
4752
|
+
type: ItemMouseMove$1,
|
|
4753
|
+
index: index
|
|
4754
|
+
});
|
|
4755
|
+
})
|
|
4756
|
+
}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, function itemHandleClick() {
|
|
4513
4757
|
dispatch({
|
|
4514
|
-
type:
|
|
4515
|
-
|
|
4758
|
+
type: ItemClick$1,
|
|
4759
|
+
index: index
|
|
4516
4760
|
});
|
|
4517
|
-
},
|
|
4518
|
-
|
|
4519
|
-
|
|
4761
|
+
}), _ref4), {}, rest);
|
|
4762
|
+
}, [dispatch, latest]);
|
|
4763
|
+
var getToggleButtonProps = react.useCallback(function (_temp4) {
|
|
4764
|
+
var _extends4;
|
|
4765
|
+
|
|
4766
|
+
var _ref5 = _temp4 === void 0 ? {} : _temp4,
|
|
4767
|
+
onClick = _ref5.onClick,
|
|
4768
|
+
onPress = _ref5.onPress,
|
|
4769
|
+
_ref5$refKey = _ref5.refKey,
|
|
4770
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
4771
|
+
ref = _ref5.ref,
|
|
4772
|
+
rest = _objectWithoutPropertiesLoose(_ref5, ["onClick", "onPress", "refKey", "ref"]);
|
|
4773
|
+
|
|
4774
|
+
var toggleButtonHandleClick = function () {
|
|
4520
4775
|
dispatch({
|
|
4521
|
-
type:
|
|
4522
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4776
|
+
type: ToggleButtonClick$1
|
|
4523
4777
|
});
|
|
4524
|
-
|
|
4525
|
-
|
|
4778
|
+
|
|
4779
|
+
if (!latest.current.state.isOpen && inputRef.current) {
|
|
4780
|
+
inputRef.current.focus();
|
|
4781
|
+
}
|
|
4782
|
+
};
|
|
4783
|
+
|
|
4784
|
+
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
4785
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
4786
|
+
}), _extends4.id = elementIdsRef.current.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
|
|
4787
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
4788
|
+
}), {}, rest);
|
|
4789
|
+
}, [dispatch, latest]);
|
|
4790
|
+
var getInputProps = react.useCallback(function (_temp5, _temp6) {
|
|
4791
|
+
var _extends5;
|
|
4792
|
+
|
|
4793
|
+
var _ref6 = _temp5 === void 0 ? {} : _temp5,
|
|
4794
|
+
onKeyDown = _ref6.onKeyDown,
|
|
4795
|
+
onChange = _ref6.onChange,
|
|
4796
|
+
onInput = _ref6.onInput,
|
|
4797
|
+
onBlur = _ref6.onBlur,
|
|
4798
|
+
onChangeText = _ref6.onChangeText,
|
|
4799
|
+
_ref6$refKey = _ref6.refKey,
|
|
4800
|
+
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
4801
|
+
ref = _ref6.ref,
|
|
4802
|
+
rest = _objectWithoutPropertiesLoose(_ref6, ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"]);
|
|
4803
|
+
|
|
4804
|
+
var _ref7 = _temp6 === void 0 ? {} : _temp6,
|
|
4805
|
+
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
4806
|
+
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
4807
|
+
|
|
4808
|
+
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
4809
|
+
var latestState = latest.current.state;
|
|
4810
|
+
|
|
4811
|
+
var inputHandleKeyDown = function (event) {
|
|
4812
|
+
var key = normalizeArrowKey(event);
|
|
4813
|
+
|
|
4814
|
+
if (key && inputKeyDownHandlers[key]) {
|
|
4815
|
+
inputKeyDownHandlers[key](event);
|
|
4816
|
+
}
|
|
4817
|
+
};
|
|
4818
|
+
|
|
4819
|
+
var inputHandleChange = function (event) {
|
|
4526
4820
|
dispatch({
|
|
4527
|
-
type:
|
|
4821
|
+
type: InputChange,
|
|
4822
|
+
inputValue: event.target.value
|
|
4528
4823
|
});
|
|
4529
|
-
}
|
|
4530
|
-
Enter: function Enter(event) {
|
|
4531
|
-
// if IME composing, wait for next Enter keydown event.
|
|
4532
|
-
if (event.which === 229) {
|
|
4533
|
-
return;
|
|
4534
|
-
}
|
|
4824
|
+
};
|
|
4535
4825
|
|
|
4536
|
-
|
|
4537
|
-
|
|
4826
|
+
var inputHandleBlur = function () {
|
|
4827
|
+
/* istanbul ignore else */
|
|
4828
|
+
if (!mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
4538
4829
|
dispatch({
|
|
4539
|
-
type:
|
|
4540
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4830
|
+
type: InputBlur
|
|
4541
4831
|
});
|
|
4542
4832
|
}
|
|
4543
|
-
}
|
|
4544
|
-
|
|
4833
|
+
};
|
|
4834
|
+
/* istanbul ignore next (preact) */
|
|
4545
4835
|
|
|
4546
|
-
var inputHandleKeyDown = function (event) {
|
|
4547
|
-
var key = normalizeArrowKey(event);
|
|
4548
4836
|
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
}
|
|
4552
|
-
};
|
|
4837
|
+
var onChangeKey = 'onChange';
|
|
4838
|
+
var eventHandlers = {};
|
|
4553
4839
|
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
type: InputChange,
|
|
4557
|
-
inputValue: event.target.value
|
|
4558
|
-
});
|
|
4559
|
-
};
|
|
4840
|
+
if (!rest.disabled) {
|
|
4841
|
+
var _eventHandlers;
|
|
4560
4842
|
|
|
4561
|
-
|
|
4562
|
-
/* istanbul ignore else */
|
|
4563
|
-
if (!mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
4564
|
-
dispatch({
|
|
4565
|
-
type: InputBlur
|
|
4566
|
-
});
|
|
4843
|
+
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers);
|
|
4567
4844
|
}
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4845
|
+
/* istanbul ignore if (react-native) */
|
|
4846
|
+
|
|
4847
|
+
|
|
4848
|
+
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
4849
|
+
inputRef.current = inputNode;
|
|
4850
|
+
}), _extends5.id = elementIdsRef.current.inputId, _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIdsRef.current.menuId, _extends5), latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
4851
|
+
'aria-activedescendant': elementIdsRef.current.getItemId(latestState.highlightedIndex)
|
|
4852
|
+
}, {
|
|
4853
|
+
'aria-labelledby': elementIdsRef.current.labelId,
|
|
4854
|
+
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
4855
|
+
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
4856
|
+
autoComplete: 'off',
|
|
4857
|
+
value: latestState.inputValue
|
|
4858
|
+
}, eventHandlers, {}, rest);
|
|
4859
|
+
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo]);
|
|
4860
|
+
var getComboboxProps = react.useCallback(function (_temp7, _temp8) {
|
|
4861
|
+
var _extends6;
|
|
4862
|
+
|
|
4863
|
+
var _ref8 = _temp7 === void 0 ? {} : _temp7,
|
|
4864
|
+
_ref8$refKey = _ref8.refKey,
|
|
4865
|
+
refKey = _ref8$refKey === void 0 ? 'ref' : _ref8$refKey,
|
|
4866
|
+
ref = _ref8.ref,
|
|
4867
|
+
rest = _objectWithoutPropertiesLoose(_ref8, ["refKey", "ref"]);
|
|
4868
|
+
|
|
4869
|
+
var _ref9 = _temp8 === void 0 ? {} : _temp8,
|
|
4870
|
+
_ref9$suppressRefErro = _ref9.suppressRefError,
|
|
4871
|
+
suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
|
|
4872
|
+
|
|
4873
|
+
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
4874
|
+
return _extends((_extends6 = {}, _extends6[refKey] = handleRefs(ref, function (comboboxNode) {
|
|
4875
|
+
comboboxRef.current = comboboxNode;
|
|
4876
|
+
}), _extends6.role = 'combobox', _extends6['aria-haspopup'] = 'listbox', _extends6['aria-owns'] = elementIdsRef.current.menuId, _extends6['aria-expanded'] = latest.current.state.isOpen, _extends6), rest);
|
|
4877
|
+
}, [latest, setGetterPropCallInfo]); // returns
|
|
4878
|
+
|
|
4879
|
+
var toggleMenu = react.useCallback(function () {
|
|
4571
4880
|
dispatch({
|
|
4572
|
-
type:
|
|
4881
|
+
type: FunctionToggleMenu$1
|
|
4573
4882
|
});
|
|
4574
|
-
};
|
|
4575
|
-
|
|
4576
|
-
var itemHandleMouseMove = function (index) {
|
|
4577
|
-
if (index === highlightedIndex) {
|
|
4578
|
-
return;
|
|
4579
|
-
}
|
|
4580
|
-
|
|
4581
|
-
shouldScroll.current = false;
|
|
4883
|
+
}, [dispatch]);
|
|
4884
|
+
var closeMenu = react.useCallback(function () {
|
|
4582
4885
|
dispatch({
|
|
4583
|
-
type:
|
|
4584
|
-
index: index
|
|
4886
|
+
type: FunctionCloseMenu$1
|
|
4585
4887
|
});
|
|
4586
|
-
};
|
|
4587
|
-
|
|
4588
|
-
var itemHandleClick = function (index) {
|
|
4888
|
+
}, [dispatch]);
|
|
4889
|
+
var openMenu = react.useCallback(function () {
|
|
4589
4890
|
dispatch({
|
|
4590
|
-
type:
|
|
4591
|
-
index: index
|
|
4891
|
+
type: FunctionOpenMenu$1
|
|
4592
4892
|
});
|
|
4593
|
-
};
|
|
4594
|
-
|
|
4595
|
-
var toggleButtonHandleClick = function () {
|
|
4893
|
+
}, [dispatch]);
|
|
4894
|
+
var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
|
|
4596
4895
|
dispatch({
|
|
4597
|
-
type:
|
|
4896
|
+
type: FunctionSetHighlightedIndex$1,
|
|
4897
|
+
highlightedIndex: newHighlightedIndex
|
|
4598
4898
|
});
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4899
|
+
}, [dispatch]);
|
|
4900
|
+
var selectItem = react.useCallback(function (newSelectedItem) {
|
|
4901
|
+
dispatch({
|
|
4902
|
+
type: FunctionSelectItem$1,
|
|
4903
|
+
selectedItem: newSelectedItem
|
|
4904
|
+
});
|
|
4905
|
+
}, [dispatch]);
|
|
4906
|
+
var setInputValue = react.useCallback(function (newInputValue) {
|
|
4907
|
+
dispatch({
|
|
4908
|
+
type: FunctionSetInputValue$1,
|
|
4909
|
+
inputValue: newInputValue
|
|
4910
|
+
});
|
|
4911
|
+
}, [dispatch]);
|
|
4912
|
+
var reset = react.useCallback(function () {
|
|
4913
|
+
dispatch({
|
|
4914
|
+
type: FunctionReset$1
|
|
4915
|
+
});
|
|
4916
|
+
}, [dispatch]);
|
|
4606
4917
|
return {
|
|
4607
4918
|
// prop getters.
|
|
4608
|
-
getItemProps:
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
onMouseMove = _ref2.onMouseMove,
|
|
4615
|
-
onClick = _ref2.onClick,
|
|
4616
|
-
onPress = _ref2.onPress,
|
|
4617
|
-
rest = _objectWithoutPropertiesLoose(_ref2, ["item", "index", "onMouseMove", "onClick", "onPress"]);
|
|
4618
|
-
|
|
4619
|
-
var itemIndex = getItemIndex(index, item, items);
|
|
4620
|
-
|
|
4621
|
-
if (itemIndex < 0) {
|
|
4622
|
-
throw new Error('Pass either item or item index in getItemProps!');
|
|
4623
|
-
}
|
|
4624
|
-
|
|
4625
|
-
var onSelectKey = 'onClick';
|
|
4626
|
-
var customClickHandler = onClick;
|
|
4627
|
-
return _extends(_extends({
|
|
4628
|
-
role: 'option',
|
|
4629
|
-
'aria-selected': "" + (itemIndex === highlightedIndex),
|
|
4630
|
-
id: elementIds.current.getItemId(itemIndex)
|
|
4631
|
-
}, !rest.disabled && (_ref3 = {
|
|
4632
|
-
onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
|
4633
|
-
itemHandleMouseMove(itemIndex);
|
|
4634
|
-
})
|
|
4635
|
-
}, _ref3[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
|
|
4636
|
-
itemHandleClick(itemIndex);
|
|
4637
|
-
}), _ref3)), rest);
|
|
4638
|
-
},
|
|
4639
|
-
getLabelProps: function getLabelProps(labelProps) {
|
|
4640
|
-
return _extends({
|
|
4641
|
-
id: elementIds.current.labelId,
|
|
4642
|
-
htmlFor: elementIds.current.inputId
|
|
4643
|
-
}, labelProps);
|
|
4644
|
-
},
|
|
4645
|
-
getMenuProps: function getMenuProps(_temp) {
|
|
4646
|
-
var _extends2;
|
|
4647
|
-
|
|
4648
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
4649
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
4650
|
-
_ref$refKey = _ref.refKey,
|
|
4651
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
4652
|
-
ref = _ref.ref,
|
|
4653
|
-
rest = _objectWithoutPropertiesLoose(_ref, ["onMouseLeave", "refKey", "ref"]);
|
|
4654
|
-
|
|
4655
|
-
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
4656
|
-
menuRef.current = menuNode;
|
|
4657
|
-
}), _extends2.id = elementIds.current.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.current.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
|
|
4658
|
-
},
|
|
4659
|
-
getInputProps: function getInputProps(_temp4) {
|
|
4660
|
-
var _extends4;
|
|
4661
|
-
|
|
4662
|
-
var _ref5 = _temp4 === void 0 ? {} : _temp4,
|
|
4663
|
-
onKeyDown = _ref5.onKeyDown,
|
|
4664
|
-
onChange = _ref5.onChange,
|
|
4665
|
-
onInput = _ref5.onInput,
|
|
4666
|
-
onBlur = _ref5.onBlur,
|
|
4667
|
-
onChangeText = _ref5.onChangeText,
|
|
4668
|
-
_ref5$refKey = _ref5.refKey,
|
|
4669
|
-
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
4670
|
-
ref = _ref5.ref,
|
|
4671
|
-
rest = _objectWithoutPropertiesLoose(_ref5, ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"]);
|
|
4672
|
-
|
|
4673
|
-
/* istanbul ignore next (preact) */
|
|
4674
|
-
var onChangeKey = 'onChange';
|
|
4675
|
-
var eventHandlers = {};
|
|
4676
|
-
|
|
4677
|
-
if (!rest.disabled) {
|
|
4678
|
-
var _eventHandlers;
|
|
4679
|
-
|
|
4680
|
-
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers);
|
|
4681
|
-
}
|
|
4682
|
-
/* istanbul ignore if (react-native) */
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
return _extends(_extends(_extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (inputNode) {
|
|
4686
|
-
inputRef.current = inputNode;
|
|
4687
|
-
}), _extends4.id = elementIds.current.inputId, _extends4['aria-autocomplete'] = 'list', _extends4['aria-controls'] = elementIds.current.menuId, _extends4), isOpen && highlightedIndex > -1 && {
|
|
4688
|
-
'aria-activedescendant': elementIds.current.getItemId(highlightedIndex)
|
|
4689
|
-
}), {}, {
|
|
4690
|
-
'aria-labelledby': elementIds.current.labelId,
|
|
4691
|
-
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
4692
|
-
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
4693
|
-
autoComplete: 'off',
|
|
4694
|
-
value: inputValue
|
|
4695
|
-
}, eventHandlers), rest);
|
|
4696
|
-
},
|
|
4697
|
-
getComboboxProps: function getComboboxProps(_temp5) {
|
|
4698
|
-
var _extends5;
|
|
4699
|
-
|
|
4700
|
-
var _ref6 = _temp5 === void 0 ? {} : _temp5,
|
|
4701
|
-
_ref6$refKey = _ref6.refKey,
|
|
4702
|
-
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
4703
|
-
ref = _ref6.ref,
|
|
4704
|
-
rest = _objectWithoutPropertiesLoose(_ref6, ["refKey", "ref"]);
|
|
4705
|
-
|
|
4706
|
-
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (comboboxNode) {
|
|
4707
|
-
comboboxRef.current = comboboxNode;
|
|
4708
|
-
}), _extends5.role = 'combobox', _extends5['aria-haspopup'] = 'listbox', _extends5['aria-owns'] = elementIds.current.menuId, _extends5['aria-expanded'] = isOpen, _extends5), rest);
|
|
4709
|
-
},
|
|
4710
|
-
getToggleButtonProps: function getToggleButtonProps(_temp3) {
|
|
4711
|
-
var _extends3;
|
|
4712
|
-
|
|
4713
|
-
var _ref4 = _temp3 === void 0 ? {} : _temp3,
|
|
4714
|
-
onClick = _ref4.onClick,
|
|
4715
|
-
onPress = _ref4.onPress,
|
|
4716
|
-
_ref4$refKey = _ref4.refKey,
|
|
4717
|
-
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
4718
|
-
ref = _ref4.ref,
|
|
4719
|
-
rest = _objectWithoutPropertiesLoose(_ref4, ["onClick", "onPress", "refKey", "ref"]);
|
|
4720
|
-
|
|
4721
|
-
return _extends(_extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
4722
|
-
toggleButtonRef.current = toggleButtonNode;
|
|
4723
|
-
}), _extends3.id = elementIds.current.toggleButtonId, _extends3.tabIndex = -1, _extends3), !rest.disabled && _extends({}, {
|
|
4724
|
-
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
4725
|
-
})), rest);
|
|
4726
|
-
},
|
|
4919
|
+
getItemProps: getItemProps,
|
|
4920
|
+
getLabelProps: getLabelProps,
|
|
4921
|
+
getMenuProps: getMenuProps,
|
|
4922
|
+
getInputProps: getInputProps,
|
|
4923
|
+
getComboboxProps: getComboboxProps,
|
|
4924
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
4727
4925
|
// actions.
|
|
4728
|
-
toggleMenu:
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
type: FunctionOpenMenu$1
|
|
4736
|
-
});
|
|
4737
|
-
},
|
|
4738
|
-
closeMenu: function closeMenu() {
|
|
4739
|
-
dispatch({
|
|
4740
|
-
type: FunctionCloseMenu$1
|
|
4741
|
-
});
|
|
4742
|
-
},
|
|
4743
|
-
setHighlightedIndex: function setHighlightedIndex(newHighlightedIndex) {
|
|
4744
|
-
dispatch({
|
|
4745
|
-
type: FunctionSetHighlightedIndex$1,
|
|
4746
|
-
highlightedIndex: newHighlightedIndex
|
|
4747
|
-
});
|
|
4748
|
-
},
|
|
4749
|
-
setInputValue: function setInputValue(newInputValue) {
|
|
4750
|
-
dispatch({
|
|
4751
|
-
type: FunctionSetInputValue$1,
|
|
4752
|
-
inputValue: newInputValue
|
|
4753
|
-
});
|
|
4754
|
-
},
|
|
4755
|
-
selectItem: function selectItem(newSelectedItem) {
|
|
4756
|
-
dispatch({
|
|
4757
|
-
type: FunctionSelectItem$1,
|
|
4758
|
-
selectedItem: newSelectedItem
|
|
4759
|
-
});
|
|
4760
|
-
},
|
|
4761
|
-
reset: function reset() {
|
|
4762
|
-
dispatch({
|
|
4763
|
-
type: FunctionReset$1
|
|
4764
|
-
});
|
|
4765
|
-
},
|
|
4926
|
+
toggleMenu: toggleMenu,
|
|
4927
|
+
openMenu: openMenu,
|
|
4928
|
+
closeMenu: closeMenu,
|
|
4929
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
4930
|
+
setInputValue: setInputValue,
|
|
4931
|
+
selectItem: selectItem,
|
|
4932
|
+
reset: reset,
|
|
4766
4933
|
// state.
|
|
4767
4934
|
highlightedIndex: highlightedIndex,
|
|
4768
4935
|
isOpen: isOpen,
|
|
@@ -5041,20 +5208,18 @@
|
|
|
5041
5208
|
throw new Error('Reducer called without proper action type.');
|
|
5042
5209
|
}
|
|
5043
5210
|
|
|
5044
|
-
return _extends(
|
|
5211
|
+
return _extends({}, state, {}, changes);
|
|
5045
5212
|
}
|
|
5046
5213
|
|
|
5047
5214
|
useMultipleSelection.stateChangeTypes = stateChangeTypes$3;
|
|
5048
5215
|
|
|
5049
5216
|
function useMultipleSelection(userProps) {
|
|
5050
|
-
var _selectedItemKeyDownH, _dropdownKeyDownHandl;
|
|
5051
|
-
|
|
5052
5217
|
if (userProps === void 0) {
|
|
5053
5218
|
userProps = {};
|
|
5054
5219
|
}
|
|
5055
5220
|
|
|
5056
5221
|
// Props defaults and destructuring.
|
|
5057
|
-
var props = _extends(
|
|
5222
|
+
var props = _extends({}, defaultProps$3, {}, userProps);
|
|
5058
5223
|
|
|
5059
5224
|
var getA11yRemovalMessage = props.getA11yRemovalMessage,
|
|
5060
5225
|
itemToString = props.itemToString,
|
|
@@ -5063,22 +5228,28 @@
|
|
|
5063
5228
|
keyNavigationPrevious = props.keyNavigationPrevious; // Reducer init.
|
|
5064
5229
|
|
|
5065
5230
|
var _useControlledReducer = useControlledReducer(downshiftMultipleSelectionReducer, getInitialState$2(props), props),
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
selectedItems = _useControlledReducer2.selectedItems,
|
|
5069
|
-
dispatch = _useControlledReducer[1]; // Refs.
|
|
5231
|
+
state = _useControlledReducer[0],
|
|
5232
|
+
dispatch = _useControlledReducer[1];
|
|
5070
5233
|
|
|
5234
|
+
var activeIndex = state.activeIndex,
|
|
5235
|
+
selectedItems = state.selectedItems; // Refs.
|
|
5071
5236
|
|
|
5072
|
-
var
|
|
5237
|
+
var isInitialMountRef = react.useRef(true);
|
|
5073
5238
|
var dropdownRef = react.useRef(null);
|
|
5074
5239
|
var previousSelectedItemsRef = react.useRef(selectedItems);
|
|
5075
5240
|
var selectedItemRefs = react.useRef();
|
|
5076
|
-
selectedItemRefs.current = []; //
|
|
5241
|
+
selectedItemRefs.current = []; // used for checking when props are moving from controlled to uncontrolled.
|
|
5242
|
+
|
|
5243
|
+
var prevPropsRef = react.useRef(props);
|
|
5244
|
+
var latest = useLatestRef({
|
|
5245
|
+
state: state,
|
|
5246
|
+
props: props
|
|
5247
|
+
}); // Effects.
|
|
5077
5248
|
|
|
5078
5249
|
/* Sets a11y status message on changes in selectedItem. */
|
|
5079
5250
|
|
|
5080
5251
|
react.useEffect(function () {
|
|
5081
|
-
if (
|
|
5252
|
+
if (isInitialMountRef.current) {
|
|
5082
5253
|
return;
|
|
5083
5254
|
}
|
|
5084
5255
|
|
|
@@ -5099,7 +5270,7 @@
|
|
|
5099
5270
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
5100
5271
|
|
|
5101
5272
|
react.useEffect(function () {
|
|
5102
|
-
if (
|
|
5273
|
+
if (isInitialMountRef.current) {
|
|
5103
5274
|
return;
|
|
5104
5275
|
}
|
|
5105
5276
|
|
|
@@ -5108,152 +5279,172 @@
|
|
|
5108
5279
|
} else if (selectedItemRefs.current[activeIndex]) {
|
|
5109
5280
|
selectedItemRefs.current[activeIndex].focus();
|
|
5110
5281
|
}
|
|
5111
|
-
}, [activeIndex]);
|
|
5112
|
-
|
|
5282
|
+
}, [activeIndex]);
|
|
5113
5283
|
react.useEffect(function () {
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
var selectedItemKeyDownHandlers = (_selectedItemKeyDownH = {}, _selectedItemKeyDownH[keyNavigationPrevious] = function () {
|
|
5118
|
-
dispatch({
|
|
5119
|
-
type: SelectedItemKeyDownNavigationPrevious
|
|
5120
|
-
});
|
|
5121
|
-
}, _selectedItemKeyDownH[keyNavigationNext] = function () {
|
|
5122
|
-
dispatch({
|
|
5123
|
-
type: SelectedItemKeyDownNavigationNext
|
|
5124
|
-
});
|
|
5125
|
-
}, _selectedItemKeyDownH.Delete = function Delete() {
|
|
5126
|
-
dispatch({
|
|
5127
|
-
type: SelectedItemKeyDownDelete
|
|
5128
|
-
});
|
|
5129
|
-
}, _selectedItemKeyDownH.Backspace = function Backspace() {
|
|
5130
|
-
dispatch({
|
|
5131
|
-
type: SelectedItemKeyDownBackspace
|
|
5132
|
-
});
|
|
5133
|
-
}, _selectedItemKeyDownH);
|
|
5134
|
-
var dropdownKeyDownHandlers = (_dropdownKeyDownHandl = {}, _dropdownKeyDownHandl[keyNavigationPrevious] = function (event) {
|
|
5135
|
-
if (isKeyDownOperationPermitted(event)) {
|
|
5136
|
-
dispatch({
|
|
5137
|
-
type: DropdownKeyDownNavigationPrevious
|
|
5138
|
-
});
|
|
5139
|
-
}
|
|
5140
|
-
}, _dropdownKeyDownHandl.Backspace = function Backspace(event) {
|
|
5141
|
-
if (isKeyDownOperationPermitted(event)) {
|
|
5142
|
-
dispatch({
|
|
5143
|
-
type: DropdownKeyDownBackspace
|
|
5144
|
-
});
|
|
5145
|
-
}
|
|
5146
|
-
}, _dropdownKeyDownHandl); // Event handlers.
|
|
5147
|
-
|
|
5148
|
-
var selectedItemHandleClick = function (index) {
|
|
5149
|
-
dispatch({
|
|
5150
|
-
type: SelectedItemClick,
|
|
5151
|
-
index: index
|
|
5152
|
-
});
|
|
5153
|
-
};
|
|
5154
|
-
|
|
5155
|
-
var selectedItemHandleKeyDown = function (event) {
|
|
5156
|
-
var key = normalizeArrowKey(event);
|
|
5157
|
-
|
|
5158
|
-
if (key && selectedItemKeyDownHandlers[key]) {
|
|
5159
|
-
selectedItemKeyDownHandlers[key](event);
|
|
5160
|
-
}
|
|
5161
|
-
};
|
|
5162
|
-
|
|
5163
|
-
var dropdownHandleKeyDown = function (event) {
|
|
5164
|
-
var key = normalizeArrowKey(event);
|
|
5165
|
-
|
|
5166
|
-
if (key && dropdownKeyDownHandlers[key]) {
|
|
5167
|
-
dropdownKeyDownHandlers[key](event);
|
|
5284
|
+
if (isInitialMountRef.current) {
|
|
5285
|
+
return;
|
|
5168
5286
|
}
|
|
5169
|
-
};
|
|
5170
5287
|
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
}; // Getter props.
|
|
5288
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
5289
|
+
prevPropsRef.current = props;
|
|
5290
|
+
}, [state, props]);
|
|
5291
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
5176
5292
|
|
|
5293
|
+
react.useEffect(function () {
|
|
5294
|
+
isInitialMountRef.current = false;
|
|
5295
|
+
}, []); // Event handler functions.
|
|
5177
5296
|
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
var _extends2;
|
|
5181
|
-
|
|
5182
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
5183
|
-
_ref$refKey = _ref.refKey,
|
|
5184
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
5185
|
-
ref = _ref.ref,
|
|
5186
|
-
onClick = _ref.onClick,
|
|
5187
|
-
onKeyDown = _ref.onKeyDown,
|
|
5188
|
-
selectedItem = _ref.selectedItem,
|
|
5189
|
-
index = _ref.index,
|
|
5190
|
-
rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"]);
|
|
5191
|
-
|
|
5192
|
-
var itemIndex = getItemIndex(index, selectedItem, selectedItems);
|
|
5193
|
-
|
|
5194
|
-
if (itemIndex < 0) {
|
|
5195
|
-
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
5196
|
-
}
|
|
5297
|
+
var selectedItemKeyDownHandlers = react.useMemo(function () {
|
|
5298
|
+
var _ref;
|
|
5197
5299
|
|
|
5198
|
-
|
|
5199
|
-
if (selectedItemNode) {
|
|
5200
|
-
selectedItemRefs.current.push(selectedItemNode);
|
|
5201
|
-
}
|
|
5202
|
-
}), _extends2.tabIndex = index === activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, function () {
|
|
5203
|
-
selectedItemHandleClick(index);
|
|
5204
|
-
}), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
5205
|
-
},
|
|
5206
|
-
getDropdownProps: function getDropdownProps(_temp2) {
|
|
5207
|
-
var _extends3;
|
|
5208
|
-
|
|
5209
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
5210
|
-
_ref2$refKey = _ref2.refKey,
|
|
5211
|
-
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
5212
|
-
ref = _ref2.ref,
|
|
5213
|
-
onKeyDown = _ref2.onKeyDown,
|
|
5214
|
-
onClick = _ref2.onClick,
|
|
5215
|
-
_ref2$preventKeyActio = _ref2.preventKeyAction,
|
|
5216
|
-
preventKeyAction = _ref2$preventKeyActio === void 0 ? false : _ref2$preventKeyActio,
|
|
5217
|
-
rest = _objectWithoutPropertiesLoose(_ref2, ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"]);
|
|
5218
|
-
|
|
5219
|
-
return _extends(_extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
|
|
5220
|
-
if (dropdownNode) {
|
|
5221
|
-
dropdownRef.current = dropdownNode;
|
|
5222
|
-
}
|
|
5223
|
-
}), _extends3), !preventKeyAction && {
|
|
5224
|
-
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
5225
|
-
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
5226
|
-
}), rest);
|
|
5227
|
-
},
|
|
5228
|
-
addSelectedItem: function addSelectedItem(selectedItem) {
|
|
5300
|
+
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
5229
5301
|
dispatch({
|
|
5230
|
-
type:
|
|
5231
|
-
selectedItem: selectedItem
|
|
5302
|
+
type: SelectedItemKeyDownNavigationPrevious
|
|
5232
5303
|
});
|
|
5233
|
-
},
|
|
5234
|
-
removeSelectedItem: function removeSelectedItem(selectedItem) {
|
|
5304
|
+
}, _ref[keyNavigationNext] = function () {
|
|
5235
5305
|
dispatch({
|
|
5236
|
-
type:
|
|
5237
|
-
selectedItem: selectedItem
|
|
5306
|
+
type: SelectedItemKeyDownNavigationNext
|
|
5238
5307
|
});
|
|
5239
|
-
},
|
|
5240
|
-
setSelectedItems: function setSelectedItems(newSelectedItems) {
|
|
5308
|
+
}, _ref.Delete = function Delete() {
|
|
5241
5309
|
dispatch({
|
|
5242
|
-
type:
|
|
5243
|
-
selectedItems: newSelectedItems
|
|
5310
|
+
type: SelectedItemKeyDownDelete
|
|
5244
5311
|
});
|
|
5245
|
-
},
|
|
5246
|
-
setActiveIndex: function setActiveIndex(newActiveIndex) {
|
|
5312
|
+
}, _ref.Backspace = function Backspace() {
|
|
5247
5313
|
dispatch({
|
|
5248
|
-
type:
|
|
5249
|
-
activeIndex: newActiveIndex
|
|
5314
|
+
type: SelectedItemKeyDownBackspace
|
|
5250
5315
|
});
|
|
5251
|
-
},
|
|
5252
|
-
|
|
5316
|
+
}, _ref;
|
|
5317
|
+
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
5318
|
+
var dropdownKeyDownHandlers = react.useMemo(function () {
|
|
5319
|
+
var _ref2;
|
|
5320
|
+
|
|
5321
|
+
return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
|
|
5322
|
+
if (isKeyDownOperationPermitted(event)) {
|
|
5323
|
+
dispatch({
|
|
5324
|
+
type: DropdownKeyDownNavigationPrevious
|
|
5325
|
+
});
|
|
5326
|
+
}
|
|
5327
|
+
}, _ref2.Backspace = function Backspace(event) {
|
|
5328
|
+
if (isKeyDownOperationPermitted(event)) {
|
|
5329
|
+
dispatch({
|
|
5330
|
+
type: DropdownKeyDownBackspace
|
|
5331
|
+
});
|
|
5332
|
+
}
|
|
5333
|
+
}, _ref2;
|
|
5334
|
+
}, [dispatch, keyNavigationPrevious]); // Getter props.
|
|
5335
|
+
|
|
5336
|
+
var getSelectedItemProps = react.useCallback(function (_temp) {
|
|
5337
|
+
var _extends2;
|
|
5338
|
+
|
|
5339
|
+
var _ref3 = _temp === void 0 ? {} : _temp,
|
|
5340
|
+
_ref3$refKey = _ref3.refKey,
|
|
5341
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
5342
|
+
ref = _ref3.ref,
|
|
5343
|
+
onClick = _ref3.onClick,
|
|
5344
|
+
onKeyDown = _ref3.onKeyDown,
|
|
5345
|
+
selectedItem = _ref3.selectedItem,
|
|
5346
|
+
index = _ref3.index,
|
|
5347
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"]);
|
|
5348
|
+
|
|
5349
|
+
var latestState = latest.current.state;
|
|
5350
|
+
var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
5351
|
+
|
|
5352
|
+
if (itemIndex < 0) {
|
|
5353
|
+
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
5354
|
+
}
|
|
5355
|
+
|
|
5356
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
|
|
5357
|
+
if (selectedItemNode) {
|
|
5358
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
5359
|
+
}
|
|
5360
|
+
}), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, function selectedItemHandleClick() {
|
|
5253
5361
|
dispatch({
|
|
5254
|
-
type:
|
|
5362
|
+
type: SelectedItemClick,
|
|
5363
|
+
index: index
|
|
5255
5364
|
});
|
|
5256
|
-
},
|
|
5365
|
+
}), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, function selectedItemHandleKeyDown(event) {
|
|
5366
|
+
var key = normalizeArrowKey(event);
|
|
5367
|
+
|
|
5368
|
+
if (key && selectedItemKeyDownHandlers[key]) {
|
|
5369
|
+
selectedItemKeyDownHandlers[key](event);
|
|
5370
|
+
}
|
|
5371
|
+
}), _extends2), rest);
|
|
5372
|
+
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
5373
|
+
var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
5374
|
+
var _extends3;
|
|
5375
|
+
|
|
5376
|
+
var _ref4 = _temp2 === void 0 ? {} : _temp2,
|
|
5377
|
+
_ref4$refKey = _ref4.refKey,
|
|
5378
|
+
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
5379
|
+
ref = _ref4.ref,
|
|
5380
|
+
onKeyDown = _ref4.onKeyDown,
|
|
5381
|
+
onClick = _ref4.onClick,
|
|
5382
|
+
_ref4$preventKeyActio = _ref4.preventKeyAction,
|
|
5383
|
+
preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
|
|
5384
|
+
rest = _objectWithoutPropertiesLoose(_ref4, ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"]);
|
|
5385
|
+
|
|
5386
|
+
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
5387
|
+
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
5388
|
+
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
5389
|
+
|
|
5390
|
+
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
5391
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
|
|
5392
|
+
if (dropdownNode) {
|
|
5393
|
+
dropdownRef.current = dropdownNode;
|
|
5394
|
+
}
|
|
5395
|
+
}), _extends3), !preventKeyAction && {
|
|
5396
|
+
onKeyDown: callAllEventHandlers(onKeyDown, function dropdownHandleKeyDown(event) {
|
|
5397
|
+
var key = normalizeArrowKey(event);
|
|
5398
|
+
|
|
5399
|
+
if (key && dropdownKeyDownHandlers[key]) {
|
|
5400
|
+
dropdownKeyDownHandlers[key](event);
|
|
5401
|
+
}
|
|
5402
|
+
}),
|
|
5403
|
+
onClick: callAllEventHandlers(onClick, function dropdownHandleClick() {
|
|
5404
|
+
dispatch({
|
|
5405
|
+
type: DropdownClick
|
|
5406
|
+
});
|
|
5407
|
+
})
|
|
5408
|
+
}, {}, rest);
|
|
5409
|
+
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
5410
|
+
|
|
5411
|
+
var addSelectedItem = react.useCallback(function (selectedItem) {
|
|
5412
|
+
dispatch({
|
|
5413
|
+
type: FunctionAddSelectedItem,
|
|
5414
|
+
selectedItem: selectedItem
|
|
5415
|
+
});
|
|
5416
|
+
}, [dispatch]);
|
|
5417
|
+
var removeSelectedItem = react.useCallback(function (selectedItem) {
|
|
5418
|
+
dispatch({
|
|
5419
|
+
type: FunctionRemoveSelectedItem,
|
|
5420
|
+
selectedItem: selectedItem
|
|
5421
|
+
});
|
|
5422
|
+
}, [dispatch]);
|
|
5423
|
+
var setSelectedItems = react.useCallback(function (newSelectedItems) {
|
|
5424
|
+
dispatch({
|
|
5425
|
+
type: FunctionSetSelectedItems,
|
|
5426
|
+
selectedItems: newSelectedItems
|
|
5427
|
+
});
|
|
5428
|
+
}, [dispatch]);
|
|
5429
|
+
var setActiveIndex = react.useCallback(function (newActiveIndex) {
|
|
5430
|
+
dispatch({
|
|
5431
|
+
type: FunctionSetActiveIndex,
|
|
5432
|
+
activeIndex: newActiveIndex
|
|
5433
|
+
});
|
|
5434
|
+
}, [dispatch]);
|
|
5435
|
+
var reset = react.useCallback(function () {
|
|
5436
|
+
dispatch({
|
|
5437
|
+
type: FunctionReset$2
|
|
5438
|
+
});
|
|
5439
|
+
}, [dispatch]);
|
|
5440
|
+
return {
|
|
5441
|
+
getSelectedItemProps: getSelectedItemProps,
|
|
5442
|
+
getDropdownProps: getDropdownProps,
|
|
5443
|
+
addSelectedItem: addSelectedItem,
|
|
5444
|
+
removeSelectedItem: removeSelectedItem,
|
|
5445
|
+
setSelectedItems: setSelectedItems,
|
|
5446
|
+
setActiveIndex: setActiveIndex,
|
|
5447
|
+
reset: reset,
|
|
5257
5448
|
selectedItems: selectedItems,
|
|
5258
5449
|
activeIndex: activeIndex
|
|
5259
5450
|
};
|