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,93 +280,149 @@ 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
|
|
287
|
-
*/
|
|
288
|
-
function cbToCb(cb) {
|
|
289
|
-
return typeof cb === 'function' ? cb : noop;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* @param {HTMLElement} parent the parent node
|
|
294
|
-
* @param {HTMLElement} child the child node
|
|
295
|
-
* @param {Window} environment The window context where downshift renders.
|
|
296
|
-
* @return {Boolean} whether the parent is the child or the child is in the parent
|
|
283
|
+
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
284
|
+
* @param event a keyboardEvent object
|
|
285
|
+
* @return keyboard key
|
|
297
286
|
*/
|
|
298
|
-
function
|
|
299
|
-
var
|
|
300
|
-
|
|
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;
|
|
301
295
|
}
|
|
302
296
|
|
|
303
297
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
309
|
-
* @
|
|
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.
|
|
310
306
|
*/
|
|
311
|
-
function
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (timeoutId) {
|
|
315
|
-
clearTimeout(timeoutId);
|
|
316
|
-
}
|
|
307
|
+
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
308
|
+
if (circular === void 0) {
|
|
309
|
+
circular = false;
|
|
317
310
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
+
}
|
|
321
323
|
}
|
|
322
|
-
cancel();
|
|
323
|
-
timeoutId = setTimeout(function () {
|
|
324
|
-
timeoutId = null;
|
|
325
|
-
fn.apply(void 0, args);
|
|
326
|
-
}, time);
|
|
327
324
|
}
|
|
328
|
-
|
|
329
|
-
|
|
325
|
+
if (circular) {
|
|
326
|
+
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
327
|
+
}
|
|
328
|
+
return -1;
|
|
330
329
|
}
|
|
331
330
|
|
|
332
331
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* @param
|
|
337
|
-
* @
|
|
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.
|
|
338
340
|
*/
|
|
339
|
-
function
|
|
340
|
-
|
|
341
|
-
|
|
341
|
+
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
342
|
+
if (circular === void 0) {
|
|
343
|
+
circular = false;
|
|
342
344
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
345
|
+
var count = items.length;
|
|
346
|
+
if (count === 0) {
|
|
347
|
+
return -1;
|
|
348
|
+
}
|
|
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);
|
|
350
381
|
}
|
|
351
|
-
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
352
382
|
});
|
|
353
383
|
};
|
|
354
384
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Checks if event target is within the downshift elements.
|
|
388
|
+
*
|
|
389
|
+
* @param target Target to check.
|
|
390
|
+
* @param downshiftElements The elements that form downshift (list, toggle button etc).
|
|
391
|
+
* @param environment The window context where downshift renders.
|
|
392
|
+
* @param checkActiveElement Whether to also check activeElement.
|
|
393
|
+
*
|
|
394
|
+
* @returns Whether or not the target is within downshift elements.
|
|
395
|
+
*/
|
|
396
|
+
function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
|
|
397
|
+
if (checkActiveElement === void 0) {
|
|
398
|
+
checkActiveElement = true;
|
|
358
399
|
}
|
|
359
|
-
return function (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
400
|
+
return !!environment && downshiftElements.some(function (contextNode) {
|
|
401
|
+
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @param parent the parent node
|
|
407
|
+
* @param child the child node
|
|
408
|
+
* @param environment The window context where downshift renders.
|
|
409
|
+
* @return Whether the parent is the child or the child is in the parent
|
|
410
|
+
*/
|
|
411
|
+
function isOrContainsNode(parent, child, environment) {
|
|
412
|
+
var result = parent === child || child instanceof environment.Node && parent.contains(child);
|
|
413
|
+
return result;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Accepts a parameter and returns it if it's a function
|
|
418
|
+
* or a noop function if it's not. This allows us to
|
|
419
|
+
* accept a callback, but not worry about it if it's not
|
|
420
|
+
* passed.
|
|
421
|
+
* @param {Function} cb the callback
|
|
422
|
+
* @return {Function} a function
|
|
423
|
+
*/
|
|
424
|
+
function cbToCb(cb) {
|
|
425
|
+
return typeof cb === 'function' ? cb : noop;
|
|
368
426
|
}
|
|
369
427
|
|
|
370
428
|
/**
|
|
@@ -453,34 +511,6 @@ function pickState(state) {
|
|
|
453
511
|
return result;
|
|
454
512
|
}
|
|
455
513
|
|
|
456
|
-
/**
|
|
457
|
-
* This determines whether a prop is a "controlled prop" meaning it is
|
|
458
|
-
* state which is controlled by the outside of this component rather
|
|
459
|
-
* than within this component.
|
|
460
|
-
*
|
|
461
|
-
* @param {Object} props The props that may contain controlled values.
|
|
462
|
-
* @param {String} key the key to check
|
|
463
|
-
* @return {Boolean} whether it is a controlled controlled prop
|
|
464
|
-
*/
|
|
465
|
-
function isControlledProp(props, key) {
|
|
466
|
-
return props[key] !== undefined;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
471
|
-
* @param {Object} event a keyboardEvent object
|
|
472
|
-
* @return {String} keyboard key
|
|
473
|
-
*/
|
|
474
|
-
function normalizeArrowKey(event) {
|
|
475
|
-
var key = event.key,
|
|
476
|
-
keyCode = event.keyCode;
|
|
477
|
-
/* istanbul ignore next (ie) */
|
|
478
|
-
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
479
|
-
return "Arrow" + key;
|
|
480
|
-
}
|
|
481
|
-
return key;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
514
|
/**
|
|
485
515
|
* Simple check if the value passed is object literal
|
|
486
516
|
* @param {*} obj any things
|
|
@@ -490,112 +520,6 @@ function isPlainObject(obj) {
|
|
|
490
520
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
491
521
|
}
|
|
492
522
|
|
|
493
|
-
/**
|
|
494
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
495
|
-
*
|
|
496
|
-
* @param {number} start The current highlightedIndex.
|
|
497
|
-
* @param {number} offset The offset from the current highlightedIndex to start searching.
|
|
498
|
-
* @param {unknown[]} items The items array.
|
|
499
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
500
|
-
* @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
|
|
501
|
-
* @returns {number} The next highlightedIndex.
|
|
502
|
-
*/
|
|
503
|
-
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
504
|
-
if (circular === void 0) {
|
|
505
|
-
circular = false;
|
|
506
|
-
}
|
|
507
|
-
var count = items.length;
|
|
508
|
-
if (count === 0) {
|
|
509
|
-
return -1;
|
|
510
|
-
}
|
|
511
|
-
var itemsLastIndex = count - 1;
|
|
512
|
-
if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
|
|
513
|
-
start = offset > 0 ? -1 : itemsLastIndex + 1;
|
|
514
|
-
}
|
|
515
|
-
var current = start + offset;
|
|
516
|
-
if (current < 0) {
|
|
517
|
-
current = circular ? itemsLastIndex : 0;
|
|
518
|
-
} else if (current > itemsLastIndex) {
|
|
519
|
-
current = circular ? 0 : itemsLastIndex;
|
|
520
|
-
}
|
|
521
|
-
var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
|
|
522
|
-
if (highlightedIndex === -1) {
|
|
523
|
-
return start >= count ? -1 : start;
|
|
524
|
-
}
|
|
525
|
-
return highlightedIndex;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
530
|
-
*
|
|
531
|
-
* @param {number} start The current highlightedIndex.
|
|
532
|
-
* @param {boolean} backwards If true, it will search backwards from the start.
|
|
533
|
-
* @param {unknown[]} items The items array.
|
|
534
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
535
|
-
* @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
|
|
536
|
-
* @returns {number} The next non-disabled index.
|
|
537
|
-
*/
|
|
538
|
-
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
539
|
-
if (circular === void 0) {
|
|
540
|
-
circular = false;
|
|
541
|
-
}
|
|
542
|
-
var count = items.length;
|
|
543
|
-
if (backwards) {
|
|
544
|
-
for (var index = start; index >= 0; index--) {
|
|
545
|
-
if (!isItemDisabled(items[index], index)) {
|
|
546
|
-
return index;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
} else {
|
|
550
|
-
for (var _index = start; _index < count; _index++) {
|
|
551
|
-
if (!isItemDisabled(items[_index], _index)) {
|
|
552
|
-
return _index;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
if (circular) {
|
|
557
|
-
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
558
|
-
}
|
|
559
|
-
return -1;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/**
|
|
563
|
-
* Checks if event target is within the downshift elements.
|
|
564
|
-
*
|
|
565
|
-
* @param {EventTarget} target Target to check.
|
|
566
|
-
* @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
|
|
567
|
-
* @param {Window} environment The window context where downshift renders.
|
|
568
|
-
* @param {boolean} checkActiveElement Whether to also check activeElement.
|
|
569
|
-
*
|
|
570
|
-
* @returns {boolean} Whether or not the target is within downshift elements.
|
|
571
|
-
*/
|
|
572
|
-
function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
|
|
573
|
-
if (checkActiveElement === void 0) {
|
|
574
|
-
checkActiveElement = true;
|
|
575
|
-
}
|
|
576
|
-
return environment && downshiftElements.some(function (contextNode) {
|
|
577
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
582
|
-
var validateControlledUnchanged = noop;
|
|
583
|
-
/* istanbul ignore next */
|
|
584
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
585
|
-
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
586
|
-
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";
|
|
587
|
-
Object.keys(state).forEach(function (propKey) {
|
|
588
|
-
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
589
|
-
// eslint-disable-next-line no-console
|
|
590
|
-
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
591
|
-
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
592
|
-
// eslint-disable-next-line no-console
|
|
593
|
-
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
|
|
599
523
|
var _excluded$4 = ["refKey", "ref"],
|
|
600
524
|
_excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
601
525
|
_excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
@@ -746,7 +670,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
746
670
|
}
|
|
747
671
|
newStateToSet[key];
|
|
748
672
|
// if it's coming from props, then we don't care to set it internally
|
|
749
|
-
if (
|
|
673
|
+
if (_this.props[key] === undefined) {
|
|
750
674
|
nextState[key] = newStateToSet[key];
|
|
751
675
|
}
|
|
752
676
|
});
|
|
@@ -1478,7 +1402,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1478
1402
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
1479
1403
|
}
|
|
1480
1404
|
}
|
|
1481
|
-
if (
|
|
1405
|
+
if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
|
|
1482
1406
|
this.internalSetState({
|
|
1483
1407
|
type: controlledPropUpdatedSelectedItem,
|
|
1484
1408
|
inputValue: this.props.itemToString(this.props.selectedItem)
|
|
@@ -1664,7 +1588,7 @@ function callOnChangeProps(action, props, state, newState) {
|
|
|
1664
1588
|
changes[key] = newState[key];
|
|
1665
1589
|
}
|
|
1666
1590
|
}
|
|
1667
|
-
if (props.onStateChange && Object.keys(changes).length) {
|
|
1591
|
+
if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
|
|
1668
1592
|
props.onStateChange(_extends({
|
|
1669
1593
|
type: type
|
|
1670
1594
|
}, changes));
|
|
@@ -1690,50 +1614,53 @@ function invokeOnChangeHandler(key, action, props, state, newState) {
|
|
|
1690
1614
|
* two reducers, one from downshift and an optional one from the user.
|
|
1691
1615
|
* Also calls the onChange handlers for state values that have changed.
|
|
1692
1616
|
*
|
|
1693
|
-
* @param
|
|
1694
|
-
* @param
|
|
1695
|
-
* @param
|
|
1696
|
-
* @param
|
|
1697
|
-
* @returns
|
|
1617
|
+
* @param reducer Reducer function from downshift.
|
|
1618
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1619
|
+
* @param createInitialState Function that returns the initial state.
|
|
1620
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1621
|
+
* @returns An array with the state and an action dispatcher.
|
|
1698
1622
|
*/
|
|
1699
1623
|
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
1700
|
-
var prevStateRef = React__namespace.useRef(
|
|
1701
|
-
var actionRef = React__namespace.useRef(
|
|
1702
|
-
var propsRef = useLatestRef(props);
|
|
1624
|
+
var prevStateRef = React__namespace.useRef({});
|
|
1625
|
+
var actionRef = React__namespace.useRef();
|
|
1703
1626
|
var enhancedReducer = React__namespace.useCallback(function (state, action) {
|
|
1704
1627
|
actionRef.current = action;
|
|
1705
|
-
state = getState(state,
|
|
1706
|
-
var changes = reducer(state,
|
|
1707
|
-
var newState =
|
|
1628
|
+
state = getState(state, action.props);
|
|
1629
|
+
var changes = reducer(state, action);
|
|
1630
|
+
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
1708
1631
|
changes: changes
|
|
1709
1632
|
}));
|
|
1710
1633
|
return _extends({}, state, newState);
|
|
1711
|
-
}, [
|
|
1634
|
+
}, [reducer]);
|
|
1712
1635
|
var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
|
|
1713
1636
|
state = _React$useReducer[0],
|
|
1714
1637
|
dispatch = _React$useReducer[1];
|
|
1638
|
+
var propsRef = useLatestRef(props);
|
|
1639
|
+
var dispatchWithProps = React__namespace.useCallback(function (action) {
|
|
1640
|
+
return dispatch(_extends({}, action, {
|
|
1641
|
+
props: propsRef.current
|
|
1642
|
+
}));
|
|
1643
|
+
}, [propsRef]);
|
|
1715
1644
|
var action = actionRef.current;
|
|
1716
1645
|
React__namespace.useEffect(function () {
|
|
1717
|
-
var
|
|
1718
|
-
var
|
|
1719
|
-
var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
|
|
1646
|
+
var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
|
|
1647
|
+
var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
|
|
1720
1648
|
if (shouldCallOnChangeProps) {
|
|
1721
|
-
callOnChangeProps(action,
|
|
1649
|
+
callOnChangeProps(action, action.props, prevState, state);
|
|
1722
1650
|
}
|
|
1723
1651
|
prevStateRef.current = state;
|
|
1724
|
-
}, [state, action, isStateEqual
|
|
1725
|
-
return [state,
|
|
1652
|
+
}, [state, action, isStateEqual]);
|
|
1653
|
+
return [state, dispatchWithProps];
|
|
1726
1654
|
}
|
|
1727
1655
|
|
|
1728
1656
|
/**
|
|
1729
1657
|
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
1730
1658
|
* returning the new state.
|
|
1731
|
-
*
|
|
1732
|
-
* @param
|
|
1733
|
-
* @param
|
|
1734
|
-
* @param
|
|
1735
|
-
* @
|
|
1736
|
-
* @returns {Array} An array with the state and an action dispatcher.
|
|
1659
|
+
* @param reducer Reducer function from downshift.
|
|
1660
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1661
|
+
* @param createInitialState Function that returns the initial state.
|
|
1662
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1663
|
+
* @returns An array with the state and an action dispatcher.
|
|
1737
1664
|
*/
|
|
1738
1665
|
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
1739
1666
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
@@ -1786,16 +1713,8 @@ function useIsInitialMount() {
|
|
|
1786
1713
|
return isInitialMountRef.current;
|
|
1787
1714
|
}
|
|
1788
1715
|
|
|
1789
|
-
/**
|
|
1790
|
-
* Default state reducer that returns the changes.
|
|
1791
|
-
*
|
|
1792
|
-
*/
|
|
1793
|
-
function stateReducer(_s, a) {
|
|
1794
|
-
return a.changes;
|
|
1795
|
-
}
|
|
1796
|
-
|
|
1797
1716
|
// Shared between all exports.
|
|
1798
|
-
var propTypes$
|
|
1717
|
+
var propTypes$4 = {
|
|
1799
1718
|
environment: PropTypes.shape({
|
|
1800
1719
|
addEventListener: PropTypes.func.isRequired,
|
|
1801
1720
|
removeEventListener: PropTypes.func.isRequired,
|
|
@@ -1811,30 +1730,47 @@ var propTypes$5 = {
|
|
|
1811
1730
|
stateReducer: PropTypes.func
|
|
1812
1731
|
};
|
|
1813
1732
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1733
|
+
/**
|
|
1734
|
+
* Returns the default value based on the defaultProp and defaultStateValue.
|
|
1735
|
+
*
|
|
1736
|
+
* @param defaultProp The default prop value.
|
|
1737
|
+
* @param defaultStateValue The default state value.
|
|
1738
|
+
* @returns The resolved default value.
|
|
1739
|
+
*/
|
|
1740
|
+
function getDefaultValue(defaultProp, defaultStateValue) {
|
|
1741
|
+
return defaultProp === undefined ? defaultStateValue : defaultProp;
|
|
1820
1742
|
}
|
|
1821
1743
|
|
|
1822
|
-
|
|
1823
|
-
|
|
1744
|
+
/**
|
|
1745
|
+
* Returns the initial value for a state variable, based on the following precedence:
|
|
1746
|
+
* 1. The controlled value (if it's not undefined)
|
|
1747
|
+
* 2. The initialValue (if it's not undefined)
|
|
1748
|
+
* 3. The defaultValue (if it's not undefined)
|
|
1749
|
+
* 4. The defaultStateValue
|
|
1750
|
+
*
|
|
1751
|
+
* @param value The controlled value of the state variable.
|
|
1752
|
+
* @param initialValue The initial value of the state variable.
|
|
1753
|
+
* @param defaultValue The default value of the state variable.
|
|
1754
|
+
* @param defaultStateValue The default state value to use if all other values are undefined.
|
|
1755
|
+
* @returns The initial value for the state variable.
|
|
1756
|
+
*/
|
|
1757
|
+
function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
|
|
1824
1758
|
if (value !== undefined) {
|
|
1825
1759
|
return value;
|
|
1826
1760
|
}
|
|
1827
|
-
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
1828
1761
|
if (initialValue !== undefined) {
|
|
1829
1762
|
return initialValue;
|
|
1830
1763
|
}
|
|
1831
|
-
|
|
1764
|
+
if (defaultValue !== undefined) {
|
|
1765
|
+
return defaultValue;
|
|
1766
|
+
}
|
|
1767
|
+
return defaultStateValue;
|
|
1832
1768
|
}
|
|
1833
1769
|
|
|
1834
1770
|
/**
|
|
1835
1771
|
* Debounced call for updating the a11y message.
|
|
1836
1772
|
*/
|
|
1837
|
-
var updateA11yStatus = debounce
|
|
1773
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
1838
1774
|
setStatus(status, document);
|
|
1839
1775
|
}, 200);
|
|
1840
1776
|
|
|
@@ -1870,7 +1806,7 @@ function useA11yMessageStatus(getA11yStatusMessage, options, dependencyArray, en
|
|
|
1870
1806
|
}
|
|
1871
1807
|
|
|
1872
1808
|
// Shared between useSelect, useCombobox, Downshift.
|
|
1873
|
-
var
|
|
1809
|
+
var dropdownPropTypes = _extends({}, propTypes$4, {
|
|
1874
1810
|
getA11yStatusMessage: PropTypes.func,
|
|
1875
1811
|
highlightedIndex: PropTypes.number,
|
|
1876
1812
|
defaultHighlightedIndex: PropTypes.number,
|
|
@@ -1893,59 +1829,145 @@ var propTypes$4 = _extends({}, propTypes$5, {
|
|
|
1893
1829
|
scrollIntoView: PropTypes.func
|
|
1894
1830
|
});
|
|
1895
1831
|
|
|
1896
|
-
var
|
|
1832
|
+
var dropdownDefaultProps = {
|
|
1897
1833
|
itemToString: function itemToString(item) {
|
|
1898
1834
|
return item ? String(item) : '';
|
|
1899
1835
|
},
|
|
1900
1836
|
itemToKey: function itemToKey(item) {
|
|
1901
1837
|
return item;
|
|
1902
1838
|
},
|
|
1903
|
-
|
|
1839
|
+
isItemDisabled: function isItemDisabled(_item) {
|
|
1840
|
+
return false;
|
|
1841
|
+
},
|
|
1842
|
+
stateReducer: function stateReducer(_state, actionAndChanges) {
|
|
1843
|
+
return actionAndChanges.changes;
|
|
1844
|
+
},
|
|
1904
1845
|
scrollIntoView: scrollIntoView,
|
|
1905
1846
|
environment: /* istanbul ignore next (ssr) */
|
|
1906
1847
|
typeof window === 'undefined' || false ? undefined : window
|
|
1907
1848
|
};
|
|
1908
1849
|
|
|
1909
|
-
var
|
|
1850
|
+
var dropdownDefaultStateValues = {
|
|
1910
1851
|
highlightedIndex: -1,
|
|
1911
1852
|
isOpen: false,
|
|
1912
1853
|
selectedItem: null,
|
|
1913
1854
|
inputValue: ''
|
|
1914
1855
|
};
|
|
1915
1856
|
|
|
1916
|
-
//
|
|
1917
|
-
var
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
var
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
}
|
|
1857
|
+
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
1858
|
+
var SafeReact$1 = _extends({}, React__namespace);
|
|
1859
|
+
var reactUseId$1 = SafeReact$1.useId;
|
|
1860
|
+
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
1861
|
+
function useElementIdsR18$1(_ref) {
|
|
1862
|
+
var id = _ref.id,
|
|
1863
|
+
labelId = _ref.labelId,
|
|
1864
|
+
menuId = _ref.menuId,
|
|
1865
|
+
getItemId = _ref.getItemId,
|
|
1866
|
+
toggleButtonId = _ref.toggleButtonId,
|
|
1867
|
+
inputId = _ref.inputId;
|
|
1868
|
+
var reactId = "downshift-" + reactUseId$1();
|
|
1869
|
+
if (!id) {
|
|
1870
|
+
id = reactId;
|
|
1871
|
+
}
|
|
1872
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1873
|
+
return {
|
|
1874
|
+
labelId: labelId != null ? labelId : id + "-label",
|
|
1875
|
+
menuId: menuId != null ? menuId : id + "-menu",
|
|
1876
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
1877
|
+
return id + "-item-" + index;
|
|
1878
|
+
},
|
|
1879
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
1880
|
+
inputId: inputId != null ? inputId : id + "-input"
|
|
1881
|
+
};
|
|
1882
|
+
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
1883
|
+
return elementIds;
|
|
1931
1884
|
}
|
|
1932
|
-
function
|
|
1933
|
-
var
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1885
|
+
function useElementIdsLegacy$1(_ref2) {
|
|
1886
|
+
var id = _ref2.id,
|
|
1887
|
+
labelId = _ref2.labelId,
|
|
1888
|
+
menuId = _ref2.menuId,
|
|
1889
|
+
getItemId = _ref2.getItemId,
|
|
1890
|
+
toggleButtonId = _ref2.toggleButtonId,
|
|
1891
|
+
inputId = _ref2.inputId;
|
|
1892
|
+
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
1893
|
+
var baseId = baseIdRef.current;
|
|
1894
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
1895
|
+
return {
|
|
1896
|
+
labelId: labelId != null ? labelId : baseId + "-label",
|
|
1897
|
+
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
1898
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
1899
|
+
return baseId + "-item-" + index;
|
|
1900
|
+
},
|
|
1901
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
1902
|
+
inputId: inputId != null ? inputId : baseId + "-input"
|
|
1903
|
+
};
|
|
1904
|
+
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
1905
|
+
return elementIds;
|
|
1906
|
+
}
|
|
1907
|
+
|
|
1908
|
+
/**
|
|
1909
|
+
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
1910
|
+
*
|
|
1911
|
+
* @param props Props passed to the hook.
|
|
1912
|
+
* @returns The highlighted index.
|
|
1913
|
+
*/
|
|
1914
|
+
function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
|
|
1915
|
+
var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
1916
|
+
if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
|
|
1917
|
+
return -1;
|
|
1918
|
+
}
|
|
1919
|
+
return highlightedIndex;
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
/**
|
|
1923
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
1924
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
1925
|
+
*
|
|
1926
|
+
* @param props The Dropdown props.
|
|
1927
|
+
* @param highlightedIndex The index from the state.
|
|
1928
|
+
* @param inputValue Also return the input value for state.
|
|
1929
|
+
* @returns The changes for the state.
|
|
1930
|
+
*/
|
|
1931
|
+
function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
|
|
1932
|
+
var shouldSelect = items.length && highlightedIndex >= 0;
|
|
1933
|
+
return _extends({
|
|
1934
|
+
isOpen: false,
|
|
1935
|
+
highlightedIndex: -1
|
|
1936
|
+
}, shouldSelect && _extends({
|
|
1937
|
+
selectedItem: items[highlightedIndex],
|
|
1938
|
+
isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
1939
|
+
highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
|
|
1940
|
+
}, inputValue && {
|
|
1941
|
+
inputValue: itemToString(items[highlightedIndex])
|
|
1942
|
+
}));
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
/* eslint-disable max-params */
|
|
1946
|
+
/**
|
|
1947
|
+
* Returns the highlighted index when the menu is opened.
|
|
1948
|
+
* Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
|
|
1949
|
+
* selectedItem, and the open direction offset.
|
|
1950
|
+
*
|
|
1951
|
+
* @param items The list of items.
|
|
1952
|
+
* @param initialHighlightedIndex The initial highlighted index prop.
|
|
1953
|
+
* @param defaultHighlightedIndex The default highlighted index prop.
|
|
1954
|
+
* @param isItemDisabled Callback to determine if an item is disabled.
|
|
1955
|
+
* @param itemToKey Callback to get a unique key from an item.
|
|
1956
|
+
* @param selectedItem The currently selected item.
|
|
1957
|
+
* @param highlightedIndex The current highlighted index from state.
|
|
1958
|
+
* @param offset The direction of navigation: positive opens downward, negative opens upward.
|
|
1959
|
+
* @returns The new highlighted index.
|
|
1960
|
+
*/
|
|
1961
|
+
function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
|
|
1940
1962
|
if (items.length === 0) {
|
|
1941
1963
|
return -1;
|
|
1942
1964
|
}
|
|
1943
1965
|
|
|
1944
1966
|
// initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
1945
|
-
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1967
|
+
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
1946
1968
|
return initialHighlightedIndex;
|
|
1947
1969
|
}
|
|
1948
|
-
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1970
|
+
if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
1949
1971
|
return defaultHighlightedIndex;
|
|
1950
1972
|
}
|
|
1951
1973
|
if (selectedItem) {
|
|
@@ -1953,21 +1975,71 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1953
1975
|
return itemToKey(selectedItem) === itemToKey(item);
|
|
1954
1976
|
});
|
|
1955
1977
|
}
|
|
1956
|
-
if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1978
|
+
if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
1957
1979
|
return items.length - 1;
|
|
1958
1980
|
}
|
|
1959
|
-
if (offset > 0 && !isItemDisabled(items[0], 0)) {
|
|
1981
|
+
if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
|
|
1960
1982
|
return 0;
|
|
1961
1983
|
}
|
|
1962
1984
|
return -1;
|
|
1963
1985
|
}
|
|
1986
|
+
|
|
1987
|
+
function getInitialState$3(props) {
|
|
1988
|
+
var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
|
|
1989
|
+
var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
1990
|
+
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
1991
|
+
var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
|
|
1992
|
+
return {
|
|
1993
|
+
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
1994
|
+
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
1995
|
+
}) : highlightedIndex,
|
|
1996
|
+
isOpen: isOpen,
|
|
1997
|
+
selectedItem: selectedItem,
|
|
1998
|
+
inputValue: inputValue
|
|
1999
|
+
};
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
/**
|
|
2003
|
+
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
2004
|
+
* @param props Props from useCombobox or useSelect.
|
|
2005
|
+
* @returns The highlighted index.
|
|
2006
|
+
*/
|
|
2007
|
+
function getInitialHighlightedIndex(props) {
|
|
2008
|
+
var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
2009
|
+
if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2010
|
+
return -1;
|
|
2011
|
+
}
|
|
2012
|
+
return highlightedIndex;
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2016
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
2017
|
+
var useControlPropsValidator = noop;
|
|
2018
|
+
/* istanbul ignore next */
|
|
2019
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2020
|
+
useControlPropsValidator = function useControlPropsValidator(_ref) {
|
|
2021
|
+
var props = _ref.props,
|
|
2022
|
+
state = _ref.state;
|
|
2023
|
+
// used for checking when props are moving from controlled to uncontrolled.
|
|
2024
|
+
var prevPropsRef = React__namespace.useRef(props);
|
|
2025
|
+
var isInitialMount = useIsInitialMount();
|
|
2026
|
+
React__namespace.useEffect(function () {
|
|
2027
|
+
if (isInitialMount) {
|
|
2028
|
+
return;
|
|
2029
|
+
}
|
|
2030
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2031
|
+
prevPropsRef.current = props;
|
|
2032
|
+
}, [state, props, isInitialMount]);
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
|
|
1964
2036
|
/**
|
|
1965
2037
|
* Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
|
|
1966
2038
|
*
|
|
1967
|
-
* @param
|
|
1968
|
-
* @param
|
|
1969
|
-
* @param
|
|
1970
|
-
* @returns
|
|
2039
|
+
* @param environment The environment to add the event listeners to, for instance window.
|
|
2040
|
+
* @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
|
|
2041
|
+
* @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
|
|
2042
|
+
* @returns The mouse and touch events information.
|
|
1971
2043
|
*/
|
|
1972
2044
|
function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
|
|
1973
2045
|
var mouseAndTouchTrackersRef = React__namespace.useRef({
|
|
@@ -2031,8 +2103,8 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
2031
2103
|
/**
|
|
2032
2104
|
* Custom hook that checks if getter props are called correctly.
|
|
2033
2105
|
*
|
|
2034
|
-
* @param
|
|
2035
|
-
* @returns
|
|
2106
|
+
* @param propKeys Getter prop names to be handled.
|
|
2107
|
+
* @returns Setter function called inside getter props to set call information.
|
|
2036
2108
|
*/
|
|
2037
2109
|
/* istanbul ignore next */
|
|
2038
2110
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -2068,120 +2140,58 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2068
2140
|
getterPropsCalledRef.current[propKey] = {
|
|
2069
2141
|
suppressRefError: suppressRefError,
|
|
2070
2142
|
refKey: refKey,
|
|
2071
|
-
elementRef: elementRef
|
|
2072
|
-
};
|
|
2073
|
-
}, []);
|
|
2074
|
-
return setGetterPropCallInfo;
|
|
2075
|
-
};
|
|
2076
|
-
}
|
|
2077
|
-
function useScrollIntoView(_ref) {
|
|
2078
|
-
var highlightedIndex = _ref.highlightedIndex,
|
|
2079
|
-
isOpen = _ref.isOpen,
|
|
2080
|
-
itemRefs = _ref.itemRefs,
|
|
2081
|
-
getItemNodeFromIndex = _ref.getItemNodeFromIndex,
|
|
2082
|
-
menuElement = _ref.menuElement,
|
|
2083
|
-
scrollIntoViewProp = _ref.scrollIntoView;
|
|
2084
|
-
// used not to scroll on highlight by mouse.
|
|
2085
|
-
var shouldScrollRef = React__namespace.useRef(true);
|
|
2086
|
-
// Scroll on highlighted item if change comes from keyboard.
|
|
2087
|
-
useIsomorphicLayoutEffect(function () {
|
|
2088
|
-
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2089
|
-
return;
|
|
2090
|
-
}
|
|
2091
|
-
if (shouldScrollRef.current === false) {
|
|
2092
|
-
shouldScrollRef.current = true;
|
|
2093
|
-
} else {
|
|
2094
|
-
scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
|
|
2095
|
-
}
|
|
2096
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2097
|
-
}, [highlightedIndex]);
|
|
2098
|
-
return shouldScrollRef;
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
2102
|
-
var useControlPropsValidator = noop;
|
|
2103
|
-
/* istanbul ignore next */
|
|
2104
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
2105
|
-
useControlPropsValidator = function useControlPropsValidator(_ref2) {
|
|
2106
|
-
var props = _ref2.props,
|
|
2107
|
-
state = _ref2.state;
|
|
2108
|
-
// used for checking when props are moving from controlled to uncontrolled.
|
|
2109
|
-
var prevPropsRef = React__namespace.useRef(props);
|
|
2110
|
-
var isInitialMount = useIsInitialMount();
|
|
2111
|
-
React__namespace.useEffect(function () {
|
|
2112
|
-
if (isInitialMount) {
|
|
2113
|
-
return;
|
|
2114
|
-
}
|
|
2115
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2116
|
-
prevPropsRef.current = props;
|
|
2117
|
-
}, [state, props, isInitialMount]);
|
|
2118
|
-
};
|
|
2119
|
-
}
|
|
2120
|
-
|
|
2121
|
-
/**
|
|
2122
|
-
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
2123
|
-
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
2124
|
-
* @param {Object} props The useCombobox props.
|
|
2125
|
-
* @param {number} highlightedIndex The index from the state.
|
|
2126
|
-
* @param {boolean} inputValue Also return the input value for state.
|
|
2127
|
-
* @returns The changes for the state.
|
|
2128
|
-
*/
|
|
2129
|
-
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
2130
|
-
var _props$items;
|
|
2131
|
-
if (inputValue === void 0) {
|
|
2132
|
-
inputValue = true;
|
|
2133
|
-
}
|
|
2134
|
-
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
2135
|
-
return _extends({
|
|
2136
|
-
isOpen: false,
|
|
2137
|
-
highlightedIndex: -1
|
|
2138
|
-
}, shouldSelect && _extends({
|
|
2139
|
-
selectedItem: props.items[highlightedIndex],
|
|
2140
|
-
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2141
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
|
|
2142
|
-
}, inputValue && {
|
|
2143
|
-
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
2144
|
-
}));
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
/**
|
|
2148
|
-
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
2149
|
-
* Used by useSelect and useCombobox.
|
|
2150
|
-
*
|
|
2151
|
-
* @param {Object} prevState
|
|
2152
|
-
* @param {Object} newState
|
|
2153
|
-
* @returns {boolean} Wheather the states are deeply equal.
|
|
2154
|
-
*/
|
|
2155
|
-
function isDropdownsStateEqual(prevState, newState) {
|
|
2156
|
-
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2143
|
+
elementRef: elementRef
|
|
2144
|
+
};
|
|
2145
|
+
}, []);
|
|
2146
|
+
return setGetterPropCallInfo;
|
|
2147
|
+
};
|
|
2157
2148
|
}
|
|
2158
2149
|
|
|
2150
|
+
// istanbul ignore next
|
|
2151
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2152
|
+
|
|
2159
2153
|
/**
|
|
2160
|
-
*
|
|
2161
|
-
*
|
|
2162
|
-
* @param
|
|
2163
|
-
* @
|
|
2154
|
+
* Utility hook that scrolls an item from a menu into view.
|
|
2155
|
+
* @param scrollIntoView The function that does the scroll.
|
|
2156
|
+
* @param highlightedIndex The index of the item that should be scrolled.
|
|
2157
|
+
* @param isOpen If the menu is open or not.
|
|
2158
|
+
* @param menuElement The menu element.
|
|
2159
|
+
* @param itemElements The object containing item elements.
|
|
2160
|
+
* @param getItemId The function to get the item id from index.
|
|
2161
|
+
* @returns Function that when called prevents the scroll.
|
|
2164
2162
|
*/
|
|
2165
|
-
function
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2163
|
+
function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
|
|
2164
|
+
// used not to scroll on highlight by mouse.
|
|
2165
|
+
var shouldScrollRef = React__namespace.useRef(true);
|
|
2166
|
+
// Scroll on highlighted item if change comes from keyboard.
|
|
2167
|
+
useIsomorphicLayoutEffect(function () {
|
|
2168
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
if (shouldScrollRef.current) {
|
|
2172
|
+
var itemElement = itemElements[getItemId(highlightedIndex)];
|
|
2173
|
+
if (itemElement && menuElement) {
|
|
2174
|
+
scrollIntoView(itemElement, menuElement);
|
|
2175
|
+
}
|
|
2176
|
+
} else {
|
|
2177
|
+
shouldScrollRef.current = true;
|
|
2178
|
+
}
|
|
2179
|
+
}, [highlightedIndex]);
|
|
2180
|
+
return React__namespace.useCallback(function preventScroll() {
|
|
2181
|
+
shouldScrollRef.current = false;
|
|
2182
|
+
}, []);
|
|
2171
2183
|
}
|
|
2172
2184
|
|
|
2173
2185
|
/**
|
|
2174
|
-
*
|
|
2186
|
+
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
2187
|
+
* Used by useSelect and useCombobox.
|
|
2175
2188
|
*
|
|
2176
|
-
* @param
|
|
2177
|
-
* @
|
|
2189
|
+
* @param prevState The previous dropdown state.
|
|
2190
|
+
* @param newState The new dropdown state.
|
|
2191
|
+
* @returns Wheather the states are deeply equal.
|
|
2178
2192
|
*/
|
|
2179
|
-
function
|
|
2180
|
-
|
|
2181
|
-
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2182
|
-
return -1;
|
|
2183
|
-
}
|
|
2184
|
-
return highlightedIndex;
|
|
2193
|
+
function isDropdownStateEqual(prevState, newState) {
|
|
2194
|
+
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2185
2195
|
}
|
|
2186
2196
|
|
|
2187
2197
|
function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
@@ -2202,13 +2212,13 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2202
2212
|
case stateChangeTypes.FunctionToggleMenu:
|
|
2203
2213
|
changes = {
|
|
2204
2214
|
isOpen: !state.isOpen,
|
|
2205
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
2215
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2206
2216
|
};
|
|
2207
2217
|
break;
|
|
2208
2218
|
case stateChangeTypes.FunctionOpenMenu:
|
|
2209
2219
|
changes = {
|
|
2210
2220
|
isOpen: true,
|
|
2211
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
|
|
2221
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2212
2222
|
};
|
|
2213
2223
|
break;
|
|
2214
2224
|
case stateChangeTypes.FunctionCloseMenu:
|
|
@@ -2217,9 +2227,12 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2217
2227
|
};
|
|
2218
2228
|
break;
|
|
2219
2229
|
case stateChangeTypes.FunctionSetHighlightedIndex:
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2230
|
+
{
|
|
2231
|
+
var highlightedIndex = action.highlightedIndex;
|
|
2232
|
+
changes = {
|
|
2233
|
+
highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
|
|
2234
|
+
};
|
|
2235
|
+
}
|
|
2223
2236
|
break;
|
|
2224
2237
|
case stateChangeTypes.FunctionSetInputValue:
|
|
2225
2238
|
changes = {
|
|
@@ -2228,10 +2241,10 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2228
2241
|
break;
|
|
2229
2242
|
case stateChangeTypes.FunctionReset:
|
|
2230
2243
|
changes = {
|
|
2231
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2232
|
-
isOpen: getDefaultValue
|
|
2233
|
-
selectedItem: getDefaultValue
|
|
2234
|
-
inputValue: getDefaultValue
|
|
2244
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2245
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2246
|
+
selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
|
|
2247
|
+
inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
|
|
2235
2248
|
};
|
|
2236
2249
|
break;
|
|
2237
2250
|
default:
|
|
@@ -2241,17 +2254,11 @@ function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
|
2241
2254
|
}
|
|
2242
2255
|
/* eslint-enable complexity */
|
|
2243
2256
|
|
|
2244
|
-
var propTypes$3 = _extends({},
|
|
2257
|
+
var propTypes$3 = _extends({}, dropdownPropTypes, {
|
|
2245
2258
|
items: PropTypes.array.isRequired,
|
|
2246
2259
|
isItemDisabled: PropTypes.func
|
|
2247
2260
|
});
|
|
2248
2261
|
|
|
2249
|
-
var defaultProps$2 = _extends({}, defaultProps$3, {
|
|
2250
|
-
isItemDisabled: function isItemDisabled() {
|
|
2251
|
-
return false;
|
|
2252
|
-
}
|
|
2253
|
-
});
|
|
2254
|
-
|
|
2255
2262
|
function getItemIndexByCharacterKey(_ref) {
|
|
2256
2263
|
var keysSoFar = _ref.keysSoFar,
|
|
2257
2264
|
highlightedIndex = _ref.highlightedIndex,
|
|
@@ -2320,16 +2327,15 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
2320
2327
|
});
|
|
2321
2328
|
|
|
2322
2329
|
/* eslint-disable complexity */
|
|
2323
|
-
function downshiftSelectReducer(state,
|
|
2324
|
-
var _props$items;
|
|
2330
|
+
function downshiftSelectReducer(state, action) {
|
|
2325
2331
|
var type = action.type,
|
|
2326
|
-
|
|
2332
|
+
props = action.props;
|
|
2327
2333
|
var changes;
|
|
2328
2334
|
switch (type) {
|
|
2329
2335
|
case ItemClick$1:
|
|
2330
2336
|
changes = {
|
|
2331
|
-
isOpen: getDefaultValue
|
|
2332
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2337
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2338
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2333
2339
|
selectedItem: props.items[action.index]
|
|
2334
2340
|
};
|
|
2335
2341
|
break;
|
|
@@ -2356,7 +2362,8 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2356
2362
|
break;
|
|
2357
2363
|
case ToggleButtonKeyDownArrowDown:
|
|
2358
2364
|
{
|
|
2359
|
-
var
|
|
2365
|
+
var altKey = action.altKey;
|
|
2366
|
+
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);
|
|
2360
2367
|
changes = {
|
|
2361
2368
|
highlightedIndex: _highlightedIndex,
|
|
2362
2369
|
isOpen: true
|
|
@@ -2364,20 +2371,23 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2364
2371
|
}
|
|
2365
2372
|
break;
|
|
2366
2373
|
case ToggleButtonKeyDownArrowUp:
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
highlightedIndex:
|
|
2373
|
-
|
|
2374
|
-
|
|
2374
|
+
{
|
|
2375
|
+
var _altKey = action.altKey;
|
|
2376
|
+
if (state.isOpen && _altKey) {
|
|
2377
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2378
|
+
} else {
|
|
2379
|
+
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);
|
|
2380
|
+
changes = {
|
|
2381
|
+
highlightedIndex: _highlightedIndex2,
|
|
2382
|
+
isOpen: true
|
|
2383
|
+
};
|
|
2384
|
+
}
|
|
2375
2385
|
}
|
|
2376
2386
|
break;
|
|
2377
2387
|
// only triggered when menu is open.
|
|
2378
2388
|
case ToggleButtonKeyDownEnter:
|
|
2379
2389
|
case ToggleButtonKeyDownSpaceButton:
|
|
2380
|
-
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2390
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2381
2391
|
break;
|
|
2382
2392
|
case ToggleButtonKeyDownHome:
|
|
2383
2393
|
changes = {
|
|
@@ -2411,7 +2421,7 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2411
2421
|
changes = _extends({
|
|
2412
2422
|
isOpen: false,
|
|
2413
2423
|
highlightedIndex: -1
|
|
2414
|
-
}, state.highlightedIndex >= 0 &&
|
|
2424
|
+
}, state.highlightedIndex >= 0 && props.items.length && {
|
|
2415
2425
|
selectedItem: props.items[state.highlightedIndex]
|
|
2416
2426
|
});
|
|
2417
2427
|
break;
|
|
@@ -2427,59 +2437,9 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2427
2437
|
}
|
|
2428
2438
|
/* eslint-enable complexity */
|
|
2429
2439
|
|
|
2430
|
-
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
2431
|
-
var reactUseId$1 = React__namespace['useId'];
|
|
2432
|
-
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
2433
|
-
function useElementIdsR18$1(_ref) {
|
|
2434
|
-
var id = _ref.id,
|
|
2435
|
-
labelId = _ref.labelId,
|
|
2436
|
-
menuId = _ref.menuId,
|
|
2437
|
-
getItemId = _ref.getItemId,
|
|
2438
|
-
toggleButtonId = _ref.toggleButtonId,
|
|
2439
|
-
inputId = _ref.inputId;
|
|
2440
|
-
var reactId = "downshift-" + reactUseId$1();
|
|
2441
|
-
if (!id) {
|
|
2442
|
-
id = reactId;
|
|
2443
|
-
}
|
|
2444
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2445
|
-
return {
|
|
2446
|
-
labelId: labelId != null ? labelId : id + "-label",
|
|
2447
|
-
menuId: menuId != null ? menuId : id + "-menu",
|
|
2448
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2449
|
-
return id + "-item-" + index;
|
|
2450
|
-
},
|
|
2451
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
2452
|
-
inputId: inputId != null ? inputId : id + "-input"
|
|
2453
|
-
};
|
|
2454
|
-
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
2455
|
-
return elementIds;
|
|
2456
|
-
}
|
|
2457
|
-
function useElementIdsLegacy$1(_ref2) {
|
|
2458
|
-
var id = _ref2.id,
|
|
2459
|
-
labelId = _ref2.labelId,
|
|
2460
|
-
menuId = _ref2.menuId,
|
|
2461
|
-
getItemId = _ref2.getItemId,
|
|
2462
|
-
toggleButtonId = _ref2.toggleButtonId,
|
|
2463
|
-
inputId = _ref2.inputId;
|
|
2464
|
-
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
2465
|
-
var baseId = baseIdRef.current;
|
|
2466
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2467
|
-
return {
|
|
2468
|
-
labelId: labelId != null ? labelId : baseId + "-label",
|
|
2469
|
-
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
2470
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2471
|
-
return baseId + "-item-" + index;
|
|
2472
|
-
},
|
|
2473
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
2474
|
-
inputId: inputId != null ? inputId : baseId + "-input"
|
|
2475
|
-
};
|
|
2476
|
-
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
2477
|
-
return elementIds;
|
|
2478
|
-
}
|
|
2479
|
-
|
|
2480
2440
|
var _excluded$3 = ["onClick"],
|
|
2481
|
-
_excluded2$3 = ["onMouseLeave", "refKey", "ref"],
|
|
2482
|
-
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2441
|
+
_excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
2442
|
+
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
|
|
2483
2443
|
_excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
|
|
2484
2444
|
useSelect.stateChangeTypes = stateChangeTypes$3;
|
|
2485
2445
|
function useSelect(userProps) {
|
|
@@ -2488,22 +2448,23 @@ function useSelect(userProps) {
|
|
|
2488
2448
|
}
|
|
2489
2449
|
validatePropTypes$1(userProps, useSelect, propTypes$3);
|
|
2490
2450
|
// Props defaults and destructuring.
|
|
2491
|
-
var props = _extends({},
|
|
2451
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
2492
2452
|
var scrollIntoView = props.scrollIntoView,
|
|
2493
2453
|
environment = props.environment,
|
|
2494
2454
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2495
2455
|
// Initial state depending on controlled props.
|
|
2496
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3,
|
|
2456
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
|
|
2497
2457
|
state = _useControlledReducer[0],
|
|
2498
2458
|
dispatch = _useControlledReducer[1];
|
|
2499
2459
|
var isOpen = state.isOpen,
|
|
2500
2460
|
highlightedIndex = state.highlightedIndex,
|
|
2501
2461
|
selectedItem = state.selectedItem,
|
|
2502
2462
|
inputValue = state.inputValue;
|
|
2503
|
-
|
|
2463
|
+
|
|
2464
|
+
// Element refs.
|
|
2504
2465
|
var toggleButtonRef = React.useRef(null);
|
|
2505
2466
|
var menuRef = React.useRef(null);
|
|
2506
|
-
var
|
|
2467
|
+
var itemsRef = React.useRef({});
|
|
2507
2468
|
|
|
2508
2469
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2509
2470
|
var clearTimeoutRef = React.useRef(null);
|
|
@@ -2515,24 +2476,12 @@ function useSelect(userProps) {
|
|
|
2515
2476
|
props: props
|
|
2516
2477
|
});
|
|
2517
2478
|
|
|
2518
|
-
// Some utils.
|
|
2519
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
2520
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2521
|
-
}, [elementIds]);
|
|
2522
|
-
|
|
2523
2479
|
// Effects.
|
|
2524
2480
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2525
2481
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2526
2482
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2527
|
-
var
|
|
2528
|
-
|
|
2529
|
-
highlightedIndex: highlightedIndex,
|
|
2530
|
-
isOpen: isOpen,
|
|
2531
|
-
itemRefs: itemRefs,
|
|
2532
|
-
scrollIntoView: scrollIntoView,
|
|
2533
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2534
|
-
});
|
|
2535
|
-
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2483
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
2484
|
+
// Sets cleanup for the keysSoFar callback, debounced after 500ms.
|
|
2536
2485
|
React.useEffect(function () {
|
|
2537
2486
|
// init the clean function here as we need access to dispatch.
|
|
2538
2487
|
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
@@ -2544,7 +2493,8 @@ function useSelect(userProps) {
|
|
|
2544
2493
|
|
|
2545
2494
|
// Cancel any pending debounced calls on mount
|
|
2546
2495
|
return function () {
|
|
2547
|
-
|
|
2496
|
+
var _clearTimeoutRef$curr;
|
|
2497
|
+
(_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
|
|
2548
2498
|
};
|
|
2549
2499
|
}, []);
|
|
2550
2500
|
// Invokes the keysSoFar callback set up above.
|
|
@@ -2552,7 +2502,7 @@ function useSelect(userProps) {
|
|
|
2552
2502
|
if (!inputValue) {
|
|
2553
2503
|
return;
|
|
2554
2504
|
}
|
|
2555
|
-
clearTimeoutRef.current(dispatch);
|
|
2505
|
+
clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
|
|
2556
2506
|
}, [dispatch, inputValue]);
|
|
2557
2507
|
useControlPropsValidator({
|
|
2558
2508
|
props: props,
|
|
@@ -2560,7 +2510,7 @@ function useSelect(userProps) {
|
|
|
2560
2510
|
});
|
|
2561
2511
|
// Focus the toggle button on first render if required.
|
|
2562
2512
|
React.useEffect(function () {
|
|
2563
|
-
var focusOnOpen = getInitialValue
|
|
2513
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
2564
2514
|
if (focusOnOpen && toggleButtonRef.current) {
|
|
2565
2515
|
toggleButtonRef.current.focus();
|
|
2566
2516
|
}
|
|
@@ -2581,7 +2531,7 @@ function useSelect(userProps) {
|
|
|
2581
2531
|
// Reset itemRefs on close.
|
|
2582
2532
|
React.useEffect(function () {
|
|
2583
2533
|
if (!isOpen) {
|
|
2584
|
-
|
|
2534
|
+
itemsRef.current = {};
|
|
2585
2535
|
}
|
|
2586
2536
|
}, [isOpen]);
|
|
2587
2537
|
|
|
@@ -2666,50 +2616,11 @@ function useSelect(userProps) {
|
|
|
2666
2616
|
};
|
|
2667
2617
|
}, [dispatch, latest]);
|
|
2668
2618
|
|
|
2669
|
-
// Action functions.
|
|
2670
|
-
var toggleMenu = React.useCallback(function () {
|
|
2671
|
-
dispatch({
|
|
2672
|
-
type: FunctionToggleMenu$1
|
|
2673
|
-
});
|
|
2674
|
-
}, [dispatch]);
|
|
2675
|
-
var closeMenu = React.useCallback(function () {
|
|
2676
|
-
dispatch({
|
|
2677
|
-
type: FunctionCloseMenu$1
|
|
2678
|
-
});
|
|
2679
|
-
}, [dispatch]);
|
|
2680
|
-
var openMenu = React.useCallback(function () {
|
|
2681
|
-
dispatch({
|
|
2682
|
-
type: FunctionOpenMenu$1
|
|
2683
|
-
});
|
|
2684
|
-
}, [dispatch]);
|
|
2685
|
-
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2686
|
-
dispatch({
|
|
2687
|
-
type: FunctionSetHighlightedIndex$1,
|
|
2688
|
-
highlightedIndex: newHighlightedIndex
|
|
2689
|
-
});
|
|
2690
|
-
}, [dispatch]);
|
|
2691
|
-
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2692
|
-
dispatch({
|
|
2693
|
-
type: FunctionSelectItem$1,
|
|
2694
|
-
selectedItem: newSelectedItem
|
|
2695
|
-
});
|
|
2696
|
-
}, [dispatch]);
|
|
2697
|
-
var reset = React.useCallback(function () {
|
|
2698
|
-
dispatch({
|
|
2699
|
-
type: FunctionReset$2
|
|
2700
|
-
});
|
|
2701
|
-
}, [dispatch]);
|
|
2702
|
-
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2703
|
-
dispatch({
|
|
2704
|
-
type: FunctionSetInputValue$1,
|
|
2705
|
-
inputValue: newInputValue
|
|
2706
|
-
});
|
|
2707
|
-
}, [dispatch]);
|
|
2708
2619
|
// Getter functions.
|
|
2709
|
-
var getLabelProps = React.useCallback(function (
|
|
2710
|
-
var _ref =
|
|
2620
|
+
var getLabelProps = React.useCallback(function (labelProps) {
|
|
2621
|
+
var _ref = labelProps != null ? labelProps : {},
|
|
2711
2622
|
onClick = _ref.onClick,
|
|
2712
|
-
|
|
2623
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2713
2624
|
var labelHandleClick = function labelHandleClick() {
|
|
2714
2625
|
var _toggleButtonRef$curr;
|
|
2715
2626
|
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
@@ -2718,17 +2629,18 @@ function useSelect(userProps) {
|
|
|
2718
2629
|
id: elementIds.labelId,
|
|
2719
2630
|
htmlFor: elementIds.toggleButtonId,
|
|
2720
2631
|
onClick: callAllEventHandlers(onClick, labelHandleClick)
|
|
2721
|
-
},
|
|
2632
|
+
}, rest);
|
|
2722
2633
|
}, [elementIds]);
|
|
2723
|
-
var getMenuProps = React.useCallback(function (
|
|
2634
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
2724
2635
|
var _extends2;
|
|
2725
|
-
var _ref2 =
|
|
2636
|
+
var _ref2 = menuProps != null ? menuProps : {},
|
|
2726
2637
|
onMouseLeave = _ref2.onMouseLeave,
|
|
2727
2638
|
_ref2$refKey = _ref2.refKey,
|
|
2728
2639
|
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
2729
2640
|
ref = _ref2.ref,
|
|
2641
|
+
ariaLabel = _ref2['aria-label'],
|
|
2730
2642
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
2731
|
-
var _ref3 =
|
|
2643
|
+
var _ref3 = otherProps != null ? otherProps : {},
|
|
2732
2644
|
_ref3$suppressRefErro = _ref3.suppressRefError,
|
|
2733
2645
|
suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
|
|
2734
2646
|
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
@@ -2739,11 +2651,11 @@ function useSelect(userProps) {
|
|
|
2739
2651
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2740
2652
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
2741
2653
|
menuRef.current = menuNode;
|
|
2742
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
2654
|
+
}), _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);
|
|
2743
2655
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2744
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
2656
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
|
|
2745
2657
|
var _extends3;
|
|
2746
|
-
var _ref4 =
|
|
2658
|
+
var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
|
|
2747
2659
|
onBlur = _ref4.onBlur;
|
|
2748
2660
|
_ref4.onClick;
|
|
2749
2661
|
var onPress = _ref4.onPress;
|
|
@@ -2751,8 +2663,9 @@ function useSelect(userProps) {
|
|
|
2751
2663
|
var _ref4$refKey = _ref4.refKey,
|
|
2752
2664
|
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
2753
2665
|
ref = _ref4.ref,
|
|
2666
|
+
disabled = _ref4.disabled,
|
|
2754
2667
|
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2755
|
-
var _ref5 =
|
|
2668
|
+
var _ref5 = otherProps != null ? otherProps : {},
|
|
2756
2669
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
2757
2670
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
2758
2671
|
var latestState = latest.current.state;
|
|
@@ -2770,19 +2683,21 @@ function useSelect(userProps) {
|
|
|
2770
2683
|
};
|
|
2771
2684
|
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
2772
2685
|
toggleButtonRef.current = toggleButtonNode;
|
|
2773
|
-
}), _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
|
|
2774
|
-
if (!
|
|
2686
|
+
}), _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);
|
|
2687
|
+
if (!disabled) {
|
|
2775
2688
|
/* istanbul ignore if (react-native) */
|
|
2776
2689
|
{
|
|
2777
|
-
|
|
2690
|
+
Object.assign(toggleProps, {
|
|
2691
|
+
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
2692
|
+
});
|
|
2778
2693
|
}
|
|
2779
2694
|
}
|
|
2780
2695
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2781
2696
|
return toggleProps;
|
|
2782
2697
|
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
|
|
2783
|
-
var getItemProps = React.useCallback(function (
|
|
2698
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
2784
2699
|
var _extends4;
|
|
2785
|
-
var _ref6 =
|
|
2700
|
+
var _ref6 = itemProps != null ? itemProps : {},
|
|
2786
2701
|
itemProp = _ref6.item,
|
|
2787
2702
|
indexProp = _ref6.index,
|
|
2788
2703
|
onMouseMove = _ref6.onMouseMove;
|
|
@@ -2808,7 +2723,7 @@ function useSelect(userProps) {
|
|
|
2808
2723
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
2809
2724
|
return;
|
|
2810
2725
|
}
|
|
2811
|
-
|
|
2726
|
+
preventScroll();
|
|
2812
2727
|
dispatch({
|
|
2813
2728
|
type: ItemMouseMove$1,
|
|
2814
2729
|
index: index,
|
|
@@ -2825,21 +2740,61 @@ function useSelect(userProps) {
|
|
|
2825
2740
|
return e.preventDefault();
|
|
2826
2741
|
}; // keep focus on the toggle after item click select.
|
|
2827
2742
|
|
|
2828
|
-
var
|
|
2743
|
+
var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2829
2744
|
if (itemNode) {
|
|
2830
|
-
|
|
2745
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
2831
2746
|
}
|
|
2832
|
-
}), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
|
|
2747
|
+
}), _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);
|
|
2833
2748
|
if (!disabled) {
|
|
2834
2749
|
/* istanbul ignore next (react-native) */
|
|
2835
2750
|
{
|
|
2836
|
-
|
|
2751
|
+
Object.assign(resultItemProps, {
|
|
2752
|
+
onPress: callAllEventHandlers(onPress, itemHandleClick)
|
|
2753
|
+
});
|
|
2837
2754
|
}
|
|
2838
2755
|
}
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2756
|
+
return resultItemProps;
|
|
2757
|
+
}, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
|
|
2758
|
+
|
|
2759
|
+
// Action functions.
|
|
2760
|
+
var toggleMenu = React.useCallback(function () {
|
|
2761
|
+
dispatch({
|
|
2762
|
+
type: FunctionToggleMenu$1
|
|
2763
|
+
});
|
|
2764
|
+
}, [dispatch]);
|
|
2765
|
+
var closeMenu = React.useCallback(function () {
|
|
2766
|
+
dispatch({
|
|
2767
|
+
type: FunctionCloseMenu$1
|
|
2768
|
+
});
|
|
2769
|
+
}, [dispatch]);
|
|
2770
|
+
var openMenu = React.useCallback(function () {
|
|
2771
|
+
dispatch({
|
|
2772
|
+
type: FunctionOpenMenu$1
|
|
2773
|
+
});
|
|
2774
|
+
}, [dispatch]);
|
|
2775
|
+
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2776
|
+
dispatch({
|
|
2777
|
+
type: FunctionSetHighlightedIndex$1,
|
|
2778
|
+
highlightedIndex: newHighlightedIndex
|
|
2779
|
+
});
|
|
2780
|
+
}, [dispatch]);
|
|
2781
|
+
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2782
|
+
dispatch({
|
|
2783
|
+
type: FunctionSelectItem$1,
|
|
2784
|
+
selectedItem: newSelectedItem
|
|
2785
|
+
});
|
|
2786
|
+
}, [dispatch]);
|
|
2787
|
+
var reset = React.useCallback(function () {
|
|
2788
|
+
dispatch({
|
|
2789
|
+
type: FunctionReset$2
|
|
2790
|
+
});
|
|
2791
|
+
}, [dispatch]);
|
|
2792
|
+
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2793
|
+
dispatch({
|
|
2794
|
+
type: FunctionSetInputValue$1,
|
|
2795
|
+
inputValue: newInputValue
|
|
2796
|
+
});
|
|
2797
|
+
}, [dispatch]);
|
|
2843
2798
|
return {
|
|
2844
2799
|
// prop getters.
|
|
2845
2800
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2862,6 +2817,18 @@ function useSelect(userProps) {
|
|
|
2862
2817
|
};
|
|
2863
2818
|
}
|
|
2864
2819
|
|
|
2820
|
+
function getInitialState$2(props) {
|
|
2821
|
+
var initialState = getInitialState$3(props);
|
|
2822
|
+
var selectedItem = initialState.selectedItem;
|
|
2823
|
+
var inputValue = initialState.inputValue;
|
|
2824
|
+
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2825
|
+
inputValue = props.itemToString(selectedItem);
|
|
2826
|
+
}
|
|
2827
|
+
return _extends({}, initialState, {
|
|
2828
|
+
inputValue: inputValue
|
|
2829
|
+
});
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2865
2832
|
var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2866
2833
|
var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2867
2834
|
var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
@@ -2913,27 +2880,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2913
2880
|
ToggleButtonClick: ToggleButtonClick
|
|
2914
2881
|
});
|
|
2915
2882
|
|
|
2916
|
-
function getInitialState$2(props) {
|
|
2917
|
-
var initialState = getInitialState$3(props);
|
|
2918
|
-
var selectedItem = initialState.selectedItem;
|
|
2919
|
-
var inputValue = initialState.inputValue;
|
|
2920
|
-
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2921
|
-
inputValue = props.itemToString(selectedItem);
|
|
2922
|
-
}
|
|
2923
|
-
return _extends({}, initialState, {
|
|
2924
|
-
inputValue: inputValue
|
|
2925
|
-
});
|
|
2926
|
-
}
|
|
2927
|
-
var propTypes$2 = _extends({}, propTypes$4, {
|
|
2928
|
-
items: PropTypes.array.isRequired,
|
|
2929
|
-
isItemDisabled: PropTypes.func,
|
|
2930
|
-
inputValue: PropTypes.string,
|
|
2931
|
-
defaultInputValue: PropTypes.string,
|
|
2932
|
-
initialInputValue: PropTypes.string,
|
|
2933
|
-
inputId: PropTypes.string,
|
|
2934
|
-
onInputValueChange: PropTypes.func
|
|
2935
|
-
});
|
|
2936
|
-
|
|
2937
2883
|
/**
|
|
2938
2884
|
* The useCombobox version of useControlledReducer, which also
|
|
2939
2885
|
* checks if the controlled prop selectedItem changed between
|
|
@@ -2941,20 +2887,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
|
|
|
2941
2887
|
* string equivalent. It uses the common useEnhancedReducer to
|
|
2942
2888
|
* compute the rest of the state.
|
|
2943
2889
|
*
|
|
2944
|
-
* @param
|
|
2945
|
-
* @param
|
|
2946
|
-
* @param
|
|
2947
|
-
* @param
|
|
2948
|
-
* @returns
|
|
2890
|
+
* @param reducer Reducer function from downshift.
|
|
2891
|
+
* @param props The hook props, also passed to createInitialState.
|
|
2892
|
+
* @param createInitialState Function that returns the initial state.
|
|
2893
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
2894
|
+
* @returns An array with the state and an action dispatcher.
|
|
2949
2895
|
*/
|
|
2950
2896
|
function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
|
|
2951
|
-
var previousSelectedItemRef = React.useRef();
|
|
2897
|
+
var previousSelectedItemRef = React.useRef(null);
|
|
2952
2898
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
2953
2899
|
state = _useEnhancedReducer[0],
|
|
2954
2900
|
dispatch = _useEnhancedReducer[1];
|
|
2955
2901
|
var isInitialMount = useIsInitialMount();
|
|
2956
2902
|
React.useEffect(function () {
|
|
2957
|
-
if (
|
|
2903
|
+
if (props.selectedItem === undefined) {
|
|
2958
2904
|
return;
|
|
2959
2905
|
}
|
|
2960
2906
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
@@ -2972,23 +2918,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2972
2918
|
}, [state.selectedItem, props.selectedItem]);
|
|
2973
2919
|
return [getState(state, props), dispatch];
|
|
2974
2920
|
}
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2921
|
+
|
|
2922
|
+
var propTypes$2 = _extends({}, dropdownPropTypes, {
|
|
2923
|
+
items: PropTypes.array.isRequired,
|
|
2924
|
+
isItemDisabled: PropTypes.func,
|
|
2925
|
+
inputValue: PropTypes.string,
|
|
2926
|
+
defaultInputValue: PropTypes.string,
|
|
2927
|
+
initialInputValue: PropTypes.string,
|
|
2928
|
+
inputId: PropTypes.string,
|
|
2929
|
+
onInputValueChange: PropTypes.func
|
|
2979
2930
|
});
|
|
2980
2931
|
|
|
2981
2932
|
/* eslint-disable complexity */
|
|
2982
|
-
function downshiftUseComboboxReducer(state,
|
|
2983
|
-
var _props$items;
|
|
2933
|
+
function downshiftUseComboboxReducer(state, action) {
|
|
2984
2934
|
var type = action.type,
|
|
2985
|
-
|
|
2935
|
+
props = action.props;
|
|
2986
2936
|
var changes;
|
|
2987
2937
|
switch (type) {
|
|
2988
2938
|
case ItemClick:
|
|
2989
2939
|
changes = {
|
|
2990
|
-
isOpen: getDefaultValue
|
|
2991
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2940
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2941
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2992
2942
|
selectedItem: props.items[action.index],
|
|
2993
2943
|
inputValue: props.itemToString(props.items[action.index])
|
|
2994
2944
|
};
|
|
@@ -3000,15 +2950,15 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3000
2950
|
};
|
|
3001
2951
|
} else {
|
|
3002
2952
|
changes = {
|
|
3003
|
-
highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
|
|
2953
|
+
highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
|
|
3004
2954
|
isOpen: props.items.length >= 0
|
|
3005
2955
|
};
|
|
3006
2956
|
}
|
|
3007
2957
|
break;
|
|
3008
2958
|
case InputKeyDownArrowUp:
|
|
3009
2959
|
if (state.isOpen) {
|
|
3010
|
-
if (altKey) {
|
|
3011
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2960
|
+
if (action.altKey) {
|
|
2961
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3012
2962
|
} else {
|
|
3013
2963
|
changes = {
|
|
3014
2964
|
highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
|
|
@@ -3016,13 +2966,13 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3016
2966
|
}
|
|
3017
2967
|
} else {
|
|
3018
2968
|
changes = {
|
|
3019
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
|
|
2969
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
|
|
3020
2970
|
isOpen: props.items.length >= 0
|
|
3021
2971
|
};
|
|
3022
2972
|
}
|
|
3023
2973
|
break;
|
|
3024
2974
|
case InputKeyDownEnter:
|
|
3025
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2975
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3026
2976
|
break;
|
|
3027
2977
|
case InputKeyDownEscape:
|
|
3028
2978
|
changes = _extends({
|
|
@@ -3057,7 +3007,7 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3057
3007
|
changes = _extends({
|
|
3058
3008
|
isOpen: false,
|
|
3059
3009
|
highlightedIndex: -1
|
|
3060
|
-
}, state.highlightedIndex >= 0 &&
|
|
3010
|
+
}, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
|
|
3061
3011
|
selectedItem: props.items[state.highlightedIndex],
|
|
3062
3012
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3063
3013
|
});
|
|
@@ -3065,14 +3015,14 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3065
3015
|
case InputChange:
|
|
3066
3016
|
changes = {
|
|
3067
3017
|
isOpen: true,
|
|
3068
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
3018
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
3069
3019
|
inputValue: action.inputValue
|
|
3070
3020
|
};
|
|
3071
3021
|
break;
|
|
3072
3022
|
case InputClick:
|
|
3073
3023
|
changes = {
|
|
3074
3024
|
isOpen: !state.isOpen,
|
|
3075
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
3025
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
3076
3026
|
};
|
|
3077
3027
|
break;
|
|
3078
3028
|
case FunctionSelectItem:
|
|
@@ -3093,10 +3043,10 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3093
3043
|
}
|
|
3094
3044
|
/* eslint-enable complexity */
|
|
3095
3045
|
|
|
3096
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
3046
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
3097
3047
|
_excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
3098
|
-
_excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
|
|
3099
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
3048
|
+
_excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
|
|
3049
|
+
_excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
3100
3050
|
useCombobox.stateChangeTypes = stateChangeTypes$2;
|
|
3101
3051
|
function useCombobox(userProps) {
|
|
3102
3052
|
if (userProps === void 0) {
|
|
@@ -3104,13 +3054,13 @@ function useCombobox(userProps) {
|
|
|
3104
3054
|
}
|
|
3105
3055
|
validatePropTypes$1(userProps, useCombobox, propTypes$2);
|
|
3106
3056
|
// Props defaults and destructuring.
|
|
3107
|
-
var props = _extends({},
|
|
3057
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
3108
3058
|
var items = props.items,
|
|
3109
3059
|
scrollIntoView = props.scrollIntoView,
|
|
3110
3060
|
environment = props.environment,
|
|
3111
3061
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3112
3062
|
// Initial state depending on controlled props.
|
|
3113
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2,
|
|
3063
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
|
|
3114
3064
|
state = _useControlledReducer[0],
|
|
3115
3065
|
dispatch = _useControlledReducer[1];
|
|
3116
3066
|
var isOpen = state.isOpen,
|
|
@@ -3120,7 +3070,7 @@ function useCombobox(userProps) {
|
|
|
3120
3070
|
|
|
3121
3071
|
// Element refs.
|
|
3122
3072
|
var menuRef = React.useRef(null);
|
|
3123
|
-
var
|
|
3073
|
+
var itemsRef = React.useRef({});
|
|
3124
3074
|
var inputRef = React.useRef(null);
|
|
3125
3075
|
var toggleButtonRef = React.useRef(null);
|
|
3126
3076
|
var isInitialMount = useIsInitialMount();
|
|
@@ -3134,29 +3084,19 @@ function useCombobox(userProps) {
|
|
|
3134
3084
|
state: state,
|
|
3135
3085
|
props: props
|
|
3136
3086
|
});
|
|
3137
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
3138
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3139
|
-
}, [elementIds]);
|
|
3140
3087
|
|
|
3141
3088
|
// Effects.
|
|
3142
3089
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3143
3090
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
3144
3091
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3145
|
-
var
|
|
3146
|
-
menuElement: menuRef.current,
|
|
3147
|
-
highlightedIndex: highlightedIndex,
|
|
3148
|
-
isOpen: isOpen,
|
|
3149
|
-
itemRefs: itemRefs,
|
|
3150
|
-
scrollIntoView: scrollIntoView,
|
|
3151
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3152
|
-
});
|
|
3092
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
3153
3093
|
useControlPropsValidator({
|
|
3154
|
-
|
|
3155
|
-
|
|
3094
|
+
state: state,
|
|
3095
|
+
props: props
|
|
3156
3096
|
});
|
|
3157
3097
|
// Focus the input on first render if required.
|
|
3158
3098
|
React.useEffect(function () {
|
|
3159
|
-
var focusOnOpen = getInitialValue
|
|
3099
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
3160
3100
|
if (focusOnOpen && inputRef.current) {
|
|
3161
3101
|
inputRef.current.focus();
|
|
3162
3102
|
}
|
|
@@ -3182,13 +3122,13 @@ function useCombobox(userProps) {
|
|
|
3182
3122
|
// Reset itemRefs on close.
|
|
3183
3123
|
React.useEffect(function () {
|
|
3184
3124
|
if (!isOpen) {
|
|
3185
|
-
|
|
3125
|
+
itemsRef.current = {};
|
|
3186
3126
|
}
|
|
3187
3127
|
}, [isOpen]);
|
|
3188
3128
|
// Reset itemRefs on close.
|
|
3189
3129
|
React.useEffect(function () {
|
|
3190
3130
|
var _inputRef$current;
|
|
3191
|
-
if (!isOpen || !(environment != null && environment.document) || !(
|
|
3131
|
+
if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3192
3132
|
return;
|
|
3193
3133
|
}
|
|
3194
3134
|
if (environment.document.activeElement !== inputRef.current) {
|
|
@@ -3278,29 +3218,30 @@ function useCombobox(userProps) {
|
|
|
3278
3218
|
htmlFor: elementIds.inputId
|
|
3279
3219
|
}, labelProps);
|
|
3280
3220
|
}, [elementIds]);
|
|
3281
|
-
var getMenuProps = React.useCallback(function (
|
|
3221
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
3282
3222
|
var _extends2;
|
|
3283
|
-
var _ref =
|
|
3223
|
+
var _ref = menuProps != null ? menuProps : {},
|
|
3284
3224
|
onMouseLeave = _ref.onMouseLeave,
|
|
3285
3225
|
_ref$refKey = _ref.refKey,
|
|
3286
3226
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3287
3227
|
ref = _ref.ref,
|
|
3228
|
+
ariaLabel = _ref['aria-label'],
|
|
3288
3229
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3289
|
-
var _ref2 =
|
|
3230
|
+
var _ref2 = otherProps != null ? otherProps : {},
|
|
3290
3231
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3291
3232
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3292
3233
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3293
3234
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3294
3235
|
menuRef.current = menuNode;
|
|
3295
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
3236
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
3296
3237
|
dispatch({
|
|
3297
3238
|
type: MenuMouseLeave
|
|
3298
3239
|
});
|
|
3299
3240
|
}), _extends2), rest);
|
|
3300
3241
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3301
|
-
var getItemProps = React.useCallback(function (
|
|
3242
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
3302
3243
|
var _extends3, _ref4;
|
|
3303
|
-
var _ref3 =
|
|
3244
|
+
var _ref3 = itemProps != null ? itemProps : {},
|
|
3304
3245
|
itemProp = _ref3.item,
|
|
3305
3246
|
indexProp = _ref3.index,
|
|
3306
3247
|
_ref3$refKey = _ref3.refKey,
|
|
@@ -3328,7 +3269,7 @@ function useCombobox(userProps) {
|
|
|
3328
3269
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
3329
3270
|
return;
|
|
3330
3271
|
}
|
|
3331
|
-
|
|
3272
|
+
preventScroll();
|
|
3332
3273
|
dispatch({
|
|
3333
3274
|
type: ItemMouseMove,
|
|
3334
3275
|
index: index,
|
|
@@ -3347,21 +3288,22 @@ function useCombobox(userProps) {
|
|
|
3347
3288
|
|
|
3348
3289
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3349
3290
|
if (itemNode) {
|
|
3350
|
-
|
|
3291
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
3351
3292
|
}
|
|
3352
3293
|
}), _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), {
|
|
3353
3294
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3354
3295
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3355
3296
|
}, rest);
|
|
3356
|
-
}, [dispatch, elementIds, latest, mouseAndTouchTrackers,
|
|
3357
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
3297
|
+
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
|
|
3298
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
|
|
3358
3299
|
var _extends4;
|
|
3359
|
-
var _ref5 =
|
|
3300
|
+
var _ref5 = toggleButtonProps != null ? toggleButtonProps : {};
|
|
3360
3301
|
_ref5.onClick;
|
|
3361
3302
|
var onPress = _ref5.onPress,
|
|
3362
3303
|
_ref5$refKey = _ref5.refKey,
|
|
3363
3304
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3364
3305
|
ref = _ref5.ref,
|
|
3306
|
+
disabled = _ref5.disabled,
|
|
3365
3307
|
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3366
3308
|
var latestState = latest.current.state;
|
|
3367
3309
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
@@ -3371,13 +3313,17 @@ function useCombobox(userProps) {
|
|
|
3371
3313
|
};
|
|
3372
3314
|
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3373
3315
|
toggleButtonRef.current = toggleButtonNode;
|
|
3374
|
-
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !
|
|
3316
|
+
}), _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) */{
|
|
3375
3317
|
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
3376
|
-
} ),
|
|
3318
|
+
} ), {
|
|
3319
|
+
disabled: disabled
|
|
3320
|
+
}, rest);
|
|
3377
3321
|
}, [dispatch, latest, elementIds]);
|
|
3378
|
-
var getInputProps = React.useCallback(function (
|
|
3322
|
+
var getInputProps = React.useCallback(function (inputProps, otherProps) {
|
|
3379
3323
|
var _extends5;
|
|
3380
|
-
var _ref6 =
|
|
3324
|
+
var _ref6 = inputProps != null ? inputProps : {},
|
|
3325
|
+
ariaLabel = _ref6['aria-label'],
|
|
3326
|
+
disabled = _ref6.disabled,
|
|
3381
3327
|
onKeyDown = _ref6.onKeyDown,
|
|
3382
3328
|
onChange = _ref6.onChange,
|
|
3383
3329
|
onInput = _ref6.onInput,
|
|
@@ -3388,15 +3334,16 @@ function useCombobox(userProps) {
|
|
|
3388
3334
|
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
3389
3335
|
ref = _ref6.ref,
|
|
3390
3336
|
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
|
|
3391
|
-
var _ref7 =
|
|
3337
|
+
var _ref7 = otherProps != null ? otherProps : {},
|
|
3392
3338
|
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3393
3339
|
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3394
3340
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3395
3341
|
var latestState = latest.current.state;
|
|
3396
3342
|
var inputHandleKeyDown = function inputHandleKeyDown(event) {
|
|
3397
3343
|
var key = normalizeArrowKey(event);
|
|
3398
|
-
if (key && inputKeyDownHandlers
|
|
3399
|
-
|
|
3344
|
+
if (key && key in inputKeyDownHandlers) {
|
|
3345
|
+
var validKey = key;
|
|
3346
|
+
inputKeyDownHandlers[validKey](event);
|
|
3400
3347
|
}
|
|
3401
3348
|
};
|
|
3402
3349
|
var inputHandleChange = function inputHandleChange(event) {
|
|
@@ -3424,13 +3371,13 @@ function useCombobox(userProps) {
|
|
|
3424
3371
|
/* istanbul ignore next (preact) */
|
|
3425
3372
|
var onChangeKey = 'onChange';
|
|
3426
3373
|
var eventHandlers = {};
|
|
3427
|
-
if (!
|
|
3374
|
+
if (!disabled) {
|
|
3428
3375
|
var _eventHandlers;
|
|
3429
3376
|
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
|
|
3430
3377
|
}
|
|
3431
3378
|
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
3432
3379
|
inputRef.current = inputNode;
|
|
3433
|
-
}), _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'] =
|
|
3380
|
+
}), _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);
|
|
3434
3381
|
}, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
|
|
3435
3382
|
|
|
3436
3383
|
// returns
|
|
@@ -3500,31 +3447,6 @@ var defaultStateValues = {
|
|
|
3500
3447
|
selectedItems: []
|
|
3501
3448
|
};
|
|
3502
3449
|
|
|
3503
|
-
/**
|
|
3504
|
-
* Returns the initial value for a state key in the following order:
|
|
3505
|
-
* 1. controlled prop, 2. initial prop, 3. default prop, 4. default
|
|
3506
|
-
* value from Downshift.
|
|
3507
|
-
*
|
|
3508
|
-
* @param {Object} props Props passed to the hook.
|
|
3509
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3510
|
-
* @returns {any} The initial value for that prop.
|
|
3511
|
-
*/
|
|
3512
|
-
function getInitialValue(props, propKey) {
|
|
3513
|
-
return getInitialValue$1(props, propKey, defaultStateValues);
|
|
3514
|
-
}
|
|
3515
|
-
|
|
3516
|
-
/**
|
|
3517
|
-
* Returns the default value for a state key in the following order:
|
|
3518
|
-
* 1. controlled prop, 2. default prop, 3. default value from Downshift.
|
|
3519
|
-
*
|
|
3520
|
-
* @param {Object} props Props passed to the hook.
|
|
3521
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3522
|
-
* @returns {any} The initial value for that prop.
|
|
3523
|
-
*/
|
|
3524
|
-
function getDefaultValue(props, propKey) {
|
|
3525
|
-
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
3526
|
-
}
|
|
3527
|
-
|
|
3528
3450
|
/**
|
|
3529
3451
|
* Gets the initial state based on the provided props. It uses initial, default
|
|
3530
3452
|
* and controlled props related to state in order to compute the initial value.
|
|
@@ -3533,8 +3455,8 @@ function getDefaultValue(props, propKey) {
|
|
|
3533
3455
|
* @returns {Object} The initial state.
|
|
3534
3456
|
*/
|
|
3535
3457
|
function getInitialState$1(props) {
|
|
3536
|
-
var activeIndex = getInitialValue(props,
|
|
3537
|
-
var selectedItems = getInitialValue(props,
|
|
3458
|
+
var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
|
|
3459
|
+
var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
|
|
3538
3460
|
return {
|
|
3539
3461
|
activeIndex: activeIndex,
|
|
3540
3462
|
selectedItems: selectedItems
|
|
@@ -3578,9 +3500,9 @@ function isStateEqual$1(prevState, newState) {
|
|
|
3578
3500
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3579
3501
|
}
|
|
3580
3502
|
var propTypes$1 = {
|
|
3581
|
-
stateReducer:
|
|
3582
|
-
itemToKey:
|
|
3583
|
-
environment:
|
|
3503
|
+
stateReducer: dropdownPropTypes.stateReducer,
|
|
3504
|
+
itemToKey: dropdownPropTypes.itemToKey,
|
|
3505
|
+
environment: dropdownPropTypes.environment,
|
|
3584
3506
|
selectedItems: PropTypes.array,
|
|
3585
3507
|
initialSelectedItems: PropTypes.array,
|
|
3586
3508
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3594,9 +3516,9 @@ var propTypes$1 = {
|
|
|
3594
3516
|
keyNavigationPrevious: PropTypes.string
|
|
3595
3517
|
};
|
|
3596
3518
|
var defaultProps = {
|
|
3597
|
-
itemToKey:
|
|
3598
|
-
stateReducer:
|
|
3599
|
-
environment:
|
|
3519
|
+
itemToKey: dropdownDefaultProps.itemToKey,
|
|
3520
|
+
stateReducer: dropdownDefaultProps.stateReducer,
|
|
3521
|
+
environment: dropdownDefaultProps.environment,
|
|
3600
3522
|
keyNavigationNext: 'ArrowRight',
|
|
3601
3523
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3602
3524
|
};
|
|
@@ -3642,10 +3564,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3642
3564
|
});
|
|
3643
3565
|
|
|
3644
3566
|
/* eslint-disable complexity */
|
|
3645
|
-
function downshiftMultipleSelectionReducer(state,
|
|
3567
|
+
function downshiftMultipleSelectionReducer(state, action) {
|
|
3646
3568
|
var type = action.type,
|
|
3647
3569
|
index = action.index,
|
|
3648
|
-
selectedItem = action.selectedItem
|
|
3570
|
+
selectedItem = action.selectedItem,
|
|
3571
|
+
props = action.props;
|
|
3649
3572
|
var activeIndex = state.activeIndex,
|
|
3650
3573
|
selectedItems = state.selectedItems;
|
|
3651
3574
|
var changes;
|
|
@@ -3742,8 +3665,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
|
|
|
3742
3665
|
}
|
|
3743
3666
|
case FunctionReset:
|
|
3744
3667
|
changes = {
|
|
3745
|
-
activeIndex: getDefaultValue(props,
|
|
3746
|
-
selectedItems: getDefaultValue(props,
|
|
3668
|
+
activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
|
|
3669
|
+
selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
|
|
3747
3670
|
};
|
|
3748
3671
|
break;
|
|
3749
3672
|
default:
|
|
@@ -3975,7 +3898,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3975
3898
|
TagRemoveClick: TagRemoveClick
|
|
3976
3899
|
});
|
|
3977
3900
|
|
|
3978
|
-
function useTagGroupReducer(state,
|
|
3901
|
+
function useTagGroupReducer(state, action) {
|
|
3979
3902
|
var type = action.type;
|
|
3980
3903
|
var changes;
|
|
3981
3904
|
switch (type) {
|
|
@@ -4036,8 +3959,9 @@ function useTagGroupReducer(state, _props, action) {
|
|
|
4036
3959
|
return _extends({}, state, changes);
|
|
4037
3960
|
}
|
|
4038
3961
|
|
|
4039
|
-
//
|
|
4040
|
-
var
|
|
3962
|
+
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
3963
|
+
var SafeReact = _extends({}, React__namespace);
|
|
3964
|
+
var reactUseId = SafeReact.useId;
|
|
4041
3965
|
|
|
4042
3966
|
// istanbul ignore next
|
|
4043
3967
|
var useElementIds = typeof reactUseId === 'function' ? useElementIdsR18 : useElementIdsLegacy;
|
|
@@ -4212,7 +4136,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4212
4136
|
'aria-atomic': 'false',
|
|
4213
4137
|
'aria-relevant': 'additions',
|
|
4214
4138
|
role: 'listbox',
|
|
4215
|
-
onKeyDown: callAllEventHandlers
|
|
4139
|
+
onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
|
|
4216
4140
|
}, rest);
|
|
4217
4141
|
return tagGroupProps;
|
|
4218
4142
|
}, [dispatch, elementIds.tagGroupId]);
|
|
@@ -4237,11 +4161,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4237
4161
|
var tagId = elementIds.getTagId(index);
|
|
4238
4162
|
return _extends((_extends2 = {
|
|
4239
4163
|
'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
|
|
4240
|
-
}, _extends2[refKey] = handleRefs
|
|
4164
|
+
}, _extends2[refKey] = handleRefs(ref, function (itemNode) {
|
|
4241
4165
|
if (itemNode) {
|
|
4242
4166
|
itemRefs.current[tagId] = itemNode;
|
|
4243
4167
|
}
|
|
4244
|
-
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers
|
|
4168
|
+
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4245
4169
|
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4246
4170
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4247
4171
|
var index = options.index,
|
|
@@ -4263,7 +4187,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4263
4187
|
id: tagRemoveId,
|
|
4264
4188
|
tabIndex: -1,
|
|
4265
4189
|
'aria-labelledby': tagRemoveId + " " + tagId,
|
|
4266
|
-
onClick: callAllEventHandlers
|
|
4190
|
+
onClick: callAllEventHandlers(onClick, handleClick)
|
|
4267
4191
|
}, rest);
|
|
4268
4192
|
}, [elementIds, dispatch]);
|
|
4269
4193
|
|