downshift 6.0.2 → 6.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -61
- package/dist/downshift.cjs.js +159 -167
- package/dist/downshift.esm.js +159 -167
- package/dist/downshift.native.cjs.js +159 -167
- package/dist/downshift.umd.js +160 -168
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +2 -2
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +33 -26
- package/preact/dist/downshift.cjs.js +159 -167
- package/preact/dist/downshift.esm.js +159 -167
- package/preact/dist/downshift.umd.js +160 -168
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +2 -2
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/typings/index.d.ts +27 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "downshift",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.6",
|
|
4
4
|
"description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
|
|
5
5
|
"main": "dist/downshift.cjs.js",
|
|
6
6
|
"react-native": "dist/downshift.native.cjs.js",
|
|
@@ -66,51 +66,47 @@
|
|
|
66
66
|
"react": ">=16.8.0"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@babel/runtime": "^7.
|
|
69
|
+
"@babel/runtime": "^7.11.2",
|
|
70
70
|
"compute-scroll-into-view": "^1.0.14",
|
|
71
71
|
"prop-types": "^15.7.2",
|
|
72
72
|
"react-is": "^16.13.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@babel/helpers": "^7.10.
|
|
76
|
-
"@
|
|
77
|
-
"@material-ui/icons": "^4.9.1",
|
|
78
|
-
"@rollup/plugin-commonjs": "^13.0.0",
|
|
75
|
+
"@babel/helpers": "^7.10.4",
|
|
76
|
+
"@rollup/plugin-commonjs": "^14.0.0",
|
|
79
77
|
"@testing-library/cypress": "^6.0.0",
|
|
80
|
-
"@testing-library/dom": "^7.
|
|
81
|
-
"@testing-library/jest-dom": "^5.
|
|
82
|
-
"@testing-library/preact": "^
|
|
83
|
-
"@testing-library/react": "^10.
|
|
84
|
-
"@testing-library/react-hooks": "^3.
|
|
85
|
-
"@testing-library/user-event": "^
|
|
86
|
-
"@types/jest": "^26.0.
|
|
87
|
-
"@types/react": "^16.9.
|
|
78
|
+
"@testing-library/dom": "^7.22.1",
|
|
79
|
+
"@testing-library/jest-dom": "^5.11.2",
|
|
80
|
+
"@testing-library/preact": "^2.0.0",
|
|
81
|
+
"@testing-library/react": "^10.4.8",
|
|
82
|
+
"@testing-library/react-hooks": "^3.4.1",
|
|
83
|
+
"@testing-library/user-event": "^12.1.1",
|
|
84
|
+
"@types/jest": "^26.0.9",
|
|
85
|
+
"@types/react": "^16.9.46",
|
|
88
86
|
"babel-plugin-macros": "^2.8.0",
|
|
89
87
|
"babel-plugin-no-side-effect-class-properties": "0.0.7",
|
|
90
88
|
"babel-preset-react-native": "^4.0.1",
|
|
91
89
|
"buble": "^0.20.0",
|
|
92
90
|
"cpy-cli": "^3.1.1",
|
|
93
91
|
"cross-env": "^7.0.2",
|
|
94
|
-
"cypress": "^4.
|
|
92
|
+
"cypress": "^4.12.1",
|
|
95
93
|
"docz": "^2.3.1",
|
|
96
94
|
"docz-theme-default": "^1.2.0",
|
|
97
95
|
"eslint-plugin-cypress": "^2.11.1",
|
|
98
|
-
"eslint-plugin-react": "7.20.
|
|
99
|
-
"flow-bin": "^0.
|
|
96
|
+
"eslint-plugin-react": "7.20.5",
|
|
97
|
+
"flow-bin": "^0.131.0",
|
|
100
98
|
"flow-coverage-report": "^0.7.0",
|
|
101
|
-
"kcd-scripts": "^6.2.
|
|
99
|
+
"kcd-scripts": "^6.2.4",
|
|
102
100
|
"npm-run-all": "^4.1.5",
|
|
103
|
-
"preact": "^10.4.
|
|
101
|
+
"preact": "^10.4.7",
|
|
104
102
|
"react": "^16.13.1",
|
|
105
103
|
"react-dom": "^16.13.1",
|
|
106
|
-
"react-
|
|
107
|
-
"react-native": "^0.62.2",
|
|
104
|
+
"react-native": "^0.63.2",
|
|
108
105
|
"react-test-renderer": "^16.13.1",
|
|
109
|
-
"react-virtual": "^2.2.0",
|
|
110
106
|
"rollup-plugin-babel": "^4.4.0",
|
|
111
107
|
"serve": "^11.3.2",
|
|
112
|
-
"start-server-and-test": "^1.11.
|
|
113
|
-
"typescript": "^3.9.
|
|
108
|
+
"start-server-and-test": "^1.11.3",
|
|
109
|
+
"typescript": "^3.9.7"
|
|
114
110
|
},
|
|
115
111
|
"eslintConfig": {
|
|
116
112
|
"extends": "./node_modules/kcd-scripts/eslint.js",
|
|
@@ -125,11 +121,22 @@
|
|
|
125
121
|
"react/prop-types": "off",
|
|
126
122
|
"jsx-a11y/label-has-for": "off",
|
|
127
123
|
"jsx-a11y/label-has-associated-control": "off",
|
|
124
|
+
"jsx-a11y/autocomplete-valid": "off",
|
|
128
125
|
"complexity": [
|
|
129
126
|
"error",
|
|
130
127
|
12
|
|
131
128
|
]
|
|
132
|
-
}
|
|
129
|
+
},
|
|
130
|
+
"overrides": [
|
|
131
|
+
{
|
|
132
|
+
"files": [
|
|
133
|
+
"cypress/**/*.js"
|
|
134
|
+
],
|
|
135
|
+
"rules": {
|
|
136
|
+
"testing-library/prefer-screen-queries": "off"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
]
|
|
133
140
|
},
|
|
134
141
|
"eslintIgnore": [
|
|
135
142
|
"node_modules",
|
|
@@ -145,7 +152,7 @@
|
|
|
145
152
|
"bugs": {
|
|
146
153
|
"url": "https://github.com/downshift-js/downshift/issues"
|
|
147
154
|
},
|
|
148
|
-
"homepage": "https://
|
|
155
|
+
"homepage": "https://downshift-js.com",
|
|
149
156
|
"flow-coverage-report": {
|
|
150
157
|
"includeGlob": [
|
|
151
158
|
"test/**/*.js"
|
|
@@ -2046,6 +2046,69 @@ function useGetterPropsCalledChecker() {
|
|
|
2046
2046
|
}, []);
|
|
2047
2047
|
return setGetterPropCallInfo;
|
|
2048
2048
|
}
|
|
2049
|
+
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
2050
|
+
var isInitialMount = _ref2.isInitialMount,
|
|
2051
|
+
previousResultCount = _ref2.previousResultCount,
|
|
2052
|
+
highlightedIndex = _ref2.highlightedIndex,
|
|
2053
|
+
items = _ref2.items,
|
|
2054
|
+
environment = _ref2.environment,
|
|
2055
|
+
rest = _objectWithoutPropertiesLoose(_ref2, ["isInitialMount", "previousResultCount", "highlightedIndex", "items", "environment"]);
|
|
2056
|
+
|
|
2057
|
+
// Sets a11y status message on changes in state.
|
|
2058
|
+
preact.useEffect(function () {
|
|
2059
|
+
if (isInitialMount) {
|
|
2060
|
+
return;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
updateA11yStatus(function () {
|
|
2064
|
+
return getA11yMessage(_extends({
|
|
2065
|
+
highlightedIndex: highlightedIndex,
|
|
2066
|
+
highlightedItem: items[highlightedIndex],
|
|
2067
|
+
resultCount: items.length,
|
|
2068
|
+
previousResultCount: previousResultCount
|
|
2069
|
+
}, rest));
|
|
2070
|
+
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2071
|
+
}, dependencyArray);
|
|
2072
|
+
}
|
|
2073
|
+
function useScrollIntoView(_ref3) {
|
|
2074
|
+
var highlightedIndex = _ref3.highlightedIndex,
|
|
2075
|
+
isOpen = _ref3.isOpen,
|
|
2076
|
+
itemRefs = _ref3.itemRefs,
|
|
2077
|
+
getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
|
|
2078
|
+
menuElement = _ref3.menuElement,
|
|
2079
|
+
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
2080
|
+
// used not to scroll on highlight by mouse.
|
|
2081
|
+
var shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
2082
|
+
|
|
2083
|
+
preact.useEffect(function () {
|
|
2084
|
+
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
if (shouldScrollRef.current === false) {
|
|
2089
|
+
shouldScrollRef.current = true;
|
|
2090
|
+
} else {
|
|
2091
|
+
scrollIntoViewProp(getItemNodeFromIndex(highlightedIndex), menuElement);
|
|
2092
|
+
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2093
|
+
|
|
2094
|
+
}, [highlightedIndex]);
|
|
2095
|
+
return shouldScrollRef;
|
|
2096
|
+
}
|
|
2097
|
+
function useControlPropsValidator(_ref4) {
|
|
2098
|
+
var isInitialMount = _ref4.isInitialMount,
|
|
2099
|
+
props = _ref4.props,
|
|
2100
|
+
state = _ref4.state;
|
|
2101
|
+
// used for checking when props are moving from controlled to uncontrolled.
|
|
2102
|
+
var prevPropsRef = preact.useRef(props);
|
|
2103
|
+
preact.useEffect(function () {
|
|
2104
|
+
if (isInitialMount) {
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2109
|
+
prevPropsRef.current = props;
|
|
2110
|
+
}, [state, props, isInitialMount]);
|
|
2111
|
+
}
|
|
2049
2112
|
|
|
2050
2113
|
function getItemIndexByCharacterKey(keysSoFar, highlightedIndex, items, itemToStringParam, getItemNodeFromIndex) {
|
|
2051
2114
|
var lowerCasedItemStrings = items.map(function (item) {
|
|
@@ -2412,9 +2475,7 @@ function useSelect(userProps) {
|
|
|
2412
2475
|
var toggleButtonRef = preact.useRef(null);
|
|
2413
2476
|
var menuRef = preact.useRef(null);
|
|
2414
2477
|
var itemRefs = preact.useRef();
|
|
2415
|
-
itemRefs.current = {}; // used not to
|
|
2416
|
-
|
|
2417
|
-
var shouldScrollRef = preact.useRef(true); // used not to trigger menu blur action in some scenarios.
|
|
2478
|
+
itemRefs.current = {}; // used not to trigger menu blur action in some scenarios.
|
|
2418
2479
|
|
|
2419
2480
|
var shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
2420
2481
|
|
|
@@ -2423,9 +2484,7 @@ function useSelect(userProps) {
|
|
|
2423
2484
|
var elementIdsRef = preact.useRef(getElementIds(props)); // used to keep track of how many items we had on previous cycle.
|
|
2424
2485
|
|
|
2425
2486
|
var previousResultCountRef = preact.useRef();
|
|
2426
|
-
var isInitialMountRef = preact.useRef(true); //
|
|
2427
|
-
|
|
2428
|
-
var prevPropsRef = preact.useRef(props); // utility callback to get item element.
|
|
2487
|
+
var isInitialMountRef = preact.useRef(true); // utility callback to get item element.
|
|
2429
2488
|
|
|
2430
2489
|
var latest = useLatestRef({
|
|
2431
2490
|
state: state,
|
|
@@ -2438,45 +2497,30 @@ function useSelect(userProps) {
|
|
|
2438
2497
|
// Sets a11y status message on changes in state.
|
|
2439
2498
|
|
|
2440
2499
|
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
var previousResultCount = previousResultCountRef.current;
|
|
2467
|
-
updateA11yStatus(function () {
|
|
2468
|
-
return getA11ySelectionMessage({
|
|
2469
|
-
isOpen: isOpen,
|
|
2470
|
-
highlightedIndex: highlightedIndex,
|
|
2471
|
-
selectedItem: selectedItem,
|
|
2472
|
-
inputValue: inputValue,
|
|
2473
|
-
highlightedItem: items[highlightedIndex],
|
|
2474
|
-
resultCount: items.length,
|
|
2475
|
-
itemToString: itemToString,
|
|
2476
|
-
previousResultCount: previousResultCount
|
|
2477
|
-
});
|
|
2478
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2479
|
-
}, [selectedItem]); // Sets cleanup for the keysSoFar after 500ms.
|
|
2500
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
|
|
2501
|
+
isInitialMount: isInitialMountRef.current,
|
|
2502
|
+
previousResultCount: previousResultCountRef.current,
|
|
2503
|
+
items: items,
|
|
2504
|
+
environment: environment,
|
|
2505
|
+
itemToString: itemToString
|
|
2506
|
+
}, state)); // Sets a11y status message on changes in selectedItem.
|
|
2507
|
+
|
|
2508
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
2509
|
+
isInitialMount: isInitialMountRef.current,
|
|
2510
|
+
previousResultCount: previousResultCountRef.current,
|
|
2511
|
+
items: items,
|
|
2512
|
+
environment: environment,
|
|
2513
|
+
itemToString: itemToString
|
|
2514
|
+
}, state)); // Scroll on highlighted item if change comes from keyboard.
|
|
2515
|
+
|
|
2516
|
+
var shouldScrollRef = useScrollIntoView({
|
|
2517
|
+
menuElement: menuRef.current,
|
|
2518
|
+
highlightedIndex: highlightedIndex,
|
|
2519
|
+
isOpen: isOpen,
|
|
2520
|
+
itemRefs: itemRefs,
|
|
2521
|
+
scrollIntoView: scrollIntoView,
|
|
2522
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2523
|
+
}); // Sets cleanup for the keysSoFar after 500ms.
|
|
2480
2524
|
|
|
2481
2525
|
preact.useEffect(function () {
|
|
2482
2526
|
// init the clean function here as we need access to dispatch.
|
|
@@ -2493,8 +2537,13 @@ function useSelect(userProps) {
|
|
|
2493
2537
|
return;
|
|
2494
2538
|
}
|
|
2495
2539
|
|
|
2496
|
-
clearTimeoutRef.current(dispatch);
|
|
2497
|
-
}, [inputValue]);
|
|
2540
|
+
clearTimeoutRef.current(dispatch);
|
|
2541
|
+
}, [dispatch, inputValue]);
|
|
2542
|
+
useControlPropsValidator({
|
|
2543
|
+
isInitialMount: isInitialMountRef.current,
|
|
2544
|
+
props: props,
|
|
2545
|
+
state: state
|
|
2546
|
+
});
|
|
2498
2547
|
/* Controls the focus on the menu or the toggle button. */
|
|
2499
2548
|
|
|
2500
2549
|
preact.useEffect(function () {
|
|
@@ -2527,35 +2576,14 @@ function useSelect(userProps) {
|
|
|
2527
2576
|
}
|
|
2528
2577
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2529
2578
|
|
|
2530
|
-
}, [isOpen]);
|
|
2531
|
-
|
|
2532
|
-
preact.useEffect(function () {
|
|
2533
|
-
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2534
|
-
return;
|
|
2535
|
-
}
|
|
2536
|
-
|
|
2537
|
-
if (shouldScrollRef.current === false) {
|
|
2538
|
-
shouldScrollRef.current = true;
|
|
2539
|
-
} else {
|
|
2540
|
-
scrollIntoView(getItemNodeFromIndex(highlightedIndex), menuRef.current);
|
|
2541
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2542
|
-
|
|
2543
|
-
}, [highlightedIndex]);
|
|
2579
|
+
}, [isOpen]);
|
|
2544
2580
|
preact.useEffect(function () {
|
|
2545
2581
|
if (isInitialMountRef.current) {
|
|
2546
2582
|
return;
|
|
2547
2583
|
}
|
|
2548
2584
|
|
|
2549
2585
|
previousResultCountRef.current = items.length;
|
|
2550
|
-
});
|
|
2551
|
-
preact.useEffect(function () {
|
|
2552
|
-
if (isInitialMountRef.current) {
|
|
2553
|
-
return;
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
2557
|
-
prevPropsRef.current = props;
|
|
2558
|
-
}, [state, props]); // Add mouse/touch events to document.
|
|
2586
|
+
}); // Add mouse/touch events to document.
|
|
2559
2587
|
|
|
2560
2588
|
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
|
|
2561
2589
|
dispatch({
|
|
@@ -2849,7 +2877,7 @@ function useSelect(userProps) {
|
|
|
2849
2877
|
}
|
|
2850
2878
|
|
|
2851
2879
|
return itemProps;
|
|
2852
|
-
}, [dispatch, latest]);
|
|
2880
|
+
}, [dispatch, latest, shouldScrollRef]);
|
|
2853
2881
|
return {
|
|
2854
2882
|
// prop getters.
|
|
2855
2883
|
getToggleButtonProps: getToggleButtonProps,
|
|
@@ -3075,7 +3103,7 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3075
3103
|
break;
|
|
3076
3104
|
|
|
3077
3105
|
case InputKeyDownEnter:
|
|
3078
|
-
changes = _extends({}, state.highlightedIndex >= 0 && {
|
|
3106
|
+
changes = _extends({}, state.isOpen && state.highlightedIndex >= 0 && {
|
|
3079
3107
|
selectedItem: props.items[state.highlightedIndex],
|
|
3080
3108
|
isOpen: getDefaultValue(props, 'isOpen'),
|
|
3081
3109
|
highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
|
@@ -3094,25 +3122,28 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3094
3122
|
break;
|
|
3095
3123
|
|
|
3096
3124
|
case InputKeyDownHome:
|
|
3097
|
-
changes = {
|
|
3125
|
+
changes = _extends({}, state.isOpen && {
|
|
3098
3126
|
highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false)
|
|
3099
|
-
};
|
|
3127
|
+
});
|
|
3100
3128
|
break;
|
|
3101
3129
|
|
|
3102
3130
|
case InputKeyDownEnd:
|
|
3103
|
-
changes = {
|
|
3131
|
+
changes = _extends({}, state.isOpen && {
|
|
3104
3132
|
highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false)
|
|
3105
|
-
};
|
|
3133
|
+
});
|
|
3106
3134
|
break;
|
|
3107
3135
|
|
|
3108
3136
|
case InputBlur:
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3137
|
+
if (state.isOpen) {
|
|
3138
|
+
changes = _extends({
|
|
3139
|
+
isOpen: false,
|
|
3140
|
+
highlightedIndex: -1
|
|
3141
|
+
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
3142
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3143
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3116
3147
|
break;
|
|
3117
3148
|
|
|
3118
3149
|
case InputChange:
|
|
@@ -3230,16 +3261,12 @@ function useCombobox(userProps) {
|
|
|
3230
3261
|
var inputRef = preact.useRef(null);
|
|
3231
3262
|
var toggleButtonRef = preact.useRef(null);
|
|
3232
3263
|
var comboboxRef = preact.useRef(null);
|
|
3233
|
-
itemRefs.current = {};
|
|
3234
|
-
|
|
3235
|
-
var shouldScrollRef = preact.useRef(true);
|
|
3264
|
+
itemRefs.current = {};
|
|
3236
3265
|
var isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
|
|
3237
3266
|
|
|
3238
3267
|
var elementIdsRef = preact.useRef(getElementIds$1(props)); // used to keep track of how many items we had on previous cycle.
|
|
3239
3268
|
|
|
3240
|
-
var previousResultCountRef = preact.useRef(); //
|
|
3241
|
-
|
|
3242
|
-
var prevPropsRef = preact.useRef(props); // utility callback to get item element.
|
|
3269
|
+
var previousResultCountRef = preact.useRef(); // utility callback to get item element.
|
|
3243
3270
|
|
|
3244
3271
|
var latest = useLatestRef({
|
|
3245
3272
|
state: state,
|
|
@@ -3252,58 +3279,35 @@ function useCombobox(userProps) {
|
|
|
3252
3279
|
// Sets a11y status message on changes in state.
|
|
3253
3280
|
|
|
3254
3281
|
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
highlightedIndex: highlightedIndex,
|
|
3285
|
-
selectedItem: selectedItem,
|
|
3286
|
-
inputValue: inputValue,
|
|
3287
|
-
highlightedItem: items[highlightedIndex],
|
|
3288
|
-
resultCount: items.length,
|
|
3289
|
-
itemToString: itemToString,
|
|
3290
|
-
previousResultCount: previousResultCount
|
|
3291
|
-
});
|
|
3292
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3293
|
-
}, [selectedItem]); // Scroll on highlighted item if change comes from keyboard.
|
|
3294
|
-
|
|
3295
|
-
preact.useEffect(function () {
|
|
3296
|
-
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
3297
|
-
return;
|
|
3298
|
-
}
|
|
3299
|
-
|
|
3300
|
-
if (shouldScrollRef.current === false) {
|
|
3301
|
-
shouldScrollRef.current = true;
|
|
3302
|
-
} else {
|
|
3303
|
-
scrollIntoView(getItemNodeFromIndex(highlightedIndex), menuRef.current);
|
|
3304
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3305
|
-
|
|
3306
|
-
}, [highlightedIndex]); // Controls the focus on the menu or the toggle button.
|
|
3282
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
|
|
3283
|
+
isInitialMount: isInitialMountRef.current,
|
|
3284
|
+
previousResultCount: previousResultCountRef.current,
|
|
3285
|
+
items: items,
|
|
3286
|
+
environment: environment,
|
|
3287
|
+
itemToString: itemToString
|
|
3288
|
+
}, state)); // Sets a11y status message on changes in selectedItem.
|
|
3289
|
+
|
|
3290
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
3291
|
+
isInitialMount: isInitialMountRef.current,
|
|
3292
|
+
previousResultCount: previousResultCountRef.current,
|
|
3293
|
+
items: items,
|
|
3294
|
+
environment: environment,
|
|
3295
|
+
itemToString: itemToString
|
|
3296
|
+
}, state)); // Scroll on highlighted item if change comes from keyboard.
|
|
3297
|
+
|
|
3298
|
+
var shouldScrollRef = useScrollIntoView({
|
|
3299
|
+
menuElement: menuRef.current,
|
|
3300
|
+
highlightedIndex: highlightedIndex,
|
|
3301
|
+
isOpen: isOpen,
|
|
3302
|
+
itemRefs: itemRefs,
|
|
3303
|
+
scrollIntoView: scrollIntoView,
|
|
3304
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3305
|
+
});
|
|
3306
|
+
useControlPropsValidator({
|
|
3307
|
+
isInitialMount: isInitialMountRef.current,
|
|
3308
|
+
props: props,
|
|
3309
|
+
state: state
|
|
3310
|
+
}); // Controls the focus on the input on open.
|
|
3307
3311
|
|
|
3308
3312
|
preact.useEffect(function () {
|
|
3309
3313
|
// Don't focus menu on first render.
|
|
@@ -3323,15 +3327,7 @@ function useCombobox(userProps) {
|
|
|
3323
3327
|
}
|
|
3324
3328
|
|
|
3325
3329
|
previousResultCountRef.current = items.length;
|
|
3326
|
-
});
|
|
3327
|
-
preact.useEffect(function () {
|
|
3328
|
-
if (isInitialMountRef.current) {
|
|
3329
|
-
return;
|
|
3330
|
-
}
|
|
3331
|
-
|
|
3332
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
3333
|
-
prevPropsRef.current = props;
|
|
3334
|
-
}, [state, props]); // Add mouse/touch events to document.
|
|
3330
|
+
}); // Add mouse/touch events to document.
|
|
3335
3331
|
|
|
3336
3332
|
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, function () {
|
|
3337
3333
|
dispatch({
|
|
@@ -3391,13 +3387,14 @@ function useCombobox(userProps) {
|
|
|
3391
3387
|
|
|
3392
3388
|
var latestState = latest.current.state;
|
|
3393
3389
|
|
|
3394
|
-
if (latestState.isOpen
|
|
3390
|
+
if (latestState.isOpen) {
|
|
3395
3391
|
event.preventDefault();
|
|
3396
|
-
dispatch({
|
|
3397
|
-
type: InputKeyDownEnter,
|
|
3398
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3399
|
-
});
|
|
3400
3392
|
}
|
|
3393
|
+
|
|
3394
|
+
dispatch({
|
|
3395
|
+
type: InputKeyDownEnter,
|
|
3396
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3397
|
+
});
|
|
3401
3398
|
}
|
|
3402
3399
|
};
|
|
3403
3400
|
}, [dispatch, latest]); // Getter props.
|
|
@@ -3482,7 +3479,7 @@ function useCombobox(userProps) {
|
|
|
3482
3479
|
inputRef.current.focus();
|
|
3483
3480
|
}
|
|
3484
3481
|
}), _ref4), rest);
|
|
3485
|
-
}, [dispatch, latest]);
|
|
3482
|
+
}, [dispatch, latest, shouldScrollRef]);
|
|
3486
3483
|
var getToggleButtonProps = preact.useCallback(function (_temp4) {
|
|
3487
3484
|
var _extends4;
|
|
3488
3485
|
|
|
@@ -3962,9 +3959,7 @@ function useMultipleSelection(userProps) {
|
|
|
3962
3959
|
var dropdownRef = preact.useRef(null);
|
|
3963
3960
|
var previousSelectedItemsRef = preact.useRef(selectedItems);
|
|
3964
3961
|
var selectedItemRefs = preact.useRef();
|
|
3965
|
-
selectedItemRefs.current = [];
|
|
3966
|
-
|
|
3967
|
-
var prevPropsRef = preact.useRef(props);
|
|
3962
|
+
selectedItemRefs.current = [];
|
|
3968
3963
|
var latest = useLatestRef({
|
|
3969
3964
|
state: state,
|
|
3970
3965
|
props: props
|
|
@@ -4004,14 +3999,11 @@ function useMultipleSelection(userProps) {
|
|
|
4004
3999
|
selectedItemRefs.current[activeIndex].focus();
|
|
4005
4000
|
}
|
|
4006
4001
|
}, [activeIndex]);
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
validateControlledUnchanged(state, prevPropsRef.current, props);
|
|
4013
|
-
prevPropsRef.current = props;
|
|
4014
|
-
}, [state, props]);
|
|
4002
|
+
useControlPropsValidator({
|
|
4003
|
+
isInitialMount: isInitialMountRef.current,
|
|
4004
|
+
props: props,
|
|
4005
|
+
state: state
|
|
4006
|
+
});
|
|
4015
4007
|
var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
4016
4008
|
|
|
4017
4009
|
preact.useEffect(function () {
|