downshift 9.3.2 → 9.4.0-alpha.1
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 +617 -698
- package/dist/downshift.d.ts +49 -55
- package/dist/downshift.esm.mjs +618 -699
- package/dist/downshift.native.cjs.cjs +575 -653
- package/dist/downshift.nativeweb.cjs.cjs +615 -693
- package/dist/downshift.types.d.ts +205 -0
- package/dist/downshift.umd.js +621 -702
- 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 +617 -698
- package/preact/dist/downshift.cjs.js +4265 -0
- package/preact/dist/downshift.esm.js +4238 -0
- package/preact/dist/downshift.esm.mjs +618 -699
- package/preact/dist/downshift.umd.js +617 -698
- 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') {
|
|
@@ -2071,117 +2143,55 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2071
2143
|
elementRef: elementRef
|
|
2072
2144
|
};
|
|
2073
2145
|
}, []);
|
|
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;
|
|
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,60 +2437,9 @@ function downshiftSelectReducer(state, props, action) {
|
|
|
2427
2437
|
}
|
|
2428
2438
|
/* eslint-enable complexity */
|
|
2429
2439
|
|
|
2430
|
-
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
2431
|
-
var SafeReact$1 = _extends({}, React__namespace);
|
|
2432
|
-
var reactUseId$1 = SafeReact$1.useId;
|
|
2433
|
-
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
2434
|
-
function useElementIdsR18$1(_ref) {
|
|
2435
|
-
var id = _ref.id,
|
|
2436
|
-
labelId = _ref.labelId,
|
|
2437
|
-
menuId = _ref.menuId,
|
|
2438
|
-
getItemId = _ref.getItemId,
|
|
2439
|
-
toggleButtonId = _ref.toggleButtonId,
|
|
2440
|
-
inputId = _ref.inputId;
|
|
2441
|
-
var reactId = "downshift-" + reactUseId$1();
|
|
2442
|
-
if (!id) {
|
|
2443
|
-
id = reactId;
|
|
2444
|
-
}
|
|
2445
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2446
|
-
return {
|
|
2447
|
-
labelId: labelId != null ? labelId : id + "-label",
|
|
2448
|
-
menuId: menuId != null ? menuId : id + "-menu",
|
|
2449
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2450
|
-
return id + "-item-" + index;
|
|
2451
|
-
},
|
|
2452
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
2453
|
-
inputId: inputId != null ? inputId : id + "-input"
|
|
2454
|
-
};
|
|
2455
|
-
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
2456
|
-
return elementIds;
|
|
2457
|
-
}
|
|
2458
|
-
function useElementIdsLegacy$1(_ref2) {
|
|
2459
|
-
var id = _ref2.id,
|
|
2460
|
-
labelId = _ref2.labelId,
|
|
2461
|
-
menuId = _ref2.menuId,
|
|
2462
|
-
getItemId = _ref2.getItemId,
|
|
2463
|
-
toggleButtonId = _ref2.toggleButtonId,
|
|
2464
|
-
inputId = _ref2.inputId;
|
|
2465
|
-
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
2466
|
-
var baseId = baseIdRef.current;
|
|
2467
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2468
|
-
return {
|
|
2469
|
-
labelId: labelId != null ? labelId : baseId + "-label",
|
|
2470
|
-
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
2471
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2472
|
-
return baseId + "-item-" + index;
|
|
2473
|
-
},
|
|
2474
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
2475
|
-
inputId: inputId != null ? inputId : baseId + "-input"
|
|
2476
|
-
};
|
|
2477
|
-
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
2478
|
-
return elementIds;
|
|
2479
|
-
}
|
|
2480
|
-
|
|
2481
2440
|
var _excluded$3 = ["onClick"],
|
|
2482
|
-
_excluded2$3 = ["onMouseLeave", "refKey", "ref"],
|
|
2483
|
-
_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"],
|
|
2484
2443
|
_excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
|
|
2485
2444
|
useSelect.stateChangeTypes = stateChangeTypes$3;
|
|
2486
2445
|
function useSelect(userProps) {
|
|
@@ -2489,22 +2448,23 @@ function useSelect(userProps) {
|
|
|
2489
2448
|
}
|
|
2490
2449
|
validatePropTypes$1(userProps, useSelect, propTypes$3);
|
|
2491
2450
|
// Props defaults and destructuring.
|
|
2492
|
-
var props = _extends({},
|
|
2451
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
2493
2452
|
var scrollIntoView = props.scrollIntoView,
|
|
2494
2453
|
environment = props.environment,
|
|
2495
2454
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2496
2455
|
// Initial state depending on controlled props.
|
|
2497
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3,
|
|
2456
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
|
|
2498
2457
|
state = _useControlledReducer[0],
|
|
2499
2458
|
dispatch = _useControlledReducer[1];
|
|
2500
2459
|
var isOpen = state.isOpen,
|
|
2501
2460
|
highlightedIndex = state.highlightedIndex,
|
|
2502
2461
|
selectedItem = state.selectedItem,
|
|
2503
2462
|
inputValue = state.inputValue;
|
|
2504
|
-
|
|
2463
|
+
|
|
2464
|
+
// Element refs.
|
|
2505
2465
|
var toggleButtonRef = React.useRef(null);
|
|
2506
2466
|
var menuRef = React.useRef(null);
|
|
2507
|
-
var
|
|
2467
|
+
var itemsRef = React.useRef({});
|
|
2508
2468
|
|
|
2509
2469
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2510
2470
|
var clearTimeoutRef = React.useRef(null);
|
|
@@ -2516,24 +2476,12 @@ function useSelect(userProps) {
|
|
|
2516
2476
|
props: props
|
|
2517
2477
|
});
|
|
2518
2478
|
|
|
2519
|
-
// Some utils.
|
|
2520
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
2521
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2522
|
-
}, [elementIds]);
|
|
2523
|
-
|
|
2524
2479
|
// Effects.
|
|
2525
2480
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2526
2481
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2527
2482
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2528
|
-
var
|
|
2529
|
-
|
|
2530
|
-
highlightedIndex: highlightedIndex,
|
|
2531
|
-
isOpen: isOpen,
|
|
2532
|
-
itemRefs: itemRefs,
|
|
2533
|
-
scrollIntoView: scrollIntoView,
|
|
2534
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2535
|
-
});
|
|
2536
|
-
// 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.
|
|
2537
2485
|
React.useEffect(function () {
|
|
2538
2486
|
// init the clean function here as we need access to dispatch.
|
|
2539
2487
|
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
@@ -2545,7 +2493,8 @@ function useSelect(userProps) {
|
|
|
2545
2493
|
|
|
2546
2494
|
// Cancel any pending debounced calls on mount
|
|
2547
2495
|
return function () {
|
|
2548
|
-
|
|
2496
|
+
var _clearTimeoutRef$curr;
|
|
2497
|
+
(_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
|
|
2549
2498
|
};
|
|
2550
2499
|
}, []);
|
|
2551
2500
|
// Invokes the keysSoFar callback set up above.
|
|
@@ -2553,7 +2502,7 @@ function useSelect(userProps) {
|
|
|
2553
2502
|
if (!inputValue) {
|
|
2554
2503
|
return;
|
|
2555
2504
|
}
|
|
2556
|
-
clearTimeoutRef.current(dispatch);
|
|
2505
|
+
clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
|
|
2557
2506
|
}, [dispatch, inputValue]);
|
|
2558
2507
|
useControlPropsValidator({
|
|
2559
2508
|
props: props,
|
|
@@ -2561,7 +2510,7 @@ function useSelect(userProps) {
|
|
|
2561
2510
|
});
|
|
2562
2511
|
// Focus the toggle button on first render if required.
|
|
2563
2512
|
React.useEffect(function () {
|
|
2564
|
-
var focusOnOpen = getInitialValue
|
|
2513
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
2565
2514
|
if (focusOnOpen && toggleButtonRef.current) {
|
|
2566
2515
|
toggleButtonRef.current.focus();
|
|
2567
2516
|
}
|
|
@@ -2582,7 +2531,7 @@ function useSelect(userProps) {
|
|
|
2582
2531
|
// Reset itemRefs on close.
|
|
2583
2532
|
React.useEffect(function () {
|
|
2584
2533
|
if (!isOpen) {
|
|
2585
|
-
|
|
2534
|
+
itemsRef.current = {};
|
|
2586
2535
|
}
|
|
2587
2536
|
}, [isOpen]);
|
|
2588
2537
|
|
|
@@ -2667,50 +2616,11 @@ function useSelect(userProps) {
|
|
|
2667
2616
|
};
|
|
2668
2617
|
}, [dispatch, latest]);
|
|
2669
2618
|
|
|
2670
|
-
// Action functions.
|
|
2671
|
-
var toggleMenu = React.useCallback(function () {
|
|
2672
|
-
dispatch({
|
|
2673
|
-
type: FunctionToggleMenu$1
|
|
2674
|
-
});
|
|
2675
|
-
}, [dispatch]);
|
|
2676
|
-
var closeMenu = React.useCallback(function () {
|
|
2677
|
-
dispatch({
|
|
2678
|
-
type: FunctionCloseMenu$1
|
|
2679
|
-
});
|
|
2680
|
-
}, [dispatch]);
|
|
2681
|
-
var openMenu = React.useCallback(function () {
|
|
2682
|
-
dispatch({
|
|
2683
|
-
type: FunctionOpenMenu$1
|
|
2684
|
-
});
|
|
2685
|
-
}, [dispatch]);
|
|
2686
|
-
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2687
|
-
dispatch({
|
|
2688
|
-
type: FunctionSetHighlightedIndex$1,
|
|
2689
|
-
highlightedIndex: newHighlightedIndex
|
|
2690
|
-
});
|
|
2691
|
-
}, [dispatch]);
|
|
2692
|
-
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2693
|
-
dispatch({
|
|
2694
|
-
type: FunctionSelectItem$1,
|
|
2695
|
-
selectedItem: newSelectedItem
|
|
2696
|
-
});
|
|
2697
|
-
}, [dispatch]);
|
|
2698
|
-
var reset = React.useCallback(function () {
|
|
2699
|
-
dispatch({
|
|
2700
|
-
type: FunctionReset$2
|
|
2701
|
-
});
|
|
2702
|
-
}, [dispatch]);
|
|
2703
|
-
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2704
|
-
dispatch({
|
|
2705
|
-
type: FunctionSetInputValue$1,
|
|
2706
|
-
inputValue: newInputValue
|
|
2707
|
-
});
|
|
2708
|
-
}, [dispatch]);
|
|
2709
2619
|
// Getter functions.
|
|
2710
|
-
var getLabelProps = React.useCallback(function (
|
|
2711
|
-
var _ref =
|
|
2620
|
+
var getLabelProps = React.useCallback(function (labelProps) {
|
|
2621
|
+
var _ref = labelProps != null ? labelProps : {},
|
|
2712
2622
|
onClick = _ref.onClick,
|
|
2713
|
-
|
|
2623
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2714
2624
|
var labelHandleClick = function labelHandleClick() {
|
|
2715
2625
|
var _toggleButtonRef$curr;
|
|
2716
2626
|
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
@@ -2719,17 +2629,18 @@ function useSelect(userProps) {
|
|
|
2719
2629
|
id: elementIds.labelId,
|
|
2720
2630
|
htmlFor: elementIds.toggleButtonId,
|
|
2721
2631
|
onClick: callAllEventHandlers(onClick, labelHandleClick)
|
|
2722
|
-
},
|
|
2632
|
+
}, rest);
|
|
2723
2633
|
}, [elementIds]);
|
|
2724
|
-
var getMenuProps = React.useCallback(function (
|
|
2634
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
2725
2635
|
var _extends2;
|
|
2726
|
-
var _ref2 =
|
|
2636
|
+
var _ref2 = menuProps != null ? menuProps : {},
|
|
2727
2637
|
onMouseLeave = _ref2.onMouseLeave,
|
|
2728
2638
|
_ref2$refKey = _ref2.refKey,
|
|
2729
2639
|
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
2730
2640
|
ref = _ref2.ref,
|
|
2641
|
+
ariaLabel = _ref2['aria-label'],
|
|
2731
2642
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
2732
|
-
var _ref3 =
|
|
2643
|
+
var _ref3 = otherProps != null ? otherProps : {},
|
|
2733
2644
|
_ref3$suppressRefErro = _ref3.suppressRefError,
|
|
2734
2645
|
suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
|
|
2735
2646
|
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
@@ -2740,11 +2651,11 @@ function useSelect(userProps) {
|
|
|
2740
2651
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2741
2652
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
2742
2653
|
menuRef.current = menuNode;
|
|
2743
|
-
}), _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);
|
|
2744
2655
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2745
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
2656
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
|
|
2746
2657
|
var _extends3;
|
|
2747
|
-
var _ref4 =
|
|
2658
|
+
var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
|
|
2748
2659
|
onBlur = _ref4.onBlur;
|
|
2749
2660
|
_ref4.onClick;
|
|
2750
2661
|
var onPress = _ref4.onPress;
|
|
@@ -2752,8 +2663,9 @@ function useSelect(userProps) {
|
|
|
2752
2663
|
var _ref4$refKey = _ref4.refKey,
|
|
2753
2664
|
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
2754
2665
|
ref = _ref4.ref,
|
|
2666
|
+
disabled = _ref4.disabled,
|
|
2755
2667
|
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2756
|
-
var _ref5 =
|
|
2668
|
+
var _ref5 = otherProps != null ? otherProps : {},
|
|
2757
2669
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
2758
2670
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
2759
2671
|
var latestState = latest.current.state;
|
|
@@ -2771,19 +2683,21 @@ function useSelect(userProps) {
|
|
|
2771
2683
|
};
|
|
2772
2684
|
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
2773
2685
|
toggleButtonRef.current = toggleButtonNode;
|
|
2774
|
-
}), _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
|
|
2775
|
-
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) {
|
|
2776
2688
|
/* istanbul ignore if (react-native) */
|
|
2777
2689
|
{
|
|
2778
|
-
|
|
2690
|
+
Object.assign(toggleProps, {
|
|
2691
|
+
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
2692
|
+
});
|
|
2779
2693
|
}
|
|
2780
2694
|
}
|
|
2781
2695
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2782
2696
|
return toggleProps;
|
|
2783
2697
|
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
|
|
2784
|
-
var getItemProps = React.useCallback(function (
|
|
2698
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
2785
2699
|
var _extends4;
|
|
2786
|
-
var _ref6 =
|
|
2700
|
+
var _ref6 = itemProps != null ? itemProps : {},
|
|
2787
2701
|
itemProp = _ref6.item,
|
|
2788
2702
|
indexProp = _ref6.index,
|
|
2789
2703
|
onMouseMove = _ref6.onMouseMove;
|
|
@@ -2809,7 +2723,7 @@ function useSelect(userProps) {
|
|
|
2809
2723
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
2810
2724
|
return;
|
|
2811
2725
|
}
|
|
2812
|
-
|
|
2726
|
+
preventScroll();
|
|
2813
2727
|
dispatch({
|
|
2814
2728
|
type: ItemMouseMove$1,
|
|
2815
2729
|
index: index,
|
|
@@ -2826,21 +2740,61 @@ function useSelect(userProps) {
|
|
|
2826
2740
|
return e.preventDefault();
|
|
2827
2741
|
}; // keep focus on the toggle after item click select.
|
|
2828
2742
|
|
|
2829
|
-
var
|
|
2743
|
+
var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
2830
2744
|
if (itemNode) {
|
|
2831
|
-
|
|
2745
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
2832
2746
|
}
|
|
2833
|
-
}), _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);
|
|
2834
2748
|
if (!disabled) {
|
|
2835
2749
|
/* istanbul ignore next (react-native) */
|
|
2836
2750
|
{
|
|
2837
|
-
|
|
2751
|
+
Object.assign(resultItemProps, {
|
|
2752
|
+
onPress: callAllEventHandlers(onPress, itemHandleClick)
|
|
2753
|
+
});
|
|
2838
2754
|
}
|
|
2839
2755
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
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]);
|
|
2844
2798
|
return {
|
|
2845
2799
|
// prop getters.
|
|
2846
2800
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -2863,6 +2817,18 @@ function useSelect(userProps) {
|
|
|
2863
2817
|
};
|
|
2864
2818
|
}
|
|
2865
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
|
+
|
|
2866
2832
|
var InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2867
2833
|
var InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2868
2834
|
var InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
@@ -2914,27 +2880,6 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2914
2880
|
ToggleButtonClick: ToggleButtonClick
|
|
2915
2881
|
});
|
|
2916
2882
|
|
|
2917
|
-
function getInitialState$2(props) {
|
|
2918
|
-
var initialState = getInitialState$3(props);
|
|
2919
|
-
var selectedItem = initialState.selectedItem;
|
|
2920
|
-
var inputValue = initialState.inputValue;
|
|
2921
|
-
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2922
|
-
inputValue = props.itemToString(selectedItem);
|
|
2923
|
-
}
|
|
2924
|
-
return _extends({}, initialState, {
|
|
2925
|
-
inputValue: inputValue
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
var propTypes$2 = _extends({}, propTypes$4, {
|
|
2929
|
-
items: PropTypes.array.isRequired,
|
|
2930
|
-
isItemDisabled: PropTypes.func,
|
|
2931
|
-
inputValue: PropTypes.string,
|
|
2932
|
-
defaultInputValue: PropTypes.string,
|
|
2933
|
-
initialInputValue: PropTypes.string,
|
|
2934
|
-
inputId: PropTypes.string,
|
|
2935
|
-
onInputValueChange: PropTypes.func
|
|
2936
|
-
});
|
|
2937
|
-
|
|
2938
2883
|
/**
|
|
2939
2884
|
* The useCombobox version of useControlledReducer, which also
|
|
2940
2885
|
* checks if the controlled prop selectedItem changed between
|
|
@@ -2942,20 +2887,20 @@ var propTypes$2 = _extends({}, propTypes$4, {
|
|
|
2942
2887
|
* string equivalent. It uses the common useEnhancedReducer to
|
|
2943
2888
|
* compute the rest of the state.
|
|
2944
2889
|
*
|
|
2945
|
-
* @param
|
|
2946
|
-
* @param
|
|
2947
|
-
* @param
|
|
2948
|
-
* @param
|
|
2949
|
-
* @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.
|
|
2950
2895
|
*/
|
|
2951
2896
|
function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
|
|
2952
|
-
var previousSelectedItemRef = React.useRef();
|
|
2897
|
+
var previousSelectedItemRef = React.useRef(null);
|
|
2953
2898
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
2954
2899
|
state = _useEnhancedReducer[0],
|
|
2955
2900
|
dispatch = _useEnhancedReducer[1];
|
|
2956
2901
|
var isInitialMount = useIsInitialMount();
|
|
2957
2902
|
React.useEffect(function () {
|
|
2958
|
-
if (
|
|
2903
|
+
if (props.selectedItem === undefined) {
|
|
2959
2904
|
return;
|
|
2960
2905
|
}
|
|
2961
2906
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
@@ -2973,23 +2918,27 @@ function useControlledReducer(reducer, props, createInitialState, isStateEqual)
|
|
|
2973
2918
|
}, [state.selectedItem, props.selectedItem]);
|
|
2974
2919
|
return [getState(state, props), dispatch];
|
|
2975
2920
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
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
|
|
2980
2930
|
});
|
|
2981
2931
|
|
|
2982
2932
|
/* eslint-disable complexity */
|
|
2983
|
-
function downshiftUseComboboxReducer(state,
|
|
2984
|
-
var _props$items;
|
|
2933
|
+
function downshiftUseComboboxReducer(state, action) {
|
|
2985
2934
|
var type = action.type,
|
|
2986
|
-
|
|
2935
|
+
props = action.props;
|
|
2987
2936
|
var changes;
|
|
2988
2937
|
switch (type) {
|
|
2989
2938
|
case ItemClick:
|
|
2990
2939
|
changes = {
|
|
2991
|
-
isOpen: getDefaultValue
|
|
2992
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2940
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2941
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2993
2942
|
selectedItem: props.items[action.index],
|
|
2994
2943
|
inputValue: props.itemToString(props.items[action.index])
|
|
2995
2944
|
};
|
|
@@ -3001,15 +2950,15 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3001
2950
|
};
|
|
3002
2951
|
} else {
|
|
3003
2952
|
changes = {
|
|
3004
|
-
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),
|
|
3005
2954
|
isOpen: props.items.length >= 0
|
|
3006
2955
|
};
|
|
3007
2956
|
}
|
|
3008
2957
|
break;
|
|
3009
2958
|
case InputKeyDownArrowUp:
|
|
3010
2959
|
if (state.isOpen) {
|
|
3011
|
-
if (altKey) {
|
|
3012
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2960
|
+
if (action.altKey) {
|
|
2961
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3013
2962
|
} else {
|
|
3014
2963
|
changes = {
|
|
3015
2964
|
highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
|
|
@@ -3017,13 +2966,13 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3017
2966
|
}
|
|
3018
2967
|
} else {
|
|
3019
2968
|
changes = {
|
|
3020
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
|
|
2969
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
|
|
3021
2970
|
isOpen: props.items.length >= 0
|
|
3022
2971
|
};
|
|
3023
2972
|
}
|
|
3024
2973
|
break;
|
|
3025
2974
|
case InputKeyDownEnter:
|
|
3026
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
2975
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3027
2976
|
break;
|
|
3028
2977
|
case InputKeyDownEscape:
|
|
3029
2978
|
changes = _extends({
|
|
@@ -3058,7 +3007,7 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3058
3007
|
changes = _extends({
|
|
3059
3008
|
isOpen: false,
|
|
3060
3009
|
highlightedIndex: -1
|
|
3061
|
-
}, state.highlightedIndex >= 0 &&
|
|
3010
|
+
}, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
|
|
3062
3011
|
selectedItem: props.items[state.highlightedIndex],
|
|
3063
3012
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3064
3013
|
});
|
|
@@ -3066,14 +3015,14 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3066
3015
|
case InputChange:
|
|
3067
3016
|
changes = {
|
|
3068
3017
|
isOpen: true,
|
|
3069
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
3018
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
3070
3019
|
inputValue: action.inputValue
|
|
3071
3020
|
};
|
|
3072
3021
|
break;
|
|
3073
3022
|
case InputClick:
|
|
3074
3023
|
changes = {
|
|
3075
3024
|
isOpen: !state.isOpen,
|
|
3076
|
-
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)
|
|
3077
3026
|
};
|
|
3078
3027
|
break;
|
|
3079
3028
|
case FunctionSelectItem:
|
|
@@ -3094,10 +3043,10 @@ function downshiftUseComboboxReducer(state, props, action) {
|
|
|
3094
3043
|
}
|
|
3095
3044
|
/* eslint-enable complexity */
|
|
3096
3045
|
|
|
3097
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
3046
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
3098
3047
|
_excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
3099
|
-
_excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
|
|
3100
|
-
_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"];
|
|
3101
3050
|
useCombobox.stateChangeTypes = stateChangeTypes$2;
|
|
3102
3051
|
function useCombobox(userProps) {
|
|
3103
3052
|
if (userProps === void 0) {
|
|
@@ -3105,13 +3054,13 @@ function useCombobox(userProps) {
|
|
|
3105
3054
|
}
|
|
3106
3055
|
validatePropTypes$1(userProps, useCombobox, propTypes$2);
|
|
3107
3056
|
// Props defaults and destructuring.
|
|
3108
|
-
var props = _extends({},
|
|
3057
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
3109
3058
|
var items = props.items,
|
|
3110
3059
|
scrollIntoView = props.scrollIntoView,
|
|
3111
3060
|
environment = props.environment,
|
|
3112
3061
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3113
3062
|
// Initial state depending on controlled props.
|
|
3114
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2,
|
|
3063
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
|
|
3115
3064
|
state = _useControlledReducer[0],
|
|
3116
3065
|
dispatch = _useControlledReducer[1];
|
|
3117
3066
|
var isOpen = state.isOpen,
|
|
@@ -3121,7 +3070,7 @@ function useCombobox(userProps) {
|
|
|
3121
3070
|
|
|
3122
3071
|
// Element refs.
|
|
3123
3072
|
var menuRef = React.useRef(null);
|
|
3124
|
-
var
|
|
3073
|
+
var itemsRef = React.useRef({});
|
|
3125
3074
|
var inputRef = React.useRef(null);
|
|
3126
3075
|
var toggleButtonRef = React.useRef(null);
|
|
3127
3076
|
var isInitialMount = useIsInitialMount();
|
|
@@ -3135,29 +3084,19 @@ function useCombobox(userProps) {
|
|
|
3135
3084
|
state: state,
|
|
3136
3085
|
props: props
|
|
3137
3086
|
});
|
|
3138
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
3139
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3140
|
-
}, [elementIds]);
|
|
3141
3087
|
|
|
3142
3088
|
// Effects.
|
|
3143
3089
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3144
3090
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
3145
3091
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3146
|
-
var
|
|
3147
|
-
menuElement: menuRef.current,
|
|
3148
|
-
highlightedIndex: highlightedIndex,
|
|
3149
|
-
isOpen: isOpen,
|
|
3150
|
-
itemRefs: itemRefs,
|
|
3151
|
-
scrollIntoView: scrollIntoView,
|
|
3152
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3153
|
-
});
|
|
3092
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
3154
3093
|
useControlPropsValidator({
|
|
3155
|
-
|
|
3156
|
-
|
|
3094
|
+
state: state,
|
|
3095
|
+
props: props
|
|
3157
3096
|
});
|
|
3158
3097
|
// Focus the input on first render if required.
|
|
3159
3098
|
React.useEffect(function () {
|
|
3160
|
-
var focusOnOpen = getInitialValue
|
|
3099
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
3161
3100
|
if (focusOnOpen && inputRef.current) {
|
|
3162
3101
|
inputRef.current.focus();
|
|
3163
3102
|
}
|
|
@@ -3183,13 +3122,13 @@ function useCombobox(userProps) {
|
|
|
3183
3122
|
// Reset itemRefs on close.
|
|
3184
3123
|
React.useEffect(function () {
|
|
3185
3124
|
if (!isOpen) {
|
|
3186
|
-
|
|
3125
|
+
itemsRef.current = {};
|
|
3187
3126
|
}
|
|
3188
3127
|
}, [isOpen]);
|
|
3189
3128
|
// Reset itemRefs on close.
|
|
3190
3129
|
React.useEffect(function () {
|
|
3191
3130
|
var _inputRef$current;
|
|
3192
|
-
if (!isOpen || !(environment != null && environment.document) || !(
|
|
3131
|
+
if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3193
3132
|
return;
|
|
3194
3133
|
}
|
|
3195
3134
|
if (environment.document.activeElement !== inputRef.current) {
|
|
@@ -3279,29 +3218,30 @@ function useCombobox(userProps) {
|
|
|
3279
3218
|
htmlFor: elementIds.inputId
|
|
3280
3219
|
}, labelProps);
|
|
3281
3220
|
}, [elementIds]);
|
|
3282
|
-
var getMenuProps = React.useCallback(function (
|
|
3221
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
3283
3222
|
var _extends2;
|
|
3284
|
-
var _ref =
|
|
3223
|
+
var _ref = menuProps != null ? menuProps : {},
|
|
3285
3224
|
onMouseLeave = _ref.onMouseLeave,
|
|
3286
3225
|
_ref$refKey = _ref.refKey,
|
|
3287
3226
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3288
3227
|
ref = _ref.ref,
|
|
3228
|
+
ariaLabel = _ref['aria-label'],
|
|
3289
3229
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3290
|
-
var _ref2 =
|
|
3230
|
+
var _ref2 = otherProps != null ? otherProps : {},
|
|
3291
3231
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3292
3232
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3293
3233
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3294
3234
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3295
3235
|
menuRef.current = menuNode;
|
|
3296
|
-
}), _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 () {
|
|
3297
3237
|
dispatch({
|
|
3298
3238
|
type: MenuMouseLeave
|
|
3299
3239
|
});
|
|
3300
3240
|
}), _extends2), rest);
|
|
3301
3241
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3302
|
-
var getItemProps = React.useCallback(function (
|
|
3242
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
3303
3243
|
var _extends3, _ref4;
|
|
3304
|
-
var _ref3 =
|
|
3244
|
+
var _ref3 = itemProps != null ? itemProps : {},
|
|
3305
3245
|
itemProp = _ref3.item,
|
|
3306
3246
|
indexProp = _ref3.index,
|
|
3307
3247
|
_ref3$refKey = _ref3.refKey,
|
|
@@ -3329,7 +3269,7 @@ function useCombobox(userProps) {
|
|
|
3329
3269
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
3330
3270
|
return;
|
|
3331
3271
|
}
|
|
3332
|
-
|
|
3272
|
+
preventScroll();
|
|
3333
3273
|
dispatch({
|
|
3334
3274
|
type: ItemMouseMove,
|
|
3335
3275
|
index: index,
|
|
@@ -3348,21 +3288,22 @@ function useCombobox(userProps) {
|
|
|
3348
3288
|
|
|
3349
3289
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3350
3290
|
if (itemNode) {
|
|
3351
|
-
|
|
3291
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
3352
3292
|
}
|
|
3353
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), {
|
|
3354
3294
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3355
3295
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3356
3296
|
}, rest);
|
|
3357
|
-
}, [dispatch, elementIds, latest, mouseAndTouchTrackers,
|
|
3358
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
3297
|
+
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
|
|
3298
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
|
|
3359
3299
|
var _extends4;
|
|
3360
|
-
var _ref5 =
|
|
3300
|
+
var _ref5 = toggleButtonProps != null ? toggleButtonProps : {};
|
|
3361
3301
|
_ref5.onClick;
|
|
3362
3302
|
var onPress = _ref5.onPress,
|
|
3363
3303
|
_ref5$refKey = _ref5.refKey,
|
|
3364
3304
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3365
3305
|
ref = _ref5.ref,
|
|
3306
|
+
disabled = _ref5.disabled,
|
|
3366
3307
|
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3367
3308
|
var latestState = latest.current.state;
|
|
3368
3309
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
@@ -3372,13 +3313,17 @@ function useCombobox(userProps) {
|
|
|
3372
3313
|
};
|
|
3373
3314
|
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3374
3315
|
toggleButtonRef.current = toggleButtonNode;
|
|
3375
|
-
}), _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) */{
|
|
3376
3317
|
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
3377
|
-
} ),
|
|
3318
|
+
} ), {
|
|
3319
|
+
disabled: disabled
|
|
3320
|
+
}, rest);
|
|
3378
3321
|
}, [dispatch, latest, elementIds]);
|
|
3379
|
-
var getInputProps = React.useCallback(function (
|
|
3322
|
+
var getInputProps = React.useCallback(function (inputProps, otherProps) {
|
|
3380
3323
|
var _extends5;
|
|
3381
|
-
var _ref6 =
|
|
3324
|
+
var _ref6 = inputProps != null ? inputProps : {},
|
|
3325
|
+
ariaLabel = _ref6['aria-label'],
|
|
3326
|
+
disabled = _ref6.disabled,
|
|
3382
3327
|
onKeyDown = _ref6.onKeyDown,
|
|
3383
3328
|
onChange = _ref6.onChange,
|
|
3384
3329
|
onInput = _ref6.onInput,
|
|
@@ -3389,15 +3334,16 @@ function useCombobox(userProps) {
|
|
|
3389
3334
|
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
3390
3335
|
ref = _ref6.ref,
|
|
3391
3336
|
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
|
|
3392
|
-
var _ref7 =
|
|
3337
|
+
var _ref7 = otherProps != null ? otherProps : {},
|
|
3393
3338
|
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3394
3339
|
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3395
3340
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3396
3341
|
var latestState = latest.current.state;
|
|
3397
3342
|
var inputHandleKeyDown = function inputHandleKeyDown(event) {
|
|
3398
3343
|
var key = normalizeArrowKey(event);
|
|
3399
|
-
if (key && inputKeyDownHandlers
|
|
3400
|
-
|
|
3344
|
+
if (key && key in inputKeyDownHandlers) {
|
|
3345
|
+
var validKey = key;
|
|
3346
|
+
inputKeyDownHandlers[validKey](event);
|
|
3401
3347
|
}
|
|
3402
3348
|
};
|
|
3403
3349
|
var inputHandleChange = function inputHandleChange(event) {
|
|
@@ -3425,13 +3371,13 @@ function useCombobox(userProps) {
|
|
|
3425
3371
|
/* istanbul ignore next (preact) */
|
|
3426
3372
|
var onChangeKey = 'onChange';
|
|
3427
3373
|
var eventHandlers = {};
|
|
3428
|
-
if (!
|
|
3374
|
+
if (!disabled) {
|
|
3429
3375
|
var _eventHandlers;
|
|
3430
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);
|
|
3431
3377
|
}
|
|
3432
3378
|
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
3433
3379
|
inputRef.current = inputNode;
|
|
3434
|
-
}), _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);
|
|
3435
3381
|
}, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
|
|
3436
3382
|
|
|
3437
3383
|
// returns
|
|
@@ -3501,31 +3447,6 @@ var defaultStateValues = {
|
|
|
3501
3447
|
selectedItems: []
|
|
3502
3448
|
};
|
|
3503
3449
|
|
|
3504
|
-
/**
|
|
3505
|
-
* Returns the initial value for a state key in the following order:
|
|
3506
|
-
* 1. controlled prop, 2. initial prop, 3. default prop, 4. default
|
|
3507
|
-
* value from Downshift.
|
|
3508
|
-
*
|
|
3509
|
-
* @param {Object} props Props passed to the hook.
|
|
3510
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3511
|
-
* @returns {any} The initial value for that prop.
|
|
3512
|
-
*/
|
|
3513
|
-
function getInitialValue(props, propKey) {
|
|
3514
|
-
return getInitialValue$1(props, propKey, defaultStateValues);
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
/**
|
|
3518
|
-
* Returns the default value for a state key in the following order:
|
|
3519
|
-
* 1. controlled prop, 2. default prop, 3. default value from Downshift.
|
|
3520
|
-
*
|
|
3521
|
-
* @param {Object} props Props passed to the hook.
|
|
3522
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3523
|
-
* @returns {any} The initial value for that prop.
|
|
3524
|
-
*/
|
|
3525
|
-
function getDefaultValue(props, propKey) {
|
|
3526
|
-
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
3527
|
-
}
|
|
3528
|
-
|
|
3529
3450
|
/**
|
|
3530
3451
|
* Gets the initial state based on the provided props. It uses initial, default
|
|
3531
3452
|
* and controlled props related to state in order to compute the initial value.
|
|
@@ -3534,8 +3455,8 @@ function getDefaultValue(props, propKey) {
|
|
|
3534
3455
|
* @returns {Object} The initial state.
|
|
3535
3456
|
*/
|
|
3536
3457
|
function getInitialState$1(props) {
|
|
3537
|
-
var activeIndex = getInitialValue(props,
|
|
3538
|
-
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);
|
|
3539
3460
|
return {
|
|
3540
3461
|
activeIndex: activeIndex,
|
|
3541
3462
|
selectedItems: selectedItems
|
|
@@ -3579,9 +3500,9 @@ function isStateEqual$1(prevState, newState) {
|
|
|
3579
3500
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3580
3501
|
}
|
|
3581
3502
|
var propTypes$1 = {
|
|
3582
|
-
stateReducer:
|
|
3583
|
-
itemToKey:
|
|
3584
|
-
environment:
|
|
3503
|
+
stateReducer: dropdownPropTypes.stateReducer,
|
|
3504
|
+
itemToKey: dropdownPropTypes.itemToKey,
|
|
3505
|
+
environment: dropdownPropTypes.environment,
|
|
3585
3506
|
selectedItems: PropTypes.array,
|
|
3586
3507
|
initialSelectedItems: PropTypes.array,
|
|
3587
3508
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3595,9 +3516,9 @@ var propTypes$1 = {
|
|
|
3595
3516
|
keyNavigationPrevious: PropTypes.string
|
|
3596
3517
|
};
|
|
3597
3518
|
var defaultProps = {
|
|
3598
|
-
itemToKey:
|
|
3599
|
-
stateReducer:
|
|
3600
|
-
environment:
|
|
3519
|
+
itemToKey: dropdownDefaultProps.itemToKey,
|
|
3520
|
+
stateReducer: dropdownDefaultProps.stateReducer,
|
|
3521
|
+
environment: dropdownDefaultProps.environment,
|
|
3601
3522
|
keyNavigationNext: 'ArrowRight',
|
|
3602
3523
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3603
3524
|
};
|
|
@@ -3643,10 +3564,11 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3643
3564
|
});
|
|
3644
3565
|
|
|
3645
3566
|
/* eslint-disable complexity */
|
|
3646
|
-
function downshiftMultipleSelectionReducer(state,
|
|
3567
|
+
function downshiftMultipleSelectionReducer(state, action) {
|
|
3647
3568
|
var type = action.type,
|
|
3648
3569
|
index = action.index,
|
|
3649
|
-
selectedItem = action.selectedItem
|
|
3570
|
+
selectedItem = action.selectedItem,
|
|
3571
|
+
props = action.props;
|
|
3650
3572
|
var activeIndex = state.activeIndex,
|
|
3651
3573
|
selectedItems = state.selectedItems;
|
|
3652
3574
|
var changes;
|
|
@@ -3743,8 +3665,8 @@ function downshiftMultipleSelectionReducer(state, props, action) {
|
|
|
3743
3665
|
}
|
|
3744
3666
|
case FunctionReset:
|
|
3745
3667
|
changes = {
|
|
3746
|
-
activeIndex: getDefaultValue(props,
|
|
3747
|
-
selectedItems: getDefaultValue(props,
|
|
3668
|
+
activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
|
|
3669
|
+
selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
|
|
3748
3670
|
};
|
|
3749
3671
|
break;
|
|
3750
3672
|
default:
|
|
@@ -3976,7 +3898,7 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3976
3898
|
TagRemoveClick: TagRemoveClick
|
|
3977
3899
|
});
|
|
3978
3900
|
|
|
3979
|
-
function useTagGroupReducer(state,
|
|
3901
|
+
function useTagGroupReducer(state, action) {
|
|
3980
3902
|
var type = action.type;
|
|
3981
3903
|
var changes;
|
|
3982
3904
|
switch (type) {
|
|
@@ -4214,7 +4136,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4214
4136
|
'aria-atomic': 'false',
|
|
4215
4137
|
'aria-relevant': 'additions',
|
|
4216
4138
|
role: 'listbox',
|
|
4217
|
-
onKeyDown: callAllEventHandlers
|
|
4139
|
+
onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
|
|
4218
4140
|
}, rest);
|
|
4219
4141
|
return tagGroupProps;
|
|
4220
4142
|
}, [dispatch, elementIds.tagGroupId]);
|
|
@@ -4239,11 +4161,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4239
4161
|
var tagId = elementIds.getTagId(index);
|
|
4240
4162
|
return _extends((_extends2 = {
|
|
4241
4163
|
'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
|
|
4242
|
-
}, _extends2[refKey] = handleRefs
|
|
4164
|
+
}, _extends2[refKey] = handleRefs(ref, function (itemNode) {
|
|
4243
4165
|
if (itemNode) {
|
|
4244
4166
|
itemRefs.current[tagId] = itemNode;
|
|
4245
4167
|
}
|
|
4246
|
-
}), _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);
|
|
4247
4169
|
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4248
4170
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4249
4171
|
var index = options.index,
|
|
@@ -4265,7 +4187,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4265
4187
|
id: tagRemoveId,
|
|
4266
4188
|
tabIndex: -1,
|
|
4267
4189
|
'aria-labelledby': tagRemoveId + " " + tagId,
|
|
4268
|
-
onClick: callAllEventHandlers
|
|
4190
|
+
onClick: callAllEventHandlers(onClick, handleClick)
|
|
4269
4191
|
}, rest);
|
|
4270
4192
|
}, [elementIds, dispatch]);
|
|
4271
4193
|
|