downshift 9.3.1 → 9.4.0-alpha.0
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.cjs +623 -702
- package/dist/downshift.d.ts +49 -55
- package/dist/downshift.esm.mjs +624 -703
- package/dist/downshift.native.cjs.cjs +578 -654
- package/dist/downshift.nativeweb.cjs.cjs +621 -697
- package/dist/downshift.types.d.ts +205 -0
- package/dist/downshift.umd.js +627 -706
- 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/hooks/testUtils/MemoizedItem.d.ts +10 -0
- package/dist/hooks/testUtils/fixtures.d.ts +16 -0
- package/dist/hooks/testUtils/index.d.ts +4 -0
- package/dist/hooks/testUtils/interactions.d.ts +16 -0
- package/dist/hooks/testUtils/testCases.d.ts +2 -0
- package/dist/hooks/useCombobox/__tests__/utils/index.d.ts +5 -0
- package/dist/hooks/useCombobox/__tests__/utils/interactions.d.ts +6 -0
- package/dist/hooks/useCombobox/__tests__/utils/renderCombobox.d.ts +72 -0
- package/dist/hooks/useCombobox/__tests__/utils/renderUseCombobox.d.ts +2 -0
- package/dist/hooks/useCombobox/index.d.ts +4 -94
- package/dist/hooks/useCombobox/index.types.d.ts +302 -0
- package/dist/hooks/useCombobox/reducer.d.ts +4 -1
- package/dist/hooks/useCombobox/stateChangeTypes.d.ts +24 -23
- package/dist/hooks/useCombobox/utils/getInitialState.d.ts +10 -0
- package/dist/hooks/useCombobox/utils/index.d.ts +3 -0
- package/dist/hooks/useCombobox/{utils.d.ts → utils/propTypes.d.ts} +2 -30
- package/dist/hooks/useCombobox/utils/useControlledReducer.d.ts +16 -0
- package/dist/hooks/useMultipleSelection/index.d.ts +25 -13
- package/dist/hooks/useMultipleSelection/index.types.d.ts +117 -0
- package/dist/hooks/useMultipleSelection/reducer.d.ts +1 -1
- package/dist/hooks/useMultipleSelection/utils.d.ts +14 -15
- package/dist/hooks/useSelect/__tests__/utils/getItemIndexByCharacter.d.ts +7 -0
- package/dist/hooks/useSelect/__tests__/utils/index.d.ts +6 -0
- package/dist/hooks/useSelect/__tests__/utils/renderSelect.d.ts +71 -0
- package/dist/hooks/useSelect/__tests__/utils/renderUseSelect.d.ts +2 -0
- package/dist/hooks/useSelect/__tests__/utils/stateChangeTestCases.d.ts +182 -0
- package/dist/hooks/useSelect/index.d.ts +4 -71
- package/dist/hooks/useSelect/index.types.d.ts +266 -0
- package/dist/hooks/useSelect/reducer.d.ts +4 -1
- package/dist/hooks/useSelect/stateChangeTypes.d.ts +23 -22
- package/dist/hooks/useSelect/utils/index.d.ts +0 -1
- package/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +1 -1
- package/dist/hooks/useTagGroup/index.types.d.ts +10 -13
- package/dist/hooks/useTagGroup/reducer.d.ts +4 -2
- package/dist/hooks/useTagGroup/utils/index.d.ts +3 -1
- package/dist/hooks/utils/__tests__/dropdownDefaultProps.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getChangesOnSelection.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getDefaultHighlightedIndex.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getDefaultValue.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getHighlightedIndexOnOpen.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getInitialValue.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/getItemAndIndex.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/isDropdownStateEqual.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useA11yMessageStatus.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useControlPropsValidator.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useControlledReducer.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useElementIds.legacy.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useElementIds.r18.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useEnhancedReducer.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useGetterPropsCalledChecker.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useIsInitialMount.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useMouseAndTouchTracker.test.d.ts +1 -0
- package/dist/hooks/utils/__tests__/useScrollIntoView.test.d.ts +1 -0
- package/dist/hooks/utils/callOnChangeProps.d.ts +4 -0
- package/dist/hooks/utils/dropdownDefaultProps.d.ts +13 -0
- package/dist/hooks/{utils.dropdown/defaultStateValues.d.ts → utils/dropdownDefaultStateValues.d.ts} +2 -2
- package/dist/hooks/{utils.dropdown/propTypes.d.ts → utils/dropdownPropTypes.d.ts} +1 -1
- package/dist/hooks/utils/getChangesOnSelection.d.ts +17 -0
- package/dist/hooks/utils/getDefaultHighlightedIndex.d.ts +7 -0
- package/dist/hooks/utils/getDefaultValue.d.ts +8 -0
- package/dist/hooks/utils/getHighlightedIndexOnOpen.d.ts +16 -0
- package/dist/hooks/utils/getInitialState.d.ts +23 -0
- package/dist/hooks/utils/getInitialValue.d.ts +14 -0
- package/dist/hooks/utils/index.d.ts +24 -0
- package/dist/hooks/utils/index.types.d.ts +26 -0
- package/dist/hooks/utils/isDropdownStateEqual.d.ts +16 -0
- package/dist/hooks/utils/reducer.d.ts +27 -0
- package/dist/hooks/utils/useControlPropsValidator.d.ts +6 -0
- package/dist/hooks/utils/useControlledReducer.d.ts +13 -0
- package/dist/hooks/utils/useEnhancedReducer.d.ts +15 -0
- package/dist/hooks/utils/useGetterPropsCalledChecker.d.ts +2 -0
- package/dist/hooks/utils/useMouseAndTouchTracker.d.ts +15 -0
- package/dist/hooks/utils/useScrollIntoView.d.ts +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/utils/__tests__/callAllEventHandlers.test.d.ts +1 -0
- package/dist/utils/__tests__/debounce.test.d.ts +1 -0
- package/dist/utils/__tests__/generateId.r18.test.d.ts +1 -0
- package/dist/utils/__tests__/generateId.test.d.ts +1 -0
- package/dist/utils/__tests__/getHighlightedIndex.test.d.ts +1 -0
- package/dist/utils/__tests__/getNonDisabledIndex.test.d.ts +1 -0
- package/dist/utils/__tests__/getState.test.d.ts +1 -0
- package/dist/utils/__tests__/handleRefs.test.d.ts +1 -0
- package/dist/utils/__tests__/normalizeArrowKey.test.d.ts +1 -0
- package/dist/utils/__tests__/scrollIntoView.test.d.ts +1 -0
- package/dist/utils/__tests__/setA11yStatus.test.d.ts +1 -0
- package/dist/utils/__tests__/targetWithinDownshift.test.d.ts +1 -0
- package/dist/utils/__tests__/useLatestRef.test.d.ts +1 -0
- package/dist/utils/__tests__/validateControlledUnchanged.test.d.ts +1 -0
- package/dist/utils/__tests__/validatePropTypes.test.d.ts +1 -0
- package/dist/utils/getHighlightedIndex.d.ts +11 -0
- package/dist/utils/getNonDisabledIndex.d.ts +11 -0
- package/dist/utils/getState.d.ts +12 -0
- package/dist/utils/handleRefs.d.ts +2 -0
- package/dist/{utils-ts → utils}/index.d.ts +5 -1
- package/dist/utils/normalizeArrowKey.d.ts +6 -0
- package/dist/utils/targetWithinDownshift.d.ts +12 -0
- package/dist/utils/validateControlledUnchanged.d.ts +1 -0
- package/dist/utils/validatePropTypes.d.ts +2 -0
- package/dist/utils.legacy.d.ts +54 -0
- package/flow-typed/npm/downshift_v2.x.x.js.flow +87 -62
- package/package.json +2 -4
- package/preact/dist/downshift.cjs.cjs +623 -702
- package/preact/dist/downshift.cjs.js +4265 -0
- package/preact/dist/downshift.esm.js +4238 -0
- package/preact/dist/downshift.esm.mjs +624 -703
- package/preact/dist/downshift.umd.js +623 -702
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -1
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/typings/index.d.ts +13 -21
- package/dist/hooks/reducer.d.ts +0 -1
- package/dist/hooks/useSelect/utils/defaultProps.d.ts +0 -8
- package/dist/hooks/utils-ts/callOnChangeProps.d.ts +0 -2
- package/dist/hooks/utils-ts/getDefaultValue.d.ts +0 -2
- package/dist/hooks/utils-ts/getInitialValue.d.ts +0 -2
- package/dist/hooks/utils-ts/index.d.ts +0 -11
- package/dist/hooks/utils-ts/stateReducer.d.ts +0 -6
- package/dist/hooks/utils-ts/useControlledReducer.d.ts +0 -12
- package/dist/hooks/utils-ts/useEnhancedReducer.d.ts +0 -13
- package/dist/hooks/utils.d.ts +0 -58
- package/dist/hooks/utils.dropdown/defaultProps.d.ts +0 -9
- package/dist/hooks/utils.dropdown/index.d.ts +0 -3
- package/dist/utils-ts/getState.d.ts +0 -22
- package/dist/utils-ts/handleRefs.d.ts +0 -2
- package/dist/utils-ts/validatePropTypes.d.ts +0 -2
- package/dist/utils.d.ts +0 -123
- package/typings/index.legacy.d.ts +0 -888
- /package/dist/hooks/{utils-ts/__tests__/getItemAndIndex.test.d.ts → useCombobox/utils/__tests__/getInitialState.test.d.ts} +0 -0
- /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.legacy.test.d.ts → useCombobox/utils/__tests__/useControlledReducer.test.d.ts} +0 -0
- /package/dist/hooks/{utils.dropdown/__tests__/useElementIds.r18.test.d.ts → useSelect/utils/__tests__/getItemIndexByCharacterKey.test.d.ts} +0 -0
- /package/dist/{utils-ts/__tests__/getState.test.d.ts → hooks/utils/__tests__/callOnChangeProps.test.d.ts} +0 -0
- /package/dist/{utils-ts/__tests__/handleRefs.test.d.ts → hooks/utils/__tests__/capitalizeString.test.d.ts} +0 -0
- /package/dist/hooks/{utils-ts → utils}/capitalizeString.d.ts +0 -0
- /package/dist/hooks/{utils-ts → utils}/getItemAndIndex.d.ts +0 -0
- /package/dist/hooks/{utils-ts → utils}/propTypes.d.ts +0 -0
- /package/dist/hooks/{utils-ts → utils}/useA11yMessageStatus.d.ts +0 -0
- /package/dist/hooks/{utils.dropdown → utils}/useElementIds.d.ts +0 -0
- /package/dist/hooks/{utils-ts → utils}/useIsInitialMount.d.ts +0 -0
- /package/dist/{utils-ts → utils}/callAllEventHandlers.d.ts +0 -0
- /package/dist/{utils-ts → utils}/debounce.d.ts +0 -0
- /package/dist/{utils-ts → utils}/generateId.d.ts +0 -0
- /package/dist/{utils-ts → utils}/noop.d.ts +0 -0
- /package/dist/{utils-ts → utils}/scrollIntoView.d.ts +0 -0
- /package/dist/{utils-ts → utils}/setA11yStatus.d.ts +0 -0
- /package/dist/{utils-ts → utils}/useLatestRef.d.ts +0 -0
|
@@ -101,7 +101,7 @@ function useLatestRef(val) {
|
|
|
101
101
|
return ref;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function handleRefs
|
|
104
|
+
function handleRefs() {
|
|
105
105
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
106
106
|
refs[_key] = arguments[_key];
|
|
107
107
|
}
|
|
@@ -123,7 +123,7 @@ function handleRefs$1() {
|
|
|
123
123
|
* @param fns the event handler functions
|
|
124
124
|
* @return the event handler to add to an element
|
|
125
125
|
*/
|
|
126
|
-
function callAllEventHandlers
|
|
126
|
+
function callAllEventHandlers() {
|
|
127
127
|
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
128
128
|
fns[_key] = arguments[_key];
|
|
129
129
|
}
|
|
@@ -145,7 +145,7 @@ function callAllEventHandlers$1() {
|
|
|
145
145
|
* function once after the time given has passed since
|
|
146
146
|
* it was last called.
|
|
147
147
|
*/
|
|
148
|
-
function debounce
|
|
148
|
+
function debounce(fn, time) {
|
|
149
149
|
var timeoutId;
|
|
150
150
|
function cancel() {
|
|
151
151
|
if (timeoutId) {
|
|
@@ -166,7 +166,7 @@ function debounce$1(fn, time) {
|
|
|
166
166
|
return wrapper;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
var cleanupStatus = debounce
|
|
169
|
+
var cleanupStatus = debounce(function (document) {
|
|
170
170
|
getStatusDiv(document).textContent = '';
|
|
171
171
|
}, 500);
|
|
172
172
|
|
|
@@ -247,6 +247,8 @@ function getState(state, props) {
|
|
|
247
247
|
}
|
|
248
248
|
var keys = Object.keys(state);
|
|
249
249
|
return keys.reduce(function (newState, key) {
|
|
250
|
+
// state keys could be in props, but with value undefined, which means they should be ignored.
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
250
252
|
if (props[key] !== undefined) {
|
|
251
253
|
newState[key] = props[key];
|
|
252
254
|
}
|
|
@@ -278,84 +280,121 @@ function scrollIntoView(node, menuNode) {
|
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* passed.
|
|
285
|
-
* @param {Function} cb the callback
|
|
286
|
-
* @return {Function} a function
|
|
283
|
+
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
284
|
+
* @param event a keyboardEvent object
|
|
285
|
+
* @return keyboard key
|
|
287
286
|
*/
|
|
288
|
-
function
|
|
289
|
-
|
|
287
|
+
function normalizeArrowKey(event) {
|
|
288
|
+
var key = event.key,
|
|
289
|
+
keyCode = event.keyCode;
|
|
290
|
+
/* istanbul ignore next (ie) */
|
|
291
|
+
if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
|
|
292
|
+
return "Arrow" + key;
|
|
293
|
+
}
|
|
294
|
+
return key;
|
|
290
295
|
}
|
|
291
296
|
|
|
292
297
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* @param
|
|
297
|
-
* @param
|
|
298
|
-
* @
|
|
298
|
+
* Returns the next non-disabled highlightedIndex value.
|
|
299
|
+
*
|
|
300
|
+
* @param start The current highlightedIndex.
|
|
301
|
+
* @param backwards If true, it will search backwards from the start.
|
|
302
|
+
* @param items The items array.
|
|
303
|
+
* @param isItemDisabled Function that tells if an item is disabled or not.
|
|
304
|
+
* @param circular If the search reaches the end, if it can search again starting from the other end.
|
|
305
|
+
* @returns The next non-disabled index.
|
|
299
306
|
*/
|
|
300
|
-
function
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (timeoutId) {
|
|
304
|
-
clearTimeout(timeoutId);
|
|
305
|
-
}
|
|
307
|
+
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
308
|
+
if (circular === void 0) {
|
|
309
|
+
circular = false;
|
|
306
310
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
311
|
+
var count = items.length;
|
|
312
|
+
if (backwards) {
|
|
313
|
+
for (var index = start; index >= 0; index--) {
|
|
314
|
+
if (!isItemDisabled(items[index], index)) {
|
|
315
|
+
return index;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
for (var _index = start; _index < count; _index++) {
|
|
320
|
+
if (!isItemDisabled(items[_index], _index)) {
|
|
321
|
+
return _index;
|
|
322
|
+
}
|
|
310
323
|
}
|
|
311
|
-
cancel();
|
|
312
|
-
timeoutId = setTimeout(function () {
|
|
313
|
-
timeoutId = null;
|
|
314
|
-
fn.apply(void 0, args);
|
|
315
|
-
}, time);
|
|
316
324
|
}
|
|
317
|
-
|
|
318
|
-
|
|
325
|
+
if (circular) {
|
|
326
|
+
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
327
|
+
}
|
|
328
|
+
return -1;
|
|
319
329
|
}
|
|
320
330
|
|
|
321
331
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* @param
|
|
326
|
-
* @
|
|
332
|
+
* Returns the next non-disabled highlightedIndex value.
|
|
333
|
+
*
|
|
334
|
+
* @param start The current highlightedIndex.
|
|
335
|
+
* @param offset The offset from the current highlightedIndex to start searching.
|
|
336
|
+
* @param items The items array.
|
|
337
|
+
* @param isItemDisabled Function that tells if an item is disabled or not.
|
|
338
|
+
* @param circular If the search reaches the end, if it can search again starting from the other end.
|
|
339
|
+
* @returns The next highlightedIndex.
|
|
327
340
|
*/
|
|
328
|
-
function
|
|
329
|
-
|
|
330
|
-
|
|
341
|
+
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
342
|
+
if (circular === void 0) {
|
|
343
|
+
circular = false;
|
|
331
344
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
return fns.some(function (fn) {
|
|
337
|
-
if (fn) {
|
|
338
|
-
fn.apply(void 0, [event].concat(args));
|
|
339
|
-
}
|
|
340
|
-
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
341
|
-
});
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
function handleRefs() {
|
|
345
|
-
for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
346
|
-
refs[_key4] = arguments[_key4];
|
|
345
|
+
var count = items.length;
|
|
346
|
+
if (count === 0) {
|
|
347
|
+
return -1;
|
|
347
348
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
349
|
+
var itemsLastIndex = count - 1;
|
|
350
|
+
if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
|
|
351
|
+
start = offset > 0 ? -1 : itemsLastIndex + 1;
|
|
352
|
+
}
|
|
353
|
+
var current = start + offset;
|
|
354
|
+
if (current < 0) {
|
|
355
|
+
current = circular ? itemsLastIndex : 0;
|
|
356
|
+
} else if (current > itemsLastIndex) {
|
|
357
|
+
current = circular ? 0 : itemsLastIndex;
|
|
358
|
+
}
|
|
359
|
+
var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
|
|
360
|
+
if (highlightedIndex === -1) {
|
|
361
|
+
return start >= count ? -1 : start;
|
|
362
|
+
}
|
|
363
|
+
return highlightedIndex;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
367
|
+
|
|
368
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
369
|
+
var validateControlledUnchanged = noop;
|
|
370
|
+
/* istanbul ignore next */
|
|
371
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
372
|
+
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
373
|
+
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";
|
|
374
|
+
Object.keys(state).forEach(function (propKey) {
|
|
375
|
+
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
376
|
+
// eslint-disable-next-line no-console
|
|
377
|
+
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
378
|
+
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
379
|
+
// eslint-disable-next-line no-console
|
|
380
|
+
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
354
381
|
}
|
|
355
382
|
});
|
|
356
383
|
};
|
|
357
384
|
}
|
|
358
385
|
|
|
386
|
+
/**
|
|
387
|
+
* Accepts a parameter and returns it if it's a function
|
|
388
|
+
* or a noop function if it's not. This allows us to
|
|
389
|
+
* accept a callback, but not worry about it if it's not
|
|
390
|
+
* passed.
|
|
391
|
+
* @param {Function} cb the callback
|
|
392
|
+
* @return {Function} a function
|
|
393
|
+
*/
|
|
394
|
+
function cbToCb(cb) {
|
|
395
|
+
return typeof cb === 'function' ? cb : noop;
|
|
396
|
+
}
|
|
397
|
+
|
|
359
398
|
/**
|
|
360
399
|
* Default implementation for status message. Only added when menu is open.
|
|
361
400
|
* Will specify if there are results in the list, and if so, how many,
|
|
@@ -442,34 +481,6 @@ function pickState(state) {
|
|
|
442
481
|
return result;
|
|
443
482
|
}
|
|
444
483
|
|
|
445
|
-
/**
|
|
446
|
-
* This determines whether a prop is a "controlled prop" meaning it is
|
|
447
|
-
* state which is controlled by the outside of this component rather
|
|
448
|
-
* than within this component.
|
|
449
|
-
*
|
|
450
|
-
* @param {Object} props The props that may contain controlled values.
|
|
451
|
-
* @param {String} key the key to check
|
|
452
|
-
* @return {Boolean} whether it is a controlled controlled prop
|
|
453
|
-
*/
|
|
454
|
-
function isControlledProp(props, key) {
|
|
455
|
-
return props[key] !== undefined;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
460
|
-
* @param {Object} event a keyboardEvent object
|
|
461
|
-
* @return {String} keyboard key
|
|
462
|
-
*/
|
|
463
|
-
function normalizeArrowKey(event) {
|
|
464
|
-
var key = event.key,
|
|
465
|
-
keyCode = event.keyCode;
|
|
466
|
-
/* istanbul ignore next (ie) */
|
|
467
|
-
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
468
|
-
return "Arrow" + key;
|
|
469
|
-
}
|
|
470
|
-
return key;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
484
|
/**
|
|
474
485
|
* Simple check if the value passed is object literal
|
|
475
486
|
* @param {*} obj any things
|
|
@@ -479,93 +490,6 @@ function isPlainObject(obj) {
|
|
|
479
490
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
480
491
|
}
|
|
481
492
|
|
|
482
|
-
/**
|
|
483
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
484
|
-
*
|
|
485
|
-
* @param {number} start The current highlightedIndex.
|
|
486
|
-
* @param {number} offset The offset from the current highlightedIndex to start searching.
|
|
487
|
-
* @param {unknown[]} items The items array.
|
|
488
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
489
|
-
* @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
|
|
490
|
-
* @returns {number} The next highlightedIndex.
|
|
491
|
-
*/
|
|
492
|
-
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
493
|
-
if (circular === void 0) {
|
|
494
|
-
circular = false;
|
|
495
|
-
}
|
|
496
|
-
var count = items.length;
|
|
497
|
-
if (count === 0) {
|
|
498
|
-
return -1;
|
|
499
|
-
}
|
|
500
|
-
var itemsLastIndex = count - 1;
|
|
501
|
-
if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
|
|
502
|
-
start = offset > 0 ? -1 : itemsLastIndex + 1;
|
|
503
|
-
}
|
|
504
|
-
var current = start + offset;
|
|
505
|
-
if (current < 0) {
|
|
506
|
-
current = circular ? itemsLastIndex : 0;
|
|
507
|
-
} else if (current > itemsLastIndex) {
|
|
508
|
-
current = circular ? 0 : itemsLastIndex;
|
|
509
|
-
}
|
|
510
|
-
var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
|
|
511
|
-
if (highlightedIndex === -1) {
|
|
512
|
-
return start >= count ? -1 : start;
|
|
513
|
-
}
|
|
514
|
-
return highlightedIndex;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
519
|
-
*
|
|
520
|
-
* @param {number} start The current highlightedIndex.
|
|
521
|
-
* @param {boolean} backwards If true, it will search backwards from the start.
|
|
522
|
-
* @param {unknown[]} items The items array.
|
|
523
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
524
|
-
* @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
|
|
525
|
-
* @returns {number} The next non-disabled index.
|
|
526
|
-
*/
|
|
527
|
-
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
528
|
-
if (circular === void 0) {
|
|
529
|
-
circular = false;
|
|
530
|
-
}
|
|
531
|
-
var count = items.length;
|
|
532
|
-
if (backwards) {
|
|
533
|
-
for (var index = start; index >= 0; index--) {
|
|
534
|
-
if (!isItemDisabled(items[index], index)) {
|
|
535
|
-
return index;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
} else {
|
|
539
|
-
for (var _index = start; _index < count; _index++) {
|
|
540
|
-
if (!isItemDisabled(items[_index], _index)) {
|
|
541
|
-
return _index;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
if (circular) {
|
|
546
|
-
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
547
|
-
}
|
|
548
|
-
return -1;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
552
|
-
var validateControlledUnchanged = noop;
|
|
553
|
-
/* istanbul ignore next */
|
|
554
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
555
|
-
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
556
|
-
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";
|
|
557
|
-
Object.keys(state).forEach(function (propKey) {
|
|
558
|
-
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
559
|
-
// eslint-disable-next-line no-console
|
|
560
|
-
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
561
|
-
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
562
|
-
// eslint-disable-next-line no-console
|
|
563
|
-
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
564
|
-
}
|
|
565
|
-
});
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
|
|
569
493
|
var _excluded$4 = ["refKey", "ref"],
|
|
570
494
|
_excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
571
495
|
_excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
@@ -716,7 +640,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
716
640
|
}
|
|
717
641
|
newStateToSet[key];
|
|
718
642
|
// if it's coming from props, then we don't care to set it internally
|
|
719
|
-
if (
|
|
643
|
+
if (_this.props[key] === undefined) {
|
|
720
644
|
nextState[key] = newStateToSet[key];
|
|
721
645
|
}
|
|
722
646
|
});
|
|
@@ -1382,7 +1306,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1382
1306
|
if (process.env.NODE_ENV !== 'production') {
|
|
1383
1307
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
1384
1308
|
}
|
|
1385
|
-
if (
|
|
1309
|
+
if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
|
|
1386
1310
|
this.internalSetState({
|
|
1387
1311
|
type: controlledPropUpdatedSelectedItem,
|
|
1388
1312
|
inputValue: this.props.itemToString(this.props.selectedItem)
|
|
@@ -1556,7 +1480,7 @@ function callOnChangeProps(action, props, state, newState) {
|
|
|
1556
1480
|
changes[key] = newState[key];
|
|
1557
1481
|
}
|
|
1558
1482
|
}
|
|
1559
|
-
if (props.onStateChange && Object.keys(changes).length) {
|
|
1483
|
+
if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
|
|
1560
1484
|
props.onStateChange(_extends({
|
|
1561
1485
|
type: type
|
|
1562
1486
|
}, changes));
|
|
@@ -1582,50 +1506,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
|
|
|
1582
1506
|
* two reducers, one from downshift and an optional one from the user.
|
|
1583
1507
|
* Also calls the onChange handlers for state values that have changed.
|
|
1584
1508
|
*
|
|
1585
|
-
* @param
|
|
1586
|
-
* @param
|
|
1587
|
-
* @param
|
|
1588
|
-
* @param
|
|
1589
|
-
* @returns
|
|
1509
|
+
* @param reducer Reducer function from downshift.
|
|
1510
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1511
|
+
* @param createInitialState Function that returns the initial state.
|
|
1512
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1513
|
+
* @returns An array with the state and an action dispatcher.
|
|
1590
1514
|
*/
|
|
1591
1515
|
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
1592
|
-
var prevStateRef = React__namespace.useRef(
|
|
1593
|
-
var actionRef = React__namespace.useRef(
|
|
1594
|
-
var propsRef = useLatestRef(props);
|
|
1516
|
+
var prevStateRef = React__namespace.useRef({});
|
|
1517
|
+
var actionRef = React__namespace.useRef();
|
|
1595
1518
|
var enhancedReducer = React__namespace.useCallback(function (state, action) {
|
|
1596
1519
|
actionRef.current = action;
|
|
1597
|
-
state = getState(state,
|
|
1598
|
-
var changes = reducer(state,
|
|
1599
|
-
var newState =
|
|
1520
|
+
state = getState(state, action.props);
|
|
1521
|
+
var changes = reducer(state, action);
|
|
1522
|
+
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
1600
1523
|
changes: changes
|
|
1601
1524
|
}));
|
|
1602
1525
|
return _extends({}, state, newState);
|
|
1603
|
-
}, [
|
|
1526
|
+
}, [reducer]);
|
|
1604
1527
|
var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
|
|
1605
1528
|
state = _React$useReducer[0],
|
|
1606
1529
|
dispatch = _React$useReducer[1];
|
|
1530
|
+
var propsRef = useLatestRef(props);
|
|
1531
|
+
var dispatchWithProps = React__namespace.useCallback(function (action) {
|
|
1532
|
+
return dispatch(_extends({}, action, {
|
|
1533
|
+
props: propsRef.current
|
|
1534
|
+
}));
|
|
1535
|
+
}, [propsRef]);
|
|
1607
1536
|
var action = actionRef.current;
|
|
1608
1537
|
React__namespace.useEffect(function () {
|
|
1609
|
-
var
|
|
1610
|
-
var
|
|
1611
|
-
var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
|
|
1538
|
+
var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
|
|
1539
|
+
var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
|
|
1612
1540
|
if (shouldCallOnChangeProps) {
|
|
1613
|
-
callOnChangeProps(action,
|
|
1541
|
+
callOnChangeProps(action, action.props, prevState, state);
|
|
1614
1542
|
}
|
|
1615
1543
|
prevStateRef.current = state;
|
|
1616
|
-
}, [state, action, isStateEqual
|
|
1617
|
-
return [state,
|
|
1544
|
+
}, [state, action, isStateEqual]);
|
|
1545
|
+
return [state, dispatchWithProps];
|
|
1618
1546
|
}
|
|
1619
1547
|
|
|
1620
1548
|
/**
|
|
1621
1549
|
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
1622
1550
|
* returning the new state.
|
|
1623
|
-
*
|
|
1624
|
-
* @param
|
|
1625
|
-
* @param
|
|
1626
|
-
* @param
|
|
1627
|
-
* @
|
|
1628
|
-
* @returns {Array} An array with the state and an action dispatcher.
|
|
1551
|
+
* @param reducer Reducer function from downshift.
|
|
1552
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1553
|
+
* @param createInitialState Function that returns the initial state.
|
|
1554
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1555
|
+
* @returns An array with the state and an action dispatcher.
|
|
1629
1556
|
*/
|
|
1630
1557
|
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
1631
1558
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
@@ -1678,16 +1605,8 @@ function useIsInitialMount() {
|
|
|
1678
1605
|
return isInitialMountRef.current;
|
|
1679
1606
|
}
|
|
1680
1607
|
|
|
1681
|
-
/**
|
|
1682
|
-
* Default state reducer that returns the changes.
|
|
1683
|
-
*
|
|
1684
|
-
*/
|
|
1685
|
-
function stateReducer(_s, a) {
|
|
1686
|
-
return a.changes;
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
1608
|
// Shared between all exports.
|
|
1690
|
-
var propTypes$
|
|
1609
|
+
var propTypes$4 = {
|
|
1691
1610
|
environment: PropTypes.shape({
|
|
1692
1611
|
addEventListener: PropTypes.func.isRequired,
|
|
1693
1612
|
removeEventListener: PropTypes.func.isRequired,
|
|
@@ -1703,30 +1622,47 @@ var propTypes$5 = {
|
|
|
1703
1622
|
stateReducer: PropTypes.func
|
|
1704
1623
|
};
|
|
1705
1624
|
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1625
|
+
/**
|
|
1626
|
+
* Returns the default value based on the defaultProp and defaultStateValue.
|
|
1627
|
+
*
|
|
1628
|
+
* @param defaultProp The default prop value.
|
|
1629
|
+
* @param defaultStateValue The default state value.
|
|
1630
|
+
* @returns The resolved default value.
|
|
1631
|
+
*/
|
|
1632
|
+
function getDefaultValue(defaultProp, defaultStateValue) {
|
|
1633
|
+
return defaultProp === undefined ? defaultStateValue : defaultProp;
|
|
1712
1634
|
}
|
|
1713
1635
|
|
|
1714
|
-
|
|
1715
|
-
|
|
1636
|
+
/**
|
|
1637
|
+
* Returns the initial value for a state variable, based on the following precedence:
|
|
1638
|
+
* 1. The controlled value (if it's not undefined)
|
|
1639
|
+
* 2. The initialValue (if it's not undefined)
|
|
1640
|
+
* 3. The defaultValue (if it's not undefined)
|
|
1641
|
+
* 4. The defaultStateValue
|
|
1642
|
+
*
|
|
1643
|
+
* @param value The controlled value of the state variable.
|
|
1644
|
+
* @param initialValue The initial value of the state variable.
|
|
1645
|
+
* @param defaultValue The default value of the state variable.
|
|
1646
|
+
* @param defaultStateValue The default state value to use if all other values are undefined.
|
|
1647
|
+
* @returns The initial value for the state variable.
|
|
1648
|
+
*/
|
|
1649
|
+
function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
|
|
1716
1650
|
if (value !== undefined) {
|
|
1717
1651
|
return value;
|
|
1718
1652
|
}
|
|
1719
|
-
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
1720
1653
|
if (initialValue !== undefined) {
|
|
1721
1654
|
return initialValue;
|
|
1722
1655
|
}
|
|
1723
|
-
|
|
1656
|
+
if (defaultValue !== undefined) {
|
|
1657
|
+
return defaultValue;
|
|
1658
|
+
}
|
|
1659
|
+
return defaultStateValue;
|
|
1724
1660
|
}
|
|
1725
1661
|
|
|
1726
1662
|
/**
|
|
1727
1663
|
* Debounced call for updating the a11y message.
|
|
1728
1664
|
*/
|
|
1729
|
-
var updateA11yStatus = debounce
|
|
1665
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
1730
1666
|
setStatus(status, document);
|
|
1731
1667
|
}, 200);
|
|
1732
1668
|
|
|
@@ -1760,7 +1696,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
|
|
|
1760
1696
|
}
|
|
1761
1697
|
|
|
1762
1698
|
// Shared between useSelect, useCombobox, Downshift.
|
|
1763
|
-
var
|
|
1699
|
+
var dropdownPropTypes = _extends({}, propTypes$4, {
|
|
1764
1700
|
getA11yStatusMessage: PropTypes.func,
|
|
1765
1701
|
highlightedIndex: PropTypes.number,
|
|
1766
1702
|
defaultHighlightedIndex: PropTypes.number,
|
|
@@ -1783,59 +1719,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
|
|
|
1783
1719
|
scrollIntoView: PropTypes.func
|
|
1784
1720
|
});
|
|
1785
1721
|
|
|
1786
|
-
var
|
|
1722
|
+
var dropdownDefaultProps = {
|
|
1787
1723
|
itemToString: function itemToString(item) {
|
|
1788
1724
|
return item ? String(item) : '';
|
|
1789
1725
|
},
|
|
1790
1726
|
itemToKey: function itemToKey(item) {
|
|
1791
1727
|
return item;
|
|
1792
1728
|
},
|
|
1793
|
-
|
|
1729
|
+
isItemDisabled: function isItemDisabled(_item) {
|
|
1730
|
+
return false;
|
|
1731
|
+
},
|
|
1732
|
+
stateReducer: function stateReducer(_state, actionAndChanges) {
|
|
1733
|
+
return actionAndChanges.changes;
|
|
1734
|
+
},
|
|
1794
1735
|
scrollIntoView: scrollIntoView,
|
|
1795
1736
|
environment: /* istanbul ignore next (ssr) */
|
|
1796
1737
|
undefined
|
|
1797
1738
|
};
|
|
1798
1739
|
|
|
1799
|
-
var
|
|
1740
|
+
var dropdownDefaultStateValues = {
|
|
1800
1741
|
highlightedIndex: -1,
|
|
1801
1742
|
isOpen: false,
|
|
1802
1743
|
selectedItem: null,
|
|
1803
1744
|
inputValue: ''
|
|
1804
1745
|
};
|
|
1805
1746
|
|
|
1806
|
-
//
|
|
1807
|
-
var
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
var
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
}
|
|
1747
|
+
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
1748
|
+
var SafeReact$1 = _extends({}, React__namespace);
|
|
1749
|
+
var reactUseId$1 = SafeReact$1.useId;
|
|
1750
|
+
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
1751
|
+
function useElementIdsR18$1(_ref) {
|
|
1752
|
+
var id = _ref.id,
|
|
1753
|
+
labelId = _ref.labelId,
|
|
1754
|
+
menuId = _ref.menuId,
|
|
1755
|
+
getItemId = _ref.getItemId,
|
|
1756
|
+
toggleButtonId = _ref.toggleButtonId,
|
|
1757
|
+
inputId = _ref.inputId;
|
|
1758
|
+
var reactId = "downshift-" + reactUseId$1();
|
|
1759
|
+
if (!id) {
|
|
1760
|
+
id = reactId;
|
|
1761
|
+
}
|
|
1762
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1763
|
+
return {
|
|
1764
|
+
labelId: labelId != null ? labelId : id + "-label",
|
|
1765
|
+
menuId: menuId != null ? menuId : id + "-menu",
|
|
1766
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
1767
|
+
return id + "-item-" + index;
|
|
1768
|
+
},
|
|
1769
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
1770
|
+
inputId: inputId != null ? inputId : id + "-input"
|
|
1771
|
+
};
|
|
1772
|
+
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
1773
|
+
return elementIds;
|
|
1821
1774
|
}
|
|
1822
|
-
function
|
|
1823
|
-
var
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1775
|
+
function useElementIdsLegacy$1(_ref2) {
|
|
1776
|
+
var id = _ref2.id,
|
|
1777
|
+
labelId = _ref2.labelId,
|
|
1778
|
+
menuId = _ref2.menuId,
|
|
1779
|
+
getItemId = _ref2.getItemId,
|
|
1780
|
+
toggleButtonId = _ref2.toggleButtonId,
|
|
1781
|
+
inputId = _ref2.inputId;
|
|
1782
|
+
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
1783
|
+
var baseId = baseIdRef.current;
|
|
1784
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1785
|
+
return {
|
|
1786
|
+
labelId: labelId != null ? labelId : baseId + "-label",
|
|
1787
|
+
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
1788
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
1789
|
+
return baseId + "-item-" + index;
|
|
1790
|
+
},
|
|
1791
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
1792
|
+
inputId: inputId != null ? inputId : baseId + "-input"
|
|
1793
|
+
};
|
|
1794
|
+
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
1795
|
+
return elementIds;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
1800
|
+
*
|
|
1801
|
+
* @param props Props passed to the hook.
|
|
1802
|
+
* @returns The highlighted index.
|
|
1803
|
+
*/
|
|
1804
|
+
function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
|
|
1805
|
+
var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
1806
|
+
if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
|
|
1807
|
+
return -1;
|
|
1808
|
+
}
|
|
1809
|
+
return highlightedIndex;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
/**
|
|
1813
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1814
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1815
|
+
*
|
|
1816
|
+
* @param props The Dropdown props.
|
|
1817
|
+
* @param highlightedIndex The index from the state.
|
|
1818
|
+
* @param inputValue Also return the input value for state.
|
|
1819
|
+
* @returns The changes for the state.
|
|
1820
|
+
*/
|
|
1821
|
+
function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
|
|
1822
|
+
var shouldSelect = items.length && highlightedIndex >= 0;
|
|
1823
|
+
return _extends({
|
|
1824
|
+
isOpen: false,
|
|
1825
|
+
highlightedIndex: -1
|
|
1826
|
+
}, shouldSelect && _extends({
|
|
1827
|
+
selectedItem: items[highlightedIndex],
|
|
1828
|
+
isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
1829
|
+
highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
|
|
1830
|
+
}, inputValue && {
|
|
1831
|
+
inputValue: itemToString(items[highlightedIndex])
|
|
1832
|
+
}));
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
/* eslint-disable max-params */
|
|
1836
|
+
/**
|
|
1837
|
+
* Returns the highlighted index when the menu is opened.
|
|
1838
|
+
* Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
|
|
1839
|
+
* selectedItem, and the open direction offset.
|
|
1840
|
+
*
|
|
1841
|
+
* @param items The list of items.
|
|
1842
|
+
* @param initialHighlightedIndex The initial highlighted index prop.
|
|
1843
|
+
* @param defaultHighlightedIndex The default highlighted index prop.
|
|
1844
|
+
* @param isItemDisabled Callback to determine if an item is disabled.
|
|
1845
|
+
* @param itemToKey Callback to get a unique key from an item.
|
|
1846
|
+
* @param selectedItem The currently selected item.
|
|
1847
|
+
* @param highlightedIndex The current highlighted index from state.
|
|
1848
|
+
* @param offset The direction of navigation: positive opens downward, negative opens upward.
|
|
1849
|
+
* @returns The new highlighted index.
|
|
1850
|
+
*/
|
|
1851
|
+
function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
|
|
1830
1852
|
if (items.length === 0) {
|
|
1831
1853
|
return -1;
|
|
1832
1854
|
}
|
|
1833
1855
|
|
|
1834
1856
|
// initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
1835
|
-
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1857
|
+
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1836
1858
|
return initialHighlightedIndex;
|
|
1837
1859
|
}
|
|
1838
|
-
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1860
|
+
if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1839
1861
|
return defaultHighlightedIndex;
|
|
1840
1862
|
}
|
|
1841
1863
|
if (selectedItem) {
|
|
@@ -1843,21 +1865,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1843
1865
|
return itemToKey(selectedItem) === itemToKey(item);
|
|
1844
1866
|
});
|
|
1845
1867
|
}
|
|
1846
|
-
if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1868
|
+
if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1847
1869
|
return items.length - 1;
|
|
1848
1870
|
}
|
|
1849
|
-
if (offset > 0 && !isItemDisabled(items[0], 0)) {
|
|
1871
|
+
if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
|
|
1850
1872
|
return 0;
|
|
1851
1873
|
}
|
|
1852
1874
|
return -1;
|
|
1853
1875
|
}
|
|
1876
|
+
|
|
1877
|
+
function getInitialState$3(props) {
|
|
1878
|
+
var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
|
|
1879
|
+
var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
1880
|
+
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
1881
|
+
var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
|
|
1882
|
+
return {
|
|
1883
|
+
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
1884
|
+
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
1885
|
+
}) : highlightedIndex,
|
|
1886
|
+
isOpen: isOpen,
|
|
1887
|
+
selectedItem: selectedItem,
|
|
1888
|
+
inputValue: inputValue
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
1894
|
+
* @param props Props from useCombobox or useSelect.
|
|
1895
|
+
* @returns The highlighted index.
|
|
1896
|
+
*/
|
|
1897
|
+
function getInitialHighlightedIndex(props) {
|
|
1898
|
+
var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
1899
|
+
if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
1900
|
+
return -1;
|
|
1901
|
+
}
|
|
1902
|
+
return highlightedIndex;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1906
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
1907
|
+
var useControlPropsValidator = noop;
|
|
1908
|
+
/* istanbul ignore next */
|
|
1909
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1910
|
+
useControlPropsValidator = function useControlPropsValidator(_ref) {
|
|
1911
|
+
var props = _ref.props,
|
|
1912
|
+
state = _ref.state;
|
|
1913
|
+
// used for checking when props are moving from controlled to uncontrolled.
|
|
1914
|
+
var prevPropsRef = React__namespace.useRef(props);
|
|
1915
|
+
var isInitialMount = useIsInitialMount();
|
|
1916
|
+
React__namespace.useEffect(function () {
|
|
1917
|
+
if (isInitialMount) {
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
1921
|
+
prevPropsRef.current = props;
|
|
1922
|
+
}, [state, props, isInitialMount]);
|
|
1923
|
+
};
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1854
1926
|
/**
|
|
1855
1927
|
* Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
|
|
1856
1928
|
*
|
|
1857
|
-
* @param
|
|
1858
|
-
* @param
|
|
1859
|
-
* @param
|
|
1860
|
-
* @returns
|
|
1929
|
+
* @param environment The environment to add the event listeners to, for instance window.
|
|
1930
|
+
* @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
|
|
1931
|
+
* @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
|
|
1932
|
+
* @returns The mouse and touch events information.
|
|
1861
1933
|
*/
|
|
1862
1934
|
function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
|
|
1863
1935
|
var mouseAndTouchTrackersRef = React__namespace.useRef({
|
|
@@ -1886,8 +1958,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
1886
1958
|
/**
|
|
1887
1959
|
* Custom hook that checks if getter props are called correctly.
|
|
1888
1960
|
*
|
|
1889
|
-
* @param
|
|
1890
|
-
* @returns
|
|
1961
|
+
* @param propKeys Getter prop names to be handled.
|
|
1962
|
+
* @returns Setter function called inside getter props to set call information.
|
|
1891
1963
|
*/
|
|
1892
1964
|
/* istanbul ignore next */
|
|
1893
1965
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -1929,116 +2001,54 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1929
2001
|
return setGetterPropCallInfo;
|
|
1930
2002
|
};
|
|
1931
2003
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2004
|
+
|
|
2005
|
+
// istanbul ignore next
|
|
2006
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2007
|
+
|
|
2008
|
+
/**
|
|
2009
|
+
* Utility hook that scrolls an item from a menu into view.
|
|
2010
|
+
* @param scrollIntoView The function that does the scroll.
|
|
2011
|
+
* @param highlightedIndex The index of the item that should be scrolled.
|
|
2012
|
+
* @param isOpen If the menu is open or not.
|
|
2013
|
+
* @param menuElement The menu element.
|
|
2014
|
+
* @param itemElements The object containing item elements.
|
|
2015
|
+
* @param getItemId The function to get the item id from index.
|
|
2016
|
+
* @returns Function that when called prevents the scroll.
|
|
2017
|
+
*/
|
|
2018
|
+
function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
|
|
1939
2019
|
// used not to scroll on highlight by mouse.
|
|
1940
2020
|
var shouldScrollRef = React__namespace.useRef(true);
|
|
1941
2021
|
// Scroll on highlighted item if change comes from keyboard.
|
|
1942
2022
|
useIsomorphicLayoutEffect(function () {
|
|
1943
|
-
if (highlightedIndex < 0 || !isOpen || !Object.keys(
|
|
2023
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
|
|
1944
2024
|
return;
|
|
1945
2025
|
}
|
|
1946
|
-
if (shouldScrollRef.current
|
|
1947
|
-
|
|
2026
|
+
if (shouldScrollRef.current) {
|
|
2027
|
+
var itemElement = itemElements[getItemId(highlightedIndex)];
|
|
2028
|
+
if (itemElement && menuElement) {
|
|
2029
|
+
scrollIntoView(itemElement, menuElement);
|
|
2030
|
+
}
|
|
1948
2031
|
} else {
|
|
1949
|
-
|
|
2032
|
+
shouldScrollRef.current = true;
|
|
1950
2033
|
}
|
|
1951
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1952
2034
|
}, [highlightedIndex]);
|
|
1953
|
-
return
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
1957
|
-
var useControlPropsValidator = noop;
|
|
1958
|
-
/* istanbul ignore next */
|
|
1959
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1960
|
-
useControlPropsValidator = function useControlPropsValidator(_ref2) {
|
|
1961
|
-
var props = _ref2.props,
|
|
1962
|
-
state = _ref2.state;
|
|
1963
|
-
// used for checking when props are moving from controlled to uncontrolled.
|
|
1964
|
-
var prevPropsRef = React__namespace.useRef(props);
|
|
1965
|
-
var isInitialMount = useIsInitialMount();
|
|
1966
|
-
React__namespace.useEffect(function () {
|
|
1967
|
-
if (isInitialMount) {
|
|
1968
|
-
return;
|
|
1969
|
-
}
|
|
1970
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
1971
|
-
prevPropsRef.current = props;
|
|
1972
|
-
}, [state, props, isInitialMount]);
|
|
1973
|
-
};
|
|
1974
|
-
}
|
|
1975
|
-
|
|
1976
|
-
/**
|
|
1977
|
-
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1978
|
-
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1979
|
-
* @param {Object} props The useCombobox props.
|
|
1980
|
-
* @param {number} highlightedIndex The index from the state.
|
|
1981
|
-
* @param {boolean} inputValue Also return the input value for state.
|
|
1982
|
-
* @returns The changes for the state.
|
|
1983
|
-
*/
|
|
1984
|
-
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
1985
|
-
var _props$items;
|
|
1986
|
-
if (inputValue === void 0) {
|
|
1987
|
-
inputValue = true;
|
|
1988
|
-
}
|
|
1989
|
-
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
1990
|
-
return _extends({
|
|
1991
|
-
isOpen: false,
|
|
1992
|
-
highlightedIndex: -1
|
|
1993
|
-
}, shouldSelect && _extends({
|
|
1994
|
-
selectedItem: props.items[highlightedIndex],
|
|
1995
|
-
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
1996
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
|
|
1997
|
-
}, inputValue && {
|
|
1998
|
-
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
1999
|
-
}));
|
|
2035
|
+
return React__namespace.useCallback(function preventScroll() {
|
|
2036
|
+
shouldScrollRef.current = false;
|
|
2037
|
+
}, []);
|
|
2000
2038
|
}
|
|
2001
2039
|
|
|
2002
2040
|
/**
|
|
2003
2041
|
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
2004
2042
|
* Used by useSelect and useCombobox.
|
|
2005
2043
|
*
|
|
2006
|
-
* @param
|
|
2007
|
-
* @param
|
|
2008
|
-
* @returns
|
|
2044
|
+
* @param prevState The previous dropdown state.
|
|
2045
|
+
* @param newState The new dropdown state.
|
|
2046
|
+
* @returns Wheather the states are deeply equal.
|
|
2009
2047
|
*/
|
|
2010
|
-
function
|
|
2048
|
+
function isDropdownStateEqual(prevState, newState) {
|
|
2011
2049
|
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2012
2050
|
}
|
|
2013
2051
|
|
|
2014
|
-
/**
|
|
2015
|
-
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
2016
|
-
*
|
|
2017
|
-
* @param {Object} props Props from useCombobox or useSelect.
|
|
2018
|
-
* @returns {number} The highlighted index.
|
|
2019
|
-
*/
|
|
2020
|
-
function getDefaultHighlightedIndex(props) {
|
|
2021
|
-
var highlightedIndex = getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1);
|
|
2022
|
-
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2023
|
-
return -1;
|
|
2024
|
-
}
|
|
2025
|
-
return highlightedIndex;
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
/**
|
|
2029
|
-
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
2030
|
-
*
|
|
2031
|
-
* @param {Object} props Props from useCombobox or useSelect.
|
|
2032
|
-
* @returns {number} The highlighted index.
|
|
2033
|
-
*/
|
|
2034
|
-
function getInitialHighlightedIndex(props) {
|
|
2035
|
-
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex', defaultStateValues$1);
|
|
2036
|
-
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2037
|
-
return -1;
|
|
2038
|
-
}
|
|
2039
|
-
return highlightedIndex;
|
|
2040
|
-
}
|
|
2041
|
-
|
|
2042
2052
|
function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
2043
2053
|
var type = action.type;
|
|
2044
2054
|
var changes;
|
|
@@ -2057,13 +2067,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2057
2067
|
case stateChangeTypes.FunctionToggleMenu:
|
|
2058
2068
|
changes = {
|
|
2059
2069
|
isOpen: !state.isOpen,
|
|
2060
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
2070
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2061
2071
|
};
|
|
2062
2072
|
break;
|
|
2063
2073
|
case stateChangeTypes.FunctionOpenMenu:
|
|
2064
2074
|
changes = {
|
|
2065
2075
|
isOpen: true,
|
|
2066
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
|
|
2076
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2067
2077
|
};
|
|
2068
2078
|
break;
|
|
2069
2079
|
case stateChangeTypes.FunctionCloseMenu:
|
|
@@ -2072,9 +2082,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2072
2082
|
};
|
|
2073
2083
|
break;
|
|
2074
2084
|
case stateChangeTypes.FunctionSetHighlightedIndex:
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2085
|
+
{
|
|
2086
|
+
var highlightedIndex = action.highlightedIndex;
|
|
2087
|
+
changes = {
|
|
2088
|
+
highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2078
2091
|
break;
|
|
2079
2092
|
case stateChangeTypes.FunctionSetInputValue:
|
|
2080
2093
|
changes = {
|
|
@@ -2083,10 +2096,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2083
2096
|
break;
|
|
2084
2097
|
case stateChangeTypes.FunctionReset:
|
|
2085
2098
|
changes = {
|
|
2086
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2087
|
-
isOpen: getDefaultValue
|
|
2088
|
-
selectedItem: getDefaultValue
|
|
2089
|
-
inputValue: getDefaultValue
|
|
2099
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2100
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2101
|
+
selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
|
|
2102
|
+
inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
|
|
2090
2103
|
};
|
|
2091
2104
|
break;
|
|
2092
2105
|
default:
|
|
@@ -2096,17 +2109,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2096
2109
|
}
|
|
2097
2110
|
/* eslint-enable complexity */
|
|
2098
2111
|
|
|
2099
|
-
var propTypes$3 = _extends({},
|
|
2112
|
+
var propTypes$3 = _extends({}, dropdownPropTypes, {
|
|
2100
2113
|
items: PropTypes.array.isRequired,
|
|
2101
2114
|
isItemDisabled: PropTypes.func
|
|
2102
2115
|
});
|
|
2103
2116
|
|
|
2104
|
-
var defaultProps$2 = _extends({}, defaultProps$3, {
|
|
2105
|
-
isItemDisabled: function isItemDisabled() {
|
|
2106
|
-
return false;
|
|
2107
|
-
}
|
|
2108
|
-
});
|
|
2109
|
-
|
|
2110
2117
|
function getItemIndexByCharacterKey(_ref) {
|
|
2111
2118
|
var keysSoFar = _ref.keysSoFar,
|
|
2112
2119
|
highlightedIndex = _ref.highlightedIndex,
|
|
@@ -2175,16 +2182,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
2175
2182
|
});
|
|
2176
2183
|
|
|
2177
2184
|
/* eslint-disable complexity */
|
|
2178
|
-
function downshiftSelectReducer(state,
|
|
2179
|
-
var _props$items;
|
|
2185
|
+
function downshiftSelectReducer(state, action) {
|
|
2180
2186
|
var type = action.type,
|
|
2181
|
-
|
|
2187
|
+
props = action.props;
|
|
2182
2188
|
var changes;
|
|
2183
2189
|
switch (type) {
|
|
2184
2190
|
case ItemClick$1:
|
|
2185
2191
|
changes = {
|
|
2186
|
-
isOpen: getDefaultValue
|
|
2187
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2192
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2193
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2188
2194
|
selectedItem: props.items[action.index]
|
|
2189
2195
|
};
|
|
2190
2196
|
break;
|
|
@@ -2211,7 +2217,8 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2211
2217
|
break;
|
|
2212
2218
|
case ToggleButtonKeyDownArrowDown:
|
|
2213
2219
|
{
|
|
2214
|
-
var
|
|
2220
|
+
var altKey = action.altKey;
|
|
2221
|
+
var _highlightedIndex = state.isOpen ? getHighlightedIndex(state.highlightedIndex, 1, props.items, props.isItemDisabled) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1);
|
|
2215
2222
|
changes = {
|
|
2216
2223
|
highlightedIndex: _highlightedIndex,
|
|
2217
2224
|
isOpen: true
|
|
@@ -2219,20 +2226,23 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2219
2226
|
}
|
|
2220
2227
|
break;
|
|
2221
2228
|
case ToggleButtonKeyDownArrowUp:
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
highlightedIndex:
|
|
2228
|
-
|
|
2229
|
-
|
|
2229
|
+
{
|
|
2230
|
+
var _altKey = action.altKey;
|
|
2231
|
+
if (state.isOpen && _altKey) {
|
|
2232
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2233
|
+
} else {
|
|
2234
|
+
var _highlightedIndex2 = state.isOpen ? getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled) : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1);
|
|
2235
|
+
changes = {
|
|
2236
|
+
highlightedIndex: _highlightedIndex2,
|
|
2237
|
+
isOpen: true
|
|
2238
|
+
};
|
|
2239
|
+
}
|
|
2230
2240
|
}
|
|
2231
2241
|
break;
|
|
2232
2242
|
// only triggered when menu is open.
|
|
2233
2243
|
case ToggleButtonKeyDownEnter:
|
|
2234
2244
|
case ToggleButtonKeyDownSpaceButton:
|
|
2235
|
-
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2245
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2236
2246
|
break;
|
|
2237
2247
|
case ToggleButtonKeyDownHome:
|
|
2238
2248
|
changes = {
|
|
@@ -2266,7 +2276,7 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2266
2276
|
changes = _extends({
|
|
2267
2277
|
isOpen: false,
|
|
2268
2278
|
highlightedIndex: -1
|
|
2269
|
-
}, state.highlightedIndex >= 0 &&
|
|
2279
|
+
}, state.highlightedIndex >= 0 && props.items.length && {
|
|
2270
2280
|
selectedItem: props.items[state.highlightedIndex]
|
|
2271
2281
|
});
|
|
2272
2282
|
break;
|
|
@@ -2282,59 +2292,9 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2282
2292
|
}
|
|
2283
2293
|
/* eslint-enable complexity */
|
|
2284
2294
|
|
|
2285
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
2286
|
-
var reactUseId$1 = React__namespace['useId'];
|
|
2287
|
-
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
2288
|
-
function useElementIdsR18$1(_ref) {
|
|
2289
|
-
var id = _ref.id,
|
|
2290
|
-
labelId = _ref.labelId,
|
|
2291
|
-
menuId = _ref.menuId,
|
|
2292
|
-
getItemId = _ref.getItemId,
|
|
2293
|
-
toggleButtonId = _ref.toggleButtonId,
|
|
2294
|
-
inputId = _ref.inputId;
|
|
2295
|
-
var reactId = "downshift-" + reactUseId$1();
|
|
2296
|
-
if (!id) {
|
|
2297
|
-
id = reactId;
|
|
2298
|
-
}
|
|
2299
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2300
|
-
return {
|
|
2301
|
-
labelId: labelId != null ? labelId : id + "-label",
|
|
2302
|
-
menuId: menuId != null ? menuId : id + "-menu",
|
|
2303
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2304
|
-
return id + "-item-" + index;
|
|
2305
|
-
},
|
|
2306
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
2307
|
-
inputId: inputId != null ? inputId : id + "-input"
|
|
2308
|
-
};
|
|
2309
|
-
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
2310
|
-
return elementIds;
|
|
2311
|
-
}
|
|
2312
|
-
function useElementIdsLegacy$1(_ref2) {
|
|
2313
|
-
var id = _ref2.id,
|
|
2314
|
-
labelId = _ref2.labelId,
|
|
2315
|
-
menuId = _ref2.menuId,
|
|
2316
|
-
getItemId = _ref2.getItemId,
|
|
2317
|
-
toggleButtonId = _ref2.toggleButtonId,
|
|
2318
|
-
inputId = _ref2.inputId;
|
|
2319
|
-
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
2320
|
-
var baseId = baseIdRef.current;
|
|
2321
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2322
|
-
return {
|
|
2323
|
-
labelId: labelId != null ? labelId : baseId + "-label",
|
|
2324
|
-
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
2325
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2326
|
-
return baseId + "-item-" + index;
|
|
2327
|
-
},
|
|
2328
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
2329
|
-
inputId: inputId != null ? inputId : baseId + "-input"
|
|
2330
|
-
};
|
|
2331
|
-
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
2332
|
-
return elementIds;
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
2295
|
var _excluded$3 = ["onClick"],
|
|
2336
|
-
_excluded2$3 = ["onMouseLeave", "refKey", "ref"],
|
|
2337
|
-
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2296
|
+
_excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
2297
|
+
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
|
|
2338
2298
|
_excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
|
|
2339
2299
|
useSelect.stateChangeTypes = stateChangeTypes$3;
|
|
2340
2300
|
function useSelect(userProps) {
|
|
@@ -2343,22 +2303,23 @@ function useSelect(userProps) {
|
|
|
2343
2303
|
}
|
|
2344
2304
|
validatePropTypes$1(userProps, useSelect, propTypes$3);
|
|
2345
2305
|
// Props defaults and destructuring.
|
|
2346
|
-
var props = _extends({},
|
|
2306
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
2347
2307
|
var scrollIntoView = props.scrollIntoView,
|
|
2348
2308
|
environment = props.environment,
|
|
2349
2309
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2350
2310
|
// Initial state depending on controlled props.
|
|
2351
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3,
|
|
2311
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
|
|
2352
2312
|
state = _useControlledReducer[0],
|
|
2353
2313
|
dispatch = _useControlledReducer[1];
|
|
2354
2314
|
var isOpen = state.isOpen,
|
|
2355
2315
|
highlightedIndex = state.highlightedIndex,
|
|
2356
2316
|
selectedItem = state.selectedItem,
|
|
2357
2317
|
inputValue = state.inputValue;
|
|
2358
|
-
|
|
2318
|
+
|
|
2319
|
+
// Element refs.
|
|
2359
2320
|
var toggleButtonRef = React.useRef(null);
|
|
2360
2321
|
var menuRef = React.useRef(null);
|
|
2361
|
-
var
|
|
2322
|
+
var itemsRef = React.useRef({});
|
|
2362
2323
|
|
|
2363
2324
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2364
2325
|
var clearTimeoutRef = React.useRef(null);
|
|
@@ -2370,24 +2331,12 @@ function useSelect(userProps) {
|
|
|
2370
2331
|
props: props
|
|
2371
2332
|
});
|
|
2372
2333
|
|
|
2373
|
-
// Some utils.
|
|
2374
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
2375
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2376
|
-
}, [elementIds]);
|
|
2377
|
-
|
|
2378
2334
|
// Effects.
|
|
2379
2335
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2380
2336
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2381
2337
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2382
|
-
var
|
|
2383
|
-
|
|
2384
|
-
highlightedIndex: highlightedIndex,
|
|
2385
|
-
isOpen: isOpen,
|
|
2386
|
-
itemRefs: itemRefs,
|
|
2387
|
-
scrollIntoView: scrollIntoView,
|
|
2388
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2389
|
-
});
|
|
2390
|
-
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2338
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
2339
|
+
// Sets cleanup for the keysSoFar callback, debounced after 500ms.
|
|
2391
2340
|
React.useEffect(function () {
|
|
2392
2341
|
// init the clean function here as we need access to dispatch.
|
|
2393
2342
|
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
@@ -2399,7 +2348,8 @@ function useSelect(userProps) {
|
|
|
2399
2348
|
|
|
2400
2349
|
// Cancel any pending debounced calls on mount
|
|
2401
2350
|
return function () {
|
|
2402
|
-
|
|
2351
|
+
var _clearTimeoutRef$curr;
|
|
2352
|
+
(_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
|
|
2403
2353
|
};
|
|
2404
2354
|
}, []);
|
|
2405
2355
|
// Invokes the keysSoFar callback set up above.
|
|
@@ -2407,7 +2357,7 @@ function useSelect(userProps) {
|
|
|
2407
2357
|
if (!inputValue) {
|
|
2408
2358
|
return;
|
|
2409
2359
|
}
|
|
2410
|
-
clearTimeoutRef.current(dispatch);
|
|
2360
|
+
clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
|
|
2411
2361
|
}, [dispatch, inputValue]);
|
|
2412
2362
|
useControlPropsValidator({
|
|
2413
2363
|
props: props,
|
|
@@ -2415,7 +2365,7 @@ function useSelect(userProps) {
|
|
|
2415
2365
|
});
|
|
2416
2366
|
// Focus the toggle button on first render if required.
|
|
2417
2367
|
React.useEffect(function () {
|
|
2418
|
-
var focusOnOpen = getInitialValue
|
|
2368
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
2419
2369
|
if (focusOnOpen && toggleButtonRef.current) {
|
|
2420
2370
|
toggleButtonRef.current.focus();
|
|
2421
2371
|
}
|
|
@@ -2436,7 +2386,7 @@ function useSelect(userProps) {
|
|
|
2436
2386
|
// Reset itemRefs on close.
|
|
2437
2387
|
React.useEffect(function () {
|
|
2438
2388
|
if (!isOpen) {
|
|
2439
|
-
|
|
2389
|
+
itemsRef.current = {};
|
|
2440
2390
|
}
|
|
2441
2391
|
}, [isOpen]);
|
|
2442
2392
|
|
|
@@ -2521,50 +2471,11 @@ function useSelect(userProps) {
|
|
|
2521
2471
|
};
|
|
2522
2472
|
}, [dispatch, latest]);
|
|
2523
2473
|
|
|
2524
|
-
// Action functions.
|
|
2525
|
-
var toggleMenu = React.useCallback(function () {
|
|
2526
|
-
dispatch({
|
|
2527
|
-
type: FunctionToggleMenu$1
|
|
2528
|
-
});
|
|
2529
|
-
}, [dispatch]);
|
|
2530
|
-
var closeMenu = React.useCallback(function () {
|
|
2531
|
-
dispatch({
|
|
2532
|
-
type: FunctionCloseMenu$1
|
|
2533
|
-
});
|
|
2534
|
-
}, [dispatch]);
|
|
2535
|
-
var openMenu = React.useCallback(function () {
|
|
2536
|
-
dispatch({
|
|
2537
|
-
type: FunctionOpenMenu$1
|
|
2538
|
-
});
|
|
2539
|
-
}, [dispatch]);
|
|
2540
|
-
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2541
|
-
dispatch({
|
|
2542
|
-
type: FunctionSetHighlightedIndex$1,
|
|
2543
|
-
highlightedIndex: newHighlightedIndex
|
|
2544
|
-
});
|
|
2545
|
-
}, [dispatch]);
|
|
2546
|
-
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2547
|
-
dispatch({
|
|
2548
|
-
type: FunctionSelectItem$1,
|
|
2549
|
-
selectedItem: newSelectedItem
|
|
2550
|
-
});
|
|
2551
|
-
}, [dispatch]);
|
|
2552
|
-
var reset = React.useCallback(function () {
|
|
2553
|
-
dispatch({
|
|
2554
|
-
type: FunctionReset$2
|
|
2555
|
-
});
|
|
2556
|
-
}, [dispatch]);
|
|
2557
|
-
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2558
|
-
dispatch({
|
|
2559
|
-
type: FunctionSetInputValue$1,
|
|
2560
|
-
inputValue: newInputValue
|
|
2561
|
-
});
|
|
2562
|
-
}, [dispatch]);
|
|
2563
2474
|
// Getter functions.
|
|
2564
|
-
var getLabelProps = React.useCallback(function (
|
|
2565
|
-
var _ref =
|
|
2475
|
+
var getLabelProps = React.useCallback(function (labelProps) {
|
|
2476
|
+
var _ref = labelProps != null ? labelProps : {},
|
|
2566
2477
|
onClick = _ref.onClick,
|
|
2567
|
-
|
|
2478
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2568
2479
|
var labelHandleClick = function labelHandleClick() {
|
|
2569
2480
|
var _toggleButtonRef$curr;
|
|
2570
2481
|
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
@@ -2573,17 +2484,18 @@ function useSelect(userProps) {
|
|
|
2573
2484
|
id: elementIds.labelId,
|
|
2574
2485
|
htmlFor: elementIds.toggleButtonId,
|
|
2575
2486
|
onClick: callAllEventHandlers(onClick, labelHandleClick)
|
|
2576
|
-
},
|
|
2487
|
+
}, rest);
|
|
2577
2488
|
}, [elementIds]);
|
|
2578
|
-
var getMenuProps = React.useCallback(function (
|
|
2489
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
2579
2490
|
var _extends2;
|
|
2580
|
-
var _ref2 =
|
|
2491
|
+
var _ref2 = menuProps != null ? menuProps : {},
|
|
2581
2492
|
onMouseLeave = _ref2.onMouseLeave,
|
|
2582
2493
|
_ref2$refKey = _ref2.refKey,
|
|
2583
2494
|
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
2584
2495
|
ref = _ref2.ref,
|
|
2496
|
+
ariaLabel = _ref2['aria-label'],
|
|
2585
2497
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
2586
|
-
var _ref3 =
|
|
2498
|
+
var _ref3 = otherProps != null ? otherProps : {},
|
|
2587
2499
|
_ref3$suppressRefErro = _ref3.suppressRefError,
|
|
2588
2500
|
suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
|
|
2589
2501
|
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
@@ -2594,11 +2506,11 @@ function useSelect(userProps) {
|
|
|
2594
2506
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2595
2507
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
2596
2508
|
menuRef.current = menuNode;
|
|
2597
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
2509
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
|
|
2598
2510
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2599
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
2511
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
|
|
2600
2512
|
var _extends3;
|
|
2601
|
-
var _ref4 =
|
|
2513
|
+
var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
|
|
2602
2514
|
onBlur = _ref4.onBlur;
|
|
2603
2515
|
_ref4.onClick;
|
|
2604
2516
|
var onPress = _ref4.onPress;
|
|
@@ -2606,8 +2518,9 @@ function useSelect(userProps) {
|
|
|
2606
2518
|
var _ref4$refKey = _ref4.refKey,
|
|
2607
2519
|
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
2608
2520
|
ref = _ref4.ref,
|
|
2521
|
+
disabled = _ref4.disabled,
|
|
2609
2522
|
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2610
|
-
var _ref5 =
|
|
2523
|
+
var _ref5 = otherProps != null ? otherProps : {},
|
|
2611
2524
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
2612
2525
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
2613
2526
|
var latestState = latest.current.state;
|
|
@@ -2625,19 +2538,21 @@ function useSelect(userProps) {
|
|
|
2625
2538
|
};
|
|
2626
2539
|
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
2627
2540
|
toggleButtonRef.current = toggleButtonNode;
|
|
2628
|
-
}), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = rest
|
|
2629
|
-
if (!
|
|
2541
|
+
}), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = rest['aria-label'] ? undefined : "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3.disabled = disabled, _extends3), rest);
|
|
2542
|
+
if (!disabled) {
|
|
2630
2543
|
/* istanbul ignore if (react-native) */
|
|
2631
2544
|
{
|
|
2632
|
-
|
|
2545
|
+
Object.assign(toggleProps, {
|
|
2546
|
+
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
2547
|
+
});
|
|
2633
2548
|
}
|
|
2634
2549
|
}
|
|
2635
2550
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2636
2551
|
return toggleProps;
|
|
2637
2552
|
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
|
|
2638
|
-
var getItemProps = React.useCallback(function (
|
|
2553
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
2639
2554
|
var _extends4;
|
|
2640
|
-
var _ref6 =
|
|
2555
|
+
var _ref6 = itemProps != null ? itemProps : {},
|
|
2641
2556
|
itemProp = _ref6.item,
|
|
2642
2557
|
indexProp = _ref6.index,
|
|
2643
2558
|
onMouseMove = _ref6.onMouseMove;
|
|
@@ -2663,7 +2578,7 @@ function useSelect(userProps) {
|
|
|
2663
2578
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
2664
2579
|
return;
|
|
2665
2580
|
}
|
|
2666
|
-
|
|
2581
|
+
preventScroll();
|
|
2667
2582
|
dispatch({
|
|
2668
2583
|
type: ItemMouseMove$1,
|
|
2669
2584
|
index: index,
|
|
@@ -2680,21 +2595,61 @@ function useSelect(userProps) {
|
|
|
2680
2595
|
return e.preventDefault();
|
|
2681
2596
|
}; // keep focus on the toggle after item click select.
|
|
2682
2597
|
|
|
2683
|
-
var
|
|
2598
|
+
var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2684
2599
|
if (itemNode) {
|
|
2685
|
-
|
|
2600
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
2686
2601
|
}
|
|
2687
|
-
}), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
|
|
2602
|
+
}), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove), _extends4.onMouseDown = callAllEventHandlers(onMouseDown, itemHandleMouseDown), _extends4), rest);
|
|
2688
2603
|
if (!disabled) {
|
|
2689
2604
|
/* istanbul ignore next (react-native) */
|
|
2690
2605
|
{
|
|
2691
|
-
|
|
2606
|
+
Object.assign(resultItemProps, {
|
|
2607
|
+
onPress: callAllEventHandlers(onPress, itemHandleClick)
|
|
2608
|
+
});
|
|
2692
2609
|
}
|
|
2693
2610
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2611
|
+
return resultItemProps;
|
|
2612
|
+
}, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
|
|
2613
|
+
|
|
2614
|
+
// Action functions.
|
|
2615
|
+
var toggleMenu = React.useCallback(function () {
|
|
2616
|
+
dispatch({
|
|
2617
|
+
type: FunctionToggleMenu$1
|
|
2618
|
+
});
|
|
2619
|
+
}, [dispatch]);
|
|
2620
|
+
var closeMenu = React.useCallback(function () {
|
|
2621
|
+
dispatch({
|
|
2622
|
+
type: FunctionCloseMenu$1
|
|
2623
|
+
});
|
|
2624
|
+
}, [dispatch]);
|
|
2625
|
+
var openMenu = React.useCallback(function () {
|
|
2626
|
+
dispatch({
|
|
2627
|
+
type: FunctionOpenMenu$1
|
|
2628
|
+
});
|
|
2629
|
+
}, [dispatch]);
|
|
2630
|
+
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2631
|
+
dispatch({
|
|
2632
|
+
type: FunctionSetHighlightedIndex$1,
|
|
2633
|
+
highlightedIndex: newHighlightedIndex
|
|
2634
|
+
});
|
|
2635
|
+
}, [dispatch]);
|
|
2636
|
+
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2637
|
+
dispatch({
|
|
2638
|
+
type: FunctionSelectItem$1,
|
|
2639
|
+
selectedItem: newSelectedItem
|
|
2640
|
+
});
|
|
2641
|
+
}, [dispatch]);
|
|
2642
|
+
var reset = React.useCallback(function () {
|
|
2643
|
+
dispatch({
|
|
2644
|
+
type: FunctionReset$2
|
|
2645
|
+
});
|
|
2646
|
+
}, [dispatch]);
|
|
2647
|
+
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2648
|
+
dispatch({
|
|
2649
|
+
type: FunctionSetInputValue$1,
|
|
2650
|
+
inputValue: newInputValue
|
|
2651
|
+
});
|
|
2652
|
+
}, [dispatch]);
|
|
2698
2653
|
return {
|
|
2699
2654
|
// prop getters.
|
|
2700
2655
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2717,6 +2672,18 @@ function useSelect(userProps) {
|
|
|
2717
2672
|
};
|
|
2718
2673
|
}
|
|
2719
2674
|
|
|
2675
|
+
function getInitialState$2(props) {
|
|
2676
|
+
var initialState = getInitialState$3(props);
|
|
2677
|
+
var selectedItem = initialState.selectedItem;
|
|
2678
|
+
var inputValue = initialState.inputValue;
|
|
2679
|
+
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2680
|
+
inputValue = props.itemToString(selectedItem);
|
|
2681
|
+
}
|
|
2682
|
+
return _extends({}, initialState, {
|
|
2683
|
+
inputValue: inputValue
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2720
2687
|
var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2721
2688
|
var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2722
2689
|
var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
@@ -2768,27 +2735,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2768
2735
|
ToggleButtonClick: ToggleButtonClick
|
|
2769
2736
|
});
|
|
2770
2737
|
|
|
2771
|
-
function getInitialState$2(props) {
|
|
2772
|
-
var initialState = getInitialState$3(props);
|
|
2773
|
-
var selectedItem = initialState.selectedItem;
|
|
2774
|
-
var inputValue = initialState.inputValue;
|
|
2775
|
-
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2776
|
-
inputValue = props.itemToString(selectedItem);
|
|
2777
|
-
}
|
|
2778
|
-
return _extends({}, initialState, {
|
|
2779
|
-
inputValue: inputValue
|
|
2780
|
-
});
|
|
2781
|
-
}
|
|
2782
|
-
var propTypes$2 = _extends({}, propTypes$4, {
|
|
2783
|
-
items: PropTypes.array.isRequired,
|
|
2784
|
-
isItemDisabled: PropTypes.func,
|
|
2785
|
-
inputValue: PropTypes.string,
|
|
2786
|
-
defaultInputValue: PropTypes.string,
|
|
2787
|
-
initialInputValue: PropTypes.string,
|
|
2788
|
-
inputId: PropTypes.string,
|
|
2789
|
-
onInputValueChange: PropTypes.func
|
|
2790
|
-
});
|
|
2791
|
-
|
|
2792
2738
|
/**
|
|
2793
2739
|
* The useCombobox version of useControlledReducer, which also
|
|
2794
2740
|
* checks if the controlled prop selectedItem changed between
|
|
@@ -2796,20 +2742,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
|
|
|
2796
2742
|
* string equivalent. It uses the common useEnhancedReducer to
|
|
2797
2743
|
* compute the rest of the state.
|
|
2798
2744
|
*
|
|
2799
|
-
* @param
|
|
2800
|
-
* @param
|
|
2801
|
-
* @param
|
|
2802
|
-
* @param
|
|
2803
|
-
* @returns
|
|
2745
|
+
* @param reducer Reducer function from downshift.
|
|
2746
|
+
* @param props The hook props, also passed to createInitialState.
|
|
2747
|
+
* @param createInitialState Function that returns the initial state.
|
|
2748
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
2749
|
+
* @returns An array with the state and an action dispatcher.
|
|
2804
2750
|
*/
|
|
2805
2751
|
function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
|
|
2806
|
-
var previousSelectedItemRef = React.useRef();
|
|
2752
|
+
var previousSelectedItemRef = React.useRef(null);
|
|
2807
2753
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
2808
2754
|
state = _useEnhancedReducer[0],
|
|
2809
2755
|
dispatch = _useEnhancedReducer[1];
|
|
2810
2756
|
var isInitialMount = useIsInitialMount();
|
|
2811
2757
|
React.useEffect(function () {
|
|
2812
|
-
if (
|
|
2758
|
+
if (props.selectedItem === undefined) {
|
|
2813
2759
|
return;
|
|
2814
2760
|
}
|
|
2815
2761
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
@@ -2827,23 +2773,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2827
2773
|
}, [state.selectedItem, props.selectedItem]);
|
|
2828
2774
|
return [getState(state, props), dispatch];
|
|
2829
2775
|
}
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2776
|
+
|
|
2777
|
+
var propTypes$2 = _extends({}, dropdownPropTypes, {
|
|
2778
|
+
items: PropTypes.array.isRequired,
|
|
2779
|
+
isItemDisabled: PropTypes.func,
|
|
2780
|
+
inputValue: PropTypes.string,
|
|
2781
|
+
defaultInputValue: PropTypes.string,
|
|
2782
|
+
initialInputValue: PropTypes.string,
|
|
2783
|
+
inputId: PropTypes.string,
|
|
2784
|
+
onInputValueChange: PropTypes.func
|
|
2834
2785
|
});
|
|
2835
2786
|
|
|
2836
2787
|
/* eslint-disable complexity */
|
|
2837
|
-
function downshiftUseComboboxReducer(state,
|
|
2838
|
-
var _props$items;
|
|
2788
|
+
function downshiftUseComboboxReducer(state, action) {
|
|
2839
2789
|
var type = action.type,
|
|
2840
|
-
|
|
2790
|
+
props = action.props;
|
|
2841
2791
|
var changes;
|
|
2842
2792
|
switch (type) {
|
|
2843
2793
|
case ItemClick:
|
|
2844
2794
|
changes = {
|
|
2845
|
-
isOpen: getDefaultValue
|
|
2846
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2795
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2796
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2847
2797
|
selectedItem: props.items[action.index],
|
|
2848
2798
|
inputValue: props.itemToString(props.items[action.index])
|
|
2849
2799
|
};
|
|
@@ -2855,15 +2805,15 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
2855
2805
|
};
|
|
2856
2806
|
} else {
|
|
2857
2807
|
changes = {
|
|
2858
|
-
highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
|
|
2808
|
+
highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
|
|
2859
2809
|
isOpen: props.items.length >= 0
|
|
2860
2810
|
};
|
|
2861
2811
|
}
|
|
2862
2812
|
break;
|
|
2863
2813
|
case InputKeyDownArrowUp:
|
|
2864
2814
|
if (state.isOpen) {
|
|
2865
|
-
if (altKey) {
|
|
2866
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2815
|
+
if (action.altKey) {
|
|
2816
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
2867
2817
|
} else {
|
|
2868
2818
|
changes = {
|
|
2869
2819
|
highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
|
|
@@ -2871,13 +2821,13 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
2871
2821
|
}
|
|
2872
2822
|
} else {
|
|
2873
2823
|
changes = {
|
|
2874
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
|
|
2824
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
|
|
2875
2825
|
isOpen: props.items.length >= 0
|
|
2876
2826
|
};
|
|
2877
2827
|
}
|
|
2878
2828
|
break;
|
|
2879
2829
|
case InputKeyDownEnter:
|
|
2880
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2830
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
2881
2831
|
break;
|
|
2882
2832
|
case InputKeyDownEscape:
|
|
2883
2833
|
changes = _extends({
|
|
@@ -2912,7 +2862,7 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
2912
2862
|
changes = _extends({
|
|
2913
2863
|
isOpen: false,
|
|
2914
2864
|
highlightedIndex: -1
|
|
2915
|
-
}, state.highlightedIndex >= 0 &&
|
|
2865
|
+
}, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
|
|
2916
2866
|
selectedItem: props.items[state.highlightedIndex],
|
|
2917
2867
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2918
2868
|
});
|
|
@@ -2920,14 +2870,14 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
2920
2870
|
case InputChange:
|
|
2921
2871
|
changes = {
|
|
2922
2872
|
isOpen: true,
|
|
2923
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2873
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2924
2874
|
inputValue: action.inputValue
|
|
2925
2875
|
};
|
|
2926
2876
|
break;
|
|
2927
2877
|
case InputClick:
|
|
2928
2878
|
changes = {
|
|
2929
2879
|
isOpen: !state.isOpen,
|
|
2930
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
2880
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2931
2881
|
};
|
|
2932
2882
|
break;
|
|
2933
2883
|
case FunctionSelectItem:
|
|
@@ -2948,10 +2898,10 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
2948
2898
|
}
|
|
2949
2899
|
/* eslint-enable complexity */
|
|
2950
2900
|
|
|
2951
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
2901
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
2952
2902
|
_excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
2953
|
-
_excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
|
|
2954
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
2903
|
+
_excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
|
|
2904
|
+
_excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
2955
2905
|
useCombobox.stateChangeTypes = stateChangeTypes$2;
|
|
2956
2906
|
function useCombobox(userProps) {
|
|
2957
2907
|
if (userProps === void 0) {
|
|
@@ -2959,13 +2909,13 @@ function useCombobox(userProps) {
|
|
|
2959
2909
|
}
|
|
2960
2910
|
validatePropTypes$1(userProps, useCombobox, propTypes$2);
|
|
2961
2911
|
// Props defaults and destructuring.
|
|
2962
|
-
var props = _extends({},
|
|
2912
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
2963
2913
|
var items = props.items,
|
|
2964
2914
|
scrollIntoView = props.scrollIntoView,
|
|
2965
2915
|
environment = props.environment,
|
|
2966
2916
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2967
2917
|
// Initial state depending on controlled props.
|
|
2968
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2,
|
|
2918
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
|
|
2969
2919
|
state = _useControlledReducer[0],
|
|
2970
2920
|
dispatch = _useControlledReducer[1];
|
|
2971
2921
|
var isOpen = state.isOpen,
|
|
@@ -2975,7 +2925,7 @@ function useCombobox(userProps) {
|
|
|
2975
2925
|
|
|
2976
2926
|
// Element refs.
|
|
2977
2927
|
var menuRef = React.useRef(null);
|
|
2978
|
-
var
|
|
2928
|
+
var itemsRef = React.useRef({});
|
|
2979
2929
|
var inputRef = React.useRef(null);
|
|
2980
2930
|
var toggleButtonRef = React.useRef(null);
|
|
2981
2931
|
var isInitialMount = useIsInitialMount();
|
|
@@ -2989,29 +2939,19 @@ function useCombobox(userProps) {
|
|
|
2989
2939
|
state: state,
|
|
2990
2940
|
props: props
|
|
2991
2941
|
});
|
|
2992
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
2993
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2994
|
-
}, [elementIds]);
|
|
2995
2942
|
|
|
2996
2943
|
// Effects.
|
|
2997
2944
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2998
2945
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2999
2946
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3000
|
-
var
|
|
3001
|
-
menuElement: menuRef.current,
|
|
3002
|
-
highlightedIndex: highlightedIndex,
|
|
3003
|
-
isOpen: isOpen,
|
|
3004
|
-
itemRefs: itemRefs,
|
|
3005
|
-
scrollIntoView: scrollIntoView,
|
|
3006
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3007
|
-
});
|
|
2947
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
3008
2948
|
useControlPropsValidator({
|
|
3009
|
-
|
|
3010
|
-
|
|
2949
|
+
state: state,
|
|
2950
|
+
props: props
|
|
3011
2951
|
});
|
|
3012
2952
|
// Focus the input on first render if required.
|
|
3013
2953
|
React.useEffect(function () {
|
|
3014
|
-
var focusOnOpen = getInitialValue
|
|
2954
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
3015
2955
|
if (focusOnOpen && inputRef.current) {
|
|
3016
2956
|
inputRef.current.focus();
|
|
3017
2957
|
}
|
|
@@ -3037,13 +2977,13 @@ function useCombobox(userProps) {
|
|
|
3037
2977
|
// Reset itemRefs on close.
|
|
3038
2978
|
React.useEffect(function () {
|
|
3039
2979
|
if (!isOpen) {
|
|
3040
|
-
|
|
2980
|
+
itemsRef.current = {};
|
|
3041
2981
|
}
|
|
3042
2982
|
}, [isOpen]);
|
|
3043
2983
|
// Reset itemRefs on close.
|
|
3044
2984
|
React.useEffect(function () {
|
|
3045
2985
|
var _inputRef$current;
|
|
3046
|
-
if (!isOpen || !(environment != null && environment.document) || !(
|
|
2986
|
+
if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3047
2987
|
return;
|
|
3048
2988
|
}
|
|
3049
2989
|
if (environment.document.activeElement !== inputRef.current) {
|
|
@@ -3133,29 +3073,30 @@ function useCombobox(userProps) {
|
|
|
3133
3073
|
htmlFor: elementIds.inputId
|
|
3134
3074
|
}, labelProps);
|
|
3135
3075
|
}, [elementIds]);
|
|
3136
|
-
var getMenuProps = React.useCallback(function (
|
|
3076
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
3137
3077
|
var _extends2;
|
|
3138
|
-
var _ref =
|
|
3078
|
+
var _ref = menuProps != null ? menuProps : {},
|
|
3139
3079
|
onMouseLeave = _ref.onMouseLeave,
|
|
3140
3080
|
_ref$refKey = _ref.refKey,
|
|
3141
3081
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3142
3082
|
ref = _ref.ref,
|
|
3083
|
+
ariaLabel = _ref['aria-label'],
|
|
3143
3084
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3144
|
-
var _ref2 =
|
|
3085
|
+
var _ref2 = otherProps != null ? otherProps : {},
|
|
3145
3086
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3146
3087
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3147
3088
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3148
3089
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3149
3090
|
menuRef.current = menuNode;
|
|
3150
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
3091
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
3151
3092
|
dispatch({
|
|
3152
3093
|
type: MenuMouseLeave
|
|
3153
3094
|
});
|
|
3154
3095
|
}), _extends2), rest);
|
|
3155
3096
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3156
|
-
var getItemProps = React.useCallback(function (
|
|
3097
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
3157
3098
|
var _extends3, _ref4;
|
|
3158
|
-
var _ref3 =
|
|
3099
|
+
var _ref3 = itemProps != null ? itemProps : {},
|
|
3159
3100
|
itemProp = _ref3.item,
|
|
3160
3101
|
indexProp = _ref3.index,
|
|
3161
3102
|
_ref3$refKey = _ref3.refKey,
|
|
@@ -3183,7 +3124,7 @@ function useCombobox(userProps) {
|
|
|
3183
3124
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
3184
3125
|
return;
|
|
3185
3126
|
}
|
|
3186
|
-
|
|
3127
|
+
preventScroll();
|
|
3187
3128
|
dispatch({
|
|
3188
3129
|
type: ItemMouseMove,
|
|
3189
3130
|
index: index,
|
|
@@ -3202,21 +3143,22 @@ function useCombobox(userProps) {
|
|
|
3202
3143
|
|
|
3203
3144
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3204
3145
|
if (itemNode) {
|
|
3205
|
-
|
|
3146
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
3206
3147
|
}
|
|
3207
3148
|
}), _extends3['aria-disabled'] = disabled, _extends3['aria-selected'] = index === latestState.highlightedIndex, _extends3.id = elementIds.getItemId(index), _extends3.role = 'option', _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
|
|
3208
3149
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3209
3150
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3210
3151
|
}, rest);
|
|
3211
|
-
}, [dispatch, elementIds, latest, mouseAndTouchTrackers,
|
|
3212
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
3152
|
+
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
|
|
3153
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
|
|
3213
3154
|
var _extends4;
|
|
3214
|
-
var _ref5 =
|
|
3155
|
+
var _ref5 = toggleButtonProps != null ? toggleButtonProps : {};
|
|
3215
3156
|
_ref5.onClick;
|
|
3216
3157
|
var onPress = _ref5.onPress,
|
|
3217
3158
|
_ref5$refKey = _ref5.refKey,
|
|
3218
3159
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3219
3160
|
ref = _ref5.ref,
|
|
3161
|
+
disabled = _ref5.disabled,
|
|
3220
3162
|
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3221
3163
|
var latestState = latest.current.state;
|
|
3222
3164
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
@@ -3226,13 +3168,17 @@ function useCombobox(userProps) {
|
|
|
3226
3168
|
};
|
|
3227
3169
|
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3228
3170
|
toggleButtonRef.current = toggleButtonNode;
|
|
3229
|
-
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !
|
|
3171
|
+
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, /* istanbul ignore next (react-native) */{
|
|
3230
3172
|
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
3231
|
-
} ),
|
|
3173
|
+
} ), {
|
|
3174
|
+
disabled: disabled
|
|
3175
|
+
}, rest);
|
|
3232
3176
|
}, [dispatch, latest, elementIds]);
|
|
3233
|
-
var getInputProps = React.useCallback(function (
|
|
3177
|
+
var getInputProps = React.useCallback(function (inputProps, otherProps) {
|
|
3234
3178
|
var _extends5;
|
|
3235
|
-
var _ref6 =
|
|
3179
|
+
var _ref6 = inputProps != null ? inputProps : {},
|
|
3180
|
+
ariaLabel = _ref6['aria-label'],
|
|
3181
|
+
disabled = _ref6.disabled,
|
|
3236
3182
|
onKeyDown = _ref6.onKeyDown,
|
|
3237
3183
|
onChange = _ref6.onChange,
|
|
3238
3184
|
onInput = _ref6.onInput,
|
|
@@ -3243,15 +3189,16 @@ function useCombobox(userProps) {
|
|
|
3243
3189
|
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
3244
3190
|
ref = _ref6.ref,
|
|
3245
3191
|
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
|
|
3246
|
-
var _ref7 =
|
|
3192
|
+
var _ref7 = otherProps != null ? otherProps : {},
|
|
3247
3193
|
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3248
3194
|
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3249
3195
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3250
3196
|
var latestState = latest.current.state;
|
|
3251
3197
|
var inputHandleKeyDown = function inputHandleKeyDown(event) {
|
|
3252
3198
|
var key = normalizeArrowKey(event);
|
|
3253
|
-
if (key && inputKeyDownHandlers
|
|
3254
|
-
|
|
3199
|
+
if (key && key in inputKeyDownHandlers) {
|
|
3200
|
+
var validKey = key;
|
|
3201
|
+
inputKeyDownHandlers[validKey](event);
|
|
3255
3202
|
}
|
|
3256
3203
|
};
|
|
3257
3204
|
var inputHandleChange = function inputHandleChange(event) {
|
|
@@ -3279,7 +3226,7 @@ function useCombobox(userProps) {
|
|
|
3279
3226
|
/* istanbul ignore next (preact) */
|
|
3280
3227
|
var onChangeKey = 'onChange';
|
|
3281
3228
|
var eventHandlers = {};
|
|
3282
|
-
if (!
|
|
3229
|
+
if (!disabled) {
|
|
3283
3230
|
var _eventHandlers;
|
|
3284
3231
|
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
|
|
3285
3232
|
}
|
|
@@ -3297,7 +3244,7 @@ function useCombobox(userProps) {
|
|
|
3297
3244
|
}
|
|
3298
3245
|
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
3299
3246
|
inputRef.current = inputNode;
|
|
3300
|
-
}), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] =
|
|
3247
|
+
}), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = ariaLabel ? undefined : elementIds.labelId, _extends5['aria-label'] = ariaLabel, _extends5.autoComplete = 'off', _extends5.disabled = disabled, _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
|
|
3301
3248
|
}, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
|
|
3302
3249
|
|
|
3303
3250
|
// returns
|
|
@@ -3367,31 +3314,6 @@ var defaultStateValues = {
|
|
|
3367
3314
|
selectedItems: []
|
|
3368
3315
|
};
|
|
3369
3316
|
|
|
3370
|
-
/**
|
|
3371
|
-
* Returns the initial value for a state key in the following order:
|
|
3372
|
-
* 1. controlled prop, 2. initial prop, 3. default prop, 4. default
|
|
3373
|
-
* value from Downshift.
|
|
3374
|
-
*
|
|
3375
|
-
* @param {Object} props Props passed to the hook.
|
|
3376
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3377
|
-
* @returns {any} The initial value for that prop.
|
|
3378
|
-
*/
|
|
3379
|
-
function getInitialValue(props, propKey) {
|
|
3380
|
-
return getInitialValue$1(props, propKey, defaultStateValues);
|
|
3381
|
-
}
|
|
3382
|
-
|
|
3383
|
-
/**
|
|
3384
|
-
* Returns the default value for a state key in the following order:
|
|
3385
|
-
* 1. controlled prop, 2. default prop, 3. default value from Downshift.
|
|
3386
|
-
*
|
|
3387
|
-
* @param {Object} props Props passed to the hook.
|
|
3388
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3389
|
-
* @returns {any} The initial value for that prop.
|
|
3390
|
-
*/
|
|
3391
|
-
function getDefaultValue(props, propKey) {
|
|
3392
|
-
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
3393
|
-
}
|
|
3394
|
-
|
|
3395
3317
|
/**
|
|
3396
3318
|
* Gets the initial state based on the provided props. It uses initial, default
|
|
3397
3319
|
* and controlled props related to state in order to compute the initial value.
|
|
@@ -3400,8 +3322,8 @@ function getDefaultValue(props, propKey) {
|
|
|
3400
3322
|
* @returns {Object} The initial state.
|
|
3401
3323
|
*/
|
|
3402
3324
|
function getInitialState$1(props) {
|
|
3403
|
-
var activeIndex = getInitialValue(props,
|
|
3404
|
-
var selectedItems = getInitialValue(props,
|
|
3325
|
+
var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
|
|
3326
|
+
var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
|
|
3405
3327
|
return {
|
|
3406
3328
|
activeIndex: activeIndex,
|
|
3407
3329
|
selectedItems: selectedItems
|
|
@@ -3445,9 +3367,9 @@ function isStateEqual$1(prevState, newState) {
|
|
|
3445
3367
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3446
3368
|
}
|
|
3447
3369
|
var propTypes$1 = {
|
|
3448
|
-
stateReducer:
|
|
3449
|
-
itemToKey:
|
|
3450
|
-
environment:
|
|
3370
|
+
stateReducer: dropdownPropTypes.stateReducer,
|
|
3371
|
+
itemToKey: dropdownPropTypes.itemToKey,
|
|
3372
|
+
environment: dropdownPropTypes.environment,
|
|
3451
3373
|
selectedItems: PropTypes.array,
|
|
3452
3374
|
initialSelectedItems: PropTypes.array,
|
|
3453
3375
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3461,9 +3383,9 @@ var propTypes$1 = {
|
|
|
3461
3383
|
keyNavigationPrevious: PropTypes.string
|
|
3462
3384
|
};
|
|
3463
3385
|
var defaultProps = {
|
|
3464
|
-
itemToKey:
|
|
3465
|
-
stateReducer:
|
|
3466
|
-
environment:
|
|
3386
|
+
itemToKey: dropdownDefaultProps.itemToKey,
|
|
3387
|
+
stateReducer: dropdownDefaultProps.stateReducer,
|
|
3388
|
+
environment: dropdownDefaultProps.environment,
|
|
3467
3389
|
keyNavigationNext: 'ArrowRight',
|
|
3468
3390
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3469
3391
|
};
|
|
@@ -3509,10 +3431,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3509
3431
|
});
|
|
3510
3432
|
|
|
3511
3433
|
/* eslint-disable complexity */
|
|
3512
|
-
function downshiftMultipleSelectionReducer(state,
|
|
3434
|
+
function downshiftMultipleSelectionReducer(state, action) {
|
|
3513
3435
|
var type = action.type,
|
|
3514
3436
|
index = action.index,
|
|
3515
|
-
selectedItem = action.selectedItem
|
|
3437
|
+
selectedItem = action.selectedItem,
|
|
3438
|
+
props = action.props;
|
|
3516
3439
|
var activeIndex = state.activeIndex,
|
|
3517
3440
|
selectedItems = state.selectedItems;
|
|
3518
3441
|
var changes;
|
|
@@ -3609,8 +3532,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
|
|
|
3609
3532
|
}
|
|
3610
3533
|
case FunctionReset:
|
|
3611
3534
|
changes = {
|
|
3612
|
-
activeIndex: getDefaultValue(props,
|
|
3613
|
-
selectedItems: getDefaultValue(props,
|
|
3535
|
+
activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
|
|
3536
|
+
selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
|
|
3614
3537
|
};
|
|
3615
3538
|
break;
|
|
3616
3539
|
default:
|
|
@@ -3842,7 +3765,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3842
3765
|
TagRemoveClick: TagRemoveClick
|
|
3843
3766
|
});
|
|
3844
3767
|
|
|
3845
|
-
function useTagGroupReducer(state,
|
|
3768
|
+
function useTagGroupReducer(state, action) {
|
|
3846
3769
|
var type = action.type;
|
|
3847
3770
|
var changes;
|
|
3848
3771
|
switch (type) {
|
|
@@ -3903,8 +3826,9 @@ function useTagGroupReducer(state, _props, action) {
|
|
|
3903
3826
|
return _extends({}, state, changes);
|
|
3904
3827
|
}
|
|
3905
3828
|
|
|
3906
|
-
//
|
|
3907
|
-
var
|
|
3829
|
+
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
3830
|
+
var SafeReact = _extends({}, React__namespace);
|
|
3831
|
+
var reactUseId = SafeReact.useId;
|
|
3908
3832
|
|
|
3909
3833
|
// istanbul ignore next
|
|
3910
3834
|
var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
|
|
@@ -4079,7 +4003,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4079
4003
|
'aria-atomic': 'false',
|
|
4080
4004
|
'aria-relevant': 'additions',
|
|
4081
4005
|
role: 'listbox',
|
|
4082
|
-
onKeyDown: callAllEventHandlers
|
|
4006
|
+
onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
|
|
4083
4007
|
}, rest);
|
|
4084
4008
|
return tagGroupProps;
|
|
4085
4009
|
}, [dispatch, elementIds.tagGroupId]);
|
|
@@ -4104,11 +4028,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4104
4028
|
var tagId = elementIds.getTagId(index);
|
|
4105
4029
|
return _extends((_extends2 = {
|
|
4106
4030
|
'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
|
|
4107
|
-
}, _extends2[refKey] = handleRefs
|
|
4031
|
+
}, _extends2[refKey] = handleRefs(ref, function (itemNode) {
|
|
4108
4032
|
if (itemNode) {
|
|
4109
4033
|
itemRefs.current[tagId] = itemNode;
|
|
4110
4034
|
}
|
|
4111
|
-
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers
|
|
4035
|
+
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4112
4036
|
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4113
4037
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4114
4038
|
var index = options.index,
|
|
@@ -4130,7 +4054,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4130
4054
|
id: tagRemoveId,
|
|
4131
4055
|
tabIndex: -1,
|
|
4132
4056
|
'aria-labelledby': tagRemoveId + " " + tagId,
|
|
4133
|
-
onClick: callAllEventHandlers
|
|
4057
|
+
onClick: callAllEventHandlers(onClick, handleClick)
|
|
4134
4058
|
}, rest);
|
|
4135
4059
|
}, [elementIds, dispatch]);
|
|
4136
4060
|
|