downshift 8.1.1 → 8.2.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.js +78 -57
- package/dist/downshift.esm.js +77 -55
- package/dist/downshift.native.cjs.js +67 -135
- package/dist/downshift.nativeweb.cjs.js +78 -57
- package/dist/downshift.umd.js +1281 -1196
- 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/src/hooks/useSelect/utils.d.ts +1 -1
- package/dist/src/hooks/utils.d.ts +1 -1
- package/dist/src/set-a11y-status.d.ts +1 -2
- package/dist/test/setup.d.ts +1 -1
- package/package.json +47 -43
- package/preact/dist/downshift.cjs.js +79 -58
- package/preact/dist/downshift.esm.js +78 -56
- package/preact/dist/downshift.umd.js +303 -283
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +4 -3
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/CHANGELOG.md +0 -5
package/dist/downshift.cjs.js
CHANGED
|
@@ -9,7 +9,7 @@ var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
|
9
9
|
var PropTypes = require('prop-types');
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var reactIs = require('react-is');
|
|
12
|
-
var
|
|
12
|
+
var computeScrollIntoView = require('compute-scroll-into-view');
|
|
13
13
|
var tslib = require('tslib');
|
|
14
14
|
|
|
15
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -20,7 +20,6 @@ var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assert
|
|
|
20
20
|
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
21
21
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
22
22
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
23
|
-
var compute__default = /*#__PURE__*/_interopDefaultLegacy(compute);
|
|
24
23
|
|
|
25
24
|
var idCounter = 0;
|
|
26
25
|
|
|
@@ -46,7 +45,7 @@ function scrollIntoView(node, menuNode) {
|
|
|
46
45
|
if (!node) {
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
|
-
var actions =
|
|
48
|
+
var actions = computeScrollIntoView.compute(node, {
|
|
50
49
|
boundary: menuNode,
|
|
51
50
|
block: 'nearest',
|
|
52
51
|
scrollMode: 'if-needed'
|
|
@@ -382,7 +381,7 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
|
|
|
382
381
|
if (checkActiveElement === void 0) {
|
|
383
382
|
checkActiveElement = true;
|
|
384
383
|
}
|
|
385
|
-
return downshiftElements.some(function (contextNode) {
|
|
384
|
+
return environment && downshiftElements.some(function (contextNode) {
|
|
386
385
|
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
387
386
|
});
|
|
388
387
|
}
|
|
@@ -409,28 +408,12 @@ var cleanupStatus = debounce(function (documentProp) {
|
|
|
409
408
|
getStatusDiv(documentProp).textContent = '';
|
|
410
409
|
}, 500);
|
|
411
410
|
|
|
412
|
-
/**
|
|
413
|
-
* @param {String} status the status message
|
|
414
|
-
* @param {Object} documentProp document passed by the user.
|
|
415
|
-
*/
|
|
416
|
-
function setStatus(status, documentProp) {
|
|
417
|
-
var div = getStatusDiv(documentProp);
|
|
418
|
-
if (!status) {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
div.textContent = status;
|
|
422
|
-
cleanupStatus(documentProp);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
411
|
/**
|
|
426
412
|
* Get the status node or create it if it does not already exist.
|
|
427
413
|
* @param {Object} documentProp document passed by the user.
|
|
428
414
|
* @return {HTMLElement} the status node.
|
|
429
415
|
*/
|
|
430
416
|
function getStatusDiv(documentProp) {
|
|
431
|
-
if (documentProp === void 0) {
|
|
432
|
-
documentProp = document;
|
|
433
|
-
}
|
|
434
417
|
var statusDiv = documentProp.getElementById('a11y-status-message');
|
|
435
418
|
if (statusDiv) {
|
|
436
419
|
return statusDiv;
|
|
@@ -454,6 +437,19 @@ function getStatusDiv(documentProp) {
|
|
|
454
437
|
return statusDiv;
|
|
455
438
|
}
|
|
456
439
|
|
|
440
|
+
/**
|
|
441
|
+
* @param {String} status the status message
|
|
442
|
+
* @param {Object} documentProp document passed by the user.
|
|
443
|
+
*/
|
|
444
|
+
function setStatus(status, documentProp) {
|
|
445
|
+
if (!status || !documentProp) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
var div = getStatusDiv(documentProp);
|
|
449
|
+
div.textContent = status;
|
|
450
|
+
cleanupStatus(documentProp);
|
|
451
|
+
}
|
|
452
|
+
|
|
457
453
|
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
458
454
|
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
459
455
|
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
@@ -514,7 +510,6 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
514
510
|
_this.getItemId = _this.props.getItemId || function (index) {
|
|
515
511
|
return _this.id + "-item-" + index;
|
|
516
512
|
};
|
|
517
|
-
_this.input = null;
|
|
518
513
|
_this.items = [];
|
|
519
514
|
// itemCount can be changed asynchronously
|
|
520
515
|
// from within downshift (so it can't come from a prop)
|
|
@@ -608,6 +603,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
608
603
|
_this.props.onInputValueChange(stateToSet.inputValue, _extends__default["default"]({}, _this.getStateAndHelpers(), stateToSet));
|
|
609
604
|
}
|
|
610
605
|
return _this.setState(function (state) {
|
|
606
|
+
var _newStateToSet;
|
|
611
607
|
state = _this.getState(state);
|
|
612
608
|
var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
|
|
613
609
|
|
|
@@ -626,7 +622,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
626
622
|
if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
|
|
627
623
|
onChangeArg = newStateToSet.selectedItem;
|
|
628
624
|
}
|
|
629
|
-
|
|
625
|
+
(_newStateToSet = newStateToSet).type || (_newStateToSet.type = unknown);
|
|
630
626
|
Object.keys(newStateToSet).forEach(function (key) {
|
|
631
627
|
// onStateChangeArg should only have the state that is
|
|
632
628
|
// actually changing
|
|
@@ -875,8 +871,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
875
871
|
// handle odd case for Safari and Firefox which
|
|
876
872
|
// don't give the button the focus properly.
|
|
877
873
|
/* istanbul ignore if (can't reasonably test this) */
|
|
878
|
-
if (_this.props.environment
|
|
879
|
-
|
|
874
|
+
if (_this.props.environment) {
|
|
875
|
+
var _this$props$environme = _this.props.environment.document,
|
|
876
|
+
body = _this$props$environme.body,
|
|
877
|
+
activeElement = _this$props$environme.activeElement;
|
|
878
|
+
if (body && body === activeElement) {
|
|
879
|
+
event.target.focus();
|
|
880
|
+
}
|
|
880
881
|
}
|
|
881
882
|
// to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
882
883
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -898,7 +899,11 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
898
899
|
var blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
899
900
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
900
901
|
_this.internalSetTimeout(function () {
|
|
901
|
-
if (
|
|
902
|
+
if (_this.isMouseDown || !_this.props.environment) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
var activeElement = _this.props.environment.document.activeElement;
|
|
906
|
+
if ((activeElement == null || activeElement.id !== _this.inputId) && activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
|
|
902
907
|
) {
|
|
903
908
|
_this.reset({
|
|
904
909
|
type: blurButton
|
|
@@ -968,8 +973,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
968
973
|
_this.inputHandleBlur = function () {
|
|
969
974
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
970
975
|
_this.internalSetTimeout(function () {
|
|
971
|
-
var
|
|
972
|
-
if (
|
|
976
|
+
var _activeElement$datase;
|
|
977
|
+
if (_this.isMouseDown || !_this.props.environment) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
var activeElement = _this.props.environment.document.activeElement;
|
|
981
|
+
var downshiftButtonIsActive = (activeElement == null || (_activeElement$datase = activeElement.dataset) == null ? void 0 : _activeElement$datase.toggle) && _this._rootNode && _this._rootNode.contains(activeElement);
|
|
982
|
+
if (!downshiftButtonIsActive) {
|
|
973
983
|
_this.reset({
|
|
974
984
|
type: blurInput
|
|
975
985
|
});
|
|
@@ -1114,6 +1124,10 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1114
1124
|
}, cb);
|
|
1115
1125
|
};
|
|
1116
1126
|
_this.updateStatus = debounce(function () {
|
|
1127
|
+
var _this$props;
|
|
1128
|
+
if (!((_this$props = _this.props) != null && (_this$props = _this$props.environment) != null && _this$props.document)) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1117
1131
|
var state = _this.getState();
|
|
1118
1132
|
var item = _this.items[state.highlightedIndex];
|
|
1119
1133
|
var resultCount = _this.getItemCount();
|
|
@@ -1126,17 +1140,17 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1126
1140
|
_this.previousResultCount = resultCount;
|
|
1127
1141
|
setStatus(status, _this.props.environment.document);
|
|
1128
1142
|
}, 200);
|
|
1129
|
-
var _this$
|
|
1130
|
-
defaultHighlightedIndex = _this$
|
|
1131
|
-
_this$
|
|
1132
|
-
_highlightedIndex = _this$
|
|
1133
|
-
defaultIsOpen = _this$
|
|
1134
|
-
_this$
|
|
1135
|
-
_isOpen = _this$
|
|
1136
|
-
_this$
|
|
1137
|
-
_inputValue = _this$
|
|
1138
|
-
_this$
|
|
1139
|
-
_selectedItem = _this$
|
|
1143
|
+
var _this$props2 = _this.props,
|
|
1144
|
+
defaultHighlightedIndex = _this$props2.defaultHighlightedIndex,
|
|
1145
|
+
_this$props2$initialH = _this$props2.initialHighlightedIndex,
|
|
1146
|
+
_highlightedIndex = _this$props2$initialH === void 0 ? defaultHighlightedIndex : _this$props2$initialH,
|
|
1147
|
+
defaultIsOpen = _this$props2.defaultIsOpen,
|
|
1148
|
+
_this$props2$initialI = _this$props2.initialIsOpen,
|
|
1149
|
+
_isOpen = _this$props2$initialI === void 0 ? defaultIsOpen : _this$props2$initialI,
|
|
1150
|
+
_this$props2$initialI2 = _this$props2.initialInputValue,
|
|
1151
|
+
_inputValue = _this$props2$initialI2 === void 0 ? '' : _this$props2$initialI2,
|
|
1152
|
+
_this$props2$initialS = _this$props2.initialSelectedItem,
|
|
1153
|
+
_selectedItem = _this$props2$initialS === void 0 ? null : _this$props2$initialS;
|
|
1140
1154
|
var _state = _this.getState({
|
|
1141
1155
|
highlightedIndex: _highlightedIndex,
|
|
1142
1156
|
isOpen: _isOpen,
|
|
@@ -1189,7 +1203,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1189
1203
|
return itemCount;
|
|
1190
1204
|
};
|
|
1191
1205
|
_proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
|
|
1192
|
-
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
1206
|
+
return this.props.environment ? this.props.environment.document.getElementById(this.getItemId(index)) : null;
|
|
1193
1207
|
};
|
|
1194
1208
|
_proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
|
|
1195
1209
|
/* istanbul ignore else (react-native) */
|
|
@@ -1276,8 +1290,12 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1276
1290
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
1277
1291
|
}
|
|
1278
1292
|
|
|
1279
|
-
/* istanbul ignore if (react-native) */
|
|
1280
|
-
{
|
|
1293
|
+
/* istanbul ignore if (react-native or SSR) */
|
|
1294
|
+
if (!this.props.environment) {
|
|
1295
|
+
this.cleanup = function () {
|
|
1296
|
+
_this4.internalClearTimeouts();
|
|
1297
|
+
};
|
|
1298
|
+
} else {
|
|
1281
1299
|
// this.isMouseDown helps us track whether the mouse is currently held down.
|
|
1282
1300
|
// This is useful when the user clicks on an item in the list, but holds the mouse
|
|
1283
1301
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
@@ -1446,7 +1464,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1446
1464
|
return prevItem !== item;
|
|
1447
1465
|
},
|
|
1448
1466
|
environment: /* istanbul ignore next (ssr) */
|
|
1449
|
-
typeof window === 'undefined' ?
|
|
1467
|
+
typeof window === 'undefined' ? undefined : window,
|
|
1450
1468
|
stateReducer: function stateReducer(state, stateToSet) {
|
|
1451
1469
|
return stateToSet;
|
|
1452
1470
|
},
|
|
@@ -1733,7 +1751,7 @@ var defaultProps$3 = {
|
|
|
1733
1751
|
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
1734
1752
|
scrollIntoView: scrollIntoView,
|
|
1735
1753
|
environment: /* istanbul ignore next (ssr) */
|
|
1736
|
-
typeof window === 'undefined' ?
|
|
1754
|
+
typeof window === 'undefined' ? undefined : window
|
|
1737
1755
|
};
|
|
1738
1756
|
function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
1739
1757
|
if (defaultStateValues === void 0) {
|
|
@@ -1812,7 +1830,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1812
1830
|
isTouchMove: false
|
|
1813
1831
|
});
|
|
1814
1832
|
React.useEffect(function () {
|
|
1815
|
-
if (
|
|
1833
|
+
if (!environment) {
|
|
1816
1834
|
return;
|
|
1817
1835
|
}
|
|
1818
1836
|
|
|
@@ -1921,7 +1939,7 @@ function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref3) {
|
|
|
1921
1939
|
rest = _objectWithoutPropertiesLoose__default["default"](_ref3, _excluded$3);
|
|
1922
1940
|
// Sets a11y status message on changes in state.
|
|
1923
1941
|
React.useEffect(function () {
|
|
1924
|
-
if (isInitialMount || false) {
|
|
1942
|
+
if (isInitialMount || false || !(environment != null && environment.document)) {
|
|
1925
1943
|
return;
|
|
1926
1944
|
}
|
|
1927
1945
|
updateA11yStatus(function () {
|
|
@@ -2118,7 +2136,6 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2118
2136
|
}
|
|
2119
2137
|
return highlightedIndex;
|
|
2120
2138
|
}
|
|
2121
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
2122
2139
|
var propTypes$2 = tslib.__assign(tslib.__assign({}, commonDropdownPropTypes), { items: PropTypes__default["default"].array.isRequired, isItemDisabled: PropTypes__default["default"].func, getA11ySelectionMessage: PropTypes__default["default"].func });
|
|
2123
2140
|
/**
|
|
2124
2141
|
* Default implementation for status message. Only added when menu is open.
|
|
@@ -2309,7 +2326,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2309
2326
|
}
|
|
2310
2327
|
/* eslint-enable complexity */
|
|
2311
2328
|
|
|
2312
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "
|
|
2329
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
2313
2330
|
_excluded2$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2314
2331
|
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "onPress", "refKey", "disabled", "ref"];
|
|
2315
2332
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
@@ -2580,10 +2597,8 @@ function useSelect(userProps) {
|
|
|
2580
2597
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
2581
2598
|
onMouseLeave = _ref.onMouseLeave,
|
|
2582
2599
|
_ref$refKey = _ref.refKey,
|
|
2583
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey
|
|
2584
|
-
_ref.
|
|
2585
|
-
_ref.onBlur;
|
|
2586
|
-
var ref = _ref.ref,
|
|
2600
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
2601
|
+
ref = _ref.ref,
|
|
2587
2602
|
rest = _objectWithoutPropertiesLoose__default["default"](_ref, _excluded$2);
|
|
2588
2603
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
2589
2604
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
@@ -3077,12 +3092,18 @@ function useCombobox(userProps) {
|
|
|
3077
3092
|
}, []);
|
|
3078
3093
|
// Reset itemRefs on close.
|
|
3079
3094
|
React.useEffect(function () {
|
|
3080
|
-
var _environment$document;
|
|
3081
3095
|
if (!isOpen) {
|
|
3082
3096
|
itemRefs.current = {};
|
|
3083
|
-
}
|
|
3084
|
-
|
|
3085
|
-
|
|
3097
|
+
}
|
|
3098
|
+
}, [isOpen]);
|
|
3099
|
+
// Reset itemRefs on close.
|
|
3100
|
+
React.useEffect(function () {
|
|
3101
|
+
var _inputRef$current;
|
|
3102
|
+
if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3103
|
+
return;
|
|
3104
|
+
}
|
|
3105
|
+
if (environment.document.activeElement !== inputRef.current) {
|
|
3106
|
+
inputRef.current.focus();
|
|
3086
3107
|
}
|
|
3087
3108
|
}, [isOpen, environment]);
|
|
3088
3109
|
|
|
@@ -3296,7 +3317,7 @@ function useCombobox(userProps) {
|
|
|
3296
3317
|
};
|
|
3297
3318
|
var inputHandleBlur = function inputHandleBlur(event) {
|
|
3298
3319
|
/* istanbul ignore else */
|
|
3299
|
-
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3320
|
+
if (environment != null && environment.document && latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3300
3321
|
var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
|
|
3301
3322
|
dispatch({
|
|
3302
3323
|
type: InputBlur,
|
|
@@ -3675,7 +3696,7 @@ function useMultipleSelection(userProps) {
|
|
|
3675
3696
|
// Effects.
|
|
3676
3697
|
/* Sets a11y status message on changes in selectedItem. */
|
|
3677
3698
|
React.useEffect(function () {
|
|
3678
|
-
if (isInitialMountRef.current || false) {
|
|
3699
|
+
if (isInitialMountRef.current || false || !(environment != null && environment.document)) {
|
|
3679
3700
|
return;
|
|
3680
3701
|
}
|
|
3681
3702
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
package/dist/downshift.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import React, { cloneElement, Component, useRef, useEffect, useCallback, useLayoutEffect, useReducer, useMemo } from 'react';
|
|
7
7
|
import { isForwardRef } from 'react-is';
|
|
8
|
-
import compute from 'compute-scroll-into-view';
|
|
8
|
+
import { compute } from 'compute-scroll-into-view';
|
|
9
9
|
import { __assign } from 'tslib';
|
|
10
10
|
|
|
11
11
|
var idCounter = 0;
|
|
@@ -368,7 +368,7 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
|
|
|
368
368
|
if (checkActiveElement === void 0) {
|
|
369
369
|
checkActiveElement = true;
|
|
370
370
|
}
|
|
371
|
-
return downshiftElements.some(function (contextNode) {
|
|
371
|
+
return environment && downshiftElements.some(function (contextNode) {
|
|
372
372
|
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
373
373
|
});
|
|
374
374
|
}
|
|
@@ -395,28 +395,12 @@ var cleanupStatus = debounce(function (documentProp) {
|
|
|
395
395
|
getStatusDiv(documentProp).textContent = '';
|
|
396
396
|
}, 500);
|
|
397
397
|
|
|
398
|
-
/**
|
|
399
|
-
* @param {String} status the status message
|
|
400
|
-
* @param {Object} documentProp document passed by the user.
|
|
401
|
-
*/
|
|
402
|
-
function setStatus(status, documentProp) {
|
|
403
|
-
var div = getStatusDiv(documentProp);
|
|
404
|
-
if (!status) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
div.textContent = status;
|
|
408
|
-
cleanupStatus(documentProp);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
398
|
/**
|
|
412
399
|
* Get the status node or create it if it does not already exist.
|
|
413
400
|
* @param {Object} documentProp document passed by the user.
|
|
414
401
|
* @return {HTMLElement} the status node.
|
|
415
402
|
*/
|
|
416
403
|
function getStatusDiv(documentProp) {
|
|
417
|
-
if (documentProp === void 0) {
|
|
418
|
-
documentProp = document;
|
|
419
|
-
}
|
|
420
404
|
var statusDiv = documentProp.getElementById('a11y-status-message');
|
|
421
405
|
if (statusDiv) {
|
|
422
406
|
return statusDiv;
|
|
@@ -440,6 +424,19 @@ function getStatusDiv(documentProp) {
|
|
|
440
424
|
return statusDiv;
|
|
441
425
|
}
|
|
442
426
|
|
|
427
|
+
/**
|
|
428
|
+
* @param {String} status the status message
|
|
429
|
+
* @param {Object} documentProp document passed by the user.
|
|
430
|
+
*/
|
|
431
|
+
function setStatus(status, documentProp) {
|
|
432
|
+
if (!status || !documentProp) {
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
var div = getStatusDiv(documentProp);
|
|
436
|
+
div.textContent = status;
|
|
437
|
+
cleanupStatus(documentProp);
|
|
438
|
+
}
|
|
439
|
+
|
|
443
440
|
var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
444
441
|
var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
445
442
|
var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
@@ -500,7 +497,6 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
500
497
|
_this.getItemId = _this.props.getItemId || function (index) {
|
|
501
498
|
return _this.id + "-item-" + index;
|
|
502
499
|
};
|
|
503
|
-
_this.input = null;
|
|
504
500
|
_this.items = [];
|
|
505
501
|
// itemCount can be changed asynchronously
|
|
506
502
|
// from within downshift (so it can't come from a prop)
|
|
@@ -594,6 +590,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
594
590
|
_this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), stateToSet));
|
|
595
591
|
}
|
|
596
592
|
return _this.setState(function (state) {
|
|
593
|
+
var _newStateToSet;
|
|
597
594
|
state = _this.getState(state);
|
|
598
595
|
var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
|
|
599
596
|
|
|
@@ -612,7 +609,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
612
609
|
if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
|
|
613
610
|
onChangeArg = newStateToSet.selectedItem;
|
|
614
611
|
}
|
|
615
|
-
|
|
612
|
+
(_newStateToSet = newStateToSet).type || (_newStateToSet.type = unknown);
|
|
616
613
|
Object.keys(newStateToSet).forEach(function (key) {
|
|
617
614
|
// onStateChangeArg should only have the state that is
|
|
618
615
|
// actually changing
|
|
@@ -861,8 +858,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
861
858
|
// handle odd case for Safari and Firefox which
|
|
862
859
|
// don't give the button the focus properly.
|
|
863
860
|
/* istanbul ignore if (can't reasonably test this) */
|
|
864
|
-
if (_this.props.environment
|
|
865
|
-
|
|
861
|
+
if (_this.props.environment) {
|
|
862
|
+
var _this$props$environme = _this.props.environment.document,
|
|
863
|
+
body = _this$props$environme.body,
|
|
864
|
+
activeElement = _this$props$environme.activeElement;
|
|
865
|
+
if (body && body === activeElement) {
|
|
866
|
+
event.target.focus();
|
|
867
|
+
}
|
|
866
868
|
}
|
|
867
869
|
// to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
868
870
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -884,7 +886,11 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
884
886
|
var blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
885
887
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
886
888
|
_this.internalSetTimeout(function () {
|
|
887
|
-
if (
|
|
889
|
+
if (_this.isMouseDown || !_this.props.environment) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
var activeElement = _this.props.environment.document.activeElement;
|
|
893
|
+
if ((activeElement == null || activeElement.id !== _this.inputId) && activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
|
|
888
894
|
) {
|
|
889
895
|
_this.reset({
|
|
890
896
|
type: blurButton
|
|
@@ -954,8 +960,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
954
960
|
_this.inputHandleBlur = function () {
|
|
955
961
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
956
962
|
_this.internalSetTimeout(function () {
|
|
957
|
-
var
|
|
958
|
-
if (
|
|
963
|
+
var _activeElement$datase;
|
|
964
|
+
if (_this.isMouseDown || !_this.props.environment) {
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
var activeElement = _this.props.environment.document.activeElement;
|
|
968
|
+
var downshiftButtonIsActive = (activeElement == null || (_activeElement$datase = activeElement.dataset) == null ? void 0 : _activeElement$datase.toggle) && _this._rootNode && _this._rootNode.contains(activeElement);
|
|
969
|
+
if (!downshiftButtonIsActive) {
|
|
959
970
|
_this.reset({
|
|
960
971
|
type: blurInput
|
|
961
972
|
});
|
|
@@ -1100,6 +1111,10 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1100
1111
|
}, cb);
|
|
1101
1112
|
};
|
|
1102
1113
|
_this.updateStatus = debounce(function () {
|
|
1114
|
+
var _this$props;
|
|
1115
|
+
if (!((_this$props = _this.props) != null && (_this$props = _this$props.environment) != null && _this$props.document)) {
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1103
1118
|
var state = _this.getState();
|
|
1104
1119
|
var item = _this.items[state.highlightedIndex];
|
|
1105
1120
|
var resultCount = _this.getItemCount();
|
|
@@ -1112,17 +1127,17 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1112
1127
|
_this.previousResultCount = resultCount;
|
|
1113
1128
|
setStatus(status, _this.props.environment.document);
|
|
1114
1129
|
}, 200);
|
|
1115
|
-
var _this$
|
|
1116
|
-
defaultHighlightedIndex = _this$
|
|
1117
|
-
_this$
|
|
1118
|
-
_highlightedIndex = _this$
|
|
1119
|
-
defaultIsOpen = _this$
|
|
1120
|
-
_this$
|
|
1121
|
-
_isOpen = _this$
|
|
1122
|
-
_this$
|
|
1123
|
-
_inputValue = _this$
|
|
1124
|
-
_this$
|
|
1125
|
-
_selectedItem = _this$
|
|
1130
|
+
var _this$props2 = _this.props,
|
|
1131
|
+
defaultHighlightedIndex = _this$props2.defaultHighlightedIndex,
|
|
1132
|
+
_this$props2$initialH = _this$props2.initialHighlightedIndex,
|
|
1133
|
+
_highlightedIndex = _this$props2$initialH === void 0 ? defaultHighlightedIndex : _this$props2$initialH,
|
|
1134
|
+
defaultIsOpen = _this$props2.defaultIsOpen,
|
|
1135
|
+
_this$props2$initialI = _this$props2.initialIsOpen,
|
|
1136
|
+
_isOpen = _this$props2$initialI === void 0 ? defaultIsOpen : _this$props2$initialI,
|
|
1137
|
+
_this$props2$initialI2 = _this$props2.initialInputValue,
|
|
1138
|
+
_inputValue = _this$props2$initialI2 === void 0 ? '' : _this$props2$initialI2,
|
|
1139
|
+
_this$props2$initialS = _this$props2.initialSelectedItem,
|
|
1140
|
+
_selectedItem = _this$props2$initialS === void 0 ? null : _this$props2$initialS;
|
|
1126
1141
|
var _state = _this.getState({
|
|
1127
1142
|
highlightedIndex: _highlightedIndex,
|
|
1128
1143
|
isOpen: _isOpen,
|
|
@@ -1175,7 +1190,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1175
1190
|
return itemCount;
|
|
1176
1191
|
};
|
|
1177
1192
|
_proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
|
|
1178
|
-
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
1193
|
+
return this.props.environment ? this.props.environment.document.getElementById(this.getItemId(index)) : null;
|
|
1179
1194
|
};
|
|
1180
1195
|
_proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
|
|
1181
1196
|
/* istanbul ignore else (react-native) */
|
|
@@ -1262,8 +1277,12 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1262
1277
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
1263
1278
|
}
|
|
1264
1279
|
|
|
1265
|
-
/* istanbul ignore if (react-native) */
|
|
1266
|
-
{
|
|
1280
|
+
/* istanbul ignore if (react-native or SSR) */
|
|
1281
|
+
if (!this.props.environment) {
|
|
1282
|
+
this.cleanup = function () {
|
|
1283
|
+
_this4.internalClearTimeouts();
|
|
1284
|
+
};
|
|
1285
|
+
} else {
|
|
1267
1286
|
// this.isMouseDown helps us track whether the mouse is currently held down.
|
|
1268
1287
|
// This is useful when the user clicks on an item in the list, but holds the mouse
|
|
1269
1288
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
@@ -1432,7 +1451,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1432
1451
|
return prevItem !== item;
|
|
1433
1452
|
},
|
|
1434
1453
|
environment: /* istanbul ignore next (ssr) */
|
|
1435
|
-
typeof window === 'undefined' ?
|
|
1454
|
+
typeof window === 'undefined' ? undefined : window,
|
|
1436
1455
|
stateReducer: function stateReducer(state, stateToSet) {
|
|
1437
1456
|
return stateToSet;
|
|
1438
1457
|
},
|
|
@@ -1719,7 +1738,7 @@ var defaultProps$3 = {
|
|
|
1719
1738
|
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
1720
1739
|
scrollIntoView: scrollIntoView,
|
|
1721
1740
|
environment: /* istanbul ignore next (ssr) */
|
|
1722
|
-
typeof window === 'undefined' ?
|
|
1741
|
+
typeof window === 'undefined' ? undefined : window
|
|
1723
1742
|
};
|
|
1724
1743
|
function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
1725
1744
|
if (defaultStateValues === void 0) {
|
|
@@ -1798,7 +1817,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1798
1817
|
isTouchMove: false
|
|
1799
1818
|
});
|
|
1800
1819
|
useEffect(function () {
|
|
1801
|
-
if (
|
|
1820
|
+
if (!environment) {
|
|
1802
1821
|
return;
|
|
1803
1822
|
}
|
|
1804
1823
|
|
|
@@ -1907,7 +1926,7 @@ function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref3) {
|
|
|
1907
1926
|
rest = _objectWithoutPropertiesLoose(_ref3, _excluded$3);
|
|
1908
1927
|
// Sets a11y status message on changes in state.
|
|
1909
1928
|
useEffect(function () {
|
|
1910
|
-
if (isInitialMount || false) {
|
|
1929
|
+
if (isInitialMount || false || !(environment != null && environment.document)) {
|
|
1911
1930
|
return;
|
|
1912
1931
|
}
|
|
1913
1932
|
updateA11yStatus(function () {
|
|
@@ -2104,7 +2123,6 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2104
2123
|
}
|
|
2105
2124
|
return highlightedIndex;
|
|
2106
2125
|
}
|
|
2107
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
2108
2126
|
var propTypes$2 = __assign(__assign({}, commonDropdownPropTypes), { items: PropTypes.array.isRequired, isItemDisabled: PropTypes.func, getA11ySelectionMessage: PropTypes.func });
|
|
2109
2127
|
/**
|
|
2110
2128
|
* Default implementation for status message. Only added when menu is open.
|
|
@@ -2295,7 +2313,7 @@ function downshiftSelectReducer(state, action) {
|
|
|
2295
2313
|
}
|
|
2296
2314
|
/* eslint-enable complexity */
|
|
2297
2315
|
|
|
2298
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "
|
|
2316
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "ref"],
|
|
2299
2317
|
_excluded2$2 = ["onBlur", "onClick", "onPress", "onKeyDown", "refKey", "ref"],
|
|
2300
2318
|
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "onPress", "refKey", "disabled", "ref"];
|
|
2301
2319
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
@@ -2566,10 +2584,8 @@ function useSelect(userProps) {
|
|
|
2566
2584
|
var _ref = _temp === void 0 ? {} : _temp,
|
|
2567
2585
|
onMouseLeave = _ref.onMouseLeave,
|
|
2568
2586
|
_ref$refKey = _ref.refKey,
|
|
2569
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey
|
|
2570
|
-
_ref.
|
|
2571
|
-
_ref.onBlur;
|
|
2572
|
-
var ref = _ref.ref,
|
|
2587
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
2588
|
+
ref = _ref.ref,
|
|
2573
2589
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
2574
2590
|
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
2575
2591
|
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
@@ -3063,12 +3079,18 @@ function useCombobox(userProps) {
|
|
|
3063
3079
|
}, []);
|
|
3064
3080
|
// Reset itemRefs on close.
|
|
3065
3081
|
useEffect(function () {
|
|
3066
|
-
var _environment$document;
|
|
3067
3082
|
if (!isOpen) {
|
|
3068
3083
|
itemRefs.current = {};
|
|
3069
|
-
}
|
|
3070
|
-
|
|
3071
|
-
|
|
3084
|
+
}
|
|
3085
|
+
}, [isOpen]);
|
|
3086
|
+
// Reset itemRefs on close.
|
|
3087
|
+
useEffect(function () {
|
|
3088
|
+
var _inputRef$current;
|
|
3089
|
+
if (!isOpen || !(environment != null && environment.document) || !(inputRef != null && (_inputRef$current = inputRef.current) != null && _inputRef$current.focus)) {
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
3092
|
+
if (environment.document.activeElement !== inputRef.current) {
|
|
3093
|
+
inputRef.current.focus();
|
|
3072
3094
|
}
|
|
3073
3095
|
}, [isOpen, environment]);
|
|
3074
3096
|
|
|
@@ -3282,7 +3304,7 @@ function useCombobox(userProps) {
|
|
|
3282
3304
|
};
|
|
3283
3305
|
var inputHandleBlur = function inputHandleBlur(event) {
|
|
3284
3306
|
/* istanbul ignore else */
|
|
3285
|
-
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3307
|
+
if (environment != null && environment.document && latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3286
3308
|
var isBlurByTabChange = event.relatedTarget === null && environment.document.activeElement !== environment.document.body;
|
|
3287
3309
|
dispatch({
|
|
3288
3310
|
type: InputBlur,
|
|
@@ -3661,7 +3683,7 @@ function useMultipleSelection(userProps) {
|
|
|
3661
3683
|
// Effects.
|
|
3662
3684
|
/* Sets a11y status message on changes in selectedItem. */
|
|
3663
3685
|
useEffect(function () {
|
|
3664
|
-
if (isInitialMountRef.current || false) {
|
|
3686
|
+
if (isInitialMountRef.current || false || !(environment != null && environment.document)) {
|
|
3665
3687
|
return;
|
|
3666
3688
|
}
|
|
3667
3689
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|