downshift 7.2.2-alpha.0 → 7.3.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/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/dist/downshift.cjs.js +37 -7
- package/dist/downshift.esm.js +37 -7
- package/dist/downshift.native.cjs.js +116 -10
- package/dist/downshift.umd.js +37 -7
- 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/package.json +1 -1
- package/preact/dist/downshift.cjs.js +37 -7
- package/preact/dist/downshift.esm.js +37 -7
- package/preact/dist/downshift.umd.js +37 -7
- 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/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ has been around for a while. It established a successful pattern for making
|
|
|
57
57
|
components accessible and functional while giving developers complete freedom
|
|
58
58
|
when building the UI.
|
|
59
59
|
|
|
60
|
-
Both _useSelect_ and _useCombobox_ support
|
|
60
|
+
Both _useSelect_ and _useCombobox_ support the latest ARIA combobox patterns for
|
|
61
61
|
W3C, which _Downshift_ does not. Consequently, we strongly recommend the you use
|
|
62
62
|
the hooks. The hooks have been migrated to the ARIA 1.2 combobox pattern in the
|
|
63
63
|
version 7 of _downshift_. There is a [Migration Guide][migration-guide-v7] that
|
package/dist/downshift.cjs.js
CHANGED
|
@@ -510,9 +510,18 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
510
510
|
};
|
|
511
511
|
_this.input = null;
|
|
512
512
|
_this.items = [];
|
|
513
|
+
// itemCount can be changed asynchronously
|
|
514
|
+
// from within downshift (so it can't come from a prop)
|
|
515
|
+
// this is why we store it as an instance and use
|
|
516
|
+
// getItemCount rather than just use items.length
|
|
517
|
+
// (to support windowing + async)
|
|
513
518
|
_this.itemCount = null;
|
|
514
519
|
_this.previousResultCount = 0;
|
|
515
520
|
_this.timeoutIds = [];
|
|
521
|
+
/**
|
|
522
|
+
* @param {Function} fn the function to call after the time
|
|
523
|
+
* @param {Number} time the time to wait
|
|
524
|
+
*/
|
|
516
525
|
_this.internalSetTimeout = function (fn, time) {
|
|
517
526
|
var id = setTimeout(function () {
|
|
518
527
|
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
@@ -567,6 +576,14 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
567
576
|
_this.selectHighlightedItem = function (otherStateToSet, cb) {
|
|
568
577
|
return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
|
569
578
|
};
|
|
579
|
+
// any piece of our state can live in two places:
|
|
580
|
+
// 1. Uncontrolled: it's internal (this.state)
|
|
581
|
+
// We will call this.setState to update that state
|
|
582
|
+
// 2. Controlled: it's external (this.props)
|
|
583
|
+
// We will call this.props.onStateChange to update that state
|
|
584
|
+
//
|
|
585
|
+
// In addition, we'll call this.props.onChange if the
|
|
586
|
+
// selectedItem is changed.
|
|
570
587
|
_this.internalSetState = function (stateToSet, cb) {
|
|
571
588
|
var isItemSelected, onChangeArg;
|
|
572
589
|
var onStateChangeArg = {};
|
|
@@ -649,6 +666,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
649
666
|
_this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
|
650
667
|
});
|
|
651
668
|
};
|
|
669
|
+
//////////////////////////// ROOT
|
|
652
670
|
_this.rootRef = function (node) {
|
|
653
671
|
return _this._rootNode = node;
|
|
654
672
|
};
|
|
@@ -671,6 +689,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
671
689
|
isOpen = _this$getState.isOpen;
|
|
672
690
|
return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
|
|
673
691
|
};
|
|
692
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
|
|
674
693
|
_this.keyDownHandlers = {
|
|
675
694
|
ArrowDown: function ArrowDown(event) {
|
|
676
695
|
var _this2 = this;
|
|
@@ -755,6 +774,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
755
774
|
}));
|
|
756
775
|
}
|
|
757
776
|
};
|
|
777
|
+
//////////////////////////// BUTTON
|
|
758
778
|
_this.buttonKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
|
|
759
779
|
' ': function _(event) {
|
|
760
780
|
event.preventDefault();
|
|
@@ -878,12 +898,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
878
898
|
}
|
|
879
899
|
});
|
|
880
900
|
};
|
|
901
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
|
|
902
|
+
/////////////////////////////// LABEL
|
|
881
903
|
_this.getLabelProps = function (props) {
|
|
882
904
|
return _extends__default["default"]({
|
|
883
905
|
htmlFor: _this.inputId,
|
|
884
906
|
id: _this.labelId
|
|
885
907
|
}, props);
|
|
886
908
|
};
|
|
909
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
|
|
910
|
+
/////////////////////////////// INPUT
|
|
887
911
|
_this.getInputProps = function (_temp4) {
|
|
888
912
|
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
889
913
|
onKeyDown = _ref4.onKeyDown,
|
|
@@ -944,6 +968,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
944
968
|
}
|
|
945
969
|
});
|
|
946
970
|
};
|
|
971
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
|
|
972
|
+
/////////////////////////////// MENU
|
|
947
973
|
_this.menuRef = function (node) {
|
|
948
974
|
_this._menuNode = node;
|
|
949
975
|
};
|
|
@@ -962,6 +988,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
962
988
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
963
989
|
return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
|
964
990
|
};
|
|
991
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
|
|
992
|
+
/////////////////////////////// ITEM
|
|
965
993
|
_this.getItemProps = function (_temp7) {
|
|
966
994
|
var _enabledEventHandlers;
|
|
967
995
|
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
@@ -1025,6 +1053,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1025
1053
|
'aria-selected': _this.getState().highlightedIndex === index
|
|
1026
1054
|
}, eventHandlers, rest);
|
|
1027
1055
|
};
|
|
1056
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
|
|
1028
1057
|
_this.clearItems = function () {
|
|
1029
1058
|
_this.items = [];
|
|
1030
1059
|
};
|
|
@@ -1232,10 +1261,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1232
1261
|
isOpen: isOpen,
|
|
1233
1262
|
selectedItem: selectedItem
|
|
1234
1263
|
};
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
//////////////////////////// ROOT
|
|
1238
|
-
;
|
|
1264
|
+
};
|
|
1239
1265
|
_proto.componentDidMount = function componentDidMount() {
|
|
1240
1266
|
var _this7 = this;
|
|
1241
1267
|
/* istanbul ignore if (react-native) */
|
|
@@ -1747,8 +1773,11 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1747
1773
|
isTouchMove: false
|
|
1748
1774
|
});
|
|
1749
1775
|
react.useEffect(function () {
|
|
1776
|
+
if ((environment == null ? void 0 : environment.addEventListener) == null) {
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1750
1779
|
|
|
1751
|
-
// The same strategy for checking if a click occurred inside or outside
|
|
1780
|
+
// The same strategy for checking if a click occurred inside or outside downshift
|
|
1752
1781
|
// as in downshift.js.
|
|
1753
1782
|
var onMouseDown = function onMouseDown() {
|
|
1754
1783
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
@@ -3020,13 +3049,14 @@ function useCombobox(userProps) {
|
|
|
3020
3049
|
}, []);
|
|
3021
3050
|
// Reset itemRefs on close.
|
|
3022
3051
|
react.useEffect(function () {
|
|
3052
|
+
var _environment$document;
|
|
3023
3053
|
if (!isOpen) {
|
|
3024
3054
|
itemRefs.current = {};
|
|
3025
|
-
} else if (document.activeElement !== inputRef.current) {
|
|
3055
|
+
} else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
|
|
3026
3056
|
var _inputRef$current;
|
|
3027
3057
|
inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
3028
3058
|
}
|
|
3029
|
-
}, [isOpen]);
|
|
3059
|
+
}, [isOpen, environment]);
|
|
3030
3060
|
|
|
3031
3061
|
/* Event handler functions */
|
|
3032
3062
|
var inputKeyDownHandlers = react.useMemo(function () {
|
package/dist/downshift.esm.js
CHANGED
|
@@ -497,9 +497,18 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
497
497
|
};
|
|
498
498
|
_this.input = null;
|
|
499
499
|
_this.items = [];
|
|
500
|
+
// itemCount can be changed asynchronously
|
|
501
|
+
// from within downshift (so it can't come from a prop)
|
|
502
|
+
// this is why we store it as an instance and use
|
|
503
|
+
// getItemCount rather than just use items.length
|
|
504
|
+
// (to support windowing + async)
|
|
500
505
|
_this.itemCount = null;
|
|
501
506
|
_this.previousResultCount = 0;
|
|
502
507
|
_this.timeoutIds = [];
|
|
508
|
+
/**
|
|
509
|
+
* @param {Function} fn the function to call after the time
|
|
510
|
+
* @param {Number} time the time to wait
|
|
511
|
+
*/
|
|
503
512
|
_this.internalSetTimeout = function (fn, time) {
|
|
504
513
|
var id = setTimeout(function () {
|
|
505
514
|
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
@@ -554,6 +563,14 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
554
563
|
_this.selectHighlightedItem = function (otherStateToSet, cb) {
|
|
555
564
|
return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
|
556
565
|
};
|
|
566
|
+
// any piece of our state can live in two places:
|
|
567
|
+
// 1. Uncontrolled: it's internal (this.state)
|
|
568
|
+
// We will call this.setState to update that state
|
|
569
|
+
// 2. Controlled: it's external (this.props)
|
|
570
|
+
// We will call this.props.onStateChange to update that state
|
|
571
|
+
//
|
|
572
|
+
// In addition, we'll call this.props.onChange if the
|
|
573
|
+
// selectedItem is changed.
|
|
557
574
|
_this.internalSetState = function (stateToSet, cb) {
|
|
558
575
|
var isItemSelected, onChangeArg;
|
|
559
576
|
var onStateChangeArg = {};
|
|
@@ -636,6 +653,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
636
653
|
_this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
|
637
654
|
});
|
|
638
655
|
};
|
|
656
|
+
//////////////////////////// ROOT
|
|
639
657
|
_this.rootRef = function (node) {
|
|
640
658
|
return _this._rootNode = node;
|
|
641
659
|
};
|
|
@@ -658,6 +676,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
658
676
|
isOpen = _this$getState.isOpen;
|
|
659
677
|
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
|
|
660
678
|
};
|
|
679
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
|
|
661
680
|
_this.keyDownHandlers = {
|
|
662
681
|
ArrowDown: function ArrowDown(event) {
|
|
663
682
|
var _this2 = this;
|
|
@@ -742,6 +761,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
742
761
|
}));
|
|
743
762
|
}
|
|
744
763
|
};
|
|
764
|
+
//////////////////////////// BUTTON
|
|
745
765
|
_this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
746
766
|
' ': function _(event) {
|
|
747
767
|
event.preventDefault();
|
|
@@ -865,12 +885,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
865
885
|
}
|
|
866
886
|
});
|
|
867
887
|
};
|
|
888
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
|
|
889
|
+
/////////////////////////////// LABEL
|
|
868
890
|
_this.getLabelProps = function (props) {
|
|
869
891
|
return _extends({
|
|
870
892
|
htmlFor: _this.inputId,
|
|
871
893
|
id: _this.labelId
|
|
872
894
|
}, props);
|
|
873
895
|
};
|
|
896
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
|
|
897
|
+
/////////////////////////////// INPUT
|
|
874
898
|
_this.getInputProps = function (_temp4) {
|
|
875
899
|
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
876
900
|
onKeyDown = _ref4.onKeyDown,
|
|
@@ -931,6 +955,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
931
955
|
}
|
|
932
956
|
});
|
|
933
957
|
};
|
|
958
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
|
|
959
|
+
/////////////////////////////// MENU
|
|
934
960
|
_this.menuRef = function (node) {
|
|
935
961
|
_this._menuNode = node;
|
|
936
962
|
};
|
|
@@ -949,6 +975,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
949
975
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
950
976
|
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
|
951
977
|
};
|
|
978
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
|
|
979
|
+
/////////////////////////////// ITEM
|
|
952
980
|
_this.getItemProps = function (_temp7) {
|
|
953
981
|
var _enabledEventHandlers;
|
|
954
982
|
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
@@ -1012,6 +1040,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1012
1040
|
'aria-selected': _this.getState().highlightedIndex === index
|
|
1013
1041
|
}, eventHandlers, rest);
|
|
1014
1042
|
};
|
|
1043
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
|
|
1015
1044
|
_this.clearItems = function () {
|
|
1016
1045
|
_this.items = [];
|
|
1017
1046
|
};
|
|
@@ -1219,10 +1248,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1219
1248
|
isOpen: isOpen,
|
|
1220
1249
|
selectedItem: selectedItem
|
|
1221
1250
|
};
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
//////////////////////////// ROOT
|
|
1225
|
-
;
|
|
1251
|
+
};
|
|
1226
1252
|
_proto.componentDidMount = function componentDidMount() {
|
|
1227
1253
|
var _this7 = this;
|
|
1228
1254
|
/* istanbul ignore if (react-native) */
|
|
@@ -1734,8 +1760,11 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1734
1760
|
isTouchMove: false
|
|
1735
1761
|
});
|
|
1736
1762
|
useEffect(function () {
|
|
1763
|
+
if ((environment == null ? void 0 : environment.addEventListener) == null) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1737
1766
|
|
|
1738
|
-
// The same strategy for checking if a click occurred inside or outside
|
|
1767
|
+
// The same strategy for checking if a click occurred inside or outside downshift
|
|
1739
1768
|
// as in downshift.js.
|
|
1740
1769
|
var onMouseDown = function onMouseDown() {
|
|
1741
1770
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
@@ -3007,13 +3036,14 @@ function useCombobox(userProps) {
|
|
|
3007
3036
|
}, []);
|
|
3008
3037
|
// Reset itemRefs on close.
|
|
3009
3038
|
useEffect(function () {
|
|
3039
|
+
var _environment$document;
|
|
3010
3040
|
if (!isOpen) {
|
|
3011
3041
|
itemRefs.current = {};
|
|
3012
|
-
} else if (document.activeElement !== inputRef.current) {
|
|
3042
|
+
} else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
|
|
3013
3043
|
var _inputRef$current;
|
|
3014
3044
|
inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
3015
3045
|
}
|
|
3016
|
-
}, [isOpen]);
|
|
3046
|
+
}, [isOpen, environment]);
|
|
3017
3047
|
|
|
3018
3048
|
/* Event handler functions */
|
|
3019
3049
|
var inputKeyDownHandlers = useMemo(function () {
|
|
@@ -59,6 +59,17 @@ function scrollIntoView(node, menuNode) {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @param {HTMLElement} parent the parent node
|
|
64
|
+
* @param {HTMLElement} child the child node
|
|
65
|
+
* @param {Window} environment The window context where downshift renders.
|
|
66
|
+
* @return {Boolean} whether the parent is the child or the child is in the parent
|
|
67
|
+
*/
|
|
68
|
+
function isOrContainsNode(parent, child, environment) {
|
|
69
|
+
var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
62
73
|
/**
|
|
63
74
|
* Simple debounce implementation. Will call the given
|
|
64
75
|
* function once after the time given has passed since
|
|
@@ -351,6 +362,25 @@ function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFr
|
|
|
351
362
|
return -1;
|
|
352
363
|
}
|
|
353
364
|
|
|
365
|
+
/**
|
|
366
|
+
* Checks if event target is within the downshift elements.
|
|
367
|
+
*
|
|
368
|
+
* @param {EventTarget} target Target to check.
|
|
369
|
+
* @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
|
|
370
|
+
* @param {Window} environment The window context where downshift renders.
|
|
371
|
+
* @param {boolean} checkActiveElement Whether to also check activeElement.
|
|
372
|
+
*
|
|
373
|
+
* @returns {boolean} Whether or not the target is within downshift elements.
|
|
374
|
+
*/
|
|
375
|
+
function targetWithinDownshift(target, downshiftElements, environment, checkActiveElement) {
|
|
376
|
+
if (checkActiveElement === void 0) {
|
|
377
|
+
checkActiveElement = true;
|
|
378
|
+
}
|
|
379
|
+
return downshiftElements.some(function (contextNode) {
|
|
380
|
+
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
354
384
|
// eslint-disable-next-line import/no-mutable-exports
|
|
355
385
|
var validateControlledUnchanged = noop;
|
|
356
386
|
/* istanbul ignore next */
|
|
@@ -480,9 +510,18 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
480
510
|
};
|
|
481
511
|
_this.input = null;
|
|
482
512
|
_this.items = [];
|
|
513
|
+
// itemCount can be changed asynchronously
|
|
514
|
+
// from within downshift (so it can't come from a prop)
|
|
515
|
+
// this is why we store it as an instance and use
|
|
516
|
+
// getItemCount rather than just use items.length
|
|
517
|
+
// (to support windowing + async)
|
|
483
518
|
_this.itemCount = null;
|
|
484
519
|
_this.previousResultCount = 0;
|
|
485
520
|
_this.timeoutIds = [];
|
|
521
|
+
/**
|
|
522
|
+
* @param {Function} fn the function to call after the time
|
|
523
|
+
* @param {Number} time the time to wait
|
|
524
|
+
*/
|
|
486
525
|
_this.internalSetTimeout = function (fn, time) {
|
|
487
526
|
var id = setTimeout(function () {
|
|
488
527
|
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
@@ -537,6 +576,14 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
537
576
|
_this.selectHighlightedItem = function (otherStateToSet, cb) {
|
|
538
577
|
return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
|
539
578
|
};
|
|
579
|
+
// any piece of our state can live in two places:
|
|
580
|
+
// 1. Uncontrolled: it's internal (this.state)
|
|
581
|
+
// We will call this.setState to update that state
|
|
582
|
+
// 2. Controlled: it's external (this.props)
|
|
583
|
+
// We will call this.props.onStateChange to update that state
|
|
584
|
+
//
|
|
585
|
+
// In addition, we'll call this.props.onChange if the
|
|
586
|
+
// selectedItem is changed.
|
|
540
587
|
_this.internalSetState = function (stateToSet, cb) {
|
|
541
588
|
var isItemSelected, onChangeArg;
|
|
542
589
|
var onStateChangeArg = {};
|
|
@@ -619,6 +666,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
619
666
|
_this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
|
620
667
|
});
|
|
621
668
|
};
|
|
669
|
+
//////////////////////////// ROOT
|
|
622
670
|
_this.rootRef = function (node) {
|
|
623
671
|
return _this._rootNode = node;
|
|
624
672
|
};
|
|
@@ -641,6 +689,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
641
689
|
isOpen = _this$getState.isOpen;
|
|
642
690
|
return _extends__default["default"]((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
|
|
643
691
|
};
|
|
692
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
|
|
644
693
|
_this.keyDownHandlers = {
|
|
645
694
|
ArrowDown: function ArrowDown(event) {
|
|
646
695
|
var _this2 = this;
|
|
@@ -725,6 +774,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
725
774
|
}));
|
|
726
775
|
}
|
|
727
776
|
};
|
|
777
|
+
//////////////////////////// BUTTON
|
|
728
778
|
_this.buttonKeyDownHandlers = _extends__default["default"]({}, _this.keyDownHandlers, {
|
|
729
779
|
' ': function _(event) {
|
|
730
780
|
event.preventDefault();
|
|
@@ -840,12 +890,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
840
890
|
}
|
|
841
891
|
});
|
|
842
892
|
};
|
|
893
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
|
|
894
|
+
/////////////////////////////// LABEL
|
|
843
895
|
_this.getLabelProps = function (props) {
|
|
844
896
|
return _extends__default["default"]({
|
|
845
897
|
htmlFor: _this.inputId,
|
|
846
898
|
id: _this.labelId
|
|
847
899
|
}, props);
|
|
848
900
|
};
|
|
901
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
|
|
902
|
+
/////////////////////////////// INPUT
|
|
849
903
|
_this.getInputProps = function (_temp4) {
|
|
850
904
|
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
851
905
|
onKeyDown = _ref4.onKeyDown,
|
|
@@ -921,6 +975,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
921
975
|
}
|
|
922
976
|
});
|
|
923
977
|
};
|
|
978
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
|
|
979
|
+
/////////////////////////////// MENU
|
|
924
980
|
_this.menuRef = function (node) {
|
|
925
981
|
_this._menuNode = node;
|
|
926
982
|
};
|
|
@@ -939,6 +995,8 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
939
995
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
940
996
|
return _extends__default["default"]((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
|
941
997
|
};
|
|
998
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
|
|
999
|
+
/////////////////////////////// ITEM
|
|
942
1000
|
_this.getItemProps = function (_temp7) {
|
|
943
1001
|
var _enabledEventHandlers;
|
|
944
1002
|
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
@@ -1002,6 +1060,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1002
1060
|
'aria-selected': _this.getState().highlightedIndex === index
|
|
1003
1061
|
}, eventHandlers, rest);
|
|
1004
1062
|
};
|
|
1063
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
|
|
1005
1064
|
_this.clearItems = function () {
|
|
1006
1065
|
_this.items = [];
|
|
1007
1066
|
};
|
|
@@ -1204,10 +1263,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1204
1263
|
isOpen: isOpen,
|
|
1205
1264
|
selectedItem: selectedItem
|
|
1206
1265
|
};
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
//////////////////////////// ROOT
|
|
1210
|
-
;
|
|
1266
|
+
};
|
|
1211
1267
|
_proto.componentDidMount = function componentDidMount() {
|
|
1212
1268
|
var _this7 = this;
|
|
1213
1269
|
/* istanbul ignore if (react-native) */
|
|
@@ -1652,10 +1708,50 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1652
1708
|
isTouchMove: false
|
|
1653
1709
|
});
|
|
1654
1710
|
react.useEffect(function () {
|
|
1655
|
-
|
|
1656
|
-
{
|
|
1711
|
+
if ((environment == null ? void 0 : environment.addEventListener) == null) {
|
|
1657
1712
|
return;
|
|
1658
1713
|
}
|
|
1714
|
+
|
|
1715
|
+
// The same strategy for checking if a click occurred inside or outside downshift
|
|
1716
|
+
// as in downshift.js.
|
|
1717
|
+
var onMouseDown = function onMouseDown() {
|
|
1718
|
+
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
1719
|
+
};
|
|
1720
|
+
var onMouseUp = function onMouseUp(event) {
|
|
1721
|
+
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
1722
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
|
|
1723
|
+
return ref.current;
|
|
1724
|
+
}), environment)) {
|
|
1725
|
+
handleBlur();
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
var onTouchStart = function onTouchStart() {
|
|
1729
|
+
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
1730
|
+
};
|
|
1731
|
+
var onTouchMove = function onTouchMove() {
|
|
1732
|
+
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
1733
|
+
};
|
|
1734
|
+
var onTouchEnd = function onTouchEnd(event) {
|
|
1735
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
|
|
1736
|
+
return ref.current;
|
|
1737
|
+
}), environment, false)) {
|
|
1738
|
+
handleBlur();
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
environment.addEventListener('mousedown', onMouseDown);
|
|
1742
|
+
environment.addEventListener('mouseup', onMouseUp);
|
|
1743
|
+
environment.addEventListener('touchstart', onTouchStart);
|
|
1744
|
+
environment.addEventListener('touchmove', onTouchMove);
|
|
1745
|
+
environment.addEventListener('touchend', onTouchEnd);
|
|
1746
|
+
|
|
1747
|
+
// eslint-disable-next-line consistent-return
|
|
1748
|
+
return function cleanup() {
|
|
1749
|
+
environment.removeEventListener('mousedown', onMouseDown);
|
|
1750
|
+
environment.removeEventListener('mouseup', onMouseUp);
|
|
1751
|
+
environment.removeEventListener('touchstart', onTouchStart);
|
|
1752
|
+
environment.removeEventListener('touchmove', onTouchMove);
|
|
1753
|
+
environment.removeEventListener('touchend', onTouchEnd);
|
|
1754
|
+
};
|
|
1659
1755
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1660
1756
|
}, [isOpen, environment]);
|
|
1661
1757
|
return mouseAndTouchTrackersRef;
|
|
@@ -2194,7 +2290,11 @@ function useSelect(userProps) {
|
|
|
2194
2290
|
previousResultCountRef.current = items.length;
|
|
2195
2291
|
});
|
|
2196
2292
|
// Add mouse/touch events to document.
|
|
2197
|
-
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment)
|
|
2293
|
+
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
|
|
2294
|
+
dispatch({
|
|
2295
|
+
type: ToggleButtonBlur
|
|
2296
|
+
});
|
|
2297
|
+
});
|
|
2198
2298
|
var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
|
|
2199
2299
|
// Make initial ref false.
|
|
2200
2300
|
react.useEffect(function () {
|
|
@@ -2855,7 +2955,12 @@ function useCombobox(userProps) {
|
|
|
2855
2955
|
previousResultCountRef.current = items.length;
|
|
2856
2956
|
});
|
|
2857
2957
|
// Add mouse/touch events to document.
|
|
2858
|
-
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment)
|
|
2958
|
+
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
|
|
2959
|
+
dispatch({
|
|
2960
|
+
type: InputBlur,
|
|
2961
|
+
selectItem: false
|
|
2962
|
+
});
|
|
2963
|
+
});
|
|
2859
2964
|
var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
|
|
2860
2965
|
// Make initial ref false.
|
|
2861
2966
|
react.useEffect(function () {
|
|
@@ -2866,13 +2971,14 @@ function useCombobox(userProps) {
|
|
|
2866
2971
|
}, []);
|
|
2867
2972
|
// Reset itemRefs on close.
|
|
2868
2973
|
react.useEffect(function () {
|
|
2974
|
+
var _environment$document;
|
|
2869
2975
|
if (!isOpen) {
|
|
2870
2976
|
itemRefs.current = {};
|
|
2871
|
-
} else if (document.activeElement !== inputRef.current) {
|
|
2977
|
+
} else if (((_environment$document = environment.document) == null ? void 0 : _environment$document.activeElement) !== inputRef.current) {
|
|
2872
2978
|
var _inputRef$current;
|
|
2873
2979
|
inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
2874
2980
|
}
|
|
2875
|
-
}, [isOpen]);
|
|
2981
|
+
}, [isOpen, environment]);
|
|
2876
2982
|
|
|
2877
2983
|
/* Event handler functions */
|
|
2878
2984
|
var inputKeyDownHandlers = react.useMemo(function () {
|