downshift 9.3.2 → 9.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/downshift.cjs.cjs +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
|
@@ -370,7 +370,7 @@
|
|
|
370
370
|
return ref;
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
-
function handleRefs
|
|
373
|
+
function handleRefs() {
|
|
374
374
|
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
375
375
|
refs[_key] = arguments[_key];
|
|
376
376
|
}
|
|
@@ -392,7 +392,7 @@
|
|
|
392
392
|
* @param fns the event handler functions
|
|
393
393
|
* @return the event handler to add to an element
|
|
394
394
|
*/
|
|
395
|
-
function callAllEventHandlers
|
|
395
|
+
function callAllEventHandlers() {
|
|
396
396
|
for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
397
397
|
fns[_key] = arguments[_key];
|
|
398
398
|
}
|
|
@@ -414,7 +414,7 @@
|
|
|
414
414
|
* function once after the time given has passed since
|
|
415
415
|
* it was last called.
|
|
416
416
|
*/
|
|
417
|
-
function debounce
|
|
417
|
+
function debounce(fn, time) {
|
|
418
418
|
var timeoutId;
|
|
419
419
|
function cancel() {
|
|
420
420
|
if (timeoutId) {
|
|
@@ -435,7 +435,7 @@
|
|
|
435
435
|
return wrapper;
|
|
436
436
|
}
|
|
437
437
|
|
|
438
|
-
var cleanupStatus = debounce
|
|
438
|
+
var cleanupStatus = debounce(function (document) {
|
|
439
439
|
getStatusDiv(document).textContent = '';
|
|
440
440
|
}, 500);
|
|
441
441
|
|
|
@@ -516,6 +516,8 @@
|
|
|
516
516
|
}
|
|
517
517
|
var keys = Object.keys(state);
|
|
518
518
|
return keys.reduce(function (newState, key) {
|
|
519
|
+
// state keys could be in props, but with value undefined, which means they should be ignored.
|
|
520
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
519
521
|
if (props[key] !== undefined) {
|
|
520
522
|
newState[key] = props[key];
|
|
521
523
|
}
|
|
@@ -546,93 +548,149 @@
|
|
|
546
548
|
}
|
|
547
549
|
|
|
548
550
|
/**
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
* passed.
|
|
553
|
-
* @param {Function} cb the callback
|
|
554
|
-
* @return {Function} a function
|
|
555
|
-
*/
|
|
556
|
-
function cbToCb(cb) {
|
|
557
|
-
return typeof cb === 'function' ? cb : noop;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* @param {HTMLElement} parent the parent node
|
|
562
|
-
* @param {HTMLElement} child the child node
|
|
563
|
-
* @param {Window} environment The window context where downshift renders.
|
|
564
|
-
* @return {Boolean} whether the parent is the child or the child is in the parent
|
|
551
|
+
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
552
|
+
* @param event a keyboardEvent object
|
|
553
|
+
* @return keyboard key
|
|
565
554
|
*/
|
|
566
|
-
function
|
|
567
|
-
var
|
|
568
|
-
|
|
555
|
+
function normalizeArrowKey(event) {
|
|
556
|
+
var key = event.key,
|
|
557
|
+
keyCode = event.keyCode;
|
|
558
|
+
/* istanbul ignore next (ie) */
|
|
559
|
+
if (keyCode >= 37 && keyCode <= 40 && !key.startsWith('Arrow')) {
|
|
560
|
+
return "Arrow" + key;
|
|
561
|
+
}
|
|
562
|
+
return key;
|
|
569
563
|
}
|
|
570
564
|
|
|
571
565
|
/**
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
* @param
|
|
576
|
-
* @param
|
|
577
|
-
* @
|
|
566
|
+
* Returns the next non-disabled highlightedIndex value.
|
|
567
|
+
*
|
|
568
|
+
* @param start The current highlightedIndex.
|
|
569
|
+
* @param backwards If true, it will search backwards from the start.
|
|
570
|
+
* @param items The items array.
|
|
571
|
+
* @param isItemDisabled Function that tells if an item is disabled or not.
|
|
572
|
+
* @param circular If the search reaches the end, if it can search again starting from the other end.
|
|
573
|
+
* @returns The next non-disabled index.
|
|
578
574
|
*/
|
|
579
|
-
function
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
if (timeoutId) {
|
|
583
|
-
clearTimeout(timeoutId);
|
|
584
|
-
}
|
|
575
|
+
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
576
|
+
if (circular === void 0) {
|
|
577
|
+
circular = false;
|
|
585
578
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
579
|
+
var count = items.length;
|
|
580
|
+
if (backwards) {
|
|
581
|
+
for (var index = start; index >= 0; index--) {
|
|
582
|
+
if (!isItemDisabled(items[index], index)) {
|
|
583
|
+
return index;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
} else {
|
|
587
|
+
for (var _index = start; _index < count; _index++) {
|
|
588
|
+
if (!isItemDisabled(items[_index], _index)) {
|
|
589
|
+
return _index;
|
|
590
|
+
}
|
|
589
591
|
}
|
|
590
|
-
cancel();
|
|
591
|
-
timeoutId = setTimeout(function () {
|
|
592
|
-
timeoutId = null;
|
|
593
|
-
fn.apply(void 0, args);
|
|
594
|
-
}, time);
|
|
595
592
|
}
|
|
596
|
-
|
|
597
|
-
|
|
593
|
+
if (circular) {
|
|
594
|
+
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
595
|
+
}
|
|
596
|
+
return -1;
|
|
598
597
|
}
|
|
599
598
|
|
|
600
599
|
/**
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* @param
|
|
605
|
-
* @
|
|
600
|
+
* Returns the next non-disabled highlightedIndex value.
|
|
601
|
+
*
|
|
602
|
+
* @param start The current highlightedIndex.
|
|
603
|
+
* @param offset The offset from the current highlightedIndex to start searching.
|
|
604
|
+
* @param items The items array.
|
|
605
|
+
* @param isItemDisabled Function that tells if an item is disabled or not.
|
|
606
|
+
* @param circular If the search reaches the end, if it can search again starting from the other end.
|
|
607
|
+
* @returns The next highlightedIndex.
|
|
606
608
|
*/
|
|
607
|
-
function
|
|
608
|
-
|
|
609
|
-
|
|
609
|
+
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
610
|
+
if (circular === void 0) {
|
|
611
|
+
circular = false;
|
|
610
612
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
613
|
+
var count = items.length;
|
|
614
|
+
if (count === 0) {
|
|
615
|
+
return -1;
|
|
616
|
+
}
|
|
617
|
+
var itemsLastIndex = count - 1;
|
|
618
|
+
if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
|
|
619
|
+
start = offset > 0 ? -1 : itemsLastIndex + 1;
|
|
620
|
+
}
|
|
621
|
+
var current = start + offset;
|
|
622
|
+
if (current < 0) {
|
|
623
|
+
current = circular ? itemsLastIndex : 0;
|
|
624
|
+
} else if (current > itemsLastIndex) {
|
|
625
|
+
current = circular ? 0 : itemsLastIndex;
|
|
626
|
+
}
|
|
627
|
+
var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
|
|
628
|
+
if (highlightedIndex === -1) {
|
|
629
|
+
return start >= count ? -1 : start;
|
|
630
|
+
}
|
|
631
|
+
return highlightedIndex;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
635
|
+
|
|
636
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
637
|
+
var validateControlledUnchanged = noop;
|
|
638
|
+
/* istanbul ignore next */
|
|
639
|
+
{
|
|
640
|
+
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
641
|
+
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";
|
|
642
|
+
Object.keys(state).forEach(function (propKey) {
|
|
643
|
+
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
644
|
+
// eslint-disable-next-line no-console
|
|
645
|
+
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
646
|
+
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
647
|
+
// eslint-disable-next-line no-console
|
|
648
|
+
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
618
649
|
}
|
|
619
|
-
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
620
650
|
});
|
|
621
651
|
};
|
|
622
652
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Checks if event target is within the downshift elements.
|
|
656
|
+
*
|
|
657
|
+
* @param target Target to check.
|
|
658
|
+
* @param downshiftElements The elements that form downshift (list, toggle button etc).
|
|
659
|
+
* @param environment The window context where downshift renders.
|
|
660
|
+
* @param checkActiveElement Whether to also check activeElement.
|
|
661
|
+
*
|
|
662
|
+
* @returns Whether or not the target is within downshift elements.
|
|
663
|
+
*/
|
|
664
|
+
function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
|
|
665
|
+
if (checkActiveElement === void 0) {
|
|
666
|
+
checkActiveElement = true;
|
|
626
667
|
}
|
|
627
|
-
return function (
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
668
|
+
return !!environment && downshiftElements.some(function (contextNode) {
|
|
669
|
+
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* @param parent the parent node
|
|
675
|
+
* @param child the child node
|
|
676
|
+
* @param environment The window context where downshift renders.
|
|
677
|
+
* @return Whether the parent is the child or the child is in the parent
|
|
678
|
+
*/
|
|
679
|
+
function isOrContainsNode(parent, child, environment) {
|
|
680
|
+
var result = parent === child || child instanceof environment.Node && parent.contains(child);
|
|
681
|
+
return result;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Accepts a parameter and returns it if it's a function
|
|
686
|
+
* or a noop function if it's not. This allows us to
|
|
687
|
+
* accept a callback, but not worry about it if it's not
|
|
688
|
+
* passed.
|
|
689
|
+
* @param {Function} cb the callback
|
|
690
|
+
* @return {Function} a function
|
|
691
|
+
*/
|
|
692
|
+
function cbToCb(cb) {
|
|
693
|
+
return typeof cb === 'function' ? cb : noop;
|
|
636
694
|
}
|
|
637
695
|
|
|
638
696
|
/**
|
|
@@ -728,34 +786,6 @@
|
|
|
728
786
|
return result;
|
|
729
787
|
}
|
|
730
788
|
|
|
731
|
-
/**
|
|
732
|
-
* This determines whether a prop is a "controlled prop" meaning it is
|
|
733
|
-
* state which is controlled by the outside of this component rather
|
|
734
|
-
* than within this component.
|
|
735
|
-
*
|
|
736
|
-
* @param {Object} props The props that may contain controlled values.
|
|
737
|
-
* @param {String} key the key to check
|
|
738
|
-
* @return {Boolean} whether it is a controlled controlled prop
|
|
739
|
-
*/
|
|
740
|
-
function isControlledProp(props, key) {
|
|
741
|
-
return props[key] !== undefined;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/**
|
|
745
|
-
* Normalizes the 'key' property of a KeyboardEvent in IE/Edge
|
|
746
|
-
* @param {Object} event a keyboardEvent object
|
|
747
|
-
* @return {String} keyboard key
|
|
748
|
-
*/
|
|
749
|
-
function normalizeArrowKey(event) {
|
|
750
|
-
var key = event.key,
|
|
751
|
-
keyCode = event.keyCode;
|
|
752
|
-
/* istanbul ignore next (ie) */
|
|
753
|
-
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
754
|
-
return "Arrow" + key;
|
|
755
|
-
}
|
|
756
|
-
return key;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
789
|
/**
|
|
760
790
|
* Simple check if the value passed is object literal
|
|
761
791
|
* @param {*} obj any things
|
|
@@ -765,112 +795,6 @@
|
|
|
765
795
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
766
796
|
}
|
|
767
797
|
|
|
768
|
-
/**
|
|
769
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
770
|
-
*
|
|
771
|
-
* @param {number} start The current highlightedIndex.
|
|
772
|
-
* @param {number} offset The offset from the current highlightedIndex to start searching.
|
|
773
|
-
* @param {unknown[]} items The items array.
|
|
774
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
775
|
-
* @param {boolean?} circular If the search reaches the end, if it can search again starting from the other end.
|
|
776
|
-
* @returns {number} The next highlightedIndex.
|
|
777
|
-
*/
|
|
778
|
-
function getHighlightedIndex(start, offset, items, isItemDisabled, circular) {
|
|
779
|
-
if (circular === void 0) {
|
|
780
|
-
circular = false;
|
|
781
|
-
}
|
|
782
|
-
var count = items.length;
|
|
783
|
-
if (count === 0) {
|
|
784
|
-
return -1;
|
|
785
|
-
}
|
|
786
|
-
var itemsLastIndex = count - 1;
|
|
787
|
-
if (typeof start !== 'number' || start < 0 || start > itemsLastIndex) {
|
|
788
|
-
start = offset > 0 ? -1 : itemsLastIndex + 1;
|
|
789
|
-
}
|
|
790
|
-
var current = start + offset;
|
|
791
|
-
if (current < 0) {
|
|
792
|
-
current = circular ? itemsLastIndex : 0;
|
|
793
|
-
} else if (current > itemsLastIndex) {
|
|
794
|
-
current = circular ? 0 : itemsLastIndex;
|
|
795
|
-
}
|
|
796
|
-
var highlightedIndex = getNonDisabledIndex(current, offset < 0, items, isItemDisabled, circular);
|
|
797
|
-
if (highlightedIndex === -1) {
|
|
798
|
-
return start >= count ? -1 : start;
|
|
799
|
-
}
|
|
800
|
-
return highlightedIndex;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Returns the next non-disabled highlightedIndex value.
|
|
805
|
-
*
|
|
806
|
-
* @param {number} start The current highlightedIndex.
|
|
807
|
-
* @param {boolean} backwards If true, it will search backwards from the start.
|
|
808
|
-
* @param {unknown[]} items The items array.
|
|
809
|
-
* @param {(item: unknown, index: number) => boolean} isItemDisabled Function that tells if an item is disabled or not.
|
|
810
|
-
* @param {boolean} circular If the search reaches the end, if it can search again starting from the other end.
|
|
811
|
-
* @returns {number} The next non-disabled index.
|
|
812
|
-
*/
|
|
813
|
-
function getNonDisabledIndex(start, backwards, items, isItemDisabled, circular) {
|
|
814
|
-
if (circular === void 0) {
|
|
815
|
-
circular = false;
|
|
816
|
-
}
|
|
817
|
-
var count = items.length;
|
|
818
|
-
if (backwards) {
|
|
819
|
-
for (var index = start; index >= 0; index--) {
|
|
820
|
-
if (!isItemDisabled(items[index], index)) {
|
|
821
|
-
return index;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
} else {
|
|
825
|
-
for (var _index = start; _index < count; _index++) {
|
|
826
|
-
if (!isItemDisabled(items[_index], _index)) {
|
|
827
|
-
return _index;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
if (circular) {
|
|
832
|
-
return getNonDisabledIndex(backwards ? count - 1 : 0, backwards, items, isItemDisabled);
|
|
833
|
-
}
|
|
834
|
-
return -1;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
/**
|
|
838
|
-
* Checks if event target is within the downshift elements.
|
|
839
|
-
*
|
|
840
|
-
* @param {EventTarget} target Target to check.
|
|
841
|
-
* @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
|
|
842
|
-
* @param {Window} environment The window context where downshift renders.
|
|
843
|
-
* @param {boolean} checkActiveElement Whether to also check activeElement.
|
|
844
|
-
*
|
|
845
|
-
* @returns {boolean} Whether or not the target is within downshift elements.
|
|
846
|
-
*/
|
|
847
|
-
function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
|
|
848
|
-
if (checkActiveElement === void 0) {
|
|
849
|
-
checkActiveElement = true;
|
|
850
|
-
}
|
|
851
|
-
return environment && downshiftElements.some(function (contextNode) {
|
|
852
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
857
|
-
var validateControlledUnchanged = noop;
|
|
858
|
-
/* istanbul ignore next */
|
|
859
|
-
{
|
|
860
|
-
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
861
|
-
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";
|
|
862
|
-
Object.keys(state).forEach(function (propKey) {
|
|
863
|
-
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
864
|
-
// eslint-disable-next-line no-console
|
|
865
|
-
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
866
|
-
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
867
|
-
// eslint-disable-next-line no-console
|
|
868
|
-
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
869
|
-
}
|
|
870
|
-
});
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
|
-
|
|
874
798
|
var _excluded$4 = ["refKey", "ref"],
|
|
875
799
|
_excluded2$4 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
876
800
|
_excluded3$3 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
@@ -1021,7 +945,7 @@
|
|
|
1021
945
|
}
|
|
1022
946
|
newStateToSet[key];
|
|
1023
947
|
// if it's coming from props, then we don't care to set it internally
|
|
1024
|
-
if (
|
|
948
|
+
if (_this.props[key] === undefined) {
|
|
1025
949
|
nextState[key] = newStateToSet[key];
|
|
1026
950
|
}
|
|
1027
951
|
});
|
|
@@ -1751,7 +1675,7 @@
|
|
|
1751
1675
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
1752
1676
|
}
|
|
1753
1677
|
}
|
|
1754
|
-
if (
|
|
1678
|
+
if (this.props.selectedItem !== undefined && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
|
|
1755
1679
|
this.internalSetState({
|
|
1756
1680
|
type: controlledPropUpdatedSelectedItem,
|
|
1757
1681
|
inputValue: this.props.itemToString(this.props.selectedItem)
|
|
@@ -1888,7 +1812,7 @@
|
|
|
1888
1812
|
changes[key] = newState[key];
|
|
1889
1813
|
}
|
|
1890
1814
|
}
|
|
1891
|
-
if (props.onStateChange && Object.keys(changes).length) {
|
|
1815
|
+
if (typeof props.onStateChange === 'function' && Object.keys(changes).length) {
|
|
1892
1816
|
props.onStateChange(_extends({
|
|
1893
1817
|
type: type
|
|
1894
1818
|
}, changes));
|
|
@@ -1914,50 +1838,53 @@
|
|
|
1914
1838
|
* two reducers, one from downshift and an optional one from the user.
|
|
1915
1839
|
* Also calls the onChange handlers for state values that have changed.
|
|
1916
1840
|
*
|
|
1917
|
-
* @param
|
|
1918
|
-
* @param
|
|
1919
|
-
* @param
|
|
1920
|
-
* @param
|
|
1921
|
-
* @returns
|
|
1841
|
+
* @param reducer Reducer function from downshift.
|
|
1842
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1843
|
+
* @param createInitialState Function that returns the initial state.
|
|
1844
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1845
|
+
* @returns An array with the state and an action dispatcher.
|
|
1922
1846
|
*/
|
|
1923
1847
|
function useEnhancedReducer(reducer, props, createInitialState, isStateEqual) {
|
|
1924
|
-
var prevStateRef = React__namespace.useRef(
|
|
1925
|
-
var actionRef = React__namespace.useRef(
|
|
1926
|
-
var propsRef = useLatestRef(props);
|
|
1848
|
+
var prevStateRef = React__namespace.useRef({});
|
|
1849
|
+
var actionRef = React__namespace.useRef();
|
|
1927
1850
|
var enhancedReducer = React__namespace.useCallback(function (state, action) {
|
|
1928
1851
|
actionRef.current = action;
|
|
1929
|
-
state = getState(state,
|
|
1930
|
-
var changes = reducer(state,
|
|
1931
|
-
var newState =
|
|
1852
|
+
state = getState(state, action.props);
|
|
1853
|
+
var changes = reducer(state, action);
|
|
1854
|
+
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
1932
1855
|
changes: changes
|
|
1933
1856
|
}));
|
|
1934
1857
|
return _extends({}, state, newState);
|
|
1935
|
-
}, [
|
|
1858
|
+
}, [reducer]);
|
|
1936
1859
|
var _React$useReducer = React__namespace.useReducer(enhancedReducer, props, createInitialState),
|
|
1937
1860
|
state = _React$useReducer[0],
|
|
1938
1861
|
dispatch = _React$useReducer[1];
|
|
1862
|
+
var propsRef = useLatestRef(props);
|
|
1863
|
+
var dispatchWithProps = React__namespace.useCallback(function (action) {
|
|
1864
|
+
return dispatch(_extends({}, action, {
|
|
1865
|
+
props: propsRef.current
|
|
1866
|
+
}));
|
|
1867
|
+
}, [propsRef]);
|
|
1939
1868
|
var action = actionRef.current;
|
|
1940
1869
|
React__namespace.useEffect(function () {
|
|
1941
|
-
var
|
|
1942
|
-
var
|
|
1943
|
-
var shouldCallOnChangeProps = action && prevStateRef.current && !isStateEqual(prevState, state);
|
|
1870
|
+
var prevState = getState(prevStateRef.current, action == null ? void 0 : action.props);
|
|
1871
|
+
var shouldCallOnChangeProps = action && !isStateEqual(prevState, state);
|
|
1944
1872
|
if (shouldCallOnChangeProps) {
|
|
1945
|
-
callOnChangeProps(action,
|
|
1873
|
+
callOnChangeProps(action, action.props, prevState, state);
|
|
1946
1874
|
}
|
|
1947
1875
|
prevStateRef.current = state;
|
|
1948
|
-
}, [state, action, isStateEqual
|
|
1949
|
-
return [state,
|
|
1876
|
+
}, [state, action, isStateEqual]);
|
|
1877
|
+
return [state, dispatchWithProps];
|
|
1950
1878
|
}
|
|
1951
1879
|
|
|
1952
1880
|
/**
|
|
1953
1881
|
* Wraps the useEnhancedReducer and applies the controlled prop values before
|
|
1954
1882
|
* returning the new state.
|
|
1955
|
-
*
|
|
1956
|
-
* @param
|
|
1957
|
-
* @param
|
|
1958
|
-
* @param
|
|
1959
|
-
* @
|
|
1960
|
-
* @returns {Array} An array with the state and an action dispatcher.
|
|
1883
|
+
* @param reducer Reducer function from downshift.
|
|
1884
|
+
* @param props The hook props, also passed to createInitialState.
|
|
1885
|
+
* @param createInitialState Function that returns the initial state.
|
|
1886
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
1887
|
+
* @returns An array with the state and an action dispatcher.
|
|
1961
1888
|
*/
|
|
1962
1889
|
function useControlledReducer$1(reducer, props, createInitialState, isStateEqual) {
|
|
1963
1890
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
@@ -2010,16 +1937,8 @@
|
|
|
2010
1937
|
return isInitialMountRef.current;
|
|
2011
1938
|
}
|
|
2012
1939
|
|
|
2013
|
-
/**
|
|
2014
|
-
* Default state reducer that returns the changes.
|
|
2015
|
-
*
|
|
2016
|
-
*/
|
|
2017
|
-
function stateReducer(_s, a) {
|
|
2018
|
-
return a.changes;
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
1940
|
// Shared between all exports.
|
|
2022
|
-
var propTypes$
|
|
1941
|
+
var propTypes$4 = {
|
|
2023
1942
|
environment: PropTypes.shape({
|
|
2024
1943
|
addEventListener: PropTypes.func.isRequired,
|
|
2025
1944
|
removeEventListener: PropTypes.func.isRequired,
|
|
@@ -2035,30 +1954,47 @@
|
|
|
2035
1954
|
stateReducer: PropTypes.func
|
|
2036
1955
|
};
|
|
2037
1956
|
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
1957
|
+
/**
|
|
1958
|
+
* Returns the default value based on the defaultProp and defaultStateValue.
|
|
1959
|
+
*
|
|
1960
|
+
* @param defaultProp The default prop value.
|
|
1961
|
+
* @param defaultStateValue The default state value.
|
|
1962
|
+
* @returns The resolved default value.
|
|
1963
|
+
*/
|
|
1964
|
+
function getDefaultValue(defaultProp, defaultStateValue) {
|
|
1965
|
+
return defaultProp === undefined ? defaultStateValue : defaultProp;
|
|
2044
1966
|
}
|
|
2045
1967
|
|
|
2046
|
-
|
|
2047
|
-
|
|
1968
|
+
/**
|
|
1969
|
+
* Returns the initial value for a state variable, based on the following precedence:
|
|
1970
|
+
* 1. The controlled value (if it's not undefined)
|
|
1971
|
+
* 2. The initialValue (if it's not undefined)
|
|
1972
|
+
* 3. The defaultValue (if it's not undefined)
|
|
1973
|
+
* 4. The defaultStateValue
|
|
1974
|
+
*
|
|
1975
|
+
* @param value The controlled value of the state variable.
|
|
1976
|
+
* @param initialValue The initial value of the state variable.
|
|
1977
|
+
* @param defaultValue The default value of the state variable.
|
|
1978
|
+
* @param defaultStateValue The default state value to use if all other values are undefined.
|
|
1979
|
+
* @returns The initial value for the state variable.
|
|
1980
|
+
*/
|
|
1981
|
+
function getInitialValue(value, initialValue, defaultValue, defaultStateValue) {
|
|
2048
1982
|
if (value !== undefined) {
|
|
2049
1983
|
return value;
|
|
2050
1984
|
}
|
|
2051
|
-
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
2052
1985
|
if (initialValue !== undefined) {
|
|
2053
1986
|
return initialValue;
|
|
2054
1987
|
}
|
|
2055
|
-
|
|
1988
|
+
if (defaultValue !== undefined) {
|
|
1989
|
+
return defaultValue;
|
|
1990
|
+
}
|
|
1991
|
+
return defaultStateValue;
|
|
2056
1992
|
}
|
|
2057
1993
|
|
|
2058
1994
|
/**
|
|
2059
1995
|
* Debounced call for updating the a11y message.
|
|
2060
1996
|
*/
|
|
2061
|
-
var updateA11yStatus = debounce
|
|
1997
|
+
var updateA11yStatus = debounce(function (status, document) {
|
|
2062
1998
|
setStatus(status, document);
|
|
2063
1999
|
}, 200);
|
|
2064
2000
|
|
|
@@ -2094,7 +2030,7 @@
|
|
|
2094
2030
|
}
|
|
2095
2031
|
|
|
2096
2032
|
// Shared between useSelect, useCombobox, Downshift.
|
|
2097
|
-
var
|
|
2033
|
+
var dropdownPropTypes = _extends({}, propTypes$4, {
|
|
2098
2034
|
getA11yStatusMessage: PropTypes.func,
|
|
2099
2035
|
highlightedIndex: PropTypes.number,
|
|
2100
2036
|
defaultHighlightedIndex: PropTypes.number,
|
|
@@ -2117,62 +2053,145 @@
|
|
|
2117
2053
|
scrollIntoView: PropTypes.func
|
|
2118
2054
|
});
|
|
2119
2055
|
|
|
2120
|
-
var
|
|
2056
|
+
var dropdownDefaultProps = {
|
|
2121
2057
|
itemToString: function itemToString(item) {
|
|
2122
2058
|
return item ? String(item) : '';
|
|
2123
2059
|
},
|
|
2124
2060
|
itemToKey: function itemToKey(item) {
|
|
2125
2061
|
return item;
|
|
2126
2062
|
},
|
|
2127
|
-
|
|
2063
|
+
isItemDisabled: function isItemDisabled(_item) {
|
|
2064
|
+
return false;
|
|
2065
|
+
},
|
|
2066
|
+
stateReducer: function stateReducer(_state, actionAndChanges) {
|
|
2067
|
+
return actionAndChanges.changes;
|
|
2068
|
+
},
|
|
2128
2069
|
scrollIntoView: scrollIntoView,
|
|
2129
2070
|
environment: /* istanbul ignore next (ssr) */
|
|
2130
2071
|
typeof window === 'undefined' || false ? undefined : window
|
|
2131
2072
|
};
|
|
2132
2073
|
|
|
2133
|
-
var
|
|
2074
|
+
var dropdownDefaultStateValues = {
|
|
2134
2075
|
highlightedIndex: -1,
|
|
2135
2076
|
isOpen: false,
|
|
2136
2077
|
selectedItem: null,
|
|
2137
2078
|
inputValue: ''
|
|
2138
2079
|
};
|
|
2139
2080
|
|
|
2140
|
-
//
|
|
2141
|
-
var
|
|
2142
|
-
|
|
2143
|
-
|
|
2081
|
+
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
2082
|
+
var SafeReact$1 = _extends({}, React__namespace);
|
|
2083
|
+
var reactUseId$1 = SafeReact$1.useId;
|
|
2084
|
+
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
2085
|
+
function useElementIdsR18$1(_ref) {
|
|
2086
|
+
var id = _ref.id,
|
|
2087
|
+
labelId = _ref.labelId,
|
|
2088
|
+
menuId = _ref.menuId,
|
|
2089
|
+
getItemId = _ref.getItemId,
|
|
2090
|
+
toggleButtonId = _ref.toggleButtonId,
|
|
2091
|
+
inputId = _ref.inputId;
|
|
2092
|
+
var reactId = "downshift-" + reactUseId$1();
|
|
2093
|
+
if (!id) {
|
|
2094
|
+
id = reactId;
|
|
2095
|
+
}
|
|
2096
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
2097
|
+
return {
|
|
2098
|
+
labelId: labelId != null ? labelId : id + "-label",
|
|
2099
|
+
menuId: menuId != null ? menuId : id + "-menu",
|
|
2100
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2101
|
+
return id + "-item-" + index;
|
|
2102
|
+
},
|
|
2103
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
2104
|
+
inputId: inputId != null ? inputId : id + "-input"
|
|
2105
|
+
};
|
|
2106
|
+
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
2107
|
+
return elementIds;
|
|
2144
2108
|
}
|
|
2145
|
-
function
|
|
2146
|
-
var
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2109
|
+
function useElementIdsLegacy$1(_ref2) {
|
|
2110
|
+
var id = _ref2.id,
|
|
2111
|
+
labelId = _ref2.labelId,
|
|
2112
|
+
menuId = _ref2.menuId,
|
|
2113
|
+
getItemId = _ref2.getItemId,
|
|
2114
|
+
toggleButtonId = _ref2.toggleButtonId,
|
|
2115
|
+
inputId = _ref2.inputId;
|
|
2116
|
+
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
2117
|
+
var baseId = baseIdRef.current;
|
|
2118
|
+
var elementIds = React__namespace.useMemo(function () {
|
|
2119
|
+
return {
|
|
2120
|
+
labelId: labelId != null ? labelId : baseId + "-label",
|
|
2121
|
+
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
2122
|
+
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2123
|
+
return baseId + "-item-" + index;
|
|
2124
|
+
},
|
|
2125
|
+
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
2126
|
+
inputId: inputId != null ? inputId : baseId + "-input"
|
|
2127
|
+
};
|
|
2128
|
+
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
2129
|
+
return elementIds;
|
|
2158
2130
|
}
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* Returns the new highlightedIndex based on the defaultHighlightedIndex prop, if it's not disabled.
|
|
2134
|
+
*
|
|
2135
|
+
* @param props Props passed to the hook.
|
|
2136
|
+
* @returns The highlighted index.
|
|
2137
|
+
*/
|
|
2138
|
+
function getDefaultHighlightedIndex(items, isItemDisabled, defaultHighlightedIndex) {
|
|
2139
|
+
var highlightedIndex = getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
2140
|
+
if (items[highlightedIndex] && isItemDisabled(items[highlightedIndex], highlightedIndex)) {
|
|
2141
|
+
return -1;
|
|
2142
|
+
}
|
|
2143
|
+
return highlightedIndex;
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
/**
|
|
2147
|
+
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
2148
|
+
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
2149
|
+
*
|
|
2150
|
+
* @param props The Dropdown props.
|
|
2151
|
+
* @param highlightedIndex The index from the state.
|
|
2152
|
+
* @param inputValue Also return the input value for state.
|
|
2153
|
+
* @returns The changes for the state.
|
|
2154
|
+
*/
|
|
2155
|
+
function getChangesOnSelection(items, itemToString, defaultIsOpen, defaultHighlightedIndex, highlightedIndex, inputValue) {
|
|
2156
|
+
var shouldSelect = items.length && highlightedIndex >= 0;
|
|
2157
|
+
return _extends({
|
|
2158
|
+
isOpen: false,
|
|
2159
|
+
highlightedIndex: -1
|
|
2160
|
+
}, shouldSelect && _extends({
|
|
2161
|
+
selectedItem: items[highlightedIndex],
|
|
2162
|
+
isOpen: getDefaultValue(defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2163
|
+
highlightedIndex: getDefaultValue(defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex)
|
|
2164
|
+
}, inputValue && {
|
|
2165
|
+
inputValue: itemToString(items[highlightedIndex])
|
|
2166
|
+
}));
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
/* eslint-disable max-params */
|
|
2170
|
+
/**
|
|
2171
|
+
* Returns the highlighted index when the menu is opened.
|
|
2172
|
+
* Takes into account the initialHighlightedIndex, defaultHighlightedIndex,
|
|
2173
|
+
* selectedItem, and the open direction offset.
|
|
2174
|
+
*
|
|
2175
|
+
* @param items The list of items.
|
|
2176
|
+
* @param initialHighlightedIndex The initial highlighted index prop.
|
|
2177
|
+
* @param defaultHighlightedIndex The default highlighted index prop.
|
|
2178
|
+
* @param isItemDisabled Callback to determine if an item is disabled.
|
|
2179
|
+
* @param itemToKey Callback to get a unique key from an item.
|
|
2180
|
+
* @param selectedItem The currently selected item.
|
|
2181
|
+
* @param highlightedIndex The current highlighted index from state.
|
|
2182
|
+
* @param offset The direction of navigation: positive opens downward, negative opens upward.
|
|
2183
|
+
* @returns The new highlighted index.
|
|
2184
|
+
*/
|
|
2185
|
+
function getHighlightedIndexOnOpen(items, initialHighlightedIndex, defaultHighlightedIndex, isItemDisabled, itemToKey, selectedItem, highlightedIndex, offset) {
|
|
2167
2186
|
if (items.length === 0) {
|
|
2168
2187
|
return -1;
|
|
2169
2188
|
}
|
|
2170
2189
|
|
|
2171
2190
|
// initialHighlightedIndex will give value to highlightedIndex on initial state only.
|
|
2172
|
-
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
2191
|
+
if (initialHighlightedIndex !== undefined && highlightedIndex === initialHighlightedIndex && items[initialHighlightedIndex] && !isItemDisabled(items[initialHighlightedIndex], initialHighlightedIndex)) {
|
|
2173
2192
|
return initialHighlightedIndex;
|
|
2174
2193
|
}
|
|
2175
|
-
if (defaultHighlightedIndex !== undefined && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
2194
|
+
if (defaultHighlightedIndex !== undefined && items[defaultHighlightedIndex] && !isItemDisabled(items[defaultHighlightedIndex], defaultHighlightedIndex)) {
|
|
2176
2195
|
return defaultHighlightedIndex;
|
|
2177
2196
|
}
|
|
2178
2197
|
if (selectedItem) {
|
|
@@ -2180,21 +2199,71 @@
|
|
|
2180
2199
|
return itemToKey(selectedItem) === itemToKey(item);
|
|
2181
2200
|
});
|
|
2182
2201
|
}
|
|
2183
|
-
if (offset < 0 && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
2202
|
+
if (offset < 0 && items[items.length - 1] && !isItemDisabled(items[items.length - 1], items.length - 1)) {
|
|
2184
2203
|
return items.length - 1;
|
|
2185
2204
|
}
|
|
2186
|
-
if (offset > 0 && !isItemDisabled(items[0], 0)) {
|
|
2205
|
+
if (offset > 0 && items[0] && !isItemDisabled(items[0], 0)) {
|
|
2187
2206
|
return 0;
|
|
2188
2207
|
}
|
|
2189
2208
|
return -1;
|
|
2190
2209
|
}
|
|
2210
|
+
|
|
2211
|
+
function getInitialState$3(props) {
|
|
2212
|
+
var selectedItem = getInitialValue(props.selectedItem, props.initialSelectedItem, props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem);
|
|
2213
|
+
var isOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
2214
|
+
var highlightedIndex = getInitialHighlightedIndex(props);
|
|
2215
|
+
var inputValue = getInitialValue(props.inputValue, props.initialInputValue, props.defaultInputValue, dropdownDefaultStateValues.inputValue);
|
|
2216
|
+
return {
|
|
2217
|
+
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.findIndex(function (item) {
|
|
2218
|
+
return props.itemToKey(item) === props.itemToKey(selectedItem);
|
|
2219
|
+
}) : highlightedIndex,
|
|
2220
|
+
isOpen: isOpen,
|
|
2221
|
+
selectedItem: selectedItem,
|
|
2222
|
+
inputValue: inputValue
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
/**
|
|
2227
|
+
* Returns the new highlightedIndex based on the initialHighlightedIndex prop, if not disabled.
|
|
2228
|
+
* @param props Props from useCombobox or useSelect.
|
|
2229
|
+
* @returns The highlighted index.
|
|
2230
|
+
*/
|
|
2231
|
+
function getInitialHighlightedIndex(props) {
|
|
2232
|
+
var highlightedIndex = getInitialValue(props.highlightedIndex, props.initialHighlightedIndex, props.defaultHighlightedIndex, dropdownDefaultStateValues.highlightedIndex);
|
|
2233
|
+
if (highlightedIndex > -1 && props.items[highlightedIndex] && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2234
|
+
return -1;
|
|
2235
|
+
}
|
|
2236
|
+
return highlightedIndex;
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2240
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
2241
|
+
var useControlPropsValidator = noop;
|
|
2242
|
+
/* istanbul ignore next */
|
|
2243
|
+
{
|
|
2244
|
+
useControlPropsValidator = function useControlPropsValidator(_ref) {
|
|
2245
|
+
var props = _ref.props,
|
|
2246
|
+
state = _ref.state;
|
|
2247
|
+
// used for checking when props are moving from controlled to uncontrolled.
|
|
2248
|
+
var prevPropsRef = React__namespace.useRef(props);
|
|
2249
|
+
var isInitialMount = useIsInitialMount();
|
|
2250
|
+
React__namespace.useEffect(function () {
|
|
2251
|
+
if (isInitialMount) {
|
|
2252
|
+
return;
|
|
2253
|
+
}
|
|
2254
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2255
|
+
prevPropsRef.current = props;
|
|
2256
|
+
}, [state, props, isInitialMount]);
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2191
2260
|
/**
|
|
2192
2261
|
* Tracks mouse and touch events, such as mouseDown, touchMove and touchEnd.
|
|
2193
2262
|
*
|
|
2194
|
-
* @param
|
|
2195
|
-
* @param
|
|
2196
|
-
* @param
|
|
2197
|
-
* @returns
|
|
2263
|
+
* @param environment The environment to add the event listeners to, for instance window.
|
|
2264
|
+
* @param handleBlur The function that is called if mouseDown or touchEnd occured outside the downshiftElements.
|
|
2265
|
+
* @param downshiftRefs The refs for the elements that should not trigger a blur action from mouseDown or touchEnd.
|
|
2266
|
+
* @returns The mouse and touch events information.
|
|
2198
2267
|
*/
|
|
2199
2268
|
function useMouseAndTouchTracker(environment, handleBlur, downshiftRefs) {
|
|
2200
2269
|
var mouseAndTouchTrackersRef = React__namespace.useRef({
|
|
@@ -2258,8 +2327,8 @@
|
|
|
2258
2327
|
/**
|
|
2259
2328
|
* Custom hook that checks if getter props are called correctly.
|
|
2260
2329
|
*
|
|
2261
|
-
* @param
|
|
2262
|
-
* @returns
|
|
2330
|
+
* @param propKeys Getter prop names to be handled.
|
|
2331
|
+
* @returns Setter function called inside getter props to set call information.
|
|
2263
2332
|
*/
|
|
2264
2333
|
/* istanbul ignore next */
|
|
2265
2334
|
{
|
|
@@ -2298,117 +2367,55 @@
|
|
|
2298
2367
|
elementRef: elementRef
|
|
2299
2368
|
};
|
|
2300
2369
|
}, []);
|
|
2301
|
-
return setGetterPropCallInfo;
|
|
2302
|
-
};
|
|
2303
|
-
}
|
|
2304
|
-
function useScrollIntoView(_ref) {
|
|
2305
|
-
var highlightedIndex = _ref.highlightedIndex,
|
|
2306
|
-
isOpen = _ref.isOpen,
|
|
2307
|
-
itemRefs = _ref.itemRefs,
|
|
2308
|
-
getItemNodeFromIndex = _ref.getItemNodeFromIndex,
|
|
2309
|
-
menuElement = _ref.menuElement,
|
|
2310
|
-
scrollIntoViewProp = _ref.scrollIntoView;
|
|
2311
|
-
// used not to scroll on highlight by mouse.
|
|
2312
|
-
var shouldScrollRef = React__namespace.useRef(true);
|
|
2313
|
-
// Scroll on highlighted item if change comes from keyboard.
|
|
2314
|
-
useIsomorphicLayoutEffect(function () {
|
|
2315
|
-
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2316
|
-
return;
|
|
2317
|
-
}
|
|
2318
|
-
if (shouldScrollRef.current === false) {
|
|
2319
|
-
shouldScrollRef.current = true;
|
|
2320
|
-
} else {
|
|
2321
|
-
scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
|
|
2322
|
-
}
|
|
2323
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2324
|
-
}, [highlightedIndex]);
|
|
2325
|
-
return shouldScrollRef;
|
|
2326
|
-
}
|
|
2327
|
-
|
|
2328
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
2329
|
-
var useControlPropsValidator = noop;
|
|
2330
|
-
/* istanbul ignore next */
|
|
2331
|
-
{
|
|
2332
|
-
useControlPropsValidator = function useControlPropsValidator(_ref2) {
|
|
2333
|
-
var props = _ref2.props,
|
|
2334
|
-
state = _ref2.state;
|
|
2335
|
-
// used for checking when props are moving from controlled to uncontrolled.
|
|
2336
|
-
var prevPropsRef = React__namespace.useRef(props);
|
|
2337
|
-
var isInitialMount = useIsInitialMount();
|
|
2338
|
-
React__namespace.useEffect(function () {
|
|
2339
|
-
if (isInitialMount) {
|
|
2340
|
-
return;
|
|
2341
|
-
}
|
|
2342
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2343
|
-
prevPropsRef.current = props;
|
|
2344
|
-
}, [state, props, isInitialMount]);
|
|
2345
|
-
};
|
|
2346
|
-
}
|
|
2347
|
-
|
|
2348
|
-
/**
|
|
2349
|
-
* Handles selection on Enter / Alt + ArrowUp. Closes the menu and resets the highlighted index, unless there is a highlighted.
|
|
2350
|
-
* In that case, selects the item and resets to defaults for open state and highlighted idex.
|
|
2351
|
-
* @param {Object} props The useCombobox props.
|
|
2352
|
-
* @param {number} highlightedIndex The index from the state.
|
|
2353
|
-
* @param {boolean} inputValue Also return the input value for state.
|
|
2354
|
-
* @returns The changes for the state.
|
|
2355
|
-
*/
|
|
2356
|
-
function getChangesOnSelection(props, highlightedIndex, inputValue) {
|
|
2357
|
-
var _props$items;
|
|
2358
|
-
if (inputValue === void 0) {
|
|
2359
|
-
inputValue = true;
|
|
2360
|
-
}
|
|
2361
|
-
var shouldSelect = ((_props$items = props.items) == null ? void 0 : _props$items.length) && highlightedIndex >= 0;
|
|
2362
|
-
return _extends({
|
|
2363
|
-
isOpen: false,
|
|
2364
|
-
highlightedIndex: -1
|
|
2365
|
-
}, shouldSelect && _extends({
|
|
2366
|
-
selectedItem: props.items[highlightedIndex],
|
|
2367
|
-
isOpen: getDefaultValue$1(props, 'isOpen', defaultStateValues$1),
|
|
2368
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex', defaultStateValues$1)
|
|
2369
|
-
}, inputValue && {
|
|
2370
|
-
inputValue: props.itemToString(props.items[highlightedIndex])
|
|
2371
|
-
}));
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
/**
|
|
2375
|
-
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
2376
|
-
* Used by useSelect and useCombobox.
|
|
2377
|
-
*
|
|
2378
|
-
* @param {Object} prevState
|
|
2379
|
-
* @param {Object} newState
|
|
2380
|
-
* @returns {boolean} Wheather the states are deeply equal.
|
|
2381
|
-
*/
|
|
2382
|
-
function isDropdownsStateEqual(prevState, newState) {
|
|
2383
|
-
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2370
|
+
return setGetterPropCallInfo;
|
|
2371
|
+
};
|
|
2384
2372
|
}
|
|
2385
2373
|
|
|
2374
|
+
// istanbul ignore next
|
|
2375
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? React__namespace.useLayoutEffect : React__namespace.useEffect;
|
|
2376
|
+
|
|
2386
2377
|
/**
|
|
2387
|
-
*
|
|
2388
|
-
*
|
|
2389
|
-
* @param
|
|
2390
|
-
* @
|
|
2378
|
+
* Utility hook that scrolls an item from a menu into view.
|
|
2379
|
+
* @param scrollIntoView The function that does the scroll.
|
|
2380
|
+
* @param highlightedIndex The index of the item that should be scrolled.
|
|
2381
|
+
* @param isOpen If the menu is open or not.
|
|
2382
|
+
* @param menuElement The menu element.
|
|
2383
|
+
* @param itemElements The object containing item elements.
|
|
2384
|
+
* @param getItemId The function to get the item id from index.
|
|
2385
|
+
* @returns Function that when called prevents the scroll.
|
|
2391
2386
|
*/
|
|
2392
|
-
function
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2387
|
+
function useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuElement, itemElements, getItemId) {
|
|
2388
|
+
// used not to scroll on highlight by mouse.
|
|
2389
|
+
var shouldScrollRef = React__namespace.useRef(true);
|
|
2390
|
+
// Scroll on highlighted item if change comes from keyboard.
|
|
2391
|
+
useIsomorphicLayoutEffect(function () {
|
|
2392
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemElements).length) {
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
if (shouldScrollRef.current) {
|
|
2396
|
+
var itemElement = itemElements[getItemId(highlightedIndex)];
|
|
2397
|
+
if (itemElement && menuElement) {
|
|
2398
|
+
scrollIntoView(itemElement, menuElement);
|
|
2399
|
+
}
|
|
2400
|
+
} else {
|
|
2401
|
+
shouldScrollRef.current = true;
|
|
2402
|
+
}
|
|
2403
|
+
}, [highlightedIndex]);
|
|
2404
|
+
return React__namespace.useCallback(function preventScroll() {
|
|
2405
|
+
shouldScrollRef.current = false;
|
|
2406
|
+
}, []);
|
|
2398
2407
|
}
|
|
2399
2408
|
|
|
2400
2409
|
/**
|
|
2401
|
-
*
|
|
2410
|
+
* Check if a state is equal for dropdowns, by comparing isOpen, inputValue, highlightedIndex and selected item.
|
|
2411
|
+
* Used by useSelect and useCombobox.
|
|
2402
2412
|
*
|
|
2403
|
-
* @param
|
|
2404
|
-
* @
|
|
2413
|
+
* @param prevState The previous dropdown state.
|
|
2414
|
+
* @param newState The new dropdown state.
|
|
2415
|
+
* @returns Wheather the states are deeply equal.
|
|
2405
2416
|
*/
|
|
2406
|
-
function
|
|
2407
|
-
|
|
2408
|
-
if (highlightedIndex > -1 && props.isItemDisabled(props.items[highlightedIndex], highlightedIndex)) {
|
|
2409
|
-
return -1;
|
|
2410
|
-
}
|
|
2411
|
-
return highlightedIndex;
|
|
2417
|
+
function isDropdownStateEqual(prevState, newState) {
|
|
2418
|
+
return prevState.isOpen === newState.isOpen && prevState.inputValue === newState.inputValue && prevState.highlightedIndex === newState.highlightedIndex && prevState.selectedItem === newState.selectedItem;
|
|
2412
2419
|
}
|
|
2413
2420
|
|
|
2414
2421
|
function downshiftCommonReducer(state, props, action, stateChangeTypes) {
|
|
@@ -2429,13 +2436,13 @@
|
|
|
2429
2436
|
case stateChangeTypes.FunctionToggleMenu:
|
|
2430
2437
|
changes = {
|
|
2431
2438
|
isOpen: !state.isOpen,
|
|
2432
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
2439
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2433
2440
|
};
|
|
2434
2441
|
break;
|
|
2435
2442
|
case stateChangeTypes.FunctionOpenMenu:
|
|
2436
2443
|
changes = {
|
|
2437
2444
|
isOpen: true,
|
|
2438
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
|
|
2445
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
2439
2446
|
};
|
|
2440
2447
|
break;
|
|
2441
2448
|
case stateChangeTypes.FunctionCloseMenu:
|
|
@@ -2444,9 +2451,12 @@
|
|
|
2444
2451
|
};
|
|
2445
2452
|
break;
|
|
2446
2453
|
case stateChangeTypes.FunctionSetHighlightedIndex:
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2454
|
+
{
|
|
2455
|
+
var highlightedIndex = action.highlightedIndex;
|
|
2456
|
+
changes = {
|
|
2457
|
+
highlightedIndex: props.isItemDisabled(props.items[highlightedIndex], highlightedIndex) ? -1 : highlightedIndex
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2450
2460
|
break;
|
|
2451
2461
|
case stateChangeTypes.FunctionSetInputValue:
|
|
2452
2462
|
changes = {
|
|
@@ -2455,10 +2465,10 @@
|
|
|
2455
2465
|
break;
|
|
2456
2466
|
case stateChangeTypes.FunctionReset:
|
|
2457
2467
|
changes = {
|
|
2458
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2459
|
-
isOpen: getDefaultValue
|
|
2460
|
-
selectedItem: getDefaultValue
|
|
2461
|
-
inputValue: getDefaultValue
|
|
2468
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2469
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2470
|
+
selectedItem: getDefaultValue(props.defaultSelectedItem, dropdownDefaultStateValues.selectedItem),
|
|
2471
|
+
inputValue: getDefaultValue(props.defaultInputValue, dropdownDefaultStateValues.inputValue)
|
|
2462
2472
|
};
|
|
2463
2473
|
break;
|
|
2464
2474
|
default:
|
|
@@ -2468,17 +2478,11 @@
|
|
|
2468
2478
|
}
|
|
2469
2479
|
/* eslint-enable complexity */
|
|
2470
2480
|
|
|
2471
|
-
var propTypes$3 = _extends({},
|
|
2481
|
+
var propTypes$3 = _extends({}, dropdownPropTypes, {
|
|
2472
2482
|
items: PropTypes.array.isRequired,
|
|
2473
2483
|
isItemDisabled: PropTypes.func
|
|
2474
2484
|
});
|
|
2475
2485
|
|
|
2476
|
-
var defaultProps$2 = _extends({}, defaultProps$3, {
|
|
2477
|
-
isItemDisabled: function isItemDisabled() {
|
|
2478
|
-
return false;
|
|
2479
|
-
}
|
|
2480
|
-
});
|
|
2481
|
-
|
|
2482
2486
|
function getItemIndexByCharacterKey(_ref) {
|
|
2483
2487
|
var keysSoFar = _ref.keysSoFar,
|
|
2484
2488
|
highlightedIndex = _ref.highlightedIndex,
|
|
@@ -2547,16 +2551,15 @@
|
|
|
2547
2551
|
});
|
|
2548
2552
|
|
|
2549
2553
|
/* eslint-disable complexity */
|
|
2550
|
-
function downshiftSelectReducer(state,
|
|
2551
|
-
var _props$items;
|
|
2554
|
+
function downshiftSelectReducer(state, action) {
|
|
2552
2555
|
var type = action.type,
|
|
2553
|
-
|
|
2556
|
+
props = action.props;
|
|
2554
2557
|
var changes;
|
|
2555
2558
|
switch (type) {
|
|
2556
2559
|
case ItemClick$1:
|
|
2557
2560
|
changes = {
|
|
2558
|
-
isOpen: getDefaultValue
|
|
2559
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
2561
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
2562
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
2560
2563
|
selectedItem: props.items[action.index]
|
|
2561
2564
|
};
|
|
2562
2565
|
break;
|
|
@@ -2583,7 +2586,8 @@
|
|
|
2583
2586
|
break;
|
|
2584
2587
|
case ToggleButtonKeyDownArrowDown:
|
|
2585
2588
|
{
|
|
2586
|
-
var
|
|
2589
|
+
var altKey = action.altKey;
|
|
2590
|
+
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);
|
|
2587
2591
|
changes = {
|
|
2588
2592
|
highlightedIndex: _highlightedIndex,
|
|
2589
2593
|
isOpen: true
|
|
@@ -2591,20 +2595,23 @@
|
|
|
2591
2595
|
}
|
|
2592
2596
|
break;
|
|
2593
2597
|
case ToggleButtonKeyDownArrowUp:
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
highlightedIndex:
|
|
2600
|
-
|
|
2601
|
-
|
|
2598
|
+
{
|
|
2599
|
+
var _altKey = action.altKey;
|
|
2600
|
+
if (state.isOpen && _altKey) {
|
|
2601
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2602
|
+
} else {
|
|
2603
|
+
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);
|
|
2604
|
+
changes = {
|
|
2605
|
+
highlightedIndex: _highlightedIndex2,
|
|
2606
|
+
isOpen: true
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2602
2609
|
}
|
|
2603
2610
|
break;
|
|
2604
2611
|
// only triggered when menu is open.
|
|
2605
2612
|
case ToggleButtonKeyDownEnter:
|
|
2606
2613
|
case ToggleButtonKeyDownSpaceButton:
|
|
2607
|
-
changes = getChangesOnSelection(props, state.highlightedIndex, false);
|
|
2614
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, false);
|
|
2608
2615
|
break;
|
|
2609
2616
|
case ToggleButtonKeyDownHome:
|
|
2610
2617
|
changes = {
|
|
@@ -2638,7 +2645,7 @@
|
|
|
2638
2645
|
changes = _extends({
|
|
2639
2646
|
isOpen: false,
|
|
2640
2647
|
highlightedIndex: -1
|
|
2641
|
-
}, state.highlightedIndex >= 0 &&
|
|
2648
|
+
}, state.highlightedIndex >= 0 && props.items.length && {
|
|
2642
2649
|
selectedItem: props.items[state.highlightedIndex]
|
|
2643
2650
|
});
|
|
2644
2651
|
break;
|
|
@@ -2654,60 +2661,9 @@
|
|
|
2654
2661
|
}
|
|
2655
2662
|
/* eslint-enable complexity */
|
|
2656
2663
|
|
|
2657
|
-
// https://github.com/downshift-js/downshift/issues/1674#issuecomment-3924320872
|
|
2658
|
-
var SafeReact$1 = _extends({}, React__namespace);
|
|
2659
|
-
var reactUseId$1 = SafeReact$1.useId;
|
|
2660
|
-
var useElementIds$1 = typeof reactUseId$1 === 'function' ? useElementIdsR18$1 : useElementIdsLegacy$1;
|
|
2661
|
-
function useElementIdsR18$1(_ref) {
|
|
2662
|
-
var id = _ref.id,
|
|
2663
|
-
labelId = _ref.labelId,
|
|
2664
|
-
menuId = _ref.menuId,
|
|
2665
|
-
getItemId = _ref.getItemId,
|
|
2666
|
-
toggleButtonId = _ref.toggleButtonId,
|
|
2667
|
-
inputId = _ref.inputId;
|
|
2668
|
-
var reactId = "downshift-" + reactUseId$1();
|
|
2669
|
-
if (!id) {
|
|
2670
|
-
id = reactId;
|
|
2671
|
-
}
|
|
2672
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2673
|
-
return {
|
|
2674
|
-
labelId: labelId != null ? labelId : id + "-label",
|
|
2675
|
-
menuId: menuId != null ? menuId : id + "-menu",
|
|
2676
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2677
|
-
return id + "-item-" + index;
|
|
2678
|
-
},
|
|
2679
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : id + "-toggle-button",
|
|
2680
|
-
inputId: inputId != null ? inputId : id + "-input"
|
|
2681
|
-
};
|
|
2682
|
-
}, [getItemId, id, inputId, labelId, menuId, toggleButtonId]);
|
|
2683
|
-
return elementIds;
|
|
2684
|
-
}
|
|
2685
|
-
function useElementIdsLegacy$1(_ref2) {
|
|
2686
|
-
var id = _ref2.id,
|
|
2687
|
-
labelId = _ref2.labelId,
|
|
2688
|
-
menuId = _ref2.menuId,
|
|
2689
|
-
getItemId = _ref2.getItemId,
|
|
2690
|
-
toggleButtonId = _ref2.toggleButtonId,
|
|
2691
|
-
inputId = _ref2.inputId;
|
|
2692
|
-
var baseIdRef = React__namespace.useRef(id != null ? id : "downshift-" + generateId());
|
|
2693
|
-
var baseId = baseIdRef.current;
|
|
2694
|
-
var elementIds = React__namespace.useMemo(function () {
|
|
2695
|
-
return {
|
|
2696
|
-
labelId: labelId != null ? labelId : baseId + "-label",
|
|
2697
|
-
menuId: menuId != null ? menuId : baseId + "-menu",
|
|
2698
|
-
getItemId: getItemId != null ? getItemId : function (index) {
|
|
2699
|
-
return baseId + "-item-" + index;
|
|
2700
|
-
},
|
|
2701
|
-
toggleButtonId: toggleButtonId != null ? toggleButtonId : baseId + "-toggle-button",
|
|
2702
|
-
inputId: inputId != null ? inputId : baseId + "-input"
|
|
2703
|
-
};
|
|
2704
|
-
}, [getItemId, inputId, labelId, menuId, toggleButtonId, baseId]);
|
|
2705
|
-
return elementIds;
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
2664
|
var _excluded$3 = ["onClick"],
|
|
2709
|
-
_excluded2$3 = ["onMouseLeave", "refKey", "ref"],
|
|
2710
|
-
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2665
|
+
_excluded2$3 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
2666
|
+
_excluded3$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref", "disabled"],
|
|
2711
2667
|
_excluded4$1 = ["item", "index", "onMouseMove", "onClick", "onMouseDown", "onPress", "refKey", "disabled", "ref"];
|
|
2712
2668
|
useSelect.stateChangeTypes = stateChangeTypes$3;
|
|
2713
2669
|
function useSelect(userProps) {
|
|
@@ -2716,22 +2672,23 @@
|
|
|
2716
2672
|
}
|
|
2717
2673
|
validatePropTypes$1(userProps, useSelect, propTypes$3);
|
|
2718
2674
|
// Props defaults and destructuring.
|
|
2719
|
-
var props = _extends({},
|
|
2675
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
2720
2676
|
var scrollIntoView = props.scrollIntoView,
|
|
2721
2677
|
environment = props.environment,
|
|
2722
2678
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
2723
2679
|
// Initial state depending on controlled props.
|
|
2724
|
-
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3,
|
|
2680
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, props, getInitialState$3, isDropdownStateEqual),
|
|
2725
2681
|
state = _useControlledReducer[0],
|
|
2726
2682
|
dispatch = _useControlledReducer[1];
|
|
2727
2683
|
var isOpen = state.isOpen,
|
|
2728
2684
|
highlightedIndex = state.highlightedIndex,
|
|
2729
2685
|
selectedItem = state.selectedItem,
|
|
2730
2686
|
inputValue = state.inputValue;
|
|
2731
|
-
|
|
2687
|
+
|
|
2688
|
+
// Element refs.
|
|
2732
2689
|
var toggleButtonRef = React.useRef(null);
|
|
2733
2690
|
var menuRef = React.useRef(null);
|
|
2734
|
-
var
|
|
2691
|
+
var itemsRef = React.useRef({});
|
|
2735
2692
|
|
|
2736
2693
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2737
2694
|
var clearTimeoutRef = React.useRef(null);
|
|
@@ -2743,24 +2700,12 @@
|
|
|
2743
2700
|
props: props
|
|
2744
2701
|
});
|
|
2745
2702
|
|
|
2746
|
-
// Some utils.
|
|
2747
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
2748
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2749
|
-
}, [elementIds]);
|
|
2750
|
-
|
|
2751
2703
|
// Effects.
|
|
2752
2704
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
2753
2705
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
2754
2706
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2755
|
-
var
|
|
2756
|
-
|
|
2757
|
-
highlightedIndex: highlightedIndex,
|
|
2758
|
-
isOpen: isOpen,
|
|
2759
|
-
itemRefs: itemRefs,
|
|
2760
|
-
scrollIntoView: scrollIntoView,
|
|
2761
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2762
|
-
});
|
|
2763
|
-
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2707
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
2708
|
+
// Sets cleanup for the keysSoFar callback, debounced after 500ms.
|
|
2764
2709
|
React.useEffect(function () {
|
|
2765
2710
|
// init the clean function here as we need access to dispatch.
|
|
2766
2711
|
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
@@ -2772,7 +2717,8 @@
|
|
|
2772
2717
|
|
|
2773
2718
|
// Cancel any pending debounced calls on mount
|
|
2774
2719
|
return function () {
|
|
2775
|
-
|
|
2720
|
+
var _clearTimeoutRef$curr;
|
|
2721
|
+
(_clearTimeoutRef$curr = clearTimeoutRef.current) == null || _clearTimeoutRef$curr.cancel();
|
|
2776
2722
|
};
|
|
2777
2723
|
}, []);
|
|
2778
2724
|
// Invokes the keysSoFar callback set up above.
|
|
@@ -2780,7 +2726,7 @@
|
|
|
2780
2726
|
if (!inputValue) {
|
|
2781
2727
|
return;
|
|
2782
2728
|
}
|
|
2783
|
-
clearTimeoutRef.current(dispatch);
|
|
2729
|
+
clearTimeoutRef.current == null || clearTimeoutRef.current(dispatch);
|
|
2784
2730
|
}, [dispatch, inputValue]);
|
|
2785
2731
|
useControlPropsValidator({
|
|
2786
2732
|
props: props,
|
|
@@ -2788,7 +2734,7 @@
|
|
|
2788
2734
|
});
|
|
2789
2735
|
// Focus the toggle button on first render if required.
|
|
2790
2736
|
React.useEffect(function () {
|
|
2791
|
-
var focusOnOpen = getInitialValue
|
|
2737
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
2792
2738
|
if (focusOnOpen && toggleButtonRef.current) {
|
|
2793
2739
|
toggleButtonRef.current.focus();
|
|
2794
2740
|
}
|
|
@@ -2809,7 +2755,7 @@
|
|
|
2809
2755
|
// Reset itemRefs on close.
|
|
2810
2756
|
React.useEffect(function () {
|
|
2811
2757
|
if (!isOpen) {
|
|
2812
|
-
|
|
2758
|
+
itemsRef.current = {};
|
|
2813
2759
|
}
|
|
2814
2760
|
}, [isOpen]);
|
|
2815
2761
|
|
|
@@ -2894,50 +2840,11 @@
|
|
|
2894
2840
|
};
|
|
2895
2841
|
}, [dispatch, latest]);
|
|
2896
2842
|
|
|
2897
|
-
// Action functions.
|
|
2898
|
-
var toggleMenu = React.useCallback(function () {
|
|
2899
|
-
dispatch({
|
|
2900
|
-
type: FunctionToggleMenu$1
|
|
2901
|
-
});
|
|
2902
|
-
}, [dispatch]);
|
|
2903
|
-
var closeMenu = React.useCallback(function () {
|
|
2904
|
-
dispatch({
|
|
2905
|
-
type: FunctionCloseMenu$1
|
|
2906
|
-
});
|
|
2907
|
-
}, [dispatch]);
|
|
2908
|
-
var openMenu = React.useCallback(function () {
|
|
2909
|
-
dispatch({
|
|
2910
|
-
type: FunctionOpenMenu$1
|
|
2911
|
-
});
|
|
2912
|
-
}, [dispatch]);
|
|
2913
|
-
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
2914
|
-
dispatch({
|
|
2915
|
-
type: FunctionSetHighlightedIndex$1,
|
|
2916
|
-
highlightedIndex: newHighlightedIndex
|
|
2917
|
-
});
|
|
2918
|
-
}, [dispatch]);
|
|
2919
|
-
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
2920
|
-
dispatch({
|
|
2921
|
-
type: FunctionSelectItem$1,
|
|
2922
|
-
selectedItem: newSelectedItem
|
|
2923
|
-
});
|
|
2924
|
-
}, [dispatch]);
|
|
2925
|
-
var reset = React.useCallback(function () {
|
|
2926
|
-
dispatch({
|
|
2927
|
-
type: FunctionReset$2
|
|
2928
|
-
});
|
|
2929
|
-
}, [dispatch]);
|
|
2930
|
-
var setInputValue = React.useCallback(function (newInputValue) {
|
|
2931
|
-
dispatch({
|
|
2932
|
-
type: FunctionSetInputValue$1,
|
|
2933
|
-
inputValue: newInputValue
|
|
2934
|
-
});
|
|
2935
|
-
}, [dispatch]);
|
|
2936
2843
|
// Getter functions.
|
|
2937
|
-
var getLabelProps = React.useCallback(function (
|
|
2938
|
-
var _ref =
|
|
2844
|
+
var getLabelProps = React.useCallback(function (labelProps) {
|
|
2845
|
+
var _ref = labelProps != null ? labelProps : {},
|
|
2939
2846
|
onClick = _ref.onClick,
|
|
2940
|
-
|
|
2847
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
2941
2848
|
var labelHandleClick = function labelHandleClick() {
|
|
2942
2849
|
var _toggleButtonRef$curr;
|
|
2943
2850
|
(_toggleButtonRef$curr = toggleButtonRef.current) == null || _toggleButtonRef$curr.focus();
|
|
@@ -2946,17 +2853,18 @@
|
|
|
2946
2853
|
id: elementIds.labelId,
|
|
2947
2854
|
htmlFor: elementIds.toggleButtonId,
|
|
2948
2855
|
onClick: callAllEventHandlers(onClick, labelHandleClick)
|
|
2949
|
-
},
|
|
2856
|
+
}, rest);
|
|
2950
2857
|
}, [elementIds]);
|
|
2951
|
-
var getMenuProps = React.useCallback(function (
|
|
2858
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
2952
2859
|
var _extends2;
|
|
2953
|
-
var _ref2 =
|
|
2860
|
+
var _ref2 = menuProps != null ? menuProps : {},
|
|
2954
2861
|
onMouseLeave = _ref2.onMouseLeave,
|
|
2955
2862
|
_ref2$refKey = _ref2.refKey,
|
|
2956
2863
|
refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
|
2957
2864
|
ref = _ref2.ref,
|
|
2865
|
+
ariaLabel = _ref2['aria-label'],
|
|
2958
2866
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
2959
|
-
var _ref3 =
|
|
2867
|
+
var _ref3 = otherProps != null ? otherProps : {},
|
|
2960
2868
|
_ref3$suppressRefErro = _ref3.suppressRefError,
|
|
2961
2869
|
suppressRefError = _ref3$suppressRefErro === void 0 ? false : _ref3$suppressRefErro;
|
|
2962
2870
|
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
@@ -2967,11 +2875,11 @@
|
|
|
2967
2875
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2968
2876
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
2969
2877
|
menuRef.current = menuNode;
|
|
2970
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
2878
|
+
}), _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);
|
|
2971
2879
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2972
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
2880
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps, otherProps) {
|
|
2973
2881
|
var _extends3;
|
|
2974
|
-
var _ref4 =
|
|
2882
|
+
var _ref4 = toggleButtonProps != null ? toggleButtonProps : {},
|
|
2975
2883
|
onBlur = _ref4.onBlur,
|
|
2976
2884
|
onClick = _ref4.onClick;
|
|
2977
2885
|
_ref4.onPress;
|
|
@@ -2979,8 +2887,9 @@
|
|
|
2979
2887
|
_ref4$refKey = _ref4.refKey,
|
|
2980
2888
|
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
2981
2889
|
ref = _ref4.ref,
|
|
2890
|
+
disabled = _ref4.disabled,
|
|
2982
2891
|
rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2983
|
-
var _ref5 =
|
|
2892
|
+
var _ref5 = otherProps != null ? otherProps : {},
|
|
2984
2893
|
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
2985
2894
|
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
2986
2895
|
var latestState = latest.current.state;
|
|
@@ -2998,9 +2907,9 @@
|
|
|
2998
2907
|
};
|
|
2999
2908
|
var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
|
|
3000
2909
|
var key = normalizeArrowKey(event);
|
|
3001
|
-
if (key && toggleButtonKeyDownHandlers
|
|
2910
|
+
if (key && key in toggleButtonKeyDownHandlers) {
|
|
3002
2911
|
toggleButtonKeyDownHandlers[key](event);
|
|
3003
|
-
} else if (
|
|
2912
|
+
} else if (/^\S{1}$/.test(key)) {
|
|
3004
2913
|
dispatch({
|
|
3005
2914
|
type: ToggleButtonKeyDownCharacter,
|
|
3006
2915
|
key: key
|
|
@@ -3009,20 +2918,22 @@
|
|
|
3009
2918
|
};
|
|
3010
2919
|
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3011
2920
|
toggleButtonRef.current = toggleButtonNode;
|
|
3012
|
-
}), _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
|
|
3013
|
-
if (!
|
|
2921
|
+
}), _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);
|
|
2922
|
+
if (!disabled) {
|
|
3014
2923
|
/* istanbul ignore if (react-native) */
|
|
3015
2924
|
{
|
|
3016
|
-
|
|
3017
|
-
|
|
2925
|
+
Object.assign(toggleProps, {
|
|
2926
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick),
|
|
2927
|
+
onKeyDown: callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown)
|
|
2928
|
+
});
|
|
3018
2929
|
}
|
|
3019
2930
|
}
|
|
3020
2931
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
3021
2932
|
return toggleProps;
|
|
3022
2933
|
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, setGetterPropCallInfo, toggleButtonKeyDownHandlers]);
|
|
3023
|
-
var getItemProps = React.useCallback(function (
|
|
2934
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
3024
2935
|
var _extends4;
|
|
3025
|
-
var _ref6 =
|
|
2936
|
+
var _ref6 = itemProps != null ? itemProps : {},
|
|
3026
2937
|
itemProp = _ref6.item,
|
|
3027
2938
|
indexProp = _ref6.index,
|
|
3028
2939
|
onMouseMove = _ref6.onMouseMove,
|
|
@@ -3048,7 +2959,7 @@
|
|
|
3048
2959
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
3049
2960
|
return;
|
|
3050
2961
|
}
|
|
3051
|
-
|
|
2962
|
+
preventScroll();
|
|
3052
2963
|
dispatch({
|
|
3053
2964
|
type: ItemMouseMove$1,
|
|
3054
2965
|
index: index,
|
|
@@ -3065,21 +2976,61 @@
|
|
|
3065
2976
|
return e.preventDefault();
|
|
3066
2977
|
}; // keep focus on the toggle after item click select.
|
|
3067
2978
|
|
|
3068
|
-
var
|
|
2979
|
+
var resultItemProps = _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
3069
2980
|
if (itemNode) {
|
|
3070
|
-
|
|
2981
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
3071
2982
|
}
|
|
3072
|
-
}), _extends4['aria-disabled'] = disabled, _extends4['aria-selected'] = item === latestState.selectedItem, _extends4.id = elementIds.getItemId(index), _extends4.role = 'option', _extends4), rest);
|
|
2983
|
+
}), _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);
|
|
3073
2984
|
if (!disabled) {
|
|
3074
2985
|
/* istanbul ignore next (react-native) */
|
|
3075
2986
|
{
|
|
3076
|
-
|
|
2987
|
+
Object.assign(resultItemProps, {
|
|
2988
|
+
onClick: callAllEventHandlers(onClick, itemHandleClick)
|
|
2989
|
+
});
|
|
3077
2990
|
}
|
|
3078
2991
|
}
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
2992
|
+
return resultItemProps;
|
|
2993
|
+
}, [latest, elementIds, mouseAndTouchTrackers, preventScroll, dispatch]);
|
|
2994
|
+
|
|
2995
|
+
// Action functions.
|
|
2996
|
+
var toggleMenu = React.useCallback(function () {
|
|
2997
|
+
dispatch({
|
|
2998
|
+
type: FunctionToggleMenu$1
|
|
2999
|
+
});
|
|
3000
|
+
}, [dispatch]);
|
|
3001
|
+
var closeMenu = React.useCallback(function () {
|
|
3002
|
+
dispatch({
|
|
3003
|
+
type: FunctionCloseMenu$1
|
|
3004
|
+
});
|
|
3005
|
+
}, [dispatch]);
|
|
3006
|
+
var openMenu = React.useCallback(function () {
|
|
3007
|
+
dispatch({
|
|
3008
|
+
type: FunctionOpenMenu$1
|
|
3009
|
+
});
|
|
3010
|
+
}, [dispatch]);
|
|
3011
|
+
var setHighlightedIndex = React.useCallback(function (newHighlightedIndex) {
|
|
3012
|
+
dispatch({
|
|
3013
|
+
type: FunctionSetHighlightedIndex$1,
|
|
3014
|
+
highlightedIndex: newHighlightedIndex
|
|
3015
|
+
});
|
|
3016
|
+
}, [dispatch]);
|
|
3017
|
+
var selectItem = React.useCallback(function (newSelectedItem) {
|
|
3018
|
+
dispatch({
|
|
3019
|
+
type: FunctionSelectItem$1,
|
|
3020
|
+
selectedItem: newSelectedItem
|
|
3021
|
+
});
|
|
3022
|
+
}, [dispatch]);
|
|
3023
|
+
var reset = React.useCallback(function () {
|
|
3024
|
+
dispatch({
|
|
3025
|
+
type: FunctionReset$2
|
|
3026
|
+
});
|
|
3027
|
+
}, [dispatch]);
|
|
3028
|
+
var setInputValue = React.useCallback(function (newInputValue) {
|
|
3029
|
+
dispatch({
|
|
3030
|
+
type: FunctionSetInputValue$1,
|
|
3031
|
+
inputValue: newInputValue
|
|
3032
|
+
});
|
|
3033
|
+
}, [dispatch]);
|
|
3083
3034
|
return {
|
|
3084
3035
|
// prop getters.
|
|
3085
3036
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -3102,6 +3053,18 @@
|
|
|
3102
3053
|
};
|
|
3103
3054
|
}
|
|
3104
3055
|
|
|
3056
|
+
function getInitialState$2(props) {
|
|
3057
|
+
var initialState = getInitialState$3(props);
|
|
3058
|
+
var selectedItem = initialState.selectedItem;
|
|
3059
|
+
var inputValue = initialState.inputValue;
|
|
3060
|
+
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3061
|
+
inputValue = props.itemToString(selectedItem);
|
|
3062
|
+
}
|
|
3063
|
+
return _extends({}, initialState, {
|
|
3064
|
+
inputValue: inputValue
|
|
3065
|
+
});
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3105
3068
|
var InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
|
|
3106
3069
|
var InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
|
|
3107
3070
|
var InputKeyDownEscape = '__input_keydown_escape__' ;
|
|
@@ -3153,27 +3116,6 @@
|
|
|
3153
3116
|
ToggleButtonClick: ToggleButtonClick
|
|
3154
3117
|
});
|
|
3155
3118
|
|
|
3156
|
-
function getInitialState$2(props) {
|
|
3157
|
-
var initialState = getInitialState$3(props);
|
|
3158
|
-
var selectedItem = initialState.selectedItem;
|
|
3159
|
-
var inputValue = initialState.inputValue;
|
|
3160
|
-
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3161
|
-
inputValue = props.itemToString(selectedItem);
|
|
3162
|
-
}
|
|
3163
|
-
return _extends({}, initialState, {
|
|
3164
|
-
inputValue: inputValue
|
|
3165
|
-
});
|
|
3166
|
-
}
|
|
3167
|
-
var propTypes$2 = _extends({}, propTypes$4, {
|
|
3168
|
-
items: PropTypes.array.isRequired,
|
|
3169
|
-
isItemDisabled: PropTypes.func,
|
|
3170
|
-
inputValue: PropTypes.string,
|
|
3171
|
-
defaultInputValue: PropTypes.string,
|
|
3172
|
-
initialInputValue: PropTypes.string,
|
|
3173
|
-
inputId: PropTypes.string,
|
|
3174
|
-
onInputValueChange: PropTypes.func
|
|
3175
|
-
});
|
|
3176
|
-
|
|
3177
3119
|
/**
|
|
3178
3120
|
* The useCombobox version of useControlledReducer, which also
|
|
3179
3121
|
* checks if the controlled prop selectedItem changed between
|
|
@@ -3181,20 +3123,20 @@
|
|
|
3181
3123
|
* string equivalent. It uses the common useEnhancedReducer to
|
|
3182
3124
|
* compute the rest of the state.
|
|
3183
3125
|
*
|
|
3184
|
-
* @param
|
|
3185
|
-
* @param
|
|
3186
|
-
* @param
|
|
3187
|
-
* @param
|
|
3188
|
-
* @returns
|
|
3126
|
+
* @param reducer Reducer function from downshift.
|
|
3127
|
+
* @param props The hook props, also passed to createInitialState.
|
|
3128
|
+
* @param createInitialState Function that returns the initial state.
|
|
3129
|
+
* @param isStateEqual Function that checks if a previous state is equal to the next.
|
|
3130
|
+
* @returns An array with the state and an action dispatcher.
|
|
3189
3131
|
*/
|
|
3190
3132
|
function useControlledReducer(reducer, props, createInitialState, isStateEqual) {
|
|
3191
|
-
var previousSelectedItemRef = React.useRef();
|
|
3133
|
+
var previousSelectedItemRef = React.useRef(null);
|
|
3192
3134
|
var _useEnhancedReducer = useEnhancedReducer(reducer, props, createInitialState, isStateEqual),
|
|
3193
3135
|
state = _useEnhancedReducer[0],
|
|
3194
3136
|
dispatch = _useEnhancedReducer[1];
|
|
3195
3137
|
var isInitialMount = useIsInitialMount();
|
|
3196
3138
|
React.useEffect(function () {
|
|
3197
|
-
if (
|
|
3139
|
+
if (props.selectedItem === undefined) {
|
|
3198
3140
|
return;
|
|
3199
3141
|
}
|
|
3200
3142
|
if (!isInitialMount // on first mount we already have the proper inputValue for a initial selected item.
|
|
@@ -3212,23 +3154,27 @@
|
|
|
3212
3154
|
}, [state.selectedItem, props.selectedItem]);
|
|
3213
3155
|
return [getState(state, props), dispatch];
|
|
3214
3156
|
}
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3157
|
+
|
|
3158
|
+
var propTypes$2 = _extends({}, dropdownPropTypes, {
|
|
3159
|
+
items: PropTypes.array.isRequired,
|
|
3160
|
+
isItemDisabled: PropTypes.func,
|
|
3161
|
+
inputValue: PropTypes.string,
|
|
3162
|
+
defaultInputValue: PropTypes.string,
|
|
3163
|
+
initialInputValue: PropTypes.string,
|
|
3164
|
+
inputId: PropTypes.string,
|
|
3165
|
+
onInputValueChange: PropTypes.func
|
|
3219
3166
|
});
|
|
3220
3167
|
|
|
3221
3168
|
/* eslint-disable complexity */
|
|
3222
|
-
function downshiftUseComboboxReducer(state,
|
|
3223
|
-
var _props$items;
|
|
3169
|
+
function downshiftUseComboboxReducer(state, action) {
|
|
3224
3170
|
var type = action.type,
|
|
3225
|
-
|
|
3171
|
+
props = action.props;
|
|
3226
3172
|
var changes;
|
|
3227
3173
|
switch (type) {
|
|
3228
3174
|
case ItemClick:
|
|
3229
3175
|
changes = {
|
|
3230
|
-
isOpen: getDefaultValue
|
|
3231
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
3176
|
+
isOpen: getDefaultValue(props.defaultIsOpen, dropdownDefaultStateValues.isOpen),
|
|
3177
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
3232
3178
|
selectedItem: props.items[action.index],
|
|
3233
3179
|
inputValue: props.itemToString(props.items[action.index])
|
|
3234
3180
|
};
|
|
@@ -3240,15 +3186,15 @@
|
|
|
3240
3186
|
};
|
|
3241
3187
|
} else {
|
|
3242
3188
|
changes = {
|
|
3243
|
-
highlightedIndex: altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1),
|
|
3189
|
+
highlightedIndex: action.altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 1),
|
|
3244
3190
|
isOpen: props.items.length >= 0
|
|
3245
3191
|
};
|
|
3246
3192
|
}
|
|
3247
3193
|
break;
|
|
3248
3194
|
case InputKeyDownArrowUp:
|
|
3249
3195
|
if (state.isOpen) {
|
|
3250
|
-
if (altKey) {
|
|
3251
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
3196
|
+
if (action.altKey) {
|
|
3197
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3252
3198
|
} else {
|
|
3253
3199
|
changes = {
|
|
3254
3200
|
highlightedIndex: getHighlightedIndex(state.highlightedIndex, -1, props.items, props.isItemDisabled, true)
|
|
@@ -3256,13 +3202,13 @@
|
|
|
3256
3202
|
}
|
|
3257
3203
|
} else {
|
|
3258
3204
|
changes = {
|
|
3259
|
-
highlightedIndex: getHighlightedIndexOnOpen(props, state, -1),
|
|
3205
|
+
highlightedIndex: getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, -1),
|
|
3260
3206
|
isOpen: props.items.length >= 0
|
|
3261
3207
|
};
|
|
3262
3208
|
}
|
|
3263
3209
|
break;
|
|
3264
3210
|
case InputKeyDownEnter:
|
|
3265
|
-
changes = getChangesOnSelection(props, state.highlightedIndex);
|
|
3211
|
+
changes = getChangesOnSelection(props.items, props.itemToString, props.defaultIsOpen, props.defaultHighlightedIndex, state.highlightedIndex, true);
|
|
3266
3212
|
break;
|
|
3267
3213
|
case InputKeyDownEscape:
|
|
3268
3214
|
changes = _extends({
|
|
@@ -3297,7 +3243,7 @@
|
|
|
3297
3243
|
changes = _extends({
|
|
3298
3244
|
isOpen: false,
|
|
3299
3245
|
highlightedIndex: -1
|
|
3300
|
-
}, state.highlightedIndex >= 0 &&
|
|
3246
|
+
}, state.highlightedIndex >= 0 && props.items.length && action.selectItem && {
|
|
3301
3247
|
selectedItem: props.items[state.highlightedIndex],
|
|
3302
3248
|
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3303
3249
|
});
|
|
@@ -3305,14 +3251,14 @@
|
|
|
3305
3251
|
case InputChange:
|
|
3306
3252
|
changes = {
|
|
3307
3253
|
isOpen: true,
|
|
3308
|
-
highlightedIndex: getDefaultHighlightedIndex(props),
|
|
3254
|
+
highlightedIndex: getDefaultHighlightedIndex(props.items, props.isItemDisabled, props.defaultHighlightedIndex),
|
|
3309
3255
|
inputValue: action.inputValue
|
|
3310
3256
|
};
|
|
3311
3257
|
break;
|
|
3312
3258
|
case InputClick:
|
|
3313
3259
|
changes = {
|
|
3314
3260
|
isOpen: !state.isOpen,
|
|
3315
|
-
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
|
3261
|
+
highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props.items, props.initialHighlightedIndex, props.defaultHighlightedIndex, props.isItemDisabled, props.itemToKey, state.selectedItem, state.highlightedIndex, 0)
|
|
3316
3262
|
};
|
|
3317
3263
|
break;
|
|
3318
3264
|
case FunctionSelectItem:
|
|
@@ -3333,10 +3279,10 @@
|
|
|
3333
3279
|
}
|
|
3334
3280
|
/* eslint-enable complexity */
|
|
3335
3281
|
|
|
3336
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
3282
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref", "aria-label"],
|
|
3337
3283
|
_excluded2$2 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
3338
|
-
_excluded3$1 = ["onClick", "onPress", "refKey", "ref"],
|
|
3339
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
3284
|
+
_excluded3$1 = ["onClick", "onPress", "refKey", "ref", "disabled"],
|
|
3285
|
+
_excluded4 = ["aria-label", "disabled", "onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "onClick", "refKey", "ref"];
|
|
3340
3286
|
useCombobox.stateChangeTypes = stateChangeTypes$2;
|
|
3341
3287
|
function useCombobox(userProps) {
|
|
3342
3288
|
if (userProps === void 0) {
|
|
@@ -3344,13 +3290,13 @@
|
|
|
3344
3290
|
}
|
|
3345
3291
|
validatePropTypes$1(userProps, useCombobox, propTypes$2);
|
|
3346
3292
|
// Props defaults and destructuring.
|
|
3347
|
-
var props = _extends({},
|
|
3293
|
+
var props = _extends({}, dropdownDefaultProps, userProps);
|
|
3348
3294
|
var items = props.items,
|
|
3349
3295
|
scrollIntoView = props.scrollIntoView,
|
|
3350
3296
|
environment = props.environment,
|
|
3351
3297
|
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3352
3298
|
// Initial state depending on controlled props.
|
|
3353
|
-
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2,
|
|
3299
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, props, getInitialState$2, isDropdownStateEqual),
|
|
3354
3300
|
state = _useControlledReducer[0],
|
|
3355
3301
|
dispatch = _useControlledReducer[1];
|
|
3356
3302
|
var isOpen = state.isOpen,
|
|
@@ -3360,7 +3306,7 @@
|
|
|
3360
3306
|
|
|
3361
3307
|
// Element refs.
|
|
3362
3308
|
var menuRef = React.useRef(null);
|
|
3363
|
-
var
|
|
3309
|
+
var itemsRef = React.useRef({});
|
|
3364
3310
|
var inputRef = React.useRef(null);
|
|
3365
3311
|
var toggleButtonRef = React.useRef(null);
|
|
3366
3312
|
var isInitialMount = useIsInitialMount();
|
|
@@ -3374,29 +3320,19 @@
|
|
|
3374
3320
|
state: state,
|
|
3375
3321
|
props: props
|
|
3376
3322
|
});
|
|
3377
|
-
var getItemNodeFromIndex = React.useCallback(function (index) {
|
|
3378
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3379
|
-
}, [elementIds]);
|
|
3380
3323
|
|
|
3381
3324
|
// Effects.
|
|
3382
3325
|
// Adds an a11y aria live status message if getA11yStatusMessage is passed.
|
|
3383
3326
|
useA11yMessageStatus(getA11yStatusMessage, state, [isOpen, highlightedIndex, selectedItem, inputValue], environment);
|
|
3384
3327
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3385
|
-
var
|
|
3386
|
-
menuElement: menuRef.current,
|
|
3387
|
-
highlightedIndex: highlightedIndex,
|
|
3388
|
-
isOpen: isOpen,
|
|
3389
|
-
itemRefs: itemRefs,
|
|
3390
|
-
scrollIntoView: scrollIntoView,
|
|
3391
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3392
|
-
});
|
|
3328
|
+
var preventScroll = useScrollIntoView(scrollIntoView, highlightedIndex, isOpen, menuRef.current, itemsRef.current, elementIds.getItemId);
|
|
3393
3329
|
useControlPropsValidator({
|
|
3394
|
-
|
|
3395
|
-
|
|
3330
|
+
state: state,
|
|
3331
|
+
props: props
|
|
3396
3332
|
});
|
|
3397
3333
|
// Focus the input on first render if required.
|
|
3398
3334
|
React.useEffect(function () {
|
|
3399
|
-
var focusOnOpen = getInitialValue
|
|
3335
|
+
var focusOnOpen = getInitialValue(props.isOpen, props.initialIsOpen, props.defaultIsOpen, dropdownDefaultStateValues.isOpen);
|
|
3400
3336
|
if (focusOnOpen && inputRef.current) {
|
|
3401
3337
|
inputRef.current.focus();
|
|
3402
3338
|
}
|
|
@@ -3422,13 +3358,13 @@
|
|
|
3422
3358
|
// Reset itemRefs on close.
|
|
3423
3359
|
React.useEffect(function () {
|
|
3424
3360
|
if (!isOpen) {
|
|
3425
|
-
|
|
3361
|
+
itemsRef.current = {};
|
|
3426
3362
|
}
|
|
3427
3363
|
}, [isOpen]);
|
|
3428
3364
|
// Reset itemRefs on close.
|
|
3429
3365
|
React.useEffect(function () {
|
|
3430
3366
|
var _inputRef$current;
|
|
3431
|
-
if (!isOpen || !(environment != null && environment.document) || !(
|
|
3367
|
+
if (!isOpen || !(environment != null && environment.document) || !((_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3432
3368
|
return;
|
|
3433
3369
|
}
|
|
3434
3370
|
if (environment.document.activeElement !== inputRef.current) {
|
|
@@ -3518,29 +3454,30 @@
|
|
|
3518
3454
|
htmlFor: elementIds.inputId
|
|
3519
3455
|
}, labelProps);
|
|
3520
3456
|
}, [elementIds]);
|
|
3521
|
-
var getMenuProps = React.useCallback(function (
|
|
3457
|
+
var getMenuProps = React.useCallback(function (menuProps, otherProps) {
|
|
3522
3458
|
var _extends2;
|
|
3523
|
-
var _ref =
|
|
3459
|
+
var _ref = menuProps != null ? menuProps : {},
|
|
3524
3460
|
onMouseLeave = _ref.onMouseLeave,
|
|
3525
3461
|
_ref$refKey = _ref.refKey,
|
|
3526
3462
|
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3527
3463
|
ref = _ref.ref,
|
|
3464
|
+
ariaLabel = _ref['aria-label'],
|
|
3528
3465
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3529
|
-
var _ref2 =
|
|
3466
|
+
var _ref2 = otherProps != null ? otherProps : {},
|
|
3530
3467
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3531
3468
|
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3532
3469
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3533
3470
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3534
3471
|
menuRef.current = menuNode;
|
|
3535
|
-
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-
|
|
3472
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-label'] = ariaLabel, _extends2['aria-labelledby'] = ariaLabel ? undefined : "" + elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
3536
3473
|
dispatch({
|
|
3537
3474
|
type: MenuMouseLeave
|
|
3538
3475
|
});
|
|
3539
3476
|
}), _extends2), rest);
|
|
3540
3477
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3541
|
-
var getItemProps = React.useCallback(function (
|
|
3478
|
+
var getItemProps = React.useCallback(function (itemProps) {
|
|
3542
3479
|
var _extends3, _ref4;
|
|
3543
|
-
var _ref3 =
|
|
3480
|
+
var _ref3 = itemProps != null ? itemProps : {},
|
|
3544
3481
|
itemProp = _ref3.item,
|
|
3545
3482
|
indexProp = _ref3.index,
|
|
3546
3483
|
_ref3$refKey = _ref3.refKey,
|
|
@@ -3568,7 +3505,7 @@
|
|
|
3568
3505
|
if (mouseAndTouchTrackers.isTouchEnd || index === latestState.highlightedIndex) {
|
|
3569
3506
|
return;
|
|
3570
3507
|
}
|
|
3571
|
-
|
|
3508
|
+
preventScroll();
|
|
3572
3509
|
dispatch({
|
|
3573
3510
|
type: ItemMouseMove,
|
|
3574
3511
|
index: index,
|
|
@@ -3587,21 +3524,22 @@
|
|
|
3587
3524
|
|
|
3588
3525
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
3589
3526
|
if (itemNode) {
|
|
3590
|
-
|
|
3527
|
+
itemsRef.current[elementIds.getItemId(index)] = itemNode;
|
|
3591
3528
|
}
|
|
3592
3529
|
}), _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), {
|
|
3593
3530
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3594
3531
|
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3595
3532
|
}, rest);
|
|
3596
|
-
}, [dispatch, elementIds, latest, mouseAndTouchTrackers,
|
|
3597
|
-
var getToggleButtonProps = React.useCallback(function (
|
|
3533
|
+
}, [dispatch, elementIds, latest, mouseAndTouchTrackers, preventScroll]);
|
|
3534
|
+
var getToggleButtonProps = React.useCallback(function (toggleButtonProps) {
|
|
3598
3535
|
var _extends4;
|
|
3599
|
-
var _ref5 =
|
|
3536
|
+
var _ref5 = toggleButtonProps != null ? toggleButtonProps : {},
|
|
3600
3537
|
onClick = _ref5.onClick;
|
|
3601
3538
|
_ref5.onPress;
|
|
3602
3539
|
var _ref5$refKey = _ref5.refKey,
|
|
3603
3540
|
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3604
3541
|
ref = _ref5.ref,
|
|
3542
|
+
disabled = _ref5.disabled,
|
|
3605
3543
|
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3606
3544
|
var latestState = latest.current.state;
|
|
3607
3545
|
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
@@ -3611,13 +3549,17 @@
|
|
|
3611
3549
|
};
|
|
3612
3550
|
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3613
3551
|
toggleButtonRef.current = toggleButtonNode;
|
|
3614
|
-
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !
|
|
3552
|
+
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !disabled && _extends({}, {
|
|
3615
3553
|
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3616
|
-
}),
|
|
3554
|
+
}), {
|
|
3555
|
+
disabled: disabled
|
|
3556
|
+
}, rest);
|
|
3617
3557
|
}, [dispatch, latest, elementIds]);
|
|
3618
|
-
var getInputProps = React.useCallback(function (
|
|
3558
|
+
var getInputProps = React.useCallback(function (inputProps, otherProps) {
|
|
3619
3559
|
var _extends5;
|
|
3620
|
-
var _ref6 =
|
|
3560
|
+
var _ref6 = inputProps != null ? inputProps : {},
|
|
3561
|
+
ariaLabel = _ref6['aria-label'],
|
|
3562
|
+
disabled = _ref6.disabled,
|
|
3621
3563
|
onKeyDown = _ref6.onKeyDown,
|
|
3622
3564
|
onChange = _ref6.onChange,
|
|
3623
3565
|
onInput = _ref6.onInput,
|
|
@@ -3628,15 +3570,16 @@
|
|
|
3628
3570
|
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
3629
3571
|
ref = _ref6.ref,
|
|
3630
3572
|
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
|
|
3631
|
-
var _ref7 =
|
|
3573
|
+
var _ref7 = otherProps != null ? otherProps : {},
|
|
3632
3574
|
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3633
3575
|
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3634
3576
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3635
3577
|
var latestState = latest.current.state;
|
|
3636
3578
|
var inputHandleKeyDown = function inputHandleKeyDown(event) {
|
|
3637
3579
|
var key = normalizeArrowKey(event);
|
|
3638
|
-
if (key && inputKeyDownHandlers
|
|
3639
|
-
|
|
3580
|
+
if (key && key in inputKeyDownHandlers) {
|
|
3581
|
+
var validKey = key;
|
|
3582
|
+
inputKeyDownHandlers[validKey](event);
|
|
3640
3583
|
}
|
|
3641
3584
|
};
|
|
3642
3585
|
var inputHandleChange = function inputHandleChange(event) {
|
|
@@ -3664,13 +3607,13 @@
|
|
|
3664
3607
|
/* istanbul ignore next (preact) */
|
|
3665
3608
|
var onChangeKey = 'onInput' ;
|
|
3666
3609
|
var eventHandlers = {};
|
|
3667
|
-
if (!
|
|
3610
|
+
if (!disabled) {
|
|
3668
3611
|
var _eventHandlers;
|
|
3669
3612
|
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onClick = callAllEventHandlers(onClick, inputHandleClick), _eventHandlers);
|
|
3670
3613
|
}
|
|
3671
3614
|
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
3672
3615
|
inputRef.current = inputNode;
|
|
3673
|
-
}), _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'] =
|
|
3616
|
+
}), _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);
|
|
3674
3617
|
}, [dispatch, elementIds, environment, inputKeyDownHandlers, latest, mouseAndTouchTrackers, setGetterPropCallInfo]);
|
|
3675
3618
|
|
|
3676
3619
|
// returns
|
|
@@ -3740,31 +3683,6 @@
|
|
|
3740
3683
|
selectedItems: []
|
|
3741
3684
|
};
|
|
3742
3685
|
|
|
3743
|
-
/**
|
|
3744
|
-
* Returns the initial value for a state key in the following order:
|
|
3745
|
-
* 1. controlled prop, 2. initial prop, 3. default prop, 4. default
|
|
3746
|
-
* value from Downshift.
|
|
3747
|
-
*
|
|
3748
|
-
* @param {Object} props Props passed to the hook.
|
|
3749
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3750
|
-
* @returns {any} The initial value for that prop.
|
|
3751
|
-
*/
|
|
3752
|
-
function getInitialValue(props, propKey) {
|
|
3753
|
-
return getInitialValue$1(props, propKey, defaultStateValues);
|
|
3754
|
-
}
|
|
3755
|
-
|
|
3756
|
-
/**
|
|
3757
|
-
* Returns the default value for a state key in the following order:
|
|
3758
|
-
* 1. controlled prop, 2. default prop, 3. default value from Downshift.
|
|
3759
|
-
*
|
|
3760
|
-
* @param {Object} props Props passed to the hook.
|
|
3761
|
-
* @param {string} propKey Props key to generate the value for.
|
|
3762
|
-
* @returns {any} The initial value for that prop.
|
|
3763
|
-
*/
|
|
3764
|
-
function getDefaultValue(props, propKey) {
|
|
3765
|
-
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
3766
|
-
}
|
|
3767
|
-
|
|
3768
3686
|
/**
|
|
3769
3687
|
* Gets the initial state based on the provided props. It uses initial, default
|
|
3770
3688
|
* and controlled props related to state in order to compute the initial value.
|
|
@@ -3773,8 +3691,8 @@
|
|
|
3773
3691
|
* @returns {Object} The initial state.
|
|
3774
3692
|
*/
|
|
3775
3693
|
function getInitialState$1(props) {
|
|
3776
|
-
var activeIndex = getInitialValue(props,
|
|
3777
|
-
var selectedItems = getInitialValue(props,
|
|
3694
|
+
var activeIndex = getInitialValue(props.activeIndex, props.initialActiveIndex, props.defaultActiveIndex, defaultStateValues.activeIndex);
|
|
3695
|
+
var selectedItems = getInitialValue(props.selectedItems, props.initialSelectedItems, props.defaultSelectedItems, defaultStateValues.selectedItems);
|
|
3778
3696
|
return {
|
|
3779
3697
|
activeIndex: activeIndex,
|
|
3780
3698
|
selectedItems: selectedItems
|
|
@@ -3818,9 +3736,9 @@
|
|
|
3818
3736
|
return prevState.selectedItems === newState.selectedItems && prevState.activeIndex === newState.activeIndex;
|
|
3819
3737
|
}
|
|
3820
3738
|
var propTypes$1 = {
|
|
3821
|
-
stateReducer:
|
|
3822
|
-
itemToKey:
|
|
3823
|
-
environment:
|
|
3739
|
+
stateReducer: dropdownPropTypes.stateReducer,
|
|
3740
|
+
itemToKey: dropdownPropTypes.itemToKey,
|
|
3741
|
+
environment: dropdownPropTypes.environment,
|
|
3824
3742
|
selectedItems: PropTypes.array,
|
|
3825
3743
|
initialSelectedItems: PropTypes.array,
|
|
3826
3744
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3834,9 +3752,9 @@
|
|
|
3834
3752
|
keyNavigationPrevious: PropTypes.string
|
|
3835
3753
|
};
|
|
3836
3754
|
var defaultProps = {
|
|
3837
|
-
itemToKey:
|
|
3838
|
-
stateReducer:
|
|
3839
|
-
environment:
|
|
3755
|
+
itemToKey: dropdownDefaultProps.itemToKey,
|
|
3756
|
+
stateReducer: dropdownDefaultProps.stateReducer,
|
|
3757
|
+
environment: dropdownDefaultProps.environment,
|
|
3840
3758
|
keyNavigationNext: 'ArrowRight',
|
|
3841
3759
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3842
3760
|
};
|
|
@@ -3882,10 +3800,11 @@
|
|
|
3882
3800
|
});
|
|
3883
3801
|
|
|
3884
3802
|
/* eslint-disable complexity */
|
|
3885
|
-
function downshiftMultipleSelectionReducer(state,
|
|
3803
|
+
function downshiftMultipleSelectionReducer(state, action) {
|
|
3886
3804
|
var type = action.type,
|
|
3887
3805
|
index = action.index,
|
|
3888
|
-
selectedItem = action.selectedItem
|
|
3806
|
+
selectedItem = action.selectedItem,
|
|
3807
|
+
props = action.props;
|
|
3889
3808
|
var activeIndex = state.activeIndex,
|
|
3890
3809
|
selectedItems = state.selectedItems;
|
|
3891
3810
|
var changes;
|
|
@@ -3982,8 +3901,8 @@
|
|
|
3982
3901
|
}
|
|
3983
3902
|
case FunctionReset:
|
|
3984
3903
|
changes = {
|
|
3985
|
-
activeIndex: getDefaultValue(props,
|
|
3986
|
-
selectedItems: getDefaultValue(props,
|
|
3904
|
+
activeIndex: getDefaultValue(props.defaultActiveIndex, defaultStateValues.activeIndex),
|
|
3905
|
+
selectedItems: getDefaultValue(props.defaultSelectedItems, defaultStateValues.selectedItems)
|
|
3987
3906
|
};
|
|
3988
3907
|
break;
|
|
3989
3908
|
default:
|
|
@@ -4215,7 +4134,7 @@
|
|
|
4215
4134
|
TagRemoveClick: TagRemoveClick
|
|
4216
4135
|
});
|
|
4217
4136
|
|
|
4218
|
-
function useTagGroupReducer(state,
|
|
4137
|
+
function useTagGroupReducer(state, action) {
|
|
4219
4138
|
var type = action.type;
|
|
4220
4139
|
var changes;
|
|
4221
4140
|
switch (type) {
|
|
@@ -4453,7 +4372,7 @@
|
|
|
4453
4372
|
'aria-atomic': 'false',
|
|
4454
4373
|
'aria-relevant': 'additions',
|
|
4455
4374
|
role: 'listbox',
|
|
4456
|
-
onKeyDown: callAllEventHandlers
|
|
4375
|
+
onKeyDown: callAllEventHandlers(onKeyDown, handleKeyDown)
|
|
4457
4376
|
}, rest);
|
|
4458
4377
|
return tagGroupProps;
|
|
4459
4378
|
}, [dispatch, elementIds.tagGroupId]);
|
|
@@ -4478,11 +4397,11 @@
|
|
|
4478
4397
|
var tagId = elementIds.getTagId(index);
|
|
4479
4398
|
return _extends((_extends2 = {
|
|
4480
4399
|
'aria-describedby': A11Y_DESCRIPTION_ELEMENT_ID
|
|
4481
|
-
}, _extends2[refKey] = handleRefs
|
|
4400
|
+
}, _extends2[refKey] = handleRefs(ref, function (itemNode) {
|
|
4482
4401
|
if (itemNode) {
|
|
4483
4402
|
itemRefs.current[tagId] = itemNode;
|
|
4484
4403
|
}
|
|
4485
|
-
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers
|
|
4404
|
+
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4486
4405
|
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4487
4406
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4488
4407
|
var index = options.index,
|
|
@@ -4504,7 +4423,7 @@
|
|
|
4504
4423
|
id: tagRemoveId,
|
|
4505
4424
|
tabIndex: -1,
|
|
4506
4425
|
'aria-labelledby': tagRemoveId + " " + tagId,
|
|
4507
|
-
onClick: callAllEventHandlers
|
|
4426
|
+
onClick: callAllEventHandlers(onClick, handleClick)
|
|
4508
4427
|
}, rest);
|
|
4509
4428
|
}, [elementIds, dispatch]);
|
|
4510
4429
|
|