downshift 6.1.5 → 6.1.8
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 +14 -9
- package/dist/downshift.cjs.js +1695 -1631
- package/dist/downshift.esm.js +1569 -1501
- package/dist/downshift.native.cjs.js +1680 -1614
- package/dist/downshift.umd.js +1606 -1568
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -21
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +25 -11
- package/preact/dist/downshift.cjs.js +1659 -1595
- package/preact/dist/downshift.esm.js +1569 -1501
- package/preact/dist/downshift.umd.js +1659 -1643
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -23
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/typings/index.d.ts +11 -2
|
@@ -2,68 +2,12 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('preact'), require('prop-types')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'preact', 'prop-types'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Downshift = {}, global.preact, global.PropTypes));
|
|
5
|
-
}(this, (function (exports, preact, PropTypes) { 'use strict';
|
|
5
|
+
})(this, (function (exports, preact, PropTypes) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
9
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
10
10
|
|
|
11
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
12
|
-
if (source == null) return {};
|
|
13
|
-
var target = {};
|
|
14
|
-
var sourceKeys = Object.keys(source);
|
|
15
|
-
var key, i;
|
|
16
|
-
|
|
17
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
18
|
-
key = sourceKeys[i];
|
|
19
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
20
|
-
target[key] = source[key];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return target;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function _extends() {
|
|
27
|
-
_extends = Object.assign || function (target) {
|
|
28
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
29
|
-
var source = arguments[i];
|
|
30
|
-
|
|
31
|
-
for (var key in source) {
|
|
32
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
33
|
-
target[key] = source[key];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return target;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return _extends.apply(this, arguments);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _assertThisInitialized(self) {
|
|
45
|
-
if (self === void 0) {
|
|
46
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return self;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _setPrototypeOf(o, p) {
|
|
53
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
54
|
-
o.__proto__ = p;
|
|
55
|
-
return o;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return _setPrototypeOf(o, p);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function _inheritsLoose(subClass, superClass) {
|
|
62
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
63
|
-
subClass.prototype.constructor = subClass;
|
|
64
|
-
_setPrototypeOf(subClass, superClass);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
11
|
var reactIs = {exports: {}};
|
|
68
12
|
|
|
69
13
|
/** @license React v17.0.2
|
|
@@ -305,7 +249,7 @@
|
|
|
305
249
|
|
|
306
250
|
function t(t){return "object"==typeof t&&null!=t&&1===t.nodeType}function e(t,e){return (!e||"hidden"!==t)&&"visible"!==t&&"clip"!==t}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){var r=getComputedStyle(t,null);return e(r.overflowY,n)||e(r.overflowX,n)||function(t){var e=function(t){if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}}(t);return !!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)}(t)}return !1}function r(t,e,n,r,i,o,l,d){return o<t&&l>e||o>t&&l<e?0:o<=t&&d<=n||l>=e&&d>=n?o-t-r:l>e&&d<n||o<t&&d>n?l-e+i:0}function computeScrollIntoView(e,i){var o=window,l=i.scrollMode,d=i.block,u=i.inline,h=i.boundary,a=i.skipOverflowHiddenElements,c="function"==typeof h?h:function(t){return t!==h};if(!t(e))throw new TypeError("Invalid target");for(var f=document.scrollingElement||document.documentElement,s=[],p=e;t(p)&&c(p);){if((p=p.parentElement)===f){s.push(p);break}null!=p&&p===document.body&&n(p)&&!n(document.documentElement)||null!=p&&n(p,a)&&s.push(p);}for(var m=o.visualViewport?o.visualViewport.width:innerWidth,g=o.visualViewport?o.visualViewport.height:innerHeight,w=window.scrollX||pageXOffset,v=window.scrollY||pageYOffset,W=e.getBoundingClientRect(),b=W.height,H=W.width,y=W.top,E=W.right,M=W.bottom,V=W.left,x="start"===d||"nearest"===d?y:"end"===d?M:y+b/2,I="center"===u?V+H/2:"end"===u?E:V,C=[],T=0;T<s.length;T++){var k=s[T],B=k.getBoundingClientRect(),D=B.height,O=B.width,R=B.top,X=B.right,Y=B.bottom,L=B.left;if("if-needed"===l&&y>=0&&V>=0&&M<=g&&E<=m&&y>=R&&M<=Y&&V>=L&&E<=X)return C;var S=getComputedStyle(k),j=parseInt(S.borderLeftWidth,10),q=parseInt(S.borderTopWidth,10),z=parseInt(S.borderRightWidth,10),A=parseInt(S.borderBottomWidth,10),F=0,G=0,J="offsetWidth"in k?k.offsetWidth-k.clientWidth-j-z:0,K="offsetHeight"in k?k.offsetHeight-k.clientHeight-q-A:0;if(f===k)F="start"===d?x:"end"===d?x-g:"nearest"===d?r(v,v+g,g,q,A,v+x,v+x+b,b):x-g/2,G="start"===u?I:"center"===u?I-m/2:"end"===u?I-m:r(w,w+m,m,j,z,w+I,w+I+H,H),F=Math.max(0,F+v),G=Math.max(0,G+w);else {F="start"===d?x-R-q:"end"===d?x-Y+A+K:"nearest"===d?r(R,Y,D,q,A+K,x,x+b,b):x-(R+D/2)+K/2,G="start"===u?I-L-j:"center"===u?I-(L+O/2)+J/2:"end"===u?I-X+z+J:r(L,X,O,j,z+J,I,I+H,H);var N=k.scrollLeft,P=k.scrollTop;x+=P-(F=Math.max(0,Math.min(P+F,k.scrollHeight-D+K))),I+=N-(G=Math.max(0,Math.min(N+G,k.scrollWidth-O+J)));}C.push({el:k,top:F,left:G});}return C}
|
|
307
251
|
|
|
308
|
-
|
|
252
|
+
let idCounter = 0;
|
|
309
253
|
/**
|
|
310
254
|
* Accepts a parameter and returns it if it's a function
|
|
311
255
|
* or a noop function if it's not. This allows us to
|
|
@@ -332,15 +276,17 @@
|
|
|
332
276
|
return;
|
|
333
277
|
}
|
|
334
278
|
|
|
335
|
-
|
|
279
|
+
const actions = computeScrollIntoView(node, {
|
|
336
280
|
boundary: menuNode,
|
|
337
281
|
block: 'nearest',
|
|
338
282
|
scrollMode: 'if-needed'
|
|
339
283
|
});
|
|
340
|
-
actions.forEach(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
284
|
+
actions.forEach(_ref => {
|
|
285
|
+
let {
|
|
286
|
+
el,
|
|
287
|
+
top,
|
|
288
|
+
left
|
|
289
|
+
} = _ref;
|
|
344
290
|
el.scrollTop = top;
|
|
345
291
|
el.scrollLeft = left;
|
|
346
292
|
});
|
|
@@ -354,7 +300,7 @@
|
|
|
354
300
|
|
|
355
301
|
|
|
356
302
|
function isOrContainsNode(parent, child, environment) {
|
|
357
|
-
|
|
303
|
+
const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
358
304
|
return result;
|
|
359
305
|
}
|
|
360
306
|
/**
|
|
@@ -368,7 +314,7 @@
|
|
|
368
314
|
|
|
369
315
|
|
|
370
316
|
function debounce(fn, time) {
|
|
371
|
-
|
|
317
|
+
let timeoutId;
|
|
372
318
|
|
|
373
319
|
function cancel() {
|
|
374
320
|
if (timeoutId) {
|
|
@@ -382,9 +328,9 @@
|
|
|
382
328
|
}
|
|
383
329
|
|
|
384
330
|
cancel();
|
|
385
|
-
timeoutId = setTimeout(
|
|
331
|
+
timeoutId = setTimeout(() => {
|
|
386
332
|
timeoutId = null;
|
|
387
|
-
fn
|
|
333
|
+
fn(...args);
|
|
388
334
|
}, time);
|
|
389
335
|
}
|
|
390
336
|
|
|
@@ -410,9 +356,9 @@
|
|
|
410
356
|
args[_key3 - 1] = arguments[_key3];
|
|
411
357
|
}
|
|
412
358
|
|
|
413
|
-
return fns.some(
|
|
359
|
+
return fns.some(fn => {
|
|
414
360
|
if (fn) {
|
|
415
|
-
fn
|
|
361
|
+
fn(event, ...args);
|
|
416
362
|
}
|
|
417
363
|
|
|
418
364
|
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
@@ -425,8 +371,8 @@
|
|
|
425
371
|
refs[_key4] = arguments[_key4];
|
|
426
372
|
}
|
|
427
373
|
|
|
428
|
-
return
|
|
429
|
-
refs.forEach(
|
|
374
|
+
return node => {
|
|
375
|
+
refs.forEach(ref => {
|
|
430
376
|
if (typeof ref === 'function') {
|
|
431
377
|
ref(node);
|
|
432
378
|
} else if (ref) {
|
|
@@ -463,9 +409,11 @@
|
|
|
463
409
|
|
|
464
410
|
|
|
465
411
|
function getA11yStatusMessage$1(_ref2) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
412
|
+
let {
|
|
413
|
+
isOpen,
|
|
414
|
+
resultCount,
|
|
415
|
+
previousResultCount
|
|
416
|
+
} = _ref2;
|
|
469
417
|
|
|
470
418
|
if (!isOpen) {
|
|
471
419
|
return '';
|
|
@@ -541,7 +489,7 @@
|
|
|
541
489
|
console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
|
|
542
490
|
}
|
|
543
491
|
|
|
544
|
-
|
|
492
|
+
const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
|
545
493
|
/**
|
|
546
494
|
* @param {Object} state the state object
|
|
547
495
|
* @return {Object} state that is relevant to downshift
|
|
@@ -552,8 +500,8 @@
|
|
|
552
500
|
state = {};
|
|
553
501
|
}
|
|
554
502
|
|
|
555
|
-
|
|
556
|
-
stateKeys.forEach(
|
|
503
|
+
const result = {};
|
|
504
|
+
stateKeys.forEach(k => {
|
|
557
505
|
if (state.hasOwnProperty(k)) {
|
|
558
506
|
result[k] = state[k];
|
|
559
507
|
}
|
|
@@ -574,7 +522,7 @@
|
|
|
574
522
|
|
|
575
523
|
|
|
576
524
|
function getState(state, props) {
|
|
577
|
-
return Object.keys(state).reduce(
|
|
525
|
+
return Object.keys(state).reduce((prevState, key) => {
|
|
578
526
|
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
579
527
|
return prevState;
|
|
580
528
|
}, {});
|
|
@@ -601,8 +549,10 @@
|
|
|
601
549
|
|
|
602
550
|
|
|
603
551
|
function normalizeArrowKey(event) {
|
|
604
|
-
|
|
605
|
-
|
|
552
|
+
const {
|
|
553
|
+
key,
|
|
554
|
+
keyCode
|
|
555
|
+
} = event;
|
|
606
556
|
/* istanbul ignore next (ie) */
|
|
607
557
|
|
|
608
558
|
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
@@ -643,13 +593,13 @@
|
|
|
643
593
|
return -1;
|
|
644
594
|
}
|
|
645
595
|
|
|
646
|
-
|
|
596
|
+
const itemsLastIndex = itemCount - 1;
|
|
647
597
|
|
|
648
598
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
649
599
|
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
|
650
600
|
}
|
|
651
601
|
|
|
652
|
-
|
|
602
|
+
let newIndex = baseIndex + moveAmount;
|
|
653
603
|
|
|
654
604
|
if (newIndex < 0) {
|
|
655
605
|
newIndex = circular ? itemsLastIndex : 0;
|
|
@@ -657,7 +607,7 @@
|
|
|
657
607
|
newIndex = circular ? 0 : itemsLastIndex;
|
|
658
608
|
}
|
|
659
609
|
|
|
660
|
-
|
|
610
|
+
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
|
|
661
611
|
|
|
662
612
|
if (nonDisabledNewIndex === -1) {
|
|
663
613
|
return baseIndex >= itemCount ? -1 : baseIndex;
|
|
@@ -678,22 +628,22 @@
|
|
|
678
628
|
|
|
679
629
|
|
|
680
630
|
function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
|
|
681
|
-
|
|
631
|
+
const currentElementNode = getItemNodeFromIndex(baseIndex);
|
|
682
632
|
|
|
683
633
|
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
|
|
684
634
|
return baseIndex;
|
|
685
635
|
}
|
|
686
636
|
|
|
687
637
|
if (moveAmount > 0) {
|
|
688
|
-
for (
|
|
638
|
+
for (let index = baseIndex + 1; index < itemCount; index++) {
|
|
689
639
|
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
690
640
|
return index;
|
|
691
641
|
}
|
|
692
642
|
}
|
|
693
643
|
} else {
|
|
694
|
-
for (
|
|
695
|
-
if (!getItemNodeFromIndex(
|
|
696
|
-
return
|
|
644
|
+
for (let index = baseIndex - 1; index >= 0; index--) {
|
|
645
|
+
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
646
|
+
return index;
|
|
697
647
|
}
|
|
698
648
|
}
|
|
699
649
|
}
|
|
@@ -721,19 +671,17 @@
|
|
|
721
671
|
checkActiveElement = true;
|
|
722
672
|
}
|
|
723
673
|
|
|
724
|
-
return downshiftElements.some(
|
|
725
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
726
|
-
});
|
|
674
|
+
return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
|
|
727
675
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
728
676
|
|
|
729
677
|
|
|
730
|
-
|
|
678
|
+
let validateControlledUnchanged = noop;
|
|
731
679
|
/* istanbul ignore next */
|
|
732
680
|
|
|
733
681
|
{
|
|
734
|
-
validateControlledUnchanged =
|
|
735
|
-
|
|
736
|
-
Object.keys(state).forEach(
|
|
682
|
+
validateControlledUnchanged = (state, prevProps, nextProps) => {
|
|
683
|
+
const 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";
|
|
684
|
+
Object.keys(state).forEach(propKey => {
|
|
737
685
|
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
738
686
|
// eslint-disable-next-line no-console
|
|
739
687
|
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
@@ -745,7 +693,7 @@
|
|
|
745
693
|
};
|
|
746
694
|
}
|
|
747
695
|
|
|
748
|
-
|
|
696
|
+
const cleanupStatus = debounce(documentProp => {
|
|
749
697
|
getStatusDiv(documentProp).textContent = '';
|
|
750
698
|
}, 500);
|
|
751
699
|
/**
|
|
@@ -754,7 +702,7 @@
|
|
|
754
702
|
*/
|
|
755
703
|
|
|
756
704
|
function setStatus(status, documentProp) {
|
|
757
|
-
|
|
705
|
+
const div = getStatusDiv(documentProp);
|
|
758
706
|
|
|
759
707
|
if (!status) {
|
|
760
708
|
return;
|
|
@@ -775,7 +723,7 @@
|
|
|
775
723
|
documentProp = document;
|
|
776
724
|
}
|
|
777
725
|
|
|
778
|
-
|
|
726
|
+
let statusDiv = documentProp.getElementById('a11y-status-message');
|
|
779
727
|
|
|
780
728
|
if (statusDiv) {
|
|
781
729
|
return statusDiv;
|
|
@@ -800,23 +748,23 @@
|
|
|
800
748
|
return statusDiv;
|
|
801
749
|
}
|
|
802
750
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
751
|
+
const unknown = '__autocomplete_unknown__' ;
|
|
752
|
+
const mouseUp = '__autocomplete_mouseup__' ;
|
|
753
|
+
const itemMouseEnter = '__autocomplete_item_mouseenter__' ;
|
|
754
|
+
const keyDownArrowUp = '__autocomplete_keydown_arrow_up__' ;
|
|
755
|
+
const keyDownArrowDown = '__autocomplete_keydown_arrow_down__' ;
|
|
756
|
+
const keyDownEscape = '__autocomplete_keydown_escape__' ;
|
|
757
|
+
const keyDownEnter = '__autocomplete_keydown_enter__' ;
|
|
758
|
+
const keyDownHome = '__autocomplete_keydown_home__' ;
|
|
759
|
+
const keyDownEnd = '__autocomplete_keydown_end__' ;
|
|
760
|
+
const clickItem = '__autocomplete_click_item__' ;
|
|
761
|
+
const blurInput = '__autocomplete_blur_input__' ;
|
|
762
|
+
const changeInput = '__autocomplete_change_input__' ;
|
|
763
|
+
const keyDownSpaceButton = '__autocomplete_keydown_space_button__' ;
|
|
764
|
+
const clickButton = '__autocomplete_click_button__' ;
|
|
765
|
+
const blurButton = '__autocomplete_blur_button__' ;
|
|
766
|
+
const controlledPropUpdatedSelectedItem = '__autocomplete_controlled_prop_updated_selected_item__' ;
|
|
767
|
+
const touchEnd = '__autocomplete_touchend__' ;
|
|
820
768
|
|
|
821
769
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
822
770
|
__proto__: null,
|
|
@@ -839,58 +787,45 @@
|
|
|
839
787
|
touchEnd: touchEnd
|
|
840
788
|
});
|
|
841
789
|
|
|
842
|
-
|
|
843
|
-
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
844
|
-
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
845
|
-
_excluded4$1 = ["refKey", "ref"],
|
|
846
|
-
_excluded5$1 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
790
|
+
/* eslint camelcase:0 */
|
|
847
791
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
function Downshift(_props) {
|
|
792
|
+
const Downshift = /*#__PURE__*/(() => {
|
|
793
|
+
class Downshift extends preact.Component {
|
|
794
|
+
constructor(_props) {
|
|
853
795
|
var _this;
|
|
854
796
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
_this.labelId = _this.props.labelId || _this.id + "-label";
|
|
862
|
-
_this.inputId = _this.props.inputId || _this.id + "-input";
|
|
797
|
+
super(_props);
|
|
798
|
+
_this = this;
|
|
799
|
+
this.id = this.props.id || "downshift-" + generateId();
|
|
800
|
+
this.menuId = this.props.menuId || this.id + "-menu";
|
|
801
|
+
this.labelId = this.props.labelId || this.id + "-label";
|
|
802
|
+
this.inputId = this.props.inputId || this.id + "-input";
|
|
863
803
|
|
|
864
|
-
|
|
865
|
-
return _this.id + "-item-" + index;
|
|
866
|
-
};
|
|
804
|
+
this.getItemId = this.props.getItemId || (index => this.id + "-item-" + index);
|
|
867
805
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
806
|
+
this.input = null;
|
|
807
|
+
this.items = [];
|
|
808
|
+
this.itemCount = null;
|
|
809
|
+
this.previousResultCount = 0;
|
|
810
|
+
this.timeoutIds = [];
|
|
873
811
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
return i !== id;
|
|
878
|
-
});
|
|
812
|
+
this.internalSetTimeout = (fn, time) => {
|
|
813
|
+
const id = setTimeout(() => {
|
|
814
|
+
this.timeoutIds = this.timeoutIds.filter(i => i !== id);
|
|
879
815
|
fn();
|
|
880
816
|
}, time);
|
|
881
|
-
|
|
882
|
-
_this.timeoutIds.push(id);
|
|
817
|
+
this.timeoutIds.push(id);
|
|
883
818
|
};
|
|
884
819
|
|
|
885
|
-
|
|
886
|
-
|
|
820
|
+
this.setItemCount = count => {
|
|
821
|
+
this.itemCount = count;
|
|
887
822
|
};
|
|
888
823
|
|
|
889
|
-
|
|
890
|
-
|
|
824
|
+
this.unsetItemCount = () => {
|
|
825
|
+
this.itemCount = null;
|
|
891
826
|
};
|
|
892
827
|
|
|
893
|
-
|
|
828
|
+
this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
894
829
|
if (highlightedIndex === void 0) {
|
|
895
830
|
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
896
831
|
}
|
|
@@ -901,71 +836,72 @@
|
|
|
901
836
|
|
|
902
837
|
otherStateToSet = pickState(otherStateToSet);
|
|
903
838
|
|
|
904
|
-
_this.internalSetState(
|
|
905
|
-
highlightedIndex
|
|
906
|
-
|
|
839
|
+
_this.internalSetState({
|
|
840
|
+
highlightedIndex,
|
|
841
|
+
...otherStateToSet
|
|
842
|
+
});
|
|
907
843
|
};
|
|
908
844
|
|
|
909
|
-
|
|
910
|
-
|
|
845
|
+
this.clearSelection = cb => {
|
|
846
|
+
this.internalSetState({
|
|
911
847
|
selectedItem: null,
|
|
912
848
|
inputValue: '',
|
|
913
|
-
highlightedIndex:
|
|
914
|
-
isOpen:
|
|
849
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
850
|
+
isOpen: this.props.defaultIsOpen
|
|
915
851
|
}, cb);
|
|
916
852
|
};
|
|
917
853
|
|
|
918
|
-
|
|
854
|
+
this.selectItem = (item, otherStateToSet, cb) => {
|
|
919
855
|
otherStateToSet = pickState(otherStateToSet);
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
856
|
+
this.internalSetState({
|
|
857
|
+
isOpen: this.props.defaultIsOpen,
|
|
858
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
924
859
|
selectedItem: item,
|
|
925
|
-
inputValue:
|
|
926
|
-
|
|
860
|
+
inputValue: this.props.itemToString(item),
|
|
861
|
+
...otherStateToSet
|
|
862
|
+
}, cb);
|
|
927
863
|
};
|
|
928
864
|
|
|
929
|
-
|
|
930
|
-
|
|
865
|
+
this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
|
|
866
|
+
const item = this.items[itemIndex];
|
|
931
867
|
|
|
932
868
|
if (item == null) {
|
|
933
869
|
return;
|
|
934
870
|
}
|
|
935
871
|
|
|
936
|
-
|
|
872
|
+
this.selectItem(item, otherStateToSet, cb);
|
|
937
873
|
};
|
|
938
874
|
|
|
939
|
-
|
|
940
|
-
return
|
|
875
|
+
this.selectHighlightedItem = (otherStateToSet, cb) => {
|
|
876
|
+
return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
|
|
941
877
|
};
|
|
942
878
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
879
|
+
this.internalSetState = (stateToSet, cb) => {
|
|
880
|
+
let isItemSelected, onChangeArg;
|
|
881
|
+
const onStateChangeArg = {};
|
|
882
|
+
const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
|
|
947
883
|
// so someone controlling the `inputValue` state gets notified of
|
|
948
884
|
// the input change as soon as possible. This avoids issues with
|
|
949
885
|
// preserving the cursor position.
|
|
950
886
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
951
887
|
|
|
952
888
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
953
|
-
|
|
889
|
+
this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
890
|
+
...stateToSet
|
|
891
|
+
});
|
|
954
892
|
}
|
|
955
893
|
|
|
956
|
-
return
|
|
957
|
-
state =
|
|
958
|
-
|
|
894
|
+
return this.setState(state => {
|
|
895
|
+
state = this.getState(state);
|
|
896
|
+
let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
|
|
959
897
|
|
|
960
|
-
newStateToSet =
|
|
898
|
+
newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
|
|
961
899
|
// what was selected before
|
|
962
900
|
// used to determine if onSelect and onChange callbacks should be called
|
|
963
901
|
|
|
964
902
|
isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
|
|
965
903
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
|
|
904
|
+
const nextState = {}; // this is just used to tell whether the state changed
|
|
969
905
|
// and we're trying to update that state. OR if the selection has changed and we're
|
|
970
906
|
// trying to update the selection
|
|
971
907
|
|
|
@@ -974,7 +910,7 @@
|
|
|
974
910
|
}
|
|
975
911
|
|
|
976
912
|
newStateToSet.type = newStateToSet.type || unknown;
|
|
977
|
-
Object.keys(newStateToSet).forEach(
|
|
913
|
+
Object.keys(newStateToSet).forEach(key => {
|
|
978
914
|
// onStateChangeArg should only have the state that is
|
|
979
915
|
// actually changing
|
|
980
916
|
if (state[key] !== newStateToSet[key]) {
|
|
@@ -991,81 +927,84 @@
|
|
|
991
927
|
return;
|
|
992
928
|
}
|
|
993
929
|
|
|
994
|
-
|
|
930
|
+
newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
|
|
995
931
|
|
|
996
|
-
if (!isControlledProp(
|
|
932
|
+
if (!isControlledProp(this.props, key)) {
|
|
997
933
|
nextState[key] = newStateToSet[key];
|
|
998
934
|
}
|
|
999
935
|
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
1000
936
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
1001
937
|
|
|
1002
938
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
1003
|
-
|
|
939
|
+
this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
940
|
+
...newStateToSet
|
|
941
|
+
});
|
|
1004
942
|
}
|
|
1005
943
|
|
|
1006
944
|
return nextState;
|
|
1007
|
-
},
|
|
945
|
+
}, () => {
|
|
1008
946
|
// call the provided callback if it's a function
|
|
1009
947
|
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
|
|
1010
948
|
// we have relevant information to pass them.
|
|
1011
949
|
|
|
1012
|
-
|
|
950
|
+
const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
1013
951
|
|
|
1014
952
|
if (hasMoreStateThanType) {
|
|
1015
|
-
|
|
953
|
+
this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
|
|
1016
954
|
}
|
|
1017
955
|
|
|
1018
956
|
if (isItemSelected) {
|
|
1019
|
-
|
|
957
|
+
this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
|
|
1020
958
|
}
|
|
1021
959
|
|
|
1022
960
|
if (onChangeArg !== undefined) {
|
|
1023
|
-
|
|
961
|
+
this.props.onChange(onChangeArg, this.getStateAndHelpers());
|
|
1024
962
|
} // this is currently undocumented and therefore subject to change
|
|
1025
963
|
// We'll try to not break it, but just be warned.
|
|
1026
964
|
|
|
1027
965
|
|
|
1028
|
-
|
|
966
|
+
this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
|
|
1029
967
|
});
|
|
1030
968
|
};
|
|
1031
969
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
1044
|
-
|
|
1045
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
1046
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
1047
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
1048
|
-
|
|
970
|
+
this.rootRef = node => this._rootNode = node;
|
|
971
|
+
|
|
972
|
+
this.getRootProps = function (_temp, _temp2) {
|
|
973
|
+
let {
|
|
974
|
+
refKey = 'ref',
|
|
975
|
+
ref,
|
|
976
|
+
...rest
|
|
977
|
+
} = _temp === void 0 ? {} : _temp;
|
|
978
|
+
let {
|
|
979
|
+
suppressRefError = false
|
|
980
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
1049
981
|
// this is used in the render to know whether the user has called getRootProps.
|
|
1050
982
|
// It uses that to know whether to apply the props automatically
|
|
1051
983
|
_this.getRootProps.called = true;
|
|
1052
984
|
_this.getRootProps.refKey = refKey;
|
|
1053
985
|
_this.getRootProps.suppressRefError = suppressRefError;
|
|
1054
986
|
|
|
1055
|
-
|
|
1056
|
-
|
|
987
|
+
const {
|
|
988
|
+
isOpen
|
|
989
|
+
} = _this.getState();
|
|
1057
990
|
|
|
1058
|
-
return
|
|
991
|
+
return {
|
|
992
|
+
[refKey]: handleRefs(ref, _this.rootRef),
|
|
993
|
+
role: 'combobox',
|
|
994
|
+
'aria-expanded': isOpen,
|
|
995
|
+
'aria-haspopup': 'listbox',
|
|
996
|
+
'aria-owns': isOpen ? _this.menuId : null,
|
|
997
|
+
'aria-labelledby': _this.labelId,
|
|
998
|
+
...rest
|
|
999
|
+
};
|
|
1059
1000
|
};
|
|
1060
1001
|
|
|
1061
|
-
|
|
1062
|
-
ArrowDown
|
|
1063
|
-
var _this2 = this;
|
|
1064
|
-
|
|
1002
|
+
this.keyDownHandlers = {
|
|
1003
|
+
ArrowDown(event) {
|
|
1065
1004
|
event.preventDefault();
|
|
1066
1005
|
|
|
1067
1006
|
if (this.getState().isOpen) {
|
|
1068
|
-
|
|
1007
|
+
const amount = event.shiftKey ? 5 : 1;
|
|
1069
1008
|
this.moveHighlightedIndex(amount, {
|
|
1070
1009
|
type: keyDownArrowDown
|
|
1071
1010
|
});
|
|
@@ -1073,31 +1012,27 @@
|
|
|
1073
1012
|
this.internalSetState({
|
|
1074
1013
|
isOpen: true,
|
|
1075
1014
|
type: keyDownArrowDown
|
|
1076
|
-
},
|
|
1077
|
-
|
|
1015
|
+
}, () => {
|
|
1016
|
+
const itemCount = this.getItemCount();
|
|
1078
1017
|
|
|
1079
1018
|
if (itemCount > 0) {
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
});
|
|
1086
|
-
|
|
1087
|
-
_this2.setHighlightedIndex(nextHighlightedIndex, {
|
|
1019
|
+
const {
|
|
1020
|
+
highlightedIndex
|
|
1021
|
+
} = this.getState();
|
|
1022
|
+
const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
1023
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
1088
1024
|
type: keyDownArrowDown
|
|
1089
1025
|
});
|
|
1090
1026
|
}
|
|
1091
1027
|
});
|
|
1092
1028
|
}
|
|
1093
1029
|
},
|
|
1094
|
-
ArrowUp: function ArrowUp(event) {
|
|
1095
|
-
var _this3 = this;
|
|
1096
1030
|
|
|
1031
|
+
ArrowUp(event) {
|
|
1097
1032
|
event.preventDefault();
|
|
1098
1033
|
|
|
1099
1034
|
if (this.getState().isOpen) {
|
|
1100
|
-
|
|
1035
|
+
const amount = event.shiftKey ? -5 : -1;
|
|
1101
1036
|
this.moveHighlightedIndex(amount, {
|
|
1102
1037
|
type: keyDownArrowUp
|
|
1103
1038
|
});
|
|
@@ -1105,37 +1040,36 @@
|
|
|
1105
1040
|
this.internalSetState({
|
|
1106
1041
|
isOpen: true,
|
|
1107
1042
|
type: keyDownArrowUp
|
|
1108
|
-
},
|
|
1109
|
-
|
|
1043
|
+
}, () => {
|
|
1044
|
+
const itemCount = this.getItemCount();
|
|
1110
1045
|
|
|
1111
1046
|
if (itemCount > 0) {
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
});
|
|
1118
|
-
|
|
1119
|
-
_this3.setHighlightedIndex(nextHighlightedIndex, {
|
|
1047
|
+
const {
|
|
1048
|
+
highlightedIndex
|
|
1049
|
+
} = this.getState();
|
|
1050
|
+
const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
1051
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
1120
1052
|
type: keyDownArrowUp
|
|
1121
1053
|
});
|
|
1122
1054
|
}
|
|
1123
1055
|
});
|
|
1124
1056
|
}
|
|
1125
1057
|
},
|
|
1126
|
-
|
|
1058
|
+
|
|
1059
|
+
Enter(event) {
|
|
1127
1060
|
if (event.which === 229) {
|
|
1128
1061
|
return;
|
|
1129
1062
|
}
|
|
1130
1063
|
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1064
|
+
const {
|
|
1065
|
+
isOpen,
|
|
1066
|
+
highlightedIndex
|
|
1067
|
+
} = this.getState();
|
|
1134
1068
|
|
|
1135
1069
|
if (isOpen && highlightedIndex != null) {
|
|
1136
1070
|
event.preventDefault();
|
|
1137
|
-
|
|
1138
|
-
|
|
1071
|
+
const item = this.items[highlightedIndex];
|
|
1072
|
+
const itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
1139
1073
|
|
|
1140
1074
|
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
1141
1075
|
return;
|
|
@@ -1146,125 +1080,131 @@
|
|
|
1146
1080
|
});
|
|
1147
1081
|
}
|
|
1148
1082
|
},
|
|
1149
|
-
|
|
1083
|
+
|
|
1084
|
+
Escape(event) {
|
|
1150
1085
|
event.preventDefault();
|
|
1151
|
-
this.reset(
|
|
1152
|
-
type: keyDownEscape
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1086
|
+
this.reset({
|
|
1087
|
+
type: keyDownEscape,
|
|
1088
|
+
...(!this.state.isOpen && {
|
|
1089
|
+
selectedItem: null,
|
|
1090
|
+
inputValue: ''
|
|
1091
|
+
})
|
|
1092
|
+
});
|
|
1157
1093
|
}
|
|
1094
|
+
|
|
1158
1095
|
};
|
|
1159
|
-
|
|
1160
|
-
|
|
1096
|
+
this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
|
|
1097
|
+
|
|
1098
|
+
' '(event) {
|
|
1161
1099
|
event.preventDefault();
|
|
1162
1100
|
this.toggleMenu({
|
|
1163
1101
|
type: keyDownSpaceButton
|
|
1164
1102
|
});
|
|
1165
1103
|
}
|
|
1166
|
-
});
|
|
1167
|
-
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
1168
|
-
Home: function Home(event) {
|
|
1169
|
-
var _this4 = this;
|
|
1170
1104
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1105
|
+
};
|
|
1106
|
+
this.inputKeyDownHandlers = { ...this.keyDownHandlers,
|
|
1107
|
+
|
|
1108
|
+
Home(event) {
|
|
1109
|
+
const {
|
|
1110
|
+
isOpen
|
|
1111
|
+
} = this.getState();
|
|
1173
1112
|
|
|
1174
1113
|
if (!isOpen) {
|
|
1175
1114
|
return;
|
|
1176
1115
|
}
|
|
1177
1116
|
|
|
1178
1117
|
event.preventDefault();
|
|
1179
|
-
|
|
1118
|
+
const itemCount = this.getItemCount();
|
|
1180
1119
|
|
|
1181
1120
|
if (itemCount <= 0 || !isOpen) {
|
|
1182
1121
|
return;
|
|
1183
1122
|
} // get next non-disabled starting downwards from 0 if that's disabled.
|
|
1184
1123
|
|
|
1185
1124
|
|
|
1186
|
-
|
|
1187
|
-
return _this4.getItemNodeFromIndex(index);
|
|
1188
|
-
}, false);
|
|
1125
|
+
const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
1189
1126
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
1190
1127
|
type: keyDownHome
|
|
1191
1128
|
});
|
|
1192
1129
|
},
|
|
1193
|
-
End: function End(event) {
|
|
1194
|
-
var _this5 = this;
|
|
1195
1130
|
|
|
1196
|
-
|
|
1197
|
-
|
|
1131
|
+
End(event) {
|
|
1132
|
+
const {
|
|
1133
|
+
isOpen
|
|
1134
|
+
} = this.getState();
|
|
1198
1135
|
|
|
1199
1136
|
if (!isOpen) {
|
|
1200
1137
|
return;
|
|
1201
1138
|
}
|
|
1202
1139
|
|
|
1203
1140
|
event.preventDefault();
|
|
1204
|
-
|
|
1141
|
+
const itemCount = this.getItemCount();
|
|
1205
1142
|
|
|
1206
1143
|
if (itemCount <= 0 || !isOpen) {
|
|
1207
1144
|
return;
|
|
1208
1145
|
} // get next non-disabled starting upwards from last index if that's disabled.
|
|
1209
1146
|
|
|
1210
1147
|
|
|
1211
|
-
|
|
1212
|
-
return _this5.getItemNodeFromIndex(index);
|
|
1213
|
-
}, false);
|
|
1148
|
+
const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
1214
1149
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
1215
1150
|
type: keyDownEnd
|
|
1216
1151
|
});
|
|
1217
1152
|
}
|
|
1218
|
-
});
|
|
1219
1153
|
|
|
1220
|
-
|
|
1221
|
-
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
1222
|
-
onClick = _ref3.onClick;
|
|
1223
|
-
_ref3.onPress;
|
|
1224
|
-
var onKeyDown = _ref3.onKeyDown,
|
|
1225
|
-
onKeyUp = _ref3.onKeyUp,
|
|
1226
|
-
onBlur = _ref3.onBlur,
|
|
1227
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$3);
|
|
1228
|
-
|
|
1229
|
-
var _this$getState5 = _this.getState(),
|
|
1230
|
-
isOpen = _this$getState5.isOpen;
|
|
1154
|
+
};
|
|
1231
1155
|
|
|
1232
|
-
|
|
1156
|
+
this.getToggleButtonProps = function (_temp3) {
|
|
1157
|
+
let {
|
|
1158
|
+
onClick,
|
|
1159
|
+
onPress,
|
|
1160
|
+
onKeyDown,
|
|
1161
|
+
onKeyUp,
|
|
1162
|
+
onBlur,
|
|
1163
|
+
...rest
|
|
1164
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
1165
|
+
|
|
1166
|
+
const {
|
|
1167
|
+
isOpen
|
|
1168
|
+
} = _this.getState();
|
|
1169
|
+
|
|
1170
|
+
const enabledEventHandlers = {
|
|
1233
1171
|
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
1234
1172
|
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
1235
1173
|
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
1236
1174
|
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
1237
1175
|
};
|
|
1238
|
-
|
|
1239
|
-
return
|
|
1176
|
+
const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
1177
|
+
return {
|
|
1240
1178
|
type: 'button',
|
|
1241
1179
|
role: 'button',
|
|
1242
1180
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
1243
1181
|
'aria-haspopup': true,
|
|
1244
|
-
'data-toggle': true
|
|
1245
|
-
|
|
1182
|
+
'data-toggle': true,
|
|
1183
|
+
...eventHandlers,
|
|
1184
|
+
...rest
|
|
1185
|
+
};
|
|
1246
1186
|
};
|
|
1247
1187
|
|
|
1248
|
-
|
|
1188
|
+
this.buttonHandleKeyUp = event => {
|
|
1249
1189
|
// Prevent click event from emitting in Firefox
|
|
1250
1190
|
event.preventDefault();
|
|
1251
1191
|
};
|
|
1252
1192
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1193
|
+
this.buttonHandleKeyDown = event => {
|
|
1194
|
+
const key = normalizeArrowKey(event);
|
|
1255
1195
|
|
|
1256
|
-
if (
|
|
1257
|
-
|
|
1196
|
+
if (this.buttonKeyDownHandlers[key]) {
|
|
1197
|
+
this.buttonKeyDownHandlers[key].call(this, event);
|
|
1258
1198
|
}
|
|
1259
1199
|
};
|
|
1260
1200
|
|
|
1261
|
-
|
|
1201
|
+
this.buttonHandleClick = event => {
|
|
1262
1202
|
event.preventDefault(); // handle odd case for Safari and Firefox which
|
|
1263
1203
|
// don't give the button the focus properly.
|
|
1264
1204
|
|
|
1265
1205
|
/* istanbul ignore if (can't reasonably test this) */
|
|
1266
1206
|
|
|
1267
|
-
if (
|
|
1207
|
+
if (this.props.environment.document.activeElement === this.props.environment.document.body) {
|
|
1268
1208
|
event.target.focus();
|
|
1269
1209
|
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
1270
1210
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -1273,64 +1213,66 @@
|
|
|
1273
1213
|
|
|
1274
1214
|
{
|
|
1275
1215
|
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
});
|
|
1280
|
-
});
|
|
1216
|
+
this.internalSetTimeout(() => this.toggleMenu({
|
|
1217
|
+
type: clickButton
|
|
1218
|
+
}));
|
|
1281
1219
|
}
|
|
1282
1220
|
};
|
|
1283
1221
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1222
|
+
this.buttonHandleBlur = event => {
|
|
1223
|
+
const blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
1286
1224
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
1287
1225
|
|
|
1288
|
-
|
|
1289
|
-
if (!
|
|
1226
|
+
this.internalSetTimeout(() => {
|
|
1227
|
+
if (!this.isMouseDown && (this.props.environment.document.activeElement == null || this.props.environment.document.activeElement.id !== this.inputId) && this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
|
|
1290
1228
|
) {
|
|
1291
|
-
|
|
1229
|
+
this.reset({
|
|
1292
1230
|
type: blurButton
|
|
1293
1231
|
});
|
|
1294
1232
|
}
|
|
1295
1233
|
});
|
|
1296
1234
|
};
|
|
1297
1235
|
|
|
1298
|
-
|
|
1299
|
-
return
|
|
1300
|
-
htmlFor:
|
|
1301
|
-
id:
|
|
1302
|
-
|
|
1236
|
+
this.getLabelProps = props => {
|
|
1237
|
+
return {
|
|
1238
|
+
htmlFor: this.inputId,
|
|
1239
|
+
id: this.labelId,
|
|
1240
|
+
...props
|
|
1241
|
+
};
|
|
1303
1242
|
};
|
|
1304
1243
|
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1244
|
+
this.getInputProps = function (_temp4) {
|
|
1245
|
+
let {
|
|
1246
|
+
onKeyDown,
|
|
1247
|
+
onBlur,
|
|
1248
|
+
onChange,
|
|
1249
|
+
onInput,
|
|
1250
|
+
onChangeText,
|
|
1251
|
+
...rest
|
|
1252
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
1253
|
+
let onChangeKey;
|
|
1254
|
+
let eventHandlers = {};
|
|
1316
1255
|
/* istanbul ignore next (preact) */
|
|
1317
1256
|
|
|
1318
1257
|
{
|
|
1319
1258
|
onChangeKey = 'onInput';
|
|
1320
1259
|
}
|
|
1321
1260
|
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1261
|
+
const {
|
|
1262
|
+
inputValue,
|
|
1263
|
+
isOpen,
|
|
1264
|
+
highlightedIndex
|
|
1265
|
+
} = _this.getState();
|
|
1326
1266
|
|
|
1327
1267
|
if (!rest.disabled) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1268
|
+
eventHandlers = {
|
|
1269
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
|
|
1270
|
+
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
|
|
1271
|
+
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
1272
|
+
};
|
|
1331
1273
|
}
|
|
1332
1274
|
|
|
1333
|
-
return
|
|
1275
|
+
return {
|
|
1334
1276
|
'aria-autocomplete': 'list',
|
|
1335
1277
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
1336
1278
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -1339,75 +1281,77 @@
|
|
|
1339
1281
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
1340
1282
|
autoComplete: 'off',
|
|
1341
1283
|
value: inputValue,
|
|
1342
|
-
id: _this.inputId
|
|
1343
|
-
|
|
1284
|
+
id: _this.inputId,
|
|
1285
|
+
...eventHandlers,
|
|
1286
|
+
...rest
|
|
1287
|
+
};
|
|
1344
1288
|
};
|
|
1345
1289
|
|
|
1346
|
-
|
|
1347
|
-
|
|
1290
|
+
this.inputHandleKeyDown = event => {
|
|
1291
|
+
const key = normalizeArrowKey(event);
|
|
1348
1292
|
|
|
1349
|
-
if (key &&
|
|
1350
|
-
|
|
1293
|
+
if (key && this.inputKeyDownHandlers[key]) {
|
|
1294
|
+
this.inputKeyDownHandlers[key].call(this, event);
|
|
1351
1295
|
}
|
|
1352
1296
|
};
|
|
1353
1297
|
|
|
1354
|
-
|
|
1355
|
-
|
|
1298
|
+
this.inputHandleChange = event => {
|
|
1299
|
+
this.internalSetState({
|
|
1356
1300
|
type: changeInput,
|
|
1357
1301
|
isOpen: true,
|
|
1358
1302
|
inputValue: event.target.value,
|
|
1359
|
-
highlightedIndex:
|
|
1303
|
+
highlightedIndex: this.props.defaultHighlightedIndex
|
|
1360
1304
|
});
|
|
1361
1305
|
};
|
|
1362
1306
|
|
|
1363
|
-
|
|
1307
|
+
this.inputHandleBlur = () => {
|
|
1364
1308
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
1365
|
-
|
|
1366
|
-
|
|
1309
|
+
this.internalSetTimeout(() => {
|
|
1310
|
+
const downshiftButtonIsActive = this.props.environment.document && !!this.props.environment.document.activeElement && !!this.props.environment.document.activeElement.dataset && this.props.environment.document.activeElement.dataset.toggle && this._rootNode && this._rootNode.contains(this.props.environment.document.activeElement);
|
|
1367
1311
|
|
|
1368
|
-
if (!
|
|
1369
|
-
|
|
1312
|
+
if (!this.isMouseDown && !downshiftButtonIsActive) {
|
|
1313
|
+
this.reset({
|
|
1370
1314
|
type: blurInput
|
|
1371
1315
|
});
|
|
1372
1316
|
}
|
|
1373
1317
|
});
|
|
1374
1318
|
};
|
|
1375
1319
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1320
|
+
this.menuRef = node => {
|
|
1321
|
+
this._menuNode = node;
|
|
1378
1322
|
};
|
|
1379
1323
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
1390
|
-
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
1391
|
-
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
1392
|
-
|
|
1324
|
+
this.getMenuProps = function (_temp5, _temp6) {
|
|
1325
|
+
let {
|
|
1326
|
+
refKey = 'ref',
|
|
1327
|
+
ref,
|
|
1328
|
+
...props
|
|
1329
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
1330
|
+
let {
|
|
1331
|
+
suppressRefError = false
|
|
1332
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
1393
1333
|
_this.getMenuProps.called = true;
|
|
1394
1334
|
_this.getMenuProps.refKey = refKey;
|
|
1395
1335
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
1396
|
-
return
|
|
1336
|
+
return {
|
|
1337
|
+
[refKey]: handleRefs(ref, _this.menuRef),
|
|
1338
|
+
role: 'listbox',
|
|
1339
|
+
'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
|
|
1340
|
+
id: _this.menuId,
|
|
1341
|
+
...props
|
|
1342
|
+
};
|
|
1397
1343
|
};
|
|
1398
1344
|
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
item = _ref7$item === void 0 ? requiredProp('getItemProps', 'item') : _ref7$item,
|
|
1410
|
-
rest = _objectWithoutPropertiesLoose(_ref7, _excluded5$1);
|
|
1345
|
+
this.getItemProps = function (_temp7) {
|
|
1346
|
+
let {
|
|
1347
|
+
onMouseMove,
|
|
1348
|
+
onMouseDown,
|
|
1349
|
+
onClick,
|
|
1350
|
+
onPress,
|
|
1351
|
+
index,
|
|
1352
|
+
item = requiredProp('getItemProps', 'item'),
|
|
1353
|
+
...rest
|
|
1354
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
1411
1355
|
|
|
1412
1356
|
if (index === undefined) {
|
|
1413
1357
|
_this.items.push(item);
|
|
@@ -1417,13 +1361,13 @@
|
|
|
1417
1361
|
_this.items[index] = item;
|
|
1418
1362
|
}
|
|
1419
1363
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1364
|
+
const onSelectKey = 'onClick';
|
|
1365
|
+
const customClickHandler = onClick;
|
|
1366
|
+
const enabledEventHandlers = {
|
|
1423
1367
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
1424
1368
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
1425
1369
|
// can fire on DOM changes, interrupting keyboard navigation
|
|
1426
|
-
onMouseMove: callAllEventHandlers(onMouseMove,
|
|
1370
|
+
onMouseMove: callAllEventHandlers(onMouseMove, () => {
|
|
1427
1371
|
if (index === _this.getState().highlightedIndex) {
|
|
1428
1372
|
return;
|
|
1429
1373
|
}
|
|
@@ -1438,72 +1382,81 @@
|
|
|
1438
1382
|
|
|
1439
1383
|
_this.avoidScrolling = true;
|
|
1440
1384
|
|
|
1441
|
-
_this.internalSetTimeout(
|
|
1442
|
-
return _this.avoidScrolling = false;
|
|
1443
|
-
}, 250);
|
|
1385
|
+
_this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
|
|
1444
1386
|
}),
|
|
1445
|
-
onMouseDown: callAllEventHandlers(onMouseDown,
|
|
1387
|
+
onMouseDown: callAllEventHandlers(onMouseDown, event => {
|
|
1446
1388
|
// This prevents the activeElement from being changed
|
|
1447
1389
|
// to the item so it can remain with the current activeElement
|
|
1448
1390
|
// which is a more common use case.
|
|
1449
1391
|
event.preventDefault();
|
|
1392
|
+
}),
|
|
1393
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, () => {
|
|
1394
|
+
_this.selectItemAtIndex(index, {
|
|
1395
|
+
type: clickItem
|
|
1396
|
+
});
|
|
1450
1397
|
})
|
|
1451
|
-
}
|
|
1452
|
-
_this.selectItemAtIndex(index, {
|
|
1453
|
-
type: clickItem
|
|
1454
|
-
});
|
|
1455
|
-
}), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
|
|
1398
|
+
}; // Passing down the onMouseDown handler to prevent redirect
|
|
1456
1399
|
// of the activeElement if clicking on disabled items
|
|
1457
1400
|
|
|
1458
|
-
|
|
1401
|
+
const eventHandlers = rest.disabled ? {
|
|
1459
1402
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
1460
1403
|
} : enabledEventHandlers;
|
|
1461
|
-
return
|
|
1404
|
+
return {
|
|
1462
1405
|
id: _this.getItemId(index),
|
|
1463
1406
|
role: 'option',
|
|
1464
|
-
'aria-selected': _this.getState().highlightedIndex === index
|
|
1465
|
-
|
|
1407
|
+
'aria-selected': _this.getState().highlightedIndex === index,
|
|
1408
|
+
...eventHandlers,
|
|
1409
|
+
...rest
|
|
1410
|
+
};
|
|
1466
1411
|
};
|
|
1467
1412
|
|
|
1468
|
-
|
|
1469
|
-
|
|
1413
|
+
this.clearItems = () => {
|
|
1414
|
+
this.items = [];
|
|
1470
1415
|
};
|
|
1471
1416
|
|
|
1472
|
-
|
|
1417
|
+
this.reset = function (otherStateToSet, cb) {
|
|
1473
1418
|
if (otherStateToSet === void 0) {
|
|
1474
1419
|
otherStateToSet = {};
|
|
1475
1420
|
}
|
|
1476
1421
|
|
|
1477
1422
|
otherStateToSet = pickState(otherStateToSet);
|
|
1478
1423
|
|
|
1479
|
-
_this.internalSetState(
|
|
1480
|
-
|
|
1481
|
-
|
|
1424
|
+
_this.internalSetState(_ref => {
|
|
1425
|
+
let {
|
|
1426
|
+
selectedItem
|
|
1427
|
+
} = _ref;
|
|
1428
|
+
return {
|
|
1482
1429
|
isOpen: _this.props.defaultIsOpen,
|
|
1483
1430
|
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1484
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
1485
|
-
|
|
1431
|
+
inputValue: _this.props.itemToString(selectedItem),
|
|
1432
|
+
...otherStateToSet
|
|
1433
|
+
};
|
|
1486
1434
|
}, cb);
|
|
1487
1435
|
};
|
|
1488
1436
|
|
|
1489
|
-
|
|
1437
|
+
this.toggleMenu = function (otherStateToSet, cb) {
|
|
1490
1438
|
if (otherStateToSet === void 0) {
|
|
1491
1439
|
otherStateToSet = {};
|
|
1492
1440
|
}
|
|
1493
1441
|
|
|
1494
1442
|
otherStateToSet = pickState(otherStateToSet);
|
|
1495
1443
|
|
|
1496
|
-
_this.internalSetState(
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1444
|
+
_this.internalSetState(_ref2 => {
|
|
1445
|
+
let {
|
|
1446
|
+
isOpen
|
|
1447
|
+
} = _ref2;
|
|
1448
|
+
return {
|
|
1449
|
+
isOpen: !isOpen,
|
|
1450
|
+
...(isOpen && {
|
|
1451
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
1452
|
+
}),
|
|
1453
|
+
...otherStateToSet
|
|
1454
|
+
};
|
|
1455
|
+
}, () => {
|
|
1456
|
+
const {
|
|
1457
|
+
isOpen,
|
|
1458
|
+
highlightedIndex
|
|
1459
|
+
} = _this.getState();
|
|
1507
1460
|
|
|
1508
1461
|
if (isOpen) {
|
|
1509
1462
|
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
@@ -1515,70 +1468,63 @@
|
|
|
1515
1468
|
});
|
|
1516
1469
|
};
|
|
1517
1470
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1471
|
+
this.openMenu = cb => {
|
|
1472
|
+
this.internalSetState({
|
|
1520
1473
|
isOpen: true
|
|
1521
1474
|
}, cb);
|
|
1522
1475
|
};
|
|
1523
1476
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1477
|
+
this.closeMenu = cb => {
|
|
1478
|
+
this.internalSetState({
|
|
1526
1479
|
isOpen: false
|
|
1527
1480
|
}, cb);
|
|
1528
1481
|
};
|
|
1529
1482
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
_this.previousResultCount = resultCount;
|
|
1545
|
-
setStatus(status, _this.props.environment.document);
|
|
1483
|
+
this.updateStatus = debounce(() => {
|
|
1484
|
+
const state = this.getState();
|
|
1485
|
+
const item = this.items[state.highlightedIndex];
|
|
1486
|
+
const resultCount = this.getItemCount();
|
|
1487
|
+
const status = this.props.getA11yStatusMessage({
|
|
1488
|
+
itemToString: this.props.itemToString,
|
|
1489
|
+
previousResultCount: this.previousResultCount,
|
|
1490
|
+
resultCount,
|
|
1491
|
+
highlightedItem: item,
|
|
1492
|
+
...state
|
|
1493
|
+
});
|
|
1494
|
+
this.previousResultCount = resultCount;
|
|
1495
|
+
setStatus(status, this.props.environment.document);
|
|
1546
1496
|
}, 200);
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
var _state = _this.getState({
|
|
1497
|
+
// fancy destructuring + defaults + aliases
|
|
1498
|
+
// this basically says each value of state should either be set to
|
|
1499
|
+
// the initial value or the default value if the initial value is not provided
|
|
1500
|
+
const {
|
|
1501
|
+
defaultHighlightedIndex,
|
|
1502
|
+
initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
|
|
1503
|
+
defaultIsOpen,
|
|
1504
|
+
initialIsOpen: _isOpen = defaultIsOpen,
|
|
1505
|
+
initialInputValue: _inputValue = '',
|
|
1506
|
+
initialSelectedItem: _selectedItem = null
|
|
1507
|
+
} = this.props;
|
|
1508
|
+
|
|
1509
|
+
const _state = this.getState({
|
|
1561
1510
|
highlightedIndex: _highlightedIndex,
|
|
1562
1511
|
isOpen: _isOpen,
|
|
1563
1512
|
inputValue: _inputValue,
|
|
1564
1513
|
selectedItem: _selectedItem
|
|
1565
1514
|
});
|
|
1566
1515
|
|
|
1567
|
-
if (_state.selectedItem != null &&
|
|
1568
|
-
_state.inputValue =
|
|
1516
|
+
if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
|
|
1517
|
+
_state.inputValue = this.props.itemToString(_state.selectedItem);
|
|
1569
1518
|
}
|
|
1570
1519
|
|
|
1571
|
-
|
|
1572
|
-
return _this;
|
|
1520
|
+
this.state = _state;
|
|
1573
1521
|
}
|
|
1574
1522
|
|
|
1575
|
-
var _proto = Downshift.prototype;
|
|
1576
|
-
|
|
1577
1523
|
/**
|
|
1578
1524
|
* Clear all running timeouts
|
|
1579
1525
|
*/
|
|
1580
|
-
|
|
1581
|
-
this.timeoutIds.forEach(
|
|
1526
|
+
internalClearTimeouts() {
|
|
1527
|
+
this.timeoutIds.forEach(id => {
|
|
1582
1528
|
clearTimeout(id);
|
|
1583
1529
|
});
|
|
1584
1530
|
this.timeoutIds = [];
|
|
@@ -1592,22 +1538,22 @@
|
|
|
1592
1538
|
* @param {Object} stateToMerge defaults to this.state
|
|
1593
1539
|
* @return {Object} the state
|
|
1594
1540
|
*/
|
|
1595
|
-
;
|
|
1596
1541
|
|
|
1597
|
-
|
|
1542
|
+
|
|
1543
|
+
getState(stateToMerge) {
|
|
1598
1544
|
if (stateToMerge === void 0) {
|
|
1599
1545
|
stateToMerge = this.state;
|
|
1600
1546
|
}
|
|
1601
1547
|
|
|
1602
1548
|
return getState(stateToMerge, this.props);
|
|
1603
|
-
}
|
|
1549
|
+
}
|
|
1604
1550
|
|
|
1605
|
-
|
|
1551
|
+
getItemCount() {
|
|
1606
1552
|
// things read better this way. They're in priority order:
|
|
1607
1553
|
// 1. `this.itemCount`
|
|
1608
1554
|
// 2. `this.props.itemCount`
|
|
1609
1555
|
// 3. `this.items.length`
|
|
1610
|
-
|
|
1556
|
+
let itemCount = this.items.length;
|
|
1611
1557
|
|
|
1612
1558
|
if (this.itemCount != null) {
|
|
1613
1559
|
itemCount = this.itemCount;
|
|
@@ -1616,102 +1562,102 @@
|
|
|
1616
1562
|
}
|
|
1617
1563
|
|
|
1618
1564
|
return itemCount;
|
|
1619
|
-
}
|
|
1565
|
+
}
|
|
1620
1566
|
|
|
1621
|
-
|
|
1567
|
+
getItemNodeFromIndex(index) {
|
|
1622
1568
|
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
1623
|
-
}
|
|
1569
|
+
}
|
|
1624
1570
|
|
|
1625
|
-
|
|
1571
|
+
scrollHighlightedItemIntoView() {
|
|
1626
1572
|
/* istanbul ignore else (react-native) */
|
|
1627
1573
|
{
|
|
1628
|
-
|
|
1574
|
+
const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
1629
1575
|
this.props.scrollIntoView(node, this._menuNode);
|
|
1630
1576
|
}
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
_proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
|
1634
|
-
var _this6 = this;
|
|
1635
|
-
|
|
1636
|
-
var itemCount = this.getItemCount();
|
|
1577
|
+
}
|
|
1637
1578
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1579
|
+
moveHighlightedIndex(amount, otherStateToSet) {
|
|
1580
|
+
const itemCount = this.getItemCount();
|
|
1581
|
+
const {
|
|
1582
|
+
highlightedIndex
|
|
1583
|
+
} = this.getState();
|
|
1640
1584
|
|
|
1641
1585
|
if (itemCount > 0) {
|
|
1642
|
-
|
|
1643
|
-
return _this6.getItemNodeFromIndex(index);
|
|
1644
|
-
});
|
|
1586
|
+
const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
1645
1587
|
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
1646
1588
|
}
|
|
1647
|
-
}
|
|
1589
|
+
}
|
|
1648
1590
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1591
|
+
getStateAndHelpers() {
|
|
1592
|
+
const {
|
|
1593
|
+
highlightedIndex,
|
|
1594
|
+
inputValue,
|
|
1595
|
+
selectedItem,
|
|
1596
|
+
isOpen
|
|
1597
|
+
} = this.getState();
|
|
1598
|
+
const {
|
|
1599
|
+
itemToString
|
|
1600
|
+
} = this.props;
|
|
1601
|
+
const {
|
|
1602
|
+
id
|
|
1603
|
+
} = this;
|
|
1604
|
+
const {
|
|
1605
|
+
getRootProps,
|
|
1606
|
+
getToggleButtonProps,
|
|
1607
|
+
getLabelProps,
|
|
1608
|
+
getMenuProps,
|
|
1609
|
+
getInputProps,
|
|
1610
|
+
getItemProps,
|
|
1611
|
+
openMenu,
|
|
1612
|
+
closeMenu,
|
|
1613
|
+
toggleMenu,
|
|
1614
|
+
selectItem,
|
|
1615
|
+
selectItemAtIndex,
|
|
1616
|
+
selectHighlightedItem,
|
|
1617
|
+
setHighlightedIndex,
|
|
1618
|
+
clearSelection,
|
|
1619
|
+
clearItems,
|
|
1620
|
+
reset,
|
|
1621
|
+
setItemCount,
|
|
1622
|
+
unsetItemCount,
|
|
1623
|
+
internalSetState: setState
|
|
1624
|
+
} = this;
|
|
1677
1625
|
return {
|
|
1678
1626
|
// prop getters
|
|
1679
|
-
getRootProps
|
|
1680
|
-
getToggleButtonProps
|
|
1681
|
-
getLabelProps
|
|
1682
|
-
getMenuProps
|
|
1683
|
-
getInputProps
|
|
1684
|
-
getItemProps
|
|
1627
|
+
getRootProps,
|
|
1628
|
+
getToggleButtonProps,
|
|
1629
|
+
getLabelProps,
|
|
1630
|
+
getMenuProps,
|
|
1631
|
+
getInputProps,
|
|
1632
|
+
getItemProps,
|
|
1685
1633
|
// actions
|
|
1686
|
-
reset
|
|
1687
|
-
openMenu
|
|
1688
|
-
closeMenu
|
|
1689
|
-
toggleMenu
|
|
1690
|
-
selectItem
|
|
1691
|
-
selectItemAtIndex
|
|
1692
|
-
selectHighlightedItem
|
|
1693
|
-
setHighlightedIndex
|
|
1694
|
-
clearSelection
|
|
1695
|
-
clearItems
|
|
1696
|
-
setItemCount
|
|
1697
|
-
unsetItemCount
|
|
1698
|
-
setState
|
|
1634
|
+
reset,
|
|
1635
|
+
openMenu,
|
|
1636
|
+
closeMenu,
|
|
1637
|
+
toggleMenu,
|
|
1638
|
+
selectItem,
|
|
1639
|
+
selectItemAtIndex,
|
|
1640
|
+
selectHighlightedItem,
|
|
1641
|
+
setHighlightedIndex,
|
|
1642
|
+
clearSelection,
|
|
1643
|
+
clearItems,
|
|
1644
|
+
setItemCount,
|
|
1645
|
+
unsetItemCount,
|
|
1646
|
+
setState,
|
|
1699
1647
|
// props
|
|
1700
|
-
itemToString
|
|
1648
|
+
itemToString,
|
|
1701
1649
|
// derived
|
|
1702
|
-
id
|
|
1650
|
+
id,
|
|
1703
1651
|
// state
|
|
1704
|
-
highlightedIndex
|
|
1705
|
-
inputValue
|
|
1706
|
-
isOpen
|
|
1707
|
-
selectedItem
|
|
1652
|
+
highlightedIndex,
|
|
1653
|
+
inputValue,
|
|
1654
|
+
isOpen,
|
|
1655
|
+
selectedItem
|
|
1708
1656
|
};
|
|
1709
1657
|
} //////////////////////////// ROOT
|
|
1710
|
-
;
|
|
1711
1658
|
|
|
1712
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
1713
|
-
var _this7 = this;
|
|
1714
1659
|
|
|
1660
|
+
componentDidMount() {
|
|
1715
1661
|
/* istanbul ignore if (react-native) */
|
|
1716
1662
|
if (this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
1717
1663
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
@@ -1725,22 +1671,20 @@
|
|
|
1725
1671
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
1726
1672
|
// this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
|
|
1727
1673
|
// trigger hiding the menu.
|
|
1728
|
-
|
|
1729
|
-
|
|
1674
|
+
const onMouseDown = () => {
|
|
1675
|
+
this.isMouseDown = true;
|
|
1730
1676
|
};
|
|
1731
1677
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1678
|
+
const onMouseUp = event => {
|
|
1679
|
+
this.isMouseDown = false; // if the target element or the activeElement is within a downshift node
|
|
1734
1680
|
// then we don't want to reset downshift
|
|
1735
1681
|
|
|
1736
|
-
|
|
1682
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
|
|
1737
1683
|
|
|
1738
|
-
if (!contextWithinDownshift &&
|
|
1739
|
-
|
|
1684
|
+
if (!contextWithinDownshift && this.getState().isOpen) {
|
|
1685
|
+
this.reset({
|
|
1740
1686
|
type: mouseUp
|
|
1741
|
-
},
|
|
1742
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
1743
|
-
});
|
|
1687
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
1744
1688
|
}
|
|
1745
1689
|
}; // Touching an element in iOS gives focus and hover states, but touching out of
|
|
1746
1690
|
// the element will remove hover, and persist the focus state, resulting in the
|
|
@@ -1750,38 +1694,36 @@
|
|
|
1750
1694
|
// but not if the user is swiping
|
|
1751
1695
|
|
|
1752
1696
|
|
|
1753
|
-
|
|
1754
|
-
|
|
1697
|
+
const onTouchStart = () => {
|
|
1698
|
+
this.isTouchMove = false;
|
|
1755
1699
|
};
|
|
1756
1700
|
|
|
1757
|
-
|
|
1758
|
-
|
|
1701
|
+
const onTouchMove = () => {
|
|
1702
|
+
this.isTouchMove = true;
|
|
1759
1703
|
};
|
|
1760
1704
|
|
|
1761
|
-
|
|
1762
|
-
|
|
1705
|
+
const onTouchEnd = event => {
|
|
1706
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
|
|
1763
1707
|
|
|
1764
|
-
if (!
|
|
1765
|
-
|
|
1708
|
+
if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
|
|
1709
|
+
this.reset({
|
|
1766
1710
|
type: touchEnd
|
|
1767
|
-
},
|
|
1768
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
1769
|
-
});
|
|
1711
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
1770
1712
|
}
|
|
1771
1713
|
};
|
|
1772
1714
|
|
|
1773
|
-
|
|
1715
|
+
const {
|
|
1716
|
+
environment
|
|
1717
|
+
} = this.props;
|
|
1774
1718
|
environment.addEventListener('mousedown', onMouseDown);
|
|
1775
1719
|
environment.addEventListener('mouseup', onMouseUp);
|
|
1776
1720
|
environment.addEventListener('touchstart', onTouchStart);
|
|
1777
1721
|
environment.addEventListener('touchmove', onTouchMove);
|
|
1778
1722
|
environment.addEventListener('touchend', onTouchEnd);
|
|
1779
1723
|
|
|
1780
|
-
this.cleanup =
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
_this7.updateStatus.cancel();
|
|
1784
|
-
|
|
1724
|
+
this.cleanup = () => {
|
|
1725
|
+
this.internalClearTimeouts();
|
|
1726
|
+
this.updateStatus.cancel();
|
|
1785
1727
|
environment.removeEventListener('mousedown', onMouseDown);
|
|
1786
1728
|
environment.removeEventListener('mouseup', onMouseUp);
|
|
1787
1729
|
environment.removeEventListener('touchstart', onTouchStart);
|
|
@@ -1789,21 +1731,21 @@
|
|
|
1789
1731
|
environment.removeEventListener('touchend', onTouchEnd);
|
|
1790
1732
|
};
|
|
1791
1733
|
}
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
_proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
|
1795
|
-
var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
|
1796
|
-
currentHighlightedIndex = _ref10.highlightedIndex;
|
|
1797
|
-
|
|
1798
|
-
var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
|
1799
|
-
prevHighlightedIndex = _ref11.highlightedIndex;
|
|
1734
|
+
}
|
|
1800
1735
|
|
|
1801
|
-
|
|
1802
|
-
|
|
1736
|
+
shouldScroll(prevState, prevProps) {
|
|
1737
|
+
const {
|
|
1738
|
+
highlightedIndex: currentHighlightedIndex
|
|
1739
|
+
} = this.props.highlightedIndex === undefined ? this.getState() : this.props;
|
|
1740
|
+
const {
|
|
1741
|
+
highlightedIndex: prevHighlightedIndex
|
|
1742
|
+
} = prevProps.highlightedIndex === undefined ? prevState : prevProps;
|
|
1743
|
+
const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
1744
|
+
const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
1803
1745
|
return scrollWhenOpen || scrollWhenNavigating;
|
|
1804
|
-
}
|
|
1746
|
+
}
|
|
1805
1747
|
|
|
1806
|
-
|
|
1748
|
+
componentDidUpdate(prevProps, prevState) {
|
|
1807
1749
|
{
|
|
1808
1750
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
1809
1751
|
/* istanbul ignore if (react-native) */
|
|
@@ -1829,14 +1771,14 @@
|
|
|
1829
1771
|
{
|
|
1830
1772
|
this.updateStatus();
|
|
1831
1773
|
}
|
|
1832
|
-
}
|
|
1774
|
+
}
|
|
1833
1775
|
|
|
1834
|
-
|
|
1776
|
+
componentWillUnmount() {
|
|
1835
1777
|
this.cleanup(); // avoids memory leak
|
|
1836
|
-
}
|
|
1778
|
+
}
|
|
1837
1779
|
|
|
1838
|
-
|
|
1839
|
-
|
|
1780
|
+
render() {
|
|
1781
|
+
const children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
|
|
1840
1782
|
// we clear this out each render and it will be populated again as
|
|
1841
1783
|
// getItemProps is called.
|
|
1842
1784
|
|
|
@@ -1856,7 +1798,7 @@
|
|
|
1856
1798
|
this.getLabelProps.called = false; // and something similar for getInputProps
|
|
1857
1799
|
|
|
1858
1800
|
this.getInputProps.called = false;
|
|
1859
|
-
|
|
1801
|
+
const element = unwrapArray(children(this.getStateAndHelpers()));
|
|
1860
1802
|
|
|
1861
1803
|
if (!element) {
|
|
1862
1804
|
return null;
|
|
@@ -1881,16 +1823,15 @@
|
|
|
1881
1823
|
// otherwise we can't query around the autocomplete
|
|
1882
1824
|
throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
|
|
1883
1825
|
}
|
|
1884
|
-
}
|
|
1826
|
+
}
|
|
1885
1827
|
|
|
1886
|
-
|
|
1887
|
-
}(preact.Component);
|
|
1828
|
+
}
|
|
1888
1829
|
|
|
1889
1830
|
Downshift.defaultProps = {
|
|
1890
1831
|
defaultHighlightedIndex: null,
|
|
1891
1832
|
defaultIsOpen: false,
|
|
1892
1833
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
1893
|
-
itemToString:
|
|
1834
|
+
itemToString: i => {
|
|
1894
1835
|
if (i == null) {
|
|
1895
1836
|
return '';
|
|
1896
1837
|
}
|
|
@@ -1908,26 +1849,24 @@
|
|
|
1908
1849
|
onChange: noop,
|
|
1909
1850
|
onSelect: noop,
|
|
1910
1851
|
onOuterClick: noop,
|
|
1911
|
-
selectedItemChanged:
|
|
1912
|
-
return prevItem !== item;
|
|
1913
|
-
},
|
|
1852
|
+
selectedItemChanged: (prevItem, item) => prevItem !== item,
|
|
1914
1853
|
environment:
|
|
1915
1854
|
/* istanbul ignore next (ssr) */
|
|
1916
1855
|
typeof window === 'undefined' ? {} : window,
|
|
1917
|
-
stateReducer:
|
|
1918
|
-
return stateToSet;
|
|
1919
|
-
},
|
|
1856
|
+
stateReducer: (state, stateToSet) => stateToSet,
|
|
1920
1857
|
suppressRefError: false,
|
|
1921
|
-
scrollIntoView
|
|
1858
|
+
scrollIntoView
|
|
1922
1859
|
};
|
|
1923
1860
|
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
1924
1861
|
return Downshift;
|
|
1925
|
-
}();
|
|
1862
|
+
})();
|
|
1926
1863
|
|
|
1927
1864
|
var Downshift$1 = Downshift;
|
|
1928
1865
|
|
|
1929
|
-
function validateGetMenuPropsCalledCorrectly(node,
|
|
1930
|
-
|
|
1866
|
+
function validateGetMenuPropsCalledCorrectly(node, _ref3) {
|
|
1867
|
+
let {
|
|
1868
|
+
refKey
|
|
1869
|
+
} = _ref3;
|
|
1931
1870
|
|
|
1932
1871
|
if (!node) {
|
|
1933
1872
|
// eslint-disable-next-line no-console
|
|
@@ -1935,10 +1874,12 @@
|
|
|
1935
1874
|
}
|
|
1936
1875
|
}
|
|
1937
1876
|
|
|
1938
|
-
function validateGetRootPropsCalledCorrectly(element,
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1877
|
+
function validateGetRootPropsCalledCorrectly(element, _ref4) {
|
|
1878
|
+
let {
|
|
1879
|
+
refKey
|
|
1880
|
+
} = _ref4;
|
|
1881
|
+
const refKeySpecified = refKey !== 'ref';
|
|
1882
|
+
const isComposite = !isDOMElement(element);
|
|
1942
1883
|
|
|
1943
1884
|
if (isComposite && !refKeySpecified && !reactIs.exports.isForwardRef(element)) {
|
|
1944
1885
|
// eslint-disable-next-line no-console
|
|
@@ -1954,8 +1895,7 @@
|
|
|
1954
1895
|
}
|
|
1955
1896
|
}
|
|
1956
1897
|
|
|
1957
|
-
|
|
1958
|
-
var dropdownDefaultStateValues = {
|
|
1898
|
+
const dropdownDefaultStateValues = {
|
|
1959
1899
|
highlightedIndex: -1,
|
|
1960
1900
|
isOpen: false,
|
|
1961
1901
|
selectedItem: null,
|
|
@@ -1963,10 +1903,12 @@
|
|
|
1963
1903
|
};
|
|
1964
1904
|
|
|
1965
1905
|
function callOnChangeProps(action, state, newState) {
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1906
|
+
const {
|
|
1907
|
+
props,
|
|
1908
|
+
type
|
|
1909
|
+
} = action;
|
|
1910
|
+
const changes = {};
|
|
1911
|
+
Object.keys(state).forEach(key => {
|
|
1970
1912
|
invokeOnChangeHandler(key, action, state, newState);
|
|
1971
1913
|
|
|
1972
1914
|
if (newState[key] !== state[key]) {
|
|
@@ -1975,21 +1917,25 @@
|
|
|
1975
1917
|
});
|
|
1976
1918
|
|
|
1977
1919
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
1978
|
-
props.onStateChange(
|
|
1979
|
-
type
|
|
1980
|
-
|
|
1920
|
+
props.onStateChange({
|
|
1921
|
+
type,
|
|
1922
|
+
...changes
|
|
1923
|
+
});
|
|
1981
1924
|
}
|
|
1982
1925
|
}
|
|
1983
1926
|
|
|
1984
1927
|
function invokeOnChangeHandler(key, action, state, newState) {
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1928
|
+
const {
|
|
1929
|
+
props,
|
|
1930
|
+
type
|
|
1931
|
+
} = action;
|
|
1932
|
+
const handler = "on" + capitalizeString(key) + "Change";
|
|
1988
1933
|
|
|
1989
1934
|
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
1990
|
-
props[handler](
|
|
1991
|
-
type
|
|
1992
|
-
|
|
1935
|
+
props[handler]({
|
|
1936
|
+
type,
|
|
1937
|
+
...newState
|
|
1938
|
+
});
|
|
1993
1939
|
}
|
|
1994
1940
|
}
|
|
1995
1941
|
/**
|
|
@@ -2013,8 +1959,10 @@
|
|
|
2013
1959
|
|
|
2014
1960
|
|
|
2015
1961
|
function getA11ySelectionMessage(selectionParameters) {
|
|
2016
|
-
|
|
2017
|
-
|
|
1962
|
+
const {
|
|
1963
|
+
selectedItem,
|
|
1964
|
+
itemToString: itemToStringLocal
|
|
1965
|
+
} = selectionParameters;
|
|
2018
1966
|
return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
|
|
2019
1967
|
}
|
|
2020
1968
|
/**
|
|
@@ -2022,26 +1970,25 @@
|
|
|
2022
1970
|
*/
|
|
2023
1971
|
|
|
2024
1972
|
|
|
2025
|
-
|
|
1973
|
+
const updateA11yStatus = debounce((getA11yMessage, document) => {
|
|
2026
1974
|
setStatus(getA11yMessage(), document);
|
|
2027
1975
|
}, 200); // istanbul ignore next
|
|
2028
1976
|
|
|
2029
|
-
|
|
1977
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
|
|
2030
1978
|
|
|
2031
1979
|
function useElementIds(_ref) {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
1980
|
+
let {
|
|
1981
|
+
id = "downshift-" + generateId(),
|
|
1982
|
+
labelId,
|
|
1983
|
+
menuId,
|
|
1984
|
+
getItemId,
|
|
1985
|
+
toggleButtonId,
|
|
1986
|
+
inputId
|
|
1987
|
+
} = _ref;
|
|
1988
|
+
const elementIdsRef = preact.useRef({
|
|
2040
1989
|
labelId: labelId || id + "-label",
|
|
2041
1990
|
menuId: menuId || id + "-menu",
|
|
2042
|
-
getItemId: getItemId ||
|
|
2043
|
-
return id + "-item-" + index;
|
|
2044
|
-
},
|
|
1991
|
+
getItemId: getItemId || (index => id + "-item-" + index),
|
|
2045
1992
|
toggleButtonId: toggleButtonId || id + "-toggle-button",
|
|
2046
1993
|
inputId: inputId || id + "-input"
|
|
2047
1994
|
});
|
|
@@ -2073,7 +2020,7 @@
|
|
|
2073
2020
|
}
|
|
2074
2021
|
|
|
2075
2022
|
function useLatestRef(val) {
|
|
2076
|
-
|
|
2023
|
+
const ref = preact.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
|
|
2077
2024
|
// the value during render (so it's not idempotent). However, the places this
|
|
2078
2025
|
// hook is used is to support memoizing callbacks which will be called
|
|
2079
2026
|
// *during* render, so we need the latest values *during* render.
|
|
@@ -2095,30 +2042,25 @@
|
|
|
2095
2042
|
|
|
2096
2043
|
|
|
2097
2044
|
function useEnhancedReducer(reducer, initialState, props) {
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2045
|
+
const prevStateRef = preact.useRef();
|
|
2046
|
+
const actionRef = preact.useRef();
|
|
2047
|
+
const enhancedReducer = preact.useCallback((state, action) => {
|
|
2101
2048
|
actionRef.current = action;
|
|
2102
2049
|
state = getState(state, action.props);
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
changes
|
|
2106
|
-
})
|
|
2050
|
+
const changes = reducer(state, action);
|
|
2051
|
+
const newState = action.props.stateReducer(state, { ...action,
|
|
2052
|
+
changes
|
|
2053
|
+
});
|
|
2107
2054
|
return newState;
|
|
2108
2055
|
}, [reducer]);
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
props: propsRef.current
|
|
2118
|
-
}, action));
|
|
2119
|
-
}, [propsRef]);
|
|
2120
|
-
var action = actionRef.current;
|
|
2121
|
-
preact.useEffect(function () {
|
|
2056
|
+
const [state, dispatch] = preact.useReducer(enhancedReducer, initialState);
|
|
2057
|
+
const propsRef = useLatestRef(props);
|
|
2058
|
+
const dispatchWithProps = preact.useCallback(action => dispatch({
|
|
2059
|
+
props: propsRef.current,
|
|
2060
|
+
...action
|
|
2061
|
+
}), [propsRef]);
|
|
2062
|
+
const action = actionRef.current;
|
|
2063
|
+
preact.useEffect(() => {
|
|
2122
2064
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
2123
2065
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
2124
2066
|
}
|
|
@@ -2139,18 +2081,15 @@
|
|
|
2139
2081
|
|
|
2140
2082
|
|
|
2141
2083
|
function useControlledReducer$1(reducer, initialState, props) {
|
|
2142
|
-
|
|
2143
|
-
state = _useEnhancedReducer[0],
|
|
2144
|
-
dispatch = _useEnhancedReducer[1];
|
|
2145
|
-
|
|
2084
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
|
|
2146
2085
|
return [getState(state, props), dispatch];
|
|
2147
2086
|
}
|
|
2148
2087
|
|
|
2149
|
-
|
|
2150
|
-
itemToString
|
|
2151
|
-
stateReducer
|
|
2152
|
-
getA11ySelectionMessage
|
|
2153
|
-
scrollIntoView
|
|
2088
|
+
const defaultProps$3 = {
|
|
2089
|
+
itemToString,
|
|
2090
|
+
stateReducer,
|
|
2091
|
+
getA11ySelectionMessage,
|
|
2092
|
+
scrollIntoView,
|
|
2154
2093
|
circularNavigation: false,
|
|
2155
2094
|
environment:
|
|
2156
2095
|
/* istanbul ignore next (ssr) */
|
|
@@ -2162,7 +2101,7 @@
|
|
|
2162
2101
|
defaultStateValues = dropdownDefaultStateValues;
|
|
2163
2102
|
}
|
|
2164
2103
|
|
|
2165
|
-
|
|
2104
|
+
const defaultPropKey = "default" + capitalizeString(propKey);
|
|
2166
2105
|
|
|
2167
2106
|
if (defaultPropKey in props) {
|
|
2168
2107
|
return props[defaultPropKey];
|
|
@@ -2180,7 +2119,7 @@
|
|
|
2180
2119
|
return props[propKey];
|
|
2181
2120
|
}
|
|
2182
2121
|
|
|
2183
|
-
|
|
2122
|
+
const initialPropKey = "initial" + capitalizeString(propKey);
|
|
2184
2123
|
|
|
2185
2124
|
if (initialPropKey in props) {
|
|
2186
2125
|
return props[initialPropKey];
|
|
@@ -2190,24 +2129,28 @@
|
|
|
2190
2129
|
}
|
|
2191
2130
|
|
|
2192
2131
|
function getInitialState$2(props) {
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2132
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
2133
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
2134
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
2135
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
2197
2136
|
return {
|
|
2198
2137
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
2199
|
-
isOpen
|
|
2200
|
-
selectedItem
|
|
2201
|
-
inputValue
|
|
2138
|
+
isOpen,
|
|
2139
|
+
selectedItem,
|
|
2140
|
+
inputValue
|
|
2202
2141
|
};
|
|
2203
2142
|
}
|
|
2204
2143
|
|
|
2205
2144
|
function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2145
|
+
const {
|
|
2146
|
+
items,
|
|
2147
|
+
initialHighlightedIndex,
|
|
2148
|
+
defaultHighlightedIndex
|
|
2149
|
+
} = props;
|
|
2150
|
+
const {
|
|
2151
|
+
selectedItem,
|
|
2152
|
+
highlightedIndex
|
|
2153
|
+
} = state;
|
|
2211
2154
|
|
|
2212
2155
|
if (items.length === 0) {
|
|
2213
2156
|
return -1;
|
|
@@ -2248,39 +2191,35 @@
|
|
|
2248
2191
|
|
|
2249
2192
|
|
|
2250
2193
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
2251
|
-
|
|
2194
|
+
const mouseAndTouchTrackersRef = preact.useRef({
|
|
2252
2195
|
isMouseDown: false,
|
|
2253
2196
|
isTouchMove: false
|
|
2254
2197
|
});
|
|
2255
|
-
preact.useEffect(
|
|
2198
|
+
preact.useEffect(() => {
|
|
2256
2199
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
2257
2200
|
// as in downshift.js.
|
|
2258
|
-
|
|
2201
|
+
const onMouseDown = () => {
|
|
2259
2202
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
2260
2203
|
};
|
|
2261
2204
|
|
|
2262
|
-
|
|
2205
|
+
const onMouseUp = event => {
|
|
2263
2206
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
2264
2207
|
|
|
2265
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2266
|
-
return ref.current;
|
|
2267
|
-
}), environment)) {
|
|
2208
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
2268
2209
|
handleBlur();
|
|
2269
2210
|
}
|
|
2270
2211
|
};
|
|
2271
2212
|
|
|
2272
|
-
|
|
2213
|
+
const onTouchStart = () => {
|
|
2273
2214
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
2274
2215
|
};
|
|
2275
2216
|
|
|
2276
|
-
|
|
2217
|
+
const onTouchMove = () => {
|
|
2277
2218
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
2278
2219
|
};
|
|
2279
2220
|
|
|
2280
|
-
|
|
2281
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2282
|
-
return ref.current;
|
|
2283
|
-
}), environment, false)) {
|
|
2221
|
+
const onTouchEnd = event => {
|
|
2222
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
2284
2223
|
handleBlur();
|
|
2285
2224
|
}
|
|
2286
2225
|
};
|
|
@@ -2304,9 +2243,7 @@
|
|
|
2304
2243
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2305
2244
|
|
|
2306
2245
|
|
|
2307
|
-
|
|
2308
|
-
return noop;
|
|
2309
|
-
};
|
|
2246
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
2310
2247
|
/**
|
|
2311
2248
|
* Custom hook that checks if getter props are called correctly.
|
|
2312
2249
|
*
|
|
@@ -2318,20 +2255,20 @@
|
|
|
2318
2255
|
|
|
2319
2256
|
|
|
2320
2257
|
{
|
|
2321
|
-
useGetterPropsCalledChecker = function
|
|
2322
|
-
|
|
2258
|
+
useGetterPropsCalledChecker = function () {
|
|
2259
|
+
const isInitialMountRef = preact.useRef(true);
|
|
2323
2260
|
|
|
2324
2261
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2325
2262
|
propKeys[_key] = arguments[_key];
|
|
2326
2263
|
}
|
|
2327
2264
|
|
|
2328
|
-
|
|
2265
|
+
const getterPropsCalledRef = preact.useRef(propKeys.reduce((acc, propKey) => {
|
|
2329
2266
|
acc[propKey] = {};
|
|
2330
2267
|
return acc;
|
|
2331
2268
|
}, {}));
|
|
2332
|
-
preact.useEffect(
|
|
2333
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
2334
|
-
|
|
2269
|
+
preact.useEffect(() => {
|
|
2270
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
2271
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
2335
2272
|
|
|
2336
2273
|
if (isInitialMountRef.current) {
|
|
2337
2274
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -2341,9 +2278,11 @@
|
|
|
2341
2278
|
}
|
|
2342
2279
|
}
|
|
2343
2280
|
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2281
|
+
const {
|
|
2282
|
+
suppressRefError,
|
|
2283
|
+
refKey,
|
|
2284
|
+
elementRef
|
|
2285
|
+
} = propCallInfo;
|
|
2347
2286
|
|
|
2348
2287
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
2349
2288
|
// eslint-disable-next-line no-console
|
|
@@ -2352,11 +2291,11 @@
|
|
|
2352
2291
|
});
|
|
2353
2292
|
isInitialMountRef.current = false;
|
|
2354
2293
|
});
|
|
2355
|
-
|
|
2294
|
+
const setGetterPropCallInfo = preact.useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
2356
2295
|
getterPropsCalledRef.current[propKey] = {
|
|
2357
|
-
suppressRefError
|
|
2358
|
-
refKey
|
|
2359
|
-
elementRef
|
|
2296
|
+
suppressRefError,
|
|
2297
|
+
refKey,
|
|
2298
|
+
elementRef
|
|
2360
2299
|
};
|
|
2361
2300
|
}, []);
|
|
2362
2301
|
return setGetterPropCallInfo;
|
|
@@ -2364,39 +2303,41 @@
|
|
|
2364
2303
|
}
|
|
2365
2304
|
|
|
2366
2305
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2306
|
+
let {
|
|
2307
|
+
isInitialMount,
|
|
2308
|
+
highlightedIndex,
|
|
2309
|
+
items,
|
|
2310
|
+
environment,
|
|
2311
|
+
...rest
|
|
2312
|
+
} = _ref2;
|
|
2373
2313
|
// Sets a11y status message on changes in state.
|
|
2374
|
-
preact.useEffect(
|
|
2314
|
+
preact.useEffect(() => {
|
|
2375
2315
|
if (isInitialMount || false) {
|
|
2376
2316
|
return;
|
|
2377
2317
|
}
|
|
2378
2318
|
|
|
2379
|
-
updateA11yStatus(
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2319
|
+
updateA11yStatus(() => getA11yMessage({
|
|
2320
|
+
highlightedIndex,
|
|
2321
|
+
highlightedItem: items[highlightedIndex],
|
|
2322
|
+
resultCount: items.length,
|
|
2323
|
+
...rest
|
|
2324
|
+
}), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2386
2325
|
}, dependencyArray);
|
|
2387
2326
|
}
|
|
2388
2327
|
|
|
2389
2328
|
function useScrollIntoView(_ref3) {
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2329
|
+
let {
|
|
2330
|
+
highlightedIndex,
|
|
2331
|
+
isOpen,
|
|
2332
|
+
itemRefs,
|
|
2333
|
+
getItemNodeFromIndex,
|
|
2334
|
+
menuElement,
|
|
2335
|
+
scrollIntoView: scrollIntoViewProp
|
|
2336
|
+
} = _ref3;
|
|
2396
2337
|
// used not to scroll on highlight by mouse.
|
|
2397
|
-
|
|
2338
|
+
const shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
2398
2339
|
|
|
2399
|
-
useIsomorphicLayoutEffect(
|
|
2340
|
+
useIsomorphicLayoutEffect(() => {
|
|
2400
2341
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2401
2342
|
return;
|
|
2402
2343
|
}
|
|
@@ -2412,17 +2353,19 @@
|
|
|
2412
2353
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
2413
2354
|
|
|
2414
2355
|
|
|
2415
|
-
|
|
2356
|
+
let useControlPropsValidator = noop;
|
|
2416
2357
|
/* istanbul ignore next */
|
|
2417
2358
|
|
|
2418
2359
|
{
|
|
2419
|
-
useControlPropsValidator =
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2360
|
+
useControlPropsValidator = _ref4 => {
|
|
2361
|
+
let {
|
|
2362
|
+
isInitialMount,
|
|
2363
|
+
props,
|
|
2364
|
+
state
|
|
2365
|
+
} = _ref4;
|
|
2423
2366
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
2424
|
-
|
|
2425
|
-
preact.useEffect(
|
|
2367
|
+
const prevPropsRef = preact.useRef(props);
|
|
2368
|
+
preact.useEffect(() => {
|
|
2426
2369
|
if (isInitialMount) {
|
|
2427
2370
|
return;
|
|
2428
2371
|
}
|
|
@@ -2436,9 +2379,11 @@
|
|
|
2436
2379
|
/* eslint-disable complexity */
|
|
2437
2380
|
|
|
2438
2381
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2382
|
+
const {
|
|
2383
|
+
type,
|
|
2384
|
+
props
|
|
2385
|
+
} = action;
|
|
2386
|
+
let changes;
|
|
2442
2387
|
|
|
2443
2388
|
switch (type) {
|
|
2444
2389
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -2499,11 +2444,13 @@
|
|
|
2499
2444
|
throw new Error('Reducer called without proper action type.');
|
|
2500
2445
|
}
|
|
2501
2446
|
|
|
2502
|
-
return
|
|
2447
|
+
return { ...state,
|
|
2448
|
+
...changes
|
|
2449
|
+
};
|
|
2503
2450
|
}
|
|
2504
2451
|
/* eslint-enable complexity */
|
|
2505
2452
|
|
|
2506
|
-
|
|
2453
|
+
/******************************************************************************
|
|
2507
2454
|
Copyright (c) Microsoft Corporation.
|
|
2508
2455
|
|
|
2509
2456
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -2548,37 +2495,37 @@
|
|
|
2548
2495
|
return highlightedIndex;
|
|
2549
2496
|
}
|
|
2550
2497
|
var propTypes$2 = {
|
|
2551
|
-
items: PropTypes__default[
|
|
2552
|
-
itemToString: PropTypes__default[
|
|
2553
|
-
getA11yStatusMessage: PropTypes__default[
|
|
2554
|
-
getA11ySelectionMessage: PropTypes__default[
|
|
2555
|
-
circularNavigation: PropTypes__default[
|
|
2556
|
-
highlightedIndex: PropTypes__default[
|
|
2557
|
-
defaultHighlightedIndex: PropTypes__default[
|
|
2558
|
-
initialHighlightedIndex: PropTypes__default[
|
|
2559
|
-
isOpen: PropTypes__default[
|
|
2560
|
-
defaultIsOpen: PropTypes__default[
|
|
2561
|
-
initialIsOpen: PropTypes__default[
|
|
2562
|
-
selectedItem: PropTypes__default[
|
|
2563
|
-
initialSelectedItem: PropTypes__default[
|
|
2564
|
-
defaultSelectedItem: PropTypes__default[
|
|
2565
|
-
id: PropTypes__default[
|
|
2566
|
-
labelId: PropTypes__default[
|
|
2567
|
-
menuId: PropTypes__default[
|
|
2568
|
-
getItemId: PropTypes__default[
|
|
2569
|
-
toggleButtonId: PropTypes__default[
|
|
2570
|
-
stateReducer: PropTypes__default[
|
|
2571
|
-
onSelectedItemChange: PropTypes__default[
|
|
2572
|
-
onHighlightedIndexChange: PropTypes__default[
|
|
2573
|
-
onStateChange: PropTypes__default[
|
|
2574
|
-
onIsOpenChange: PropTypes__default[
|
|
2575
|
-
environment: PropTypes__default[
|
|
2576
|
-
addEventListener: PropTypes__default[
|
|
2577
|
-
removeEventListener: PropTypes__default[
|
|
2578
|
-
document: PropTypes__default[
|
|
2579
|
-
getElementById: PropTypes__default[
|
|
2580
|
-
activeElement: PropTypes__default[
|
|
2581
|
-
body: PropTypes__default[
|
|
2498
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
2499
|
+
itemToString: PropTypes__default["default"].func,
|
|
2500
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
2501
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
2502
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
2503
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
2504
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
2505
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
2506
|
+
isOpen: PropTypes__default["default"].bool,
|
|
2507
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
2508
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
2509
|
+
selectedItem: PropTypes__default["default"].any,
|
|
2510
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
2511
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
2512
|
+
id: PropTypes__default["default"].string,
|
|
2513
|
+
labelId: PropTypes__default["default"].string,
|
|
2514
|
+
menuId: PropTypes__default["default"].string,
|
|
2515
|
+
getItemId: PropTypes__default["default"].func,
|
|
2516
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
2517
|
+
stateReducer: PropTypes__default["default"].func,
|
|
2518
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
2519
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
2520
|
+
onStateChange: PropTypes__default["default"].func,
|
|
2521
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
2522
|
+
environment: PropTypes__default["default"].shape({
|
|
2523
|
+
addEventListener: PropTypes__default["default"].func,
|
|
2524
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
2525
|
+
document: PropTypes__default["default"].shape({
|
|
2526
|
+
getElementById: PropTypes__default["default"].func,
|
|
2527
|
+
activeElement: PropTypes__default["default"].any,
|
|
2528
|
+
body: PropTypes__default["default"].any
|
|
2582
2529
|
})
|
|
2583
2530
|
})
|
|
2584
2531
|
};
|
|
@@ -2599,7 +2546,7 @@
|
|
|
2599
2546
|
return 'No results are available.';
|
|
2600
2547
|
}
|
|
2601
2548
|
if (resultCount !== previousResultCount) {
|
|
2602
|
-
return resultCount
|
|
2549
|
+
return "".concat(resultCount, " result").concat(resultCount === 1 ? ' is' : 's are', " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.");
|
|
2603
2550
|
}
|
|
2604
2551
|
return '';
|
|
2605
2552
|
}
|
|
@@ -2609,33 +2556,33 @@
|
|
|
2609
2556
|
/* istanbul ignore next */
|
|
2610
2557
|
{
|
|
2611
2558
|
validatePropTypes$2 = function (options, caller) {
|
|
2612
|
-
PropTypes__default[
|
|
2559
|
+
PropTypes__default["default"].checkPropTypes(propTypes$2, options, 'prop', caller.name);
|
|
2613
2560
|
};
|
|
2614
2561
|
}
|
|
2615
2562
|
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2563
|
+
const MenuKeyDownArrowDown = '__menu_keydown_arrow_down__' ;
|
|
2564
|
+
const MenuKeyDownArrowUp = '__menu_keydown_arrow_up__' ;
|
|
2565
|
+
const MenuKeyDownEscape = '__menu_keydown_escape__' ;
|
|
2566
|
+
const MenuKeyDownHome = '__menu_keydown_home__' ;
|
|
2567
|
+
const MenuKeyDownEnd = '__menu_keydown_end__' ;
|
|
2568
|
+
const MenuKeyDownEnter = '__menu_keydown_enter__' ;
|
|
2569
|
+
const MenuKeyDownSpaceButton = '__menu_keydown_space_button__' ;
|
|
2570
|
+
const MenuKeyDownCharacter = '__menu_keydown_character__' ;
|
|
2571
|
+
const MenuBlur = '__menu_blur__' ;
|
|
2572
|
+
const MenuMouseLeave$1 = '__menu_mouse_leave__' ;
|
|
2573
|
+
const ItemMouseMove$1 = '__item_mouse_move__' ;
|
|
2574
|
+
const ItemClick$1 = '__item_click__' ;
|
|
2575
|
+
const ToggleButtonClick$1 = '__togglebutton_click__' ;
|
|
2576
|
+
const ToggleButtonKeyDownArrowDown = '__togglebutton_keydown_arrow_down__' ;
|
|
2577
|
+
const ToggleButtonKeyDownArrowUp = '__togglebutton_keydown_arrow_up__' ;
|
|
2578
|
+
const ToggleButtonKeyDownCharacter = '__togglebutton_keydown_character__' ;
|
|
2579
|
+
const FunctionToggleMenu$1 = '__function_toggle_menu__' ;
|
|
2580
|
+
const FunctionOpenMenu$1 = '__function_open_menu__' ;
|
|
2581
|
+
const FunctionCloseMenu$1 = '__function_close_menu__' ;
|
|
2582
|
+
const FunctionSetHighlightedIndex$1 = '__function_set_highlighted_index__' ;
|
|
2583
|
+
const FunctionSelectItem$1 = '__function_select_item__' ;
|
|
2584
|
+
const FunctionSetInputValue$1 = '__function_set_input_value__' ;
|
|
2585
|
+
const FunctionReset$2 = '__function_reset__' ;
|
|
2639
2586
|
|
|
2640
2587
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2641
2588
|
__proto__: null,
|
|
@@ -2667,10 +2614,12 @@
|
|
|
2667
2614
|
/* eslint-disable complexity */
|
|
2668
2615
|
|
|
2669
2616
|
function downshiftSelectReducer(state, action) {
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2617
|
+
const {
|
|
2618
|
+
type,
|
|
2619
|
+
props,
|
|
2620
|
+
shiftKey
|
|
2621
|
+
} = action;
|
|
2622
|
+
let changes;
|
|
2674
2623
|
|
|
2675
2624
|
switch (type) {
|
|
2676
2625
|
case ItemClick$1:
|
|
@@ -2683,20 +2632,21 @@
|
|
|
2683
2632
|
|
|
2684
2633
|
case ToggleButtonKeyDownCharacter:
|
|
2685
2634
|
{
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2635
|
+
const lowercasedKey = action.key;
|
|
2636
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2637
|
+
const itemIndex = getItemIndexByCharacterKey({
|
|
2689
2638
|
keysSoFar: inputValue,
|
|
2690
2639
|
highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
|
|
2691
2640
|
items: props.items,
|
|
2692
2641
|
itemToString: props.itemToString,
|
|
2693
2642
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2694
2643
|
});
|
|
2695
|
-
changes =
|
|
2696
|
-
inputValue
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2644
|
+
changes = {
|
|
2645
|
+
inputValue,
|
|
2646
|
+
...(itemIndex >= 0 && {
|
|
2647
|
+
selectedItem: props.items[itemIndex]
|
|
2648
|
+
})
|
|
2649
|
+
};
|
|
2700
2650
|
}
|
|
2701
2651
|
break;
|
|
2702
2652
|
|
|
@@ -2716,12 +2666,13 @@
|
|
|
2716
2666
|
|
|
2717
2667
|
case MenuKeyDownEnter:
|
|
2718
2668
|
case MenuKeyDownSpaceButton:
|
|
2719
|
-
changes =
|
|
2669
|
+
changes = {
|
|
2720
2670
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2721
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2671
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2672
|
+
...(state.highlightedIndex >= 0 && {
|
|
2673
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2674
|
+
})
|
|
2675
|
+
};
|
|
2725
2676
|
break;
|
|
2726
2677
|
|
|
2727
2678
|
case MenuKeyDownHome:
|
|
@@ -2752,22 +2703,21 @@
|
|
|
2752
2703
|
|
|
2753
2704
|
case MenuKeyDownCharacter:
|
|
2754
2705
|
{
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
var highlightedIndex = getItemIndexByCharacterKey({
|
|
2760
|
-
keysSoFar: _inputValue,
|
|
2706
|
+
const lowercasedKey = action.key;
|
|
2707
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2708
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
2709
|
+
keysSoFar: inputValue,
|
|
2761
2710
|
highlightedIndex: state.highlightedIndex,
|
|
2762
2711
|
items: props.items,
|
|
2763
2712
|
itemToString: props.itemToString,
|
|
2764
2713
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2765
2714
|
});
|
|
2766
|
-
changes =
|
|
2767
|
-
inputValue
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2715
|
+
changes = {
|
|
2716
|
+
inputValue,
|
|
2717
|
+
...(highlightedIndex >= 0 && {
|
|
2718
|
+
highlightedIndex
|
|
2719
|
+
})
|
|
2720
|
+
};
|
|
2771
2721
|
}
|
|
2772
2722
|
break;
|
|
2773
2723
|
|
|
@@ -2793,13 +2743,13 @@
|
|
|
2793
2743
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2794
2744
|
}
|
|
2795
2745
|
|
|
2796
|
-
return
|
|
2746
|
+
return { ...state,
|
|
2747
|
+
...changes
|
|
2748
|
+
};
|
|
2797
2749
|
}
|
|
2798
2750
|
/* eslint-enable complexity */
|
|
2799
2751
|
|
|
2800
|
-
|
|
2801
|
-
_excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
|
|
2802
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
|
|
2752
|
+
/* eslint-disable max-statements */
|
|
2803
2753
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2804
2754
|
|
|
2805
2755
|
function useSelect(userProps) {
|
|
@@ -2809,91 +2759,92 @@
|
|
|
2809
2759
|
|
|
2810
2760
|
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
2811
2761
|
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2762
|
+
const props = { ...defaultProps$2,
|
|
2763
|
+
...userProps
|
|
2764
|
+
};
|
|
2765
|
+
const {
|
|
2766
|
+
items,
|
|
2767
|
+
scrollIntoView,
|
|
2768
|
+
environment,
|
|
2769
|
+
initialIsOpen,
|
|
2770
|
+
defaultIsOpen,
|
|
2771
|
+
itemToString,
|
|
2772
|
+
getA11ySelectionMessage,
|
|
2773
|
+
getA11yStatusMessage
|
|
2774
|
+
} = props; // Initial state depending on controlled props.
|
|
2775
|
+
|
|
2776
|
+
const initialState = getInitialState$2(props);
|
|
2777
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
2778
|
+
const {
|
|
2779
|
+
isOpen,
|
|
2780
|
+
highlightedIndex,
|
|
2781
|
+
selectedItem,
|
|
2782
|
+
inputValue
|
|
2783
|
+
} = state; // Element efs.
|
|
2784
|
+
|
|
2785
|
+
const toggleButtonRef = preact.useRef(null);
|
|
2786
|
+
const menuRef = preact.useRef(null);
|
|
2787
|
+
const itemRefs = preact.useRef({}); // used not to trigger menu blur action in some scenarios.
|
|
2788
|
+
|
|
2789
|
+
const shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
2790
|
+
|
|
2791
|
+
const clearTimeoutRef = preact.useRef(null); // prevent id re-generation between renders.
|
|
2792
|
+
|
|
2793
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
2794
|
+
|
|
2795
|
+
const previousResultCountRef = preact.useRef();
|
|
2796
|
+
const isInitialMountRef = preact.useRef(true); // utility callback to get item element.
|
|
2797
|
+
|
|
2798
|
+
const latest = useLatestRef({
|
|
2799
|
+
state,
|
|
2800
|
+
props
|
|
2850
2801
|
}); // Some utils.
|
|
2851
2802
|
|
|
2852
|
-
|
|
2853
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2854
|
-
}, [elementIds]); // Effects.
|
|
2803
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
2855
2804
|
// Sets a11y status message on changes in state.
|
|
2856
2805
|
|
|
2857
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2806
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2858
2807
|
isInitialMount: isInitialMountRef.current,
|
|
2859
2808
|
previousResultCount: previousResultCountRef.current,
|
|
2860
|
-
items
|
|
2861
|
-
environment
|
|
2862
|
-
itemToString
|
|
2863
|
-
|
|
2809
|
+
items,
|
|
2810
|
+
environment,
|
|
2811
|
+
itemToString,
|
|
2812
|
+
...state
|
|
2813
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
2864
2814
|
|
|
2865
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2815
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2866
2816
|
isInitialMount: isInitialMountRef.current,
|
|
2867
2817
|
previousResultCount: previousResultCountRef.current,
|
|
2868
|
-
items
|
|
2869
|
-
environment
|
|
2870
|
-
itemToString
|
|
2871
|
-
|
|
2818
|
+
items,
|
|
2819
|
+
environment,
|
|
2820
|
+
itemToString,
|
|
2821
|
+
...state
|
|
2822
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
2872
2823
|
|
|
2873
|
-
|
|
2824
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2874
2825
|
menuElement: menuRef.current,
|
|
2875
|
-
highlightedIndex
|
|
2876
|
-
isOpen
|
|
2877
|
-
itemRefs
|
|
2878
|
-
scrollIntoView
|
|
2879
|
-
getItemNodeFromIndex
|
|
2826
|
+
highlightedIndex,
|
|
2827
|
+
isOpen,
|
|
2828
|
+
itemRefs,
|
|
2829
|
+
scrollIntoView,
|
|
2830
|
+
getItemNodeFromIndex
|
|
2880
2831
|
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2881
2832
|
|
|
2882
|
-
preact.useEffect(
|
|
2833
|
+
preact.useEffect(() => {
|
|
2883
2834
|
// init the clean function here as we need access to dispatch.
|
|
2884
|
-
clearTimeoutRef.current = debounce(
|
|
2835
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
2885
2836
|
outerDispatch({
|
|
2886
2837
|
type: FunctionSetInputValue$1,
|
|
2887
2838
|
inputValue: ''
|
|
2888
2839
|
});
|
|
2889
2840
|
}, 500); // Cancel any pending debounced calls on mount
|
|
2890
2841
|
|
|
2891
|
-
return
|
|
2842
|
+
return () => {
|
|
2892
2843
|
clearTimeoutRef.current.cancel();
|
|
2893
2844
|
};
|
|
2894
2845
|
}, []); // Invokes the keysSoFar callback set up above.
|
|
2895
2846
|
|
|
2896
|
-
preact.useEffect(
|
|
2847
|
+
preact.useEffect(() => {
|
|
2897
2848
|
if (!inputValue) {
|
|
2898
2849
|
return;
|
|
2899
2850
|
}
|
|
@@ -2902,12 +2853,12 @@
|
|
|
2902
2853
|
}, [dispatch, inputValue]);
|
|
2903
2854
|
useControlPropsValidator({
|
|
2904
2855
|
isInitialMount: isInitialMountRef.current,
|
|
2905
|
-
props
|
|
2906
|
-
state
|
|
2856
|
+
props,
|
|
2857
|
+
state
|
|
2907
2858
|
});
|
|
2908
2859
|
/* Controls the focus on the menu or the toggle button. */
|
|
2909
2860
|
|
|
2910
|
-
preact.useEffect(
|
|
2861
|
+
preact.useEffect(() => {
|
|
2911
2862
|
// Don't focus menu on first render.
|
|
2912
2863
|
if (isInitialMountRef.current) {
|
|
2913
2864
|
// Unless it was initialised as open.
|
|
@@ -2938,7 +2889,7 @@
|
|
|
2938
2889
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2939
2890
|
|
|
2940
2891
|
}, [isOpen]);
|
|
2941
|
-
preact.useEffect(
|
|
2892
|
+
preact.useEffect(() => {
|
|
2942
2893
|
if (isInitialMountRef.current) {
|
|
2943
2894
|
return;
|
|
2944
2895
|
}
|
|
@@ -2946,180 +2897,180 @@
|
|
|
2946
2897
|
previousResultCountRef.current = items.length;
|
|
2947
2898
|
}); // Add mouse/touch events to document.
|
|
2948
2899
|
|
|
2949
|
-
|
|
2900
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
2950
2901
|
dispatch({
|
|
2951
2902
|
type: MenuBlur
|
|
2952
2903
|
});
|
|
2953
2904
|
});
|
|
2954
|
-
|
|
2905
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
2955
2906
|
|
|
2956
|
-
preact.useEffect(
|
|
2907
|
+
preact.useEffect(() => {
|
|
2957
2908
|
isInitialMountRef.current = false;
|
|
2958
2909
|
}, []); // Reset itemRefs on close.
|
|
2959
2910
|
|
|
2960
|
-
preact.useEffect(
|
|
2911
|
+
preact.useEffect(() => {
|
|
2961
2912
|
if (!isOpen) {
|
|
2962
2913
|
itemRefs.current = {};
|
|
2963
2914
|
}
|
|
2964
2915
|
}, [isOpen]); // Event handler functions.
|
|
2965
2916
|
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
}, [dispatch, getItemNodeFromIndex]);
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
}
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
});
|
|
3034
|
-
}
|
|
3035
|
-
};
|
|
3036
|
-
}, [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
2917
|
+
const toggleButtonKeyDownHandlers = preact.useMemo(() => ({
|
|
2918
|
+
ArrowDown(event) {
|
|
2919
|
+
event.preventDefault();
|
|
2920
|
+
dispatch({
|
|
2921
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
2922
|
+
getItemNodeFromIndex,
|
|
2923
|
+
shiftKey: event.shiftKey
|
|
2924
|
+
});
|
|
2925
|
+
},
|
|
2926
|
+
|
|
2927
|
+
ArrowUp(event) {
|
|
2928
|
+
event.preventDefault();
|
|
2929
|
+
dispatch({
|
|
2930
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
2931
|
+
getItemNodeFromIndex,
|
|
2932
|
+
shiftKey: event.shiftKey
|
|
2933
|
+
});
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
}), [dispatch, getItemNodeFromIndex]);
|
|
2937
|
+
const menuKeyDownHandlers = preact.useMemo(() => ({
|
|
2938
|
+
ArrowDown(event) {
|
|
2939
|
+
event.preventDefault();
|
|
2940
|
+
dispatch({
|
|
2941
|
+
type: MenuKeyDownArrowDown,
|
|
2942
|
+
getItemNodeFromIndex,
|
|
2943
|
+
shiftKey: event.shiftKey
|
|
2944
|
+
});
|
|
2945
|
+
},
|
|
2946
|
+
|
|
2947
|
+
ArrowUp(event) {
|
|
2948
|
+
event.preventDefault();
|
|
2949
|
+
dispatch({
|
|
2950
|
+
type: MenuKeyDownArrowUp,
|
|
2951
|
+
getItemNodeFromIndex,
|
|
2952
|
+
shiftKey: event.shiftKey
|
|
2953
|
+
});
|
|
2954
|
+
},
|
|
2955
|
+
|
|
2956
|
+
Home(event) {
|
|
2957
|
+
event.preventDefault();
|
|
2958
|
+
dispatch({
|
|
2959
|
+
type: MenuKeyDownHome,
|
|
2960
|
+
getItemNodeFromIndex
|
|
2961
|
+
});
|
|
2962
|
+
},
|
|
2963
|
+
|
|
2964
|
+
End(event) {
|
|
2965
|
+
event.preventDefault();
|
|
2966
|
+
dispatch({
|
|
2967
|
+
type: MenuKeyDownEnd,
|
|
2968
|
+
getItemNodeFromIndex
|
|
2969
|
+
});
|
|
2970
|
+
},
|
|
2971
|
+
|
|
2972
|
+
Escape() {
|
|
2973
|
+
dispatch({
|
|
2974
|
+
type: MenuKeyDownEscape
|
|
2975
|
+
});
|
|
2976
|
+
},
|
|
2977
|
+
|
|
2978
|
+
Enter(event) {
|
|
2979
|
+
event.preventDefault();
|
|
2980
|
+
dispatch({
|
|
2981
|
+
type: MenuKeyDownEnter
|
|
2982
|
+
});
|
|
2983
|
+
},
|
|
3037
2984
|
|
|
3038
|
-
|
|
2985
|
+
' '(event) {
|
|
2986
|
+
event.preventDefault();
|
|
2987
|
+
dispatch({
|
|
2988
|
+
type: MenuKeyDownSpaceButton
|
|
2989
|
+
});
|
|
2990
|
+
}
|
|
2991
|
+
|
|
2992
|
+
}), [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
2993
|
+
|
|
2994
|
+
const toggleMenu = preact.useCallback(() => {
|
|
3039
2995
|
dispatch({
|
|
3040
2996
|
type: FunctionToggleMenu$1
|
|
3041
2997
|
});
|
|
3042
2998
|
}, [dispatch]);
|
|
3043
|
-
|
|
2999
|
+
const closeMenu = preact.useCallback(() => {
|
|
3044
3000
|
dispatch({
|
|
3045
3001
|
type: FunctionCloseMenu$1
|
|
3046
3002
|
});
|
|
3047
3003
|
}, [dispatch]);
|
|
3048
|
-
|
|
3004
|
+
const openMenu = preact.useCallback(() => {
|
|
3049
3005
|
dispatch({
|
|
3050
3006
|
type: FunctionOpenMenu$1
|
|
3051
3007
|
});
|
|
3052
3008
|
}, [dispatch]);
|
|
3053
|
-
|
|
3009
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
3054
3010
|
dispatch({
|
|
3055
3011
|
type: FunctionSetHighlightedIndex$1,
|
|
3056
3012
|
highlightedIndex: newHighlightedIndex
|
|
3057
3013
|
});
|
|
3058
3014
|
}, [dispatch]);
|
|
3059
|
-
|
|
3015
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
3060
3016
|
dispatch({
|
|
3061
3017
|
type: FunctionSelectItem$1,
|
|
3062
3018
|
selectedItem: newSelectedItem
|
|
3063
3019
|
});
|
|
3064
3020
|
}, [dispatch]);
|
|
3065
|
-
|
|
3021
|
+
const reset = preact.useCallback(() => {
|
|
3066
3022
|
dispatch({
|
|
3067
3023
|
type: FunctionReset$2
|
|
3068
3024
|
});
|
|
3069
3025
|
}, [dispatch]);
|
|
3070
|
-
|
|
3026
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
3071
3027
|
dispatch({
|
|
3072
3028
|
type: FunctionSetInputValue$1,
|
|
3073
3029
|
inputValue: newInputValue
|
|
3074
3030
|
});
|
|
3075
3031
|
}, [dispatch]); // Getter functions.
|
|
3076
3032
|
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
var latestState = latest.current.state;
|
|
3100
|
-
|
|
3101
|
-
var menuHandleKeyDown = function menuHandleKeyDown(event) {
|
|
3102
|
-
var key = normalizeArrowKey(event);
|
|
3033
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
3034
|
+
id: elementIds.labelId,
|
|
3035
|
+
htmlFor: elementIds.toggleButtonId,
|
|
3036
|
+
...labelProps
|
|
3037
|
+
}), [elementIds]);
|
|
3038
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3039
|
+
let {
|
|
3040
|
+
onMouseLeave,
|
|
3041
|
+
refKey = 'ref',
|
|
3042
|
+
onKeyDown,
|
|
3043
|
+
onBlur,
|
|
3044
|
+
ref,
|
|
3045
|
+
...rest
|
|
3046
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3047
|
+
let {
|
|
3048
|
+
suppressRefError = false
|
|
3049
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3050
|
+
const latestState = latest.current.state;
|
|
3051
|
+
|
|
3052
|
+
const menuHandleKeyDown = event => {
|
|
3053
|
+
const key = normalizeArrowKey(event);
|
|
3103
3054
|
|
|
3104
3055
|
if (key && menuKeyDownHandlers[key]) {
|
|
3105
3056
|
menuKeyDownHandlers[key](event);
|
|
3106
3057
|
} else if (isAcceptedCharacterKey(key)) {
|
|
3107
3058
|
dispatch({
|
|
3108
3059
|
type: MenuKeyDownCharacter,
|
|
3109
|
-
key
|
|
3110
|
-
getItemNodeFromIndex
|
|
3060
|
+
key,
|
|
3061
|
+
getItemNodeFromIndex
|
|
3111
3062
|
});
|
|
3112
3063
|
}
|
|
3113
3064
|
};
|
|
3114
3065
|
|
|
3115
|
-
|
|
3066
|
+
const menuHandleBlur = () => {
|
|
3116
3067
|
// if the blur was a result of selection, we don't trigger this action.
|
|
3117
3068
|
if (shouldBlurRef.current === false) {
|
|
3118
3069
|
shouldBlurRef.current = true;
|
|
3119
3070
|
return;
|
|
3120
3071
|
}
|
|
3121
3072
|
|
|
3122
|
-
|
|
3073
|
+
const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
3123
3074
|
/* istanbul ignore else */
|
|
3124
3075
|
|
|
3125
3076
|
if (shouldBlur) {
|
|
@@ -3129,61 +3080,72 @@
|
|
|
3129
3080
|
}
|
|
3130
3081
|
};
|
|
3131
3082
|
|
|
3132
|
-
|
|
3083
|
+
const menuHandleMouseLeave = () => {
|
|
3133
3084
|
dispatch({
|
|
3134
3085
|
type: MenuMouseLeave$1
|
|
3135
3086
|
});
|
|
3136
3087
|
};
|
|
3137
3088
|
|
|
3138
3089
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3139
|
-
return
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3090
|
+
return {
|
|
3091
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3092
|
+
menuRef.current = menuNode;
|
|
3093
|
+
}),
|
|
3094
|
+
id: elementIds.menuId,
|
|
3095
|
+
role: 'listbox',
|
|
3096
|
+
'aria-labelledby': elementIds.labelId,
|
|
3097
|
+
tabIndex: -1,
|
|
3098
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3099
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
3100
|
+
}),
|
|
3144
3101
|
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
3145
3102
|
onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
|
3146
|
-
onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
|
3147
|
-
|
|
3103
|
+
onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
|
|
3104
|
+
...rest
|
|
3105
|
+
};
|
|
3148
3106
|
}, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
|
|
3163
|
-
|
|
3164
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3107
|
+
const getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
|
|
3108
|
+
let {
|
|
3109
|
+
onClick,
|
|
3110
|
+
onKeyDown,
|
|
3111
|
+
refKey = 'ref',
|
|
3112
|
+
ref,
|
|
3113
|
+
...rest
|
|
3114
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3115
|
+
let {
|
|
3116
|
+
suppressRefError = false
|
|
3117
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3118
|
+
|
|
3119
|
+
const toggleButtonHandleClick = () => {
|
|
3165
3120
|
dispatch({
|
|
3166
3121
|
type: ToggleButtonClick$1
|
|
3167
3122
|
});
|
|
3168
3123
|
};
|
|
3169
3124
|
|
|
3170
|
-
|
|
3171
|
-
|
|
3125
|
+
const toggleButtonHandleKeyDown = event => {
|
|
3126
|
+
const key = normalizeArrowKey(event);
|
|
3172
3127
|
|
|
3173
3128
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
3174
3129
|
toggleButtonKeyDownHandlers[key](event);
|
|
3175
3130
|
} else if (isAcceptedCharacterKey(key)) {
|
|
3176
3131
|
dispatch({
|
|
3177
3132
|
type: ToggleButtonKeyDownCharacter,
|
|
3178
|
-
key
|
|
3179
|
-
getItemNodeFromIndex
|
|
3133
|
+
key,
|
|
3134
|
+
getItemNodeFromIndex
|
|
3180
3135
|
});
|
|
3181
3136
|
}
|
|
3182
3137
|
};
|
|
3183
3138
|
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3139
|
+
const toggleProps = {
|
|
3140
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3141
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3142
|
+
}),
|
|
3143
|
+
id: elementIds.toggleButtonId,
|
|
3144
|
+
'aria-haspopup': 'listbox',
|
|
3145
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
3146
|
+
'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
|
|
3147
|
+
...rest
|
|
3148
|
+
};
|
|
3187
3149
|
|
|
3188
3150
|
if (!rest.disabled) {
|
|
3189
3151
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
@@ -3193,24 +3155,22 @@
|
|
|
3193
3155
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
3194
3156
|
return toggleProps;
|
|
3195
3157
|
}, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
3158
|
+
const getItemProps = preact.useCallback(function (_temp5) {
|
|
3159
|
+
let {
|
|
3160
|
+
item,
|
|
3161
|
+
index,
|
|
3162
|
+
onMouseMove,
|
|
3163
|
+
onClick,
|
|
3164
|
+
refKey = 'ref',
|
|
3165
|
+
ref,
|
|
3166
|
+
...rest
|
|
3167
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3168
|
+
const {
|
|
3169
|
+
state: latestState,
|
|
3170
|
+
props: latestProps
|
|
3171
|
+
} = latest.current;
|
|
3172
|
+
|
|
3173
|
+
const itemHandleMouseMove = () => {
|
|
3214
3174
|
if (index === latestState.highlightedIndex) {
|
|
3215
3175
|
return;
|
|
3216
3176
|
}
|
|
@@ -3218,32 +3178,34 @@
|
|
|
3218
3178
|
shouldScrollRef.current = false;
|
|
3219
3179
|
dispatch({
|
|
3220
3180
|
type: ItemMouseMove$1,
|
|
3221
|
-
index
|
|
3181
|
+
index
|
|
3222
3182
|
});
|
|
3223
3183
|
};
|
|
3224
3184
|
|
|
3225
|
-
|
|
3185
|
+
const itemHandleClick = () => {
|
|
3226
3186
|
dispatch({
|
|
3227
3187
|
type: ItemClick$1,
|
|
3228
|
-
index
|
|
3188
|
+
index
|
|
3229
3189
|
});
|
|
3230
3190
|
};
|
|
3231
3191
|
|
|
3232
|
-
|
|
3192
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3233
3193
|
|
|
3234
3194
|
if (itemIndex < 0) {
|
|
3235
3195
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3236
3196
|
}
|
|
3237
3197
|
|
|
3238
|
-
|
|
3198
|
+
const itemProps = {
|
|
3239
3199
|
role: 'option',
|
|
3240
3200
|
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
3241
|
-
id: elementIds.getItemId(itemIndex)
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3201
|
+
id: elementIds.getItemId(itemIndex),
|
|
3202
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3203
|
+
if (itemNode) {
|
|
3204
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3205
|
+
}
|
|
3206
|
+
}),
|
|
3207
|
+
...rest
|
|
3208
|
+
};
|
|
3247
3209
|
|
|
3248
3210
|
if (!rest.disabled) {
|
|
3249
3211
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
@@ -3254,46 +3216,46 @@
|
|
|
3254
3216
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3255
3217
|
return {
|
|
3256
3218
|
// prop getters.
|
|
3257
|
-
getToggleButtonProps
|
|
3258
|
-
getLabelProps
|
|
3259
|
-
getMenuProps
|
|
3260
|
-
getItemProps
|
|
3219
|
+
getToggleButtonProps,
|
|
3220
|
+
getLabelProps,
|
|
3221
|
+
getMenuProps,
|
|
3222
|
+
getItemProps,
|
|
3261
3223
|
// actions.
|
|
3262
|
-
toggleMenu
|
|
3263
|
-
openMenu
|
|
3264
|
-
closeMenu
|
|
3265
|
-
setHighlightedIndex
|
|
3266
|
-
selectItem
|
|
3267
|
-
reset
|
|
3268
|
-
setInputValue
|
|
3224
|
+
toggleMenu,
|
|
3225
|
+
openMenu,
|
|
3226
|
+
closeMenu,
|
|
3227
|
+
setHighlightedIndex,
|
|
3228
|
+
selectItem,
|
|
3229
|
+
reset,
|
|
3230
|
+
setInputValue,
|
|
3269
3231
|
// state.
|
|
3270
|
-
highlightedIndex
|
|
3271
|
-
isOpen
|
|
3272
|
-
selectedItem
|
|
3273
|
-
inputValue
|
|
3232
|
+
highlightedIndex,
|
|
3233
|
+
isOpen,
|
|
3234
|
+
selectedItem,
|
|
3235
|
+
inputValue
|
|
3274
3236
|
};
|
|
3275
3237
|
}
|
|
3276
3238
|
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3239
|
+
const InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
|
|
3240
|
+
const InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
|
|
3241
|
+
const InputKeyDownEscape = '__input_keydown_escape__' ;
|
|
3242
|
+
const InputKeyDownHome = '__input_keydown_home__' ;
|
|
3243
|
+
const InputKeyDownEnd = '__input_keydown_end__' ;
|
|
3244
|
+
const InputKeyDownEnter = '__input_keydown_enter__' ;
|
|
3245
|
+
const InputChange = '__input_change__' ;
|
|
3246
|
+
const InputBlur = '__input_blur__' ;
|
|
3247
|
+
const MenuMouseLeave = '__menu_mouse_leave__' ;
|
|
3248
|
+
const ItemMouseMove = '__item_mouse_move__' ;
|
|
3249
|
+
const ItemClick = '__item_click__' ;
|
|
3250
|
+
const ToggleButtonClick = '__togglebutton_click__' ;
|
|
3251
|
+
const FunctionToggleMenu = '__function_toggle_menu__' ;
|
|
3252
|
+
const FunctionOpenMenu = '__function_open_menu__' ;
|
|
3253
|
+
const FunctionCloseMenu = '__function_close_menu__' ;
|
|
3254
|
+
const FunctionSetHighlightedIndex = '__function_set_highlighted_index__' ;
|
|
3255
|
+
const FunctionSelectItem = '__function_select_item__' ;
|
|
3256
|
+
const FunctionSetInputValue = '__function_set_input_value__' ;
|
|
3257
|
+
const FunctionReset$1 = '__function_reset__' ;
|
|
3258
|
+
const ControlledPropUpdatedSelectedItem = '__controlled_prop_updated_selected_item__' ;
|
|
3297
3259
|
|
|
3298
3260
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
3299
3261
|
__proto__: null,
|
|
@@ -3320,56 +3282,60 @@
|
|
|
3320
3282
|
});
|
|
3321
3283
|
|
|
3322
3284
|
function getInitialState$1(props) {
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3285
|
+
const initialState = getInitialState$2(props);
|
|
3286
|
+
const {
|
|
3287
|
+
selectedItem
|
|
3288
|
+
} = initialState;
|
|
3289
|
+
let {
|
|
3290
|
+
inputValue
|
|
3291
|
+
} = initialState;
|
|
3326
3292
|
|
|
3327
3293
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3328
3294
|
inputValue = props.itemToString(selectedItem);
|
|
3329
3295
|
}
|
|
3330
3296
|
|
|
3331
|
-
return
|
|
3332
|
-
inputValue
|
|
3333
|
-
}
|
|
3297
|
+
return { ...initialState,
|
|
3298
|
+
inputValue
|
|
3299
|
+
};
|
|
3334
3300
|
}
|
|
3335
3301
|
|
|
3336
|
-
|
|
3337
|
-
items: PropTypes__default[
|
|
3338
|
-
itemToString: PropTypes__default[
|
|
3339
|
-
getA11yStatusMessage: PropTypes__default[
|
|
3340
|
-
getA11ySelectionMessage: PropTypes__default[
|
|
3341
|
-
circularNavigation: PropTypes__default[
|
|
3342
|
-
highlightedIndex: PropTypes__default[
|
|
3343
|
-
defaultHighlightedIndex: PropTypes__default[
|
|
3344
|
-
initialHighlightedIndex: PropTypes__default[
|
|
3345
|
-
isOpen: PropTypes__default[
|
|
3346
|
-
defaultIsOpen: PropTypes__default[
|
|
3347
|
-
initialIsOpen: PropTypes__default[
|
|
3348
|
-
selectedItem: PropTypes__default[
|
|
3349
|
-
initialSelectedItem: PropTypes__default[
|
|
3350
|
-
defaultSelectedItem: PropTypes__default[
|
|
3351
|
-
inputValue: PropTypes__default[
|
|
3352
|
-
defaultInputValue: PropTypes__default[
|
|
3353
|
-
initialInputValue: PropTypes__default[
|
|
3354
|
-
id: PropTypes__default[
|
|
3355
|
-
labelId: PropTypes__default[
|
|
3356
|
-
menuId: PropTypes__default[
|
|
3357
|
-
getItemId: PropTypes__default[
|
|
3358
|
-
inputId: PropTypes__default[
|
|
3359
|
-
toggleButtonId: PropTypes__default[
|
|
3360
|
-
stateReducer: PropTypes__default[
|
|
3361
|
-
onSelectedItemChange: PropTypes__default[
|
|
3362
|
-
onHighlightedIndexChange: PropTypes__default[
|
|
3363
|
-
onStateChange: PropTypes__default[
|
|
3364
|
-
onIsOpenChange: PropTypes__default[
|
|
3365
|
-
onInputValueChange: PropTypes__default[
|
|
3366
|
-
environment: PropTypes__default[
|
|
3367
|
-
addEventListener: PropTypes__default[
|
|
3368
|
-
removeEventListener: PropTypes__default[
|
|
3369
|
-
document: PropTypes__default[
|
|
3370
|
-
getElementById: PropTypes__default[
|
|
3371
|
-
activeElement: PropTypes__default[
|
|
3372
|
-
body: PropTypes__default[
|
|
3302
|
+
const propTypes$1 = {
|
|
3303
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
3304
|
+
itemToString: PropTypes__default["default"].func,
|
|
3305
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
3306
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
3307
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
3308
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
3309
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
3310
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
3311
|
+
isOpen: PropTypes__default["default"].bool,
|
|
3312
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
3313
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
3314
|
+
selectedItem: PropTypes__default["default"].any,
|
|
3315
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
3316
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
3317
|
+
inputValue: PropTypes__default["default"].string,
|
|
3318
|
+
defaultInputValue: PropTypes__default["default"].string,
|
|
3319
|
+
initialInputValue: PropTypes__default["default"].string,
|
|
3320
|
+
id: PropTypes__default["default"].string,
|
|
3321
|
+
labelId: PropTypes__default["default"].string,
|
|
3322
|
+
menuId: PropTypes__default["default"].string,
|
|
3323
|
+
getItemId: PropTypes__default["default"].func,
|
|
3324
|
+
inputId: PropTypes__default["default"].string,
|
|
3325
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
3326
|
+
stateReducer: PropTypes__default["default"].func,
|
|
3327
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
3328
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
3329
|
+
onStateChange: PropTypes__default["default"].func,
|
|
3330
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
3331
|
+
onInputValueChange: PropTypes__default["default"].func,
|
|
3332
|
+
environment: PropTypes__default["default"].shape({
|
|
3333
|
+
addEventListener: PropTypes__default["default"].func,
|
|
3334
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
3335
|
+
document: PropTypes__default["default"].shape({
|
|
3336
|
+
getElementById: PropTypes__default["default"].func,
|
|
3337
|
+
activeElement: PropTypes__default["default"].any,
|
|
3338
|
+
body: PropTypes__default["default"].any
|
|
3373
3339
|
})
|
|
3374
3340
|
})
|
|
3375
3341
|
};
|
|
@@ -3387,14 +3353,10 @@
|
|
|
3387
3353
|
*/
|
|
3388
3354
|
|
|
3389
3355
|
function useControlledReducer(reducer, initialState, props) {
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
3393
|
-
state = _useEnhancedReducer[0],
|
|
3394
|
-
dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3395
|
-
|
|
3356
|
+
const previousSelectedItemRef = preact.useRef();
|
|
3357
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3396
3358
|
|
|
3397
|
-
preact.useEffect(
|
|
3359
|
+
preact.useEffect(() => {
|
|
3398
3360
|
if (isControlledProp(props, 'selectedItem')) {
|
|
3399
3361
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
3400
3362
|
dispatch({
|
|
@@ -3410,27 +3372,29 @@
|
|
|
3410
3372
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
3411
3373
|
|
|
3412
3374
|
|
|
3413
|
-
|
|
3375
|
+
let validatePropTypes$1 = noop;
|
|
3414
3376
|
/* istanbul ignore next */
|
|
3415
3377
|
|
|
3416
3378
|
{
|
|
3417
|
-
validatePropTypes$1 =
|
|
3418
|
-
PropTypes__default[
|
|
3379
|
+
validatePropTypes$1 = (options, caller) => {
|
|
3380
|
+
PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
3419
3381
|
};
|
|
3420
3382
|
}
|
|
3421
3383
|
|
|
3422
|
-
|
|
3384
|
+
const defaultProps$1 = { ...defaultProps$3,
|
|
3423
3385
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
3424
3386
|
circularNavigation: true
|
|
3425
|
-
}
|
|
3387
|
+
};
|
|
3426
3388
|
|
|
3427
3389
|
/* eslint-disable complexity */
|
|
3428
3390
|
|
|
3429
3391
|
function downshiftUseComboboxReducer(state, action) {
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3392
|
+
const {
|
|
3393
|
+
type,
|
|
3394
|
+
props,
|
|
3395
|
+
shiftKey
|
|
3396
|
+
} = action;
|
|
3397
|
+
let changes;
|
|
3434
3398
|
|
|
3435
3399
|
switch (type) {
|
|
3436
3400
|
case ItemClick:
|
|
@@ -3471,22 +3435,24 @@
|
|
|
3471
3435
|
break;
|
|
3472
3436
|
|
|
3473
3437
|
case InputKeyDownEnter:
|
|
3474
|
-
changes =
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3438
|
+
changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
|
|
3439
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3440
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3441
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3442
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3443
|
+
})
|
|
3444
|
+
};
|
|
3480
3445
|
break;
|
|
3481
3446
|
|
|
3482
3447
|
case InputKeyDownEscape:
|
|
3483
|
-
changes =
|
|
3448
|
+
changes = {
|
|
3484
3449
|
isOpen: false,
|
|
3485
|
-
highlightedIndex: -1
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3450
|
+
highlightedIndex: -1,
|
|
3451
|
+
...(!state.isOpen && {
|
|
3452
|
+
selectedItem: null,
|
|
3453
|
+
inputValue: ''
|
|
3454
|
+
})
|
|
3455
|
+
};
|
|
3490
3456
|
break;
|
|
3491
3457
|
|
|
3492
3458
|
case InputKeyDownHome:
|
|
@@ -3502,13 +3468,14 @@
|
|
|
3502
3468
|
break;
|
|
3503
3469
|
|
|
3504
3470
|
case InputBlur:
|
|
3505
|
-
changes =
|
|
3471
|
+
changes = {
|
|
3506
3472
|
isOpen: false,
|
|
3507
|
-
highlightedIndex: -1
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3473
|
+
highlightedIndex: -1,
|
|
3474
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
3475
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3476
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3477
|
+
})
|
|
3478
|
+
};
|
|
3512
3479
|
break;
|
|
3513
3480
|
|
|
3514
3481
|
case InputChange:
|
|
@@ -3536,15 +3503,13 @@
|
|
|
3536
3503
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
3537
3504
|
}
|
|
3538
3505
|
|
|
3539
|
-
return
|
|
3506
|
+
return { ...state,
|
|
3507
|
+
...changes
|
|
3508
|
+
};
|
|
3540
3509
|
}
|
|
3541
3510
|
/* eslint-enable complexity */
|
|
3542
3511
|
|
|
3543
|
-
|
|
3544
|
-
_excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"],
|
|
3545
|
-
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
3546
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"],
|
|
3547
|
-
_excluded5 = ["refKey", "ref"];
|
|
3512
|
+
/* eslint-disable max-statements */
|
|
3548
3513
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
3549
3514
|
|
|
3550
3515
|
function useCombobox(userProps) {
|
|
@@ -3554,87 +3519,88 @@
|
|
|
3554
3519
|
|
|
3555
3520
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
3556
3521
|
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3522
|
+
const props = { ...defaultProps$1,
|
|
3523
|
+
...userProps
|
|
3524
|
+
};
|
|
3525
|
+
const {
|
|
3526
|
+
initialIsOpen,
|
|
3527
|
+
defaultIsOpen,
|
|
3528
|
+
items,
|
|
3529
|
+
scrollIntoView,
|
|
3530
|
+
environment,
|
|
3531
|
+
getA11yStatusMessage,
|
|
3532
|
+
getA11ySelectionMessage,
|
|
3533
|
+
itemToString
|
|
3534
|
+
} = props; // Initial state depending on controlled props.
|
|
3535
|
+
|
|
3536
|
+
const initialState = getInitialState$1(props);
|
|
3537
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
3538
|
+
const {
|
|
3539
|
+
isOpen,
|
|
3540
|
+
highlightedIndex,
|
|
3541
|
+
selectedItem,
|
|
3542
|
+
inputValue
|
|
3543
|
+
} = state; // Element refs.
|
|
3544
|
+
|
|
3545
|
+
const menuRef = preact.useRef(null);
|
|
3546
|
+
const itemRefs = preact.useRef({});
|
|
3547
|
+
const inputRef = preact.useRef(null);
|
|
3548
|
+
const toggleButtonRef = preact.useRef(null);
|
|
3549
|
+
const comboboxRef = preact.useRef(null);
|
|
3550
|
+
const isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
|
|
3551
|
+
|
|
3552
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
3553
|
+
|
|
3554
|
+
const previousResultCountRef = preact.useRef(); // utility callback to get item element.
|
|
3555
|
+
|
|
3556
|
+
const latest = useLatestRef({
|
|
3557
|
+
state,
|
|
3558
|
+
props
|
|
3593
3559
|
});
|
|
3594
|
-
|
|
3595
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3596
|
-
}, [elementIds]); // Effects.
|
|
3560
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
3597
3561
|
// Sets a11y status message on changes in state.
|
|
3598
3562
|
|
|
3599
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
3563
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3600
3564
|
isInitialMount: isInitialMountRef.current,
|
|
3601
3565
|
previousResultCount: previousResultCountRef.current,
|
|
3602
|
-
items
|
|
3603
|
-
environment
|
|
3604
|
-
itemToString
|
|
3605
|
-
|
|
3566
|
+
items,
|
|
3567
|
+
environment,
|
|
3568
|
+
itemToString,
|
|
3569
|
+
...state
|
|
3570
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
3606
3571
|
|
|
3607
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
3572
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3608
3573
|
isInitialMount: isInitialMountRef.current,
|
|
3609
3574
|
previousResultCount: previousResultCountRef.current,
|
|
3610
|
-
items
|
|
3611
|
-
environment
|
|
3612
|
-
itemToString
|
|
3613
|
-
|
|
3575
|
+
items,
|
|
3576
|
+
environment,
|
|
3577
|
+
itemToString,
|
|
3578
|
+
...state
|
|
3579
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
3614
3580
|
|
|
3615
|
-
|
|
3581
|
+
const shouldScrollRef = useScrollIntoView({
|
|
3616
3582
|
menuElement: menuRef.current,
|
|
3617
|
-
highlightedIndex
|
|
3618
|
-
isOpen
|
|
3619
|
-
itemRefs
|
|
3620
|
-
scrollIntoView
|
|
3621
|
-
getItemNodeFromIndex
|
|
3583
|
+
highlightedIndex,
|
|
3584
|
+
isOpen,
|
|
3585
|
+
itemRefs,
|
|
3586
|
+
scrollIntoView,
|
|
3587
|
+
getItemNodeFromIndex
|
|
3622
3588
|
});
|
|
3623
3589
|
useControlPropsValidator({
|
|
3624
3590
|
isInitialMount: isInitialMountRef.current,
|
|
3625
|
-
props
|
|
3626
|
-
state
|
|
3591
|
+
props,
|
|
3592
|
+
state
|
|
3627
3593
|
}); // Focus the input on first render if required.
|
|
3628
3594
|
|
|
3629
|
-
preact.useEffect(
|
|
3630
|
-
|
|
3595
|
+
preact.useEffect(() => {
|
|
3596
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
3631
3597
|
|
|
3632
3598
|
if (focusOnOpen && inputRef.current) {
|
|
3633
3599
|
inputRef.current.focus();
|
|
3634
3600
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3635
3601
|
|
|
3636
3602
|
}, []);
|
|
3637
|
-
preact.useEffect(
|
|
3603
|
+
preact.useEffect(() => {
|
|
3638
3604
|
if (isInitialMountRef.current) {
|
|
3639
3605
|
return;
|
|
3640
3606
|
}
|
|
@@ -3642,147 +3608,151 @@
|
|
|
3642
3608
|
previousResultCountRef.current = items.length;
|
|
3643
3609
|
}); // Add mouse/touch events to document.
|
|
3644
3610
|
|
|
3645
|
-
|
|
3611
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
|
|
3646
3612
|
dispatch({
|
|
3647
3613
|
type: InputBlur,
|
|
3648
3614
|
selectItem: false
|
|
3649
3615
|
});
|
|
3650
3616
|
});
|
|
3651
|
-
|
|
3617
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
3652
3618
|
|
|
3653
|
-
preact.useEffect(
|
|
3619
|
+
preact.useEffect(() => {
|
|
3654
3620
|
isInitialMountRef.current = false;
|
|
3655
3621
|
}, []); // Reset itemRefs on close.
|
|
3656
3622
|
|
|
3657
|
-
preact.useEffect(
|
|
3623
|
+
preact.useEffect(() => {
|
|
3658
3624
|
if (!isOpen) {
|
|
3659
3625
|
itemRefs.current = {};
|
|
3660
3626
|
}
|
|
3661
3627
|
}, [isOpen]);
|
|
3662
3628
|
/* Event handler functions */
|
|
3663
3629
|
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
},
|
|
3674
|
-
ArrowUp: function ArrowUp(event) {
|
|
3675
|
-
event.preventDefault();
|
|
3676
|
-
dispatch({
|
|
3677
|
-
type: InputKeyDownArrowUp,
|
|
3678
|
-
shiftKey: event.shiftKey,
|
|
3679
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3680
|
-
});
|
|
3681
|
-
},
|
|
3682
|
-
Home: function Home(event) {
|
|
3683
|
-
if (!latest.current.state.isOpen) {
|
|
3684
|
-
return;
|
|
3685
|
-
}
|
|
3630
|
+
const inputKeyDownHandlers = preact.useMemo(() => ({
|
|
3631
|
+
ArrowDown(event) {
|
|
3632
|
+
event.preventDefault();
|
|
3633
|
+
dispatch({
|
|
3634
|
+
type: InputKeyDownArrowDown,
|
|
3635
|
+
shiftKey: event.shiftKey,
|
|
3636
|
+
getItemNodeFromIndex
|
|
3637
|
+
});
|
|
3638
|
+
},
|
|
3686
3639
|
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
return;
|
|
3696
|
-
}
|
|
3640
|
+
ArrowUp(event) {
|
|
3641
|
+
event.preventDefault();
|
|
3642
|
+
dispatch({
|
|
3643
|
+
type: InputKeyDownArrowUp,
|
|
3644
|
+
shiftKey: event.shiftKey,
|
|
3645
|
+
getItemNodeFromIndex
|
|
3646
|
+
});
|
|
3647
|
+
},
|
|
3697
3648
|
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
});
|
|
3703
|
-
},
|
|
3704
|
-
Escape: function Escape() {
|
|
3705
|
-
var latestState = latest.current.state;
|
|
3649
|
+
Home(event) {
|
|
3650
|
+
if (!latest.current.state.isOpen) {
|
|
3651
|
+
return;
|
|
3652
|
+
}
|
|
3706
3653
|
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
Enter: function Enter(event) {
|
|
3714
|
-
var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3654
|
+
event.preventDefault();
|
|
3655
|
+
dispatch({
|
|
3656
|
+
type: InputKeyDownHome,
|
|
3657
|
+
getItemNodeFromIndex
|
|
3658
|
+
});
|
|
3659
|
+
},
|
|
3715
3660
|
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3661
|
+
End(event) {
|
|
3662
|
+
if (!latest.current.state.isOpen) {
|
|
3663
|
+
return;
|
|
3664
|
+
}
|
|
3720
3665
|
|
|
3721
|
-
|
|
3666
|
+
event.preventDefault();
|
|
3667
|
+
dispatch({
|
|
3668
|
+
type: InputKeyDownEnd,
|
|
3669
|
+
getItemNodeFromIndex
|
|
3670
|
+
});
|
|
3671
|
+
},
|
|
3672
|
+
|
|
3673
|
+
Escape() {
|
|
3674
|
+
const latestState = latest.current.state;
|
|
3675
|
+
|
|
3676
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
3722
3677
|
dispatch({
|
|
3723
|
-
type:
|
|
3724
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3678
|
+
type: InputKeyDownEscape
|
|
3725
3679
|
});
|
|
3726
3680
|
}
|
|
3727
|
-
}
|
|
3728
|
-
}, [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3729
|
-
|
|
3730
|
-
var getLabelProps = preact.useCallback(function (labelProps) {
|
|
3731
|
-
return _extends({
|
|
3732
|
-
id: elementIds.labelId,
|
|
3733
|
-
htmlFor: elementIds.inputId
|
|
3734
|
-
}, labelProps);
|
|
3735
|
-
}, [elementIds]);
|
|
3736
|
-
var getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3737
|
-
var _extends2;
|
|
3738
|
-
|
|
3739
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
3740
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
3741
|
-
_ref$refKey = _ref.refKey,
|
|
3742
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3743
|
-
ref = _ref.ref,
|
|
3744
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
3745
|
-
|
|
3746
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
3747
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3748
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3681
|
+
},
|
|
3749
3682
|
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3683
|
+
Enter(event) {
|
|
3684
|
+
const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3685
|
+
|
|
3686
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3687
|
+
) {
|
|
3688
|
+
return;
|
|
3689
|
+
}
|
|
3690
|
+
|
|
3691
|
+
event.preventDefault();
|
|
3754
3692
|
dispatch({
|
|
3755
|
-
type:
|
|
3693
|
+
type: InputKeyDownEnter,
|
|
3694
|
+
getItemNodeFromIndex
|
|
3756
3695
|
});
|
|
3757
|
-
}
|
|
3696
|
+
}
|
|
3697
|
+
|
|
3698
|
+
}), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3699
|
+
|
|
3700
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
3701
|
+
id: elementIds.labelId,
|
|
3702
|
+
htmlFor: elementIds.inputId,
|
|
3703
|
+
...labelProps
|
|
3704
|
+
}), [elementIds]);
|
|
3705
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3706
|
+
let {
|
|
3707
|
+
onMouseLeave,
|
|
3708
|
+
refKey = 'ref',
|
|
3709
|
+
ref,
|
|
3710
|
+
...rest
|
|
3711
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3712
|
+
let {
|
|
3713
|
+
suppressRefError = false
|
|
3714
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3715
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3716
|
+
return {
|
|
3717
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3718
|
+
menuRef.current = menuNode;
|
|
3719
|
+
}),
|
|
3720
|
+
id: elementIds.menuId,
|
|
3721
|
+
role: 'listbox',
|
|
3722
|
+
'aria-labelledby': elementIds.labelId,
|
|
3723
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
3724
|
+
dispatch({
|
|
3725
|
+
type: MenuMouseLeave
|
|
3726
|
+
});
|
|
3727
|
+
}),
|
|
3728
|
+
...rest
|
|
3729
|
+
};
|
|
3758
3730
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
latestState = _latest$current.state;
|
|
3776
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3731
|
+
const getItemProps = preact.useCallback(function (_temp3) {
|
|
3732
|
+
let {
|
|
3733
|
+
item,
|
|
3734
|
+
index,
|
|
3735
|
+
refKey = 'ref',
|
|
3736
|
+
ref,
|
|
3737
|
+
onMouseMove,
|
|
3738
|
+
onClick,
|
|
3739
|
+
onPress,
|
|
3740
|
+
...rest
|
|
3741
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3742
|
+
const {
|
|
3743
|
+
props: latestProps,
|
|
3744
|
+
state: latestState
|
|
3745
|
+
} = latest.current;
|
|
3746
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3777
3747
|
|
|
3778
3748
|
if (itemIndex < 0) {
|
|
3779
3749
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3780
3750
|
}
|
|
3781
3751
|
|
|
3782
|
-
|
|
3783
|
-
|
|
3752
|
+
const onSelectKey = 'onClick';
|
|
3753
|
+
const customClickHandler = onClick;
|
|
3784
3754
|
|
|
3785
|
-
|
|
3755
|
+
const itemHandleMouseMove = () => {
|
|
3786
3756
|
if (index === latestState.highlightedIndex) {
|
|
3787
3757
|
return;
|
|
3788
3758
|
}
|
|
@@ -3790,14 +3760,14 @@
|
|
|
3790
3760
|
shouldScrollRef.current = false;
|
|
3791
3761
|
dispatch({
|
|
3792
3762
|
type: ItemMouseMove,
|
|
3793
|
-
index
|
|
3763
|
+
index
|
|
3794
3764
|
});
|
|
3795
3765
|
};
|
|
3796
3766
|
|
|
3797
|
-
|
|
3767
|
+
const itemHandleClick = () => {
|
|
3798
3768
|
dispatch({
|
|
3799
3769
|
type: ItemClick,
|
|
3800
|
-
index
|
|
3770
|
+
index
|
|
3801
3771
|
});
|
|
3802
3772
|
|
|
3803
3773
|
if (inputRef.current) {
|
|
@@ -3805,26 +3775,32 @@
|
|
|
3805
3775
|
}
|
|
3806
3776
|
};
|
|
3807
3777
|
|
|
3808
|
-
return
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3778
|
+
return {
|
|
3779
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3780
|
+
if (itemNode) {
|
|
3781
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3782
|
+
}
|
|
3783
|
+
}),
|
|
3784
|
+
role: 'option',
|
|
3785
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
3786
|
+
id: elementIds.getItemId(itemIndex),
|
|
3787
|
+
...(!rest.disabled && {
|
|
3788
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3789
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
3790
|
+
}),
|
|
3791
|
+
...rest
|
|
3792
|
+
};
|
|
3815
3793
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3794
|
+
const getToggleButtonProps = preact.useCallback(function (_temp4) {
|
|
3795
|
+
let {
|
|
3796
|
+
onClick,
|
|
3797
|
+
onPress,
|
|
3798
|
+
refKey = 'ref',
|
|
3799
|
+
ref,
|
|
3800
|
+
...rest
|
|
3801
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3802
|
+
|
|
3803
|
+
const toggleButtonHandleClick = () => {
|
|
3828
3804
|
dispatch({
|
|
3829
3805
|
type: ToggleButtonClick
|
|
3830
3806
|
});
|
|
@@ -3834,49 +3810,52 @@
|
|
|
3834
3810
|
}
|
|
3835
3811
|
};
|
|
3836
3812
|
|
|
3837
|
-
return
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3813
|
+
return {
|
|
3814
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3815
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3816
|
+
}),
|
|
3817
|
+
id: elementIds.toggleButtonId,
|
|
3818
|
+
tabIndex: -1,
|
|
3819
|
+
...(!rest.disabled && { ...({
|
|
3820
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3821
|
+
})
|
|
3822
|
+
}),
|
|
3823
|
+
...rest
|
|
3824
|
+
};
|
|
3842
3825
|
}, [dispatch, latest, elementIds]);
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
var _ref7 = _temp6 === void 0 ? {} : _temp6,
|
|
3858
|
-
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3859
|
-
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3860
|
-
|
|
3826
|
+
const getInputProps = preact.useCallback(function (_temp5, _temp6) {
|
|
3827
|
+
let {
|
|
3828
|
+
onKeyDown,
|
|
3829
|
+
onChange,
|
|
3830
|
+
onInput,
|
|
3831
|
+
onBlur,
|
|
3832
|
+
onChangeText,
|
|
3833
|
+
refKey = 'ref',
|
|
3834
|
+
ref,
|
|
3835
|
+
...rest
|
|
3836
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3837
|
+
let {
|
|
3838
|
+
suppressRefError = false
|
|
3839
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
3861
3840
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3862
|
-
|
|
3841
|
+
const latestState = latest.current.state;
|
|
3863
3842
|
|
|
3864
|
-
|
|
3865
|
-
|
|
3843
|
+
const inputHandleKeyDown = event => {
|
|
3844
|
+
const key = normalizeArrowKey(event);
|
|
3866
3845
|
|
|
3867
3846
|
if (key && inputKeyDownHandlers[key]) {
|
|
3868
3847
|
inputKeyDownHandlers[key](event);
|
|
3869
3848
|
}
|
|
3870
3849
|
};
|
|
3871
3850
|
|
|
3872
|
-
|
|
3851
|
+
const inputHandleChange = event => {
|
|
3873
3852
|
dispatch({
|
|
3874
3853
|
type: InputChange,
|
|
3875
3854
|
inputValue: event.target.value
|
|
3876
3855
|
});
|
|
3877
3856
|
};
|
|
3878
3857
|
|
|
3879
|
-
|
|
3858
|
+
const inputHandleBlur = () => {
|
|
3880
3859
|
/* istanbul ignore else */
|
|
3881
3860
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3882
3861
|
dispatch({
|
|
@@ -3888,109 +3867,121 @@
|
|
|
3888
3867
|
/* istanbul ignore next (preact) */
|
|
3889
3868
|
|
|
3890
3869
|
|
|
3891
|
-
|
|
3892
|
-
|
|
3870
|
+
const onChangeKey = 'onInput' ;
|
|
3871
|
+
let eventHandlers = {};
|
|
3893
3872
|
|
|
3894
3873
|
if (!rest.disabled) {
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3874
|
+
eventHandlers = {
|
|
3875
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
3876
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
3877
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
|
|
3878
|
+
};
|
|
3898
3879
|
}
|
|
3899
3880
|
|
|
3900
|
-
return
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3881
|
+
return {
|
|
3882
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
3883
|
+
inputRef.current = inputNode;
|
|
3884
|
+
}),
|
|
3885
|
+
id: elementIds.inputId,
|
|
3886
|
+
'aria-autocomplete': 'list',
|
|
3887
|
+
'aria-controls': elementIds.menuId,
|
|
3888
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3889
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
3890
|
+
}),
|
|
3905
3891
|
'aria-labelledby': elementIds.labelId,
|
|
3906
3892
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
3907
3893
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
3908
3894
|
autoComplete: 'off',
|
|
3909
|
-
value: latestState.inputValue
|
|
3910
|
-
|
|
3895
|
+
value: latestState.inputValue,
|
|
3896
|
+
...eventHandlers,
|
|
3897
|
+
...rest
|
|
3898
|
+
};
|
|
3911
3899
|
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
var _ref9 = _temp8 === void 0 ? {} : _temp8,
|
|
3922
|
-
_ref9$suppressRefErro = _ref9.suppressRefError,
|
|
3923
|
-
suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
|
|
3924
|
-
|
|
3900
|
+
const getComboboxProps = preact.useCallback(function (_temp7, _temp8) {
|
|
3901
|
+
let {
|
|
3902
|
+
refKey = 'ref',
|
|
3903
|
+
ref,
|
|
3904
|
+
...rest
|
|
3905
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
3906
|
+
let {
|
|
3907
|
+
suppressRefError = false
|
|
3908
|
+
} = _temp8 === void 0 ? {} : _temp8;
|
|
3925
3909
|
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
3926
|
-
return
|
|
3927
|
-
|
|
3928
|
-
|
|
3910
|
+
return {
|
|
3911
|
+
[refKey]: handleRefs(ref, comboboxNode => {
|
|
3912
|
+
comboboxRef.current = comboboxNode;
|
|
3913
|
+
}),
|
|
3914
|
+
role: 'combobox',
|
|
3915
|
+
'aria-haspopup': 'listbox',
|
|
3916
|
+
'aria-owns': elementIds.menuId,
|
|
3917
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
3918
|
+
...rest
|
|
3919
|
+
};
|
|
3929
3920
|
}, [latest, setGetterPropCallInfo, elementIds]); // returns
|
|
3930
3921
|
|
|
3931
|
-
|
|
3922
|
+
const toggleMenu = preact.useCallback(() => {
|
|
3932
3923
|
dispatch({
|
|
3933
3924
|
type: FunctionToggleMenu
|
|
3934
3925
|
});
|
|
3935
3926
|
}, [dispatch]);
|
|
3936
|
-
|
|
3927
|
+
const closeMenu = preact.useCallback(() => {
|
|
3937
3928
|
dispatch({
|
|
3938
3929
|
type: FunctionCloseMenu
|
|
3939
3930
|
});
|
|
3940
3931
|
}, [dispatch]);
|
|
3941
|
-
|
|
3932
|
+
const openMenu = preact.useCallback(() => {
|
|
3942
3933
|
dispatch({
|
|
3943
3934
|
type: FunctionOpenMenu
|
|
3944
3935
|
});
|
|
3945
3936
|
}, [dispatch]);
|
|
3946
|
-
|
|
3937
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
3947
3938
|
dispatch({
|
|
3948
3939
|
type: FunctionSetHighlightedIndex,
|
|
3949
3940
|
highlightedIndex: newHighlightedIndex
|
|
3950
3941
|
});
|
|
3951
3942
|
}, [dispatch]);
|
|
3952
|
-
|
|
3943
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
3953
3944
|
dispatch({
|
|
3954
3945
|
type: FunctionSelectItem,
|
|
3955
3946
|
selectedItem: newSelectedItem
|
|
3956
3947
|
});
|
|
3957
3948
|
}, [dispatch]);
|
|
3958
|
-
|
|
3949
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
3959
3950
|
dispatch({
|
|
3960
3951
|
type: FunctionSetInputValue,
|
|
3961
3952
|
inputValue: newInputValue
|
|
3962
3953
|
});
|
|
3963
3954
|
}, [dispatch]);
|
|
3964
|
-
|
|
3955
|
+
const reset = preact.useCallback(() => {
|
|
3965
3956
|
dispatch({
|
|
3966
3957
|
type: FunctionReset$1
|
|
3967
3958
|
});
|
|
3968
3959
|
}, [dispatch]);
|
|
3969
3960
|
return {
|
|
3970
3961
|
// prop getters.
|
|
3971
|
-
getItemProps
|
|
3972
|
-
getLabelProps
|
|
3973
|
-
getMenuProps
|
|
3974
|
-
getInputProps
|
|
3975
|
-
getComboboxProps
|
|
3976
|
-
getToggleButtonProps
|
|
3962
|
+
getItemProps,
|
|
3963
|
+
getLabelProps,
|
|
3964
|
+
getMenuProps,
|
|
3965
|
+
getInputProps,
|
|
3966
|
+
getComboboxProps,
|
|
3967
|
+
getToggleButtonProps,
|
|
3977
3968
|
// actions.
|
|
3978
|
-
toggleMenu
|
|
3979
|
-
openMenu
|
|
3980
|
-
closeMenu
|
|
3981
|
-
setHighlightedIndex
|
|
3982
|
-
setInputValue
|
|
3983
|
-
selectItem
|
|
3984
|
-
reset
|
|
3969
|
+
toggleMenu,
|
|
3970
|
+
openMenu,
|
|
3971
|
+
closeMenu,
|
|
3972
|
+
setHighlightedIndex,
|
|
3973
|
+
setInputValue,
|
|
3974
|
+
selectItem,
|
|
3975
|
+
reset,
|
|
3985
3976
|
// state.
|
|
3986
|
-
highlightedIndex
|
|
3987
|
-
isOpen
|
|
3988
|
-
selectedItem
|
|
3989
|
-
inputValue
|
|
3977
|
+
highlightedIndex,
|
|
3978
|
+
isOpen,
|
|
3979
|
+
selectedItem,
|
|
3980
|
+
inputValue
|
|
3990
3981
|
};
|
|
3991
3982
|
}
|
|
3992
3983
|
|
|
3993
|
-
|
|
3984
|
+
const defaultStateValues = {
|
|
3994
3985
|
activeIndex: -1,
|
|
3995
3986
|
selectedItems: []
|
|
3996
3987
|
};
|
|
@@ -4030,11 +4021,11 @@
|
|
|
4030
4021
|
|
|
4031
4022
|
|
|
4032
4023
|
function getInitialState(props) {
|
|
4033
|
-
|
|
4034
|
-
|
|
4024
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
4025
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
4035
4026
|
return {
|
|
4036
|
-
activeIndex
|
|
4037
|
-
selectedItems
|
|
4027
|
+
activeIndex,
|
|
4028
|
+
selectedItems
|
|
4038
4029
|
};
|
|
4039
4030
|
}
|
|
4040
4031
|
/**
|
|
@@ -4053,10 +4044,12 @@
|
|
|
4053
4044
|
return false;
|
|
4054
4045
|
}
|
|
4055
4046
|
|
|
4056
|
-
|
|
4047
|
+
const element = event.target;
|
|
4057
4048
|
|
|
4058
4049
|
if (element instanceof HTMLInputElement && // if element is a text input
|
|
4059
|
-
element.value !== '' && (
|
|
4050
|
+
element.value !== '' && ( // and we have text in it
|
|
4051
|
+
// and cursor is either not at the start or is currently highlighting text.
|
|
4052
|
+
element.selectionStart !== 0 || element.selectionEnd !== 0)) {
|
|
4060
4053
|
return false;
|
|
4061
4054
|
}
|
|
4062
4055
|
|
|
@@ -4071,66 +4064,68 @@
|
|
|
4071
4064
|
|
|
4072
4065
|
|
|
4073
4066
|
function getA11yRemovalMessage(selectionParameters) {
|
|
4074
|
-
|
|
4075
|
-
|
|
4067
|
+
const {
|
|
4068
|
+
removedSelectedItem,
|
|
4069
|
+
itemToString: itemToStringLocal
|
|
4070
|
+
} = selectionParameters;
|
|
4076
4071
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
4077
4072
|
}
|
|
4078
4073
|
|
|
4079
|
-
|
|
4080
|
-
selectedItems: PropTypes__default[
|
|
4081
|
-
initialSelectedItems: PropTypes__default[
|
|
4082
|
-
defaultSelectedItems: PropTypes__default[
|
|
4083
|
-
itemToString: PropTypes__default[
|
|
4084
|
-
getA11yRemovalMessage: PropTypes__default[
|
|
4085
|
-
stateReducer: PropTypes__default[
|
|
4086
|
-
activeIndex: PropTypes__default[
|
|
4087
|
-
initialActiveIndex: PropTypes__default[
|
|
4088
|
-
defaultActiveIndex: PropTypes__default[
|
|
4089
|
-
onActiveIndexChange: PropTypes__default[
|
|
4090
|
-
onSelectedItemsChange: PropTypes__default[
|
|
4091
|
-
keyNavigationNext: PropTypes__default[
|
|
4092
|
-
keyNavigationPrevious: PropTypes__default[
|
|
4093
|
-
environment: PropTypes__default[
|
|
4094
|
-
addEventListener: PropTypes__default[
|
|
4095
|
-
removeEventListener: PropTypes__default[
|
|
4096
|
-
document: PropTypes__default[
|
|
4097
|
-
getElementById: PropTypes__default[
|
|
4098
|
-
activeElement: PropTypes__default[
|
|
4099
|
-
body: PropTypes__default[
|
|
4074
|
+
const propTypes = {
|
|
4075
|
+
selectedItems: PropTypes__default["default"].array,
|
|
4076
|
+
initialSelectedItems: PropTypes__default["default"].array,
|
|
4077
|
+
defaultSelectedItems: PropTypes__default["default"].array,
|
|
4078
|
+
itemToString: PropTypes__default["default"].func,
|
|
4079
|
+
getA11yRemovalMessage: PropTypes__default["default"].func,
|
|
4080
|
+
stateReducer: PropTypes__default["default"].func,
|
|
4081
|
+
activeIndex: PropTypes__default["default"].number,
|
|
4082
|
+
initialActiveIndex: PropTypes__default["default"].number,
|
|
4083
|
+
defaultActiveIndex: PropTypes__default["default"].number,
|
|
4084
|
+
onActiveIndexChange: PropTypes__default["default"].func,
|
|
4085
|
+
onSelectedItemsChange: PropTypes__default["default"].func,
|
|
4086
|
+
keyNavigationNext: PropTypes__default["default"].string,
|
|
4087
|
+
keyNavigationPrevious: PropTypes__default["default"].string,
|
|
4088
|
+
environment: PropTypes__default["default"].shape({
|
|
4089
|
+
addEventListener: PropTypes__default["default"].func,
|
|
4090
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
4091
|
+
document: PropTypes__default["default"].shape({
|
|
4092
|
+
getElementById: PropTypes__default["default"].func,
|
|
4093
|
+
activeElement: PropTypes__default["default"].any,
|
|
4094
|
+
body: PropTypes__default["default"].any
|
|
4100
4095
|
})
|
|
4101
4096
|
})
|
|
4102
4097
|
};
|
|
4103
|
-
|
|
4098
|
+
const defaultProps = {
|
|
4104
4099
|
itemToString: defaultProps$3.itemToString,
|
|
4105
4100
|
stateReducer: defaultProps$3.stateReducer,
|
|
4106
4101
|
environment: defaultProps$3.environment,
|
|
4107
|
-
getA11yRemovalMessage
|
|
4102
|
+
getA11yRemovalMessage,
|
|
4108
4103
|
keyNavigationNext: 'ArrowRight',
|
|
4109
4104
|
keyNavigationPrevious: 'ArrowLeft'
|
|
4110
4105
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
4111
4106
|
|
|
4112
|
-
|
|
4107
|
+
let validatePropTypes = noop;
|
|
4113
4108
|
/* istanbul ignore next */
|
|
4114
4109
|
|
|
4115
4110
|
{
|
|
4116
|
-
validatePropTypes =
|
|
4117
|
-
PropTypes__default[
|
|
4111
|
+
validatePropTypes = (options, caller) => {
|
|
4112
|
+
PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
4118
4113
|
};
|
|
4119
4114
|
}
|
|
4120
4115
|
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4116
|
+
const SelectedItemClick = '__selected_item_click__' ;
|
|
4117
|
+
const SelectedItemKeyDownDelete = '__selected_item_keydown_delete__' ;
|
|
4118
|
+
const SelectedItemKeyDownBackspace = '__selected_item_keydown_backspace__' ;
|
|
4119
|
+
const SelectedItemKeyDownNavigationNext = '__selected_item_keydown_navigation_next__' ;
|
|
4120
|
+
const SelectedItemKeyDownNavigationPrevious = '__selected_item_keydown_navigation_previous__' ;
|
|
4121
|
+
const DropdownKeyDownNavigationPrevious = '__dropdown_keydown_navigation_previous__' ;
|
|
4122
|
+
const DropdownKeyDownBackspace = '__dropdown_keydown_backspace__' ;
|
|
4123
|
+
const DropdownClick = '__dropdown_click__' ;
|
|
4124
|
+
const FunctionAddSelectedItem = '__function_add_selected_item__' ;
|
|
4125
|
+
const FunctionRemoveSelectedItem = '__function_remove_selected_item__' ;
|
|
4126
|
+
const FunctionSetSelectedItems = '__function_set_selected_items__' ;
|
|
4127
|
+
const FunctionSetActiveIndex = '__function_set_active_index__' ;
|
|
4128
|
+
const FunctionReset = '__function_reset__' ;
|
|
4134
4129
|
|
|
4135
4130
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
4136
4131
|
__proto__: null,
|
|
@@ -4152,13 +4147,17 @@
|
|
|
4152
4147
|
/* eslint-disable complexity */
|
|
4153
4148
|
|
|
4154
4149
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4150
|
+
const {
|
|
4151
|
+
type,
|
|
4152
|
+
index,
|
|
4153
|
+
props,
|
|
4154
|
+
selectedItem
|
|
4155
|
+
} = action;
|
|
4156
|
+
const {
|
|
4157
|
+
activeIndex,
|
|
4158
|
+
selectedItems
|
|
4159
|
+
} = state;
|
|
4160
|
+
let changes;
|
|
4162
4161
|
|
|
4163
4162
|
switch (type) {
|
|
4164
4163
|
case SelectedItemClick:
|
|
@@ -4182,7 +4181,7 @@
|
|
|
4182
4181
|
case SelectedItemKeyDownBackspace:
|
|
4183
4182
|
case SelectedItemKeyDownDelete:
|
|
4184
4183
|
{
|
|
4185
|
-
|
|
4184
|
+
let newActiveIndex = activeIndex;
|
|
4186
4185
|
|
|
4187
4186
|
if (selectedItems.length === 1) {
|
|
4188
4187
|
newActiveIndex = -1;
|
|
@@ -4190,11 +4189,12 @@
|
|
|
4190
4189
|
newActiveIndex = selectedItems.length - 2;
|
|
4191
4190
|
}
|
|
4192
4191
|
|
|
4193
|
-
changes =
|
|
4194
|
-
selectedItems: [
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4192
|
+
changes = {
|
|
4193
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
4194
|
+
...{
|
|
4195
|
+
activeIndex: newActiveIndex
|
|
4196
|
+
}
|
|
4197
|
+
};
|
|
4198
4198
|
break;
|
|
4199
4199
|
}
|
|
4200
4200
|
|
|
@@ -4212,7 +4212,7 @@
|
|
|
4212
4212
|
|
|
4213
4213
|
case FunctionAddSelectedItem:
|
|
4214
4214
|
changes = {
|
|
4215
|
-
selectedItems: [
|
|
4215
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
4216
4216
|
};
|
|
4217
4217
|
break;
|
|
4218
4218
|
|
|
@@ -4224,26 +4224,30 @@
|
|
|
4224
4224
|
|
|
4225
4225
|
case FunctionRemoveSelectedItem:
|
|
4226
4226
|
{
|
|
4227
|
-
|
|
4228
|
-
|
|
4227
|
+
let newActiveIndex = activeIndex;
|
|
4228
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
4229
|
+
|
|
4230
|
+
if (selectedItemIndex >= 0) {
|
|
4231
|
+
if (selectedItems.length === 1) {
|
|
4232
|
+
newActiveIndex = -1;
|
|
4233
|
+
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
4234
|
+
newActiveIndex = selectedItems.length - 2;
|
|
4235
|
+
}
|
|
4229
4236
|
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4237
|
+
changes = {
|
|
4238
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
4239
|
+
activeIndex: newActiveIndex
|
|
4240
|
+
};
|
|
4234
4241
|
}
|
|
4235
4242
|
|
|
4236
|
-
changes = _extends({
|
|
4237
|
-
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
|
|
4238
|
-
}, {
|
|
4239
|
-
activeIndex: _newActiveIndex
|
|
4240
|
-
});
|
|
4241
4243
|
break;
|
|
4242
4244
|
}
|
|
4243
4245
|
|
|
4244
4246
|
case FunctionSetSelectedItems:
|
|
4245
4247
|
{
|
|
4246
|
-
|
|
4248
|
+
const {
|
|
4249
|
+
selectedItems: newSelectedItems
|
|
4250
|
+
} = action;
|
|
4247
4251
|
changes = {
|
|
4248
4252
|
selectedItems: newSelectedItems
|
|
4249
4253
|
};
|
|
@@ -4252,9 +4256,11 @@
|
|
|
4252
4256
|
|
|
4253
4257
|
case FunctionSetActiveIndex:
|
|
4254
4258
|
{
|
|
4255
|
-
|
|
4259
|
+
const {
|
|
4260
|
+
activeIndex: newActiveIndex
|
|
4261
|
+
} = action;
|
|
4256
4262
|
changes = {
|
|
4257
|
-
activeIndex:
|
|
4263
|
+
activeIndex: newActiveIndex
|
|
4258
4264
|
};
|
|
4259
4265
|
break;
|
|
4260
4266
|
}
|
|
@@ -4270,11 +4276,11 @@
|
|
|
4270
4276
|
throw new Error('Reducer called without proper action type.');
|
|
4271
4277
|
}
|
|
4272
4278
|
|
|
4273
|
-
return
|
|
4279
|
+
return { ...state,
|
|
4280
|
+
...changes
|
|
4281
|
+
};
|
|
4274
4282
|
}
|
|
4275
4283
|
|
|
4276
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
4277
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
4278
4284
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
4279
4285
|
|
|
4280
4286
|
function useMultipleSelection(userProps) {
|
|
@@ -4284,47 +4290,47 @@
|
|
|
4284
4290
|
|
|
4285
4291
|
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
4286
4292
|
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4293
|
+
const props = { ...defaultProps,
|
|
4294
|
+
...userProps
|
|
4295
|
+
};
|
|
4296
|
+
const {
|
|
4297
|
+
getA11yRemovalMessage,
|
|
4298
|
+
itemToString,
|
|
4299
|
+
environment,
|
|
4300
|
+
keyNavigationNext,
|
|
4301
|
+
keyNavigationPrevious
|
|
4302
|
+
} = props; // Reducer init.
|
|
4303
|
+
|
|
4304
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
4305
|
+
const {
|
|
4306
|
+
activeIndex,
|
|
4307
|
+
selectedItems
|
|
4308
|
+
} = state; // Refs.
|
|
4309
|
+
|
|
4310
|
+
const isInitialMountRef = preact.useRef(true);
|
|
4311
|
+
const dropdownRef = preact.useRef(null);
|
|
4312
|
+
const previousSelectedItemsRef = preact.useRef(selectedItems);
|
|
4313
|
+
const selectedItemRefs = preact.useRef();
|
|
4306
4314
|
selectedItemRefs.current = [];
|
|
4307
|
-
|
|
4308
|
-
state
|
|
4309
|
-
props
|
|
4315
|
+
const latest = useLatestRef({
|
|
4316
|
+
state,
|
|
4317
|
+
props
|
|
4310
4318
|
}); // Effects.
|
|
4311
4319
|
|
|
4312
4320
|
/* Sets a11y status message on changes in selectedItem. */
|
|
4313
4321
|
|
|
4314
|
-
preact.useEffect(
|
|
4322
|
+
preact.useEffect(() => {
|
|
4315
4323
|
if (isInitialMountRef.current) {
|
|
4316
4324
|
return;
|
|
4317
4325
|
}
|
|
4318
4326
|
|
|
4319
4327
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
4320
|
-
|
|
4321
|
-
return selectedItems.indexOf(item) < 0;
|
|
4322
|
-
});
|
|
4328
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
4323
4329
|
setStatus(getA11yRemovalMessage({
|
|
4324
|
-
itemToString
|
|
4330
|
+
itemToString,
|
|
4325
4331
|
resultCount: selectedItems.length,
|
|
4326
|
-
removedSelectedItem
|
|
4327
|
-
activeIndex
|
|
4332
|
+
removedSelectedItem,
|
|
4333
|
+
activeIndex,
|
|
4328
4334
|
activeSelectedItem: selectedItems[activeIndex]
|
|
4329
4335
|
}), environment.document);
|
|
4330
4336
|
}
|
|
@@ -4332,7 +4338,7 @@
|
|
|
4332
4338
|
previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4333
4339
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
4334
4340
|
|
|
4335
|
-
preact.useEffect(
|
|
4341
|
+
preact.useEffect(() => {
|
|
4336
4342
|
if (isInitialMountRef.current) {
|
|
4337
4343
|
return;
|
|
4338
4344
|
}
|
|
@@ -4345,181 +4351,191 @@
|
|
|
4345
4351
|
}, [activeIndex]);
|
|
4346
4352
|
useControlPropsValidator({
|
|
4347
4353
|
isInitialMount: isInitialMountRef.current,
|
|
4348
|
-
props
|
|
4349
|
-
state
|
|
4354
|
+
props,
|
|
4355
|
+
state
|
|
4350
4356
|
});
|
|
4351
|
-
|
|
4357
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
4352
4358
|
|
|
4353
|
-
preact.useEffect(
|
|
4359
|
+
preact.useEffect(() => {
|
|
4354
4360
|
isInitialMountRef.current = false;
|
|
4355
4361
|
}, []); // Event handler functions.
|
|
4356
4362
|
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
4363
|
+
const selectedItemKeyDownHandlers = preact.useMemo(() => ({
|
|
4364
|
+
[keyNavigationPrevious]() {
|
|
4361
4365
|
dispatch({
|
|
4362
4366
|
type: SelectedItemKeyDownNavigationPrevious
|
|
4363
4367
|
});
|
|
4364
|
-
},
|
|
4368
|
+
},
|
|
4369
|
+
|
|
4370
|
+
[keyNavigationNext]() {
|
|
4365
4371
|
dispatch({
|
|
4366
4372
|
type: SelectedItemKeyDownNavigationNext
|
|
4367
4373
|
});
|
|
4368
|
-
},
|
|
4374
|
+
},
|
|
4375
|
+
|
|
4376
|
+
Delete() {
|
|
4369
4377
|
dispatch({
|
|
4370
4378
|
type: SelectedItemKeyDownDelete
|
|
4371
4379
|
});
|
|
4372
|
-
},
|
|
4380
|
+
},
|
|
4381
|
+
|
|
4382
|
+
Backspace() {
|
|
4373
4383
|
dispatch({
|
|
4374
4384
|
type: SelectedItemKeyDownBackspace
|
|
4375
4385
|
});
|
|
4376
|
-
}
|
|
4377
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4378
|
-
var dropdownKeyDownHandlers = preact.useMemo(function () {
|
|
4379
|
-
var _ref2;
|
|
4386
|
+
}
|
|
4380
4387
|
|
|
4381
|
-
|
|
4388
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4389
|
+
const dropdownKeyDownHandlers = preact.useMemo(() => ({
|
|
4390
|
+
[keyNavigationPrevious](event) {
|
|
4382
4391
|
if (isKeyDownOperationPermitted(event)) {
|
|
4383
4392
|
dispatch({
|
|
4384
4393
|
type: DropdownKeyDownNavigationPrevious
|
|
4385
4394
|
});
|
|
4386
4395
|
}
|
|
4387
|
-
},
|
|
4396
|
+
},
|
|
4397
|
+
|
|
4398
|
+
Backspace(event) {
|
|
4388
4399
|
if (isKeyDownOperationPermitted(event)) {
|
|
4389
4400
|
dispatch({
|
|
4390
4401
|
type: DropdownKeyDownBackspace
|
|
4391
4402
|
});
|
|
4392
4403
|
}
|
|
4393
|
-
}
|
|
4394
|
-
}, [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4395
|
-
|
|
4396
|
-
var getSelectedItemProps = preact.useCallback(function (_temp) {
|
|
4397
|
-
var _extends2;
|
|
4398
|
-
|
|
4399
|
-
var _ref3 = _temp === void 0 ? {} : _temp,
|
|
4400
|
-
_ref3$refKey = _ref3.refKey,
|
|
4401
|
-
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4402
|
-
ref = _ref3.ref,
|
|
4403
|
-
onClick = _ref3.onClick,
|
|
4404
|
-
onKeyDown = _ref3.onKeyDown,
|
|
4405
|
-
selectedItem = _ref3.selectedItem,
|
|
4406
|
-
index = _ref3.index,
|
|
4407
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
4404
|
+
}
|
|
4408
4405
|
|
|
4409
|
-
|
|
4410
|
-
|
|
4406
|
+
}), [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4407
|
+
|
|
4408
|
+
const getSelectedItemProps = preact.useCallback(function (_temp) {
|
|
4409
|
+
let {
|
|
4410
|
+
refKey = 'ref',
|
|
4411
|
+
ref,
|
|
4412
|
+
onClick,
|
|
4413
|
+
onKeyDown,
|
|
4414
|
+
selectedItem,
|
|
4415
|
+
index,
|
|
4416
|
+
...rest
|
|
4417
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4418
|
+
const {
|
|
4419
|
+
state: latestState
|
|
4420
|
+
} = latest.current;
|
|
4421
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
4411
4422
|
|
|
4412
4423
|
if (itemIndex < 0) {
|
|
4413
4424
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
4414
4425
|
}
|
|
4415
4426
|
|
|
4416
|
-
|
|
4427
|
+
const selectedItemHandleClick = () => {
|
|
4417
4428
|
dispatch({
|
|
4418
4429
|
type: SelectedItemClick,
|
|
4419
|
-
index
|
|
4430
|
+
index
|
|
4420
4431
|
});
|
|
4421
4432
|
};
|
|
4422
4433
|
|
|
4423
|
-
|
|
4424
|
-
|
|
4434
|
+
const selectedItemHandleKeyDown = event => {
|
|
4435
|
+
const key = normalizeArrowKey(event);
|
|
4425
4436
|
|
|
4426
4437
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
4427
4438
|
selectedItemKeyDownHandlers[key](event);
|
|
4428
4439
|
}
|
|
4429
4440
|
};
|
|
4430
4441
|
|
|
4431
|
-
return
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4442
|
+
return {
|
|
4443
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
4444
|
+
if (selectedItemNode) {
|
|
4445
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
4446
|
+
}
|
|
4447
|
+
}),
|
|
4448
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
4449
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
4450
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
4451
|
+
...rest
|
|
4452
|
+
};
|
|
4436
4453
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
4451
|
-
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
4452
|
-
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
4453
|
-
|
|
4454
|
+
const getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
|
|
4455
|
+
let {
|
|
4456
|
+
refKey = 'ref',
|
|
4457
|
+
ref,
|
|
4458
|
+
onKeyDown,
|
|
4459
|
+
onClick,
|
|
4460
|
+
preventKeyAction = false,
|
|
4461
|
+
...rest
|
|
4462
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4463
|
+
let {
|
|
4464
|
+
suppressRefError = false
|
|
4465
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4454
4466
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
4455
4467
|
|
|
4456
|
-
|
|
4457
|
-
|
|
4468
|
+
const dropdownHandleKeyDown = event => {
|
|
4469
|
+
const key = normalizeArrowKey(event);
|
|
4458
4470
|
|
|
4459
4471
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
4460
4472
|
dropdownKeyDownHandlers[key](event);
|
|
4461
4473
|
}
|
|
4462
4474
|
};
|
|
4463
4475
|
|
|
4464
|
-
|
|
4476
|
+
const dropdownHandleClick = () => {
|
|
4465
4477
|
dispatch({
|
|
4466
4478
|
type: DropdownClick
|
|
4467
4479
|
});
|
|
4468
4480
|
};
|
|
4469
4481
|
|
|
4470
|
-
return
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4482
|
+
return {
|
|
4483
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
4484
|
+
if (dropdownNode) {
|
|
4485
|
+
dropdownRef.current = dropdownNode;
|
|
4486
|
+
}
|
|
4487
|
+
}),
|
|
4488
|
+
...(!preventKeyAction && {
|
|
4489
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
4490
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
4491
|
+
}),
|
|
4492
|
+
...rest
|
|
4493
|
+
};
|
|
4478
4494
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
4479
4495
|
|
|
4480
|
-
|
|
4496
|
+
const addSelectedItem = preact.useCallback(selectedItem => {
|
|
4481
4497
|
dispatch({
|
|
4482
4498
|
type: FunctionAddSelectedItem,
|
|
4483
|
-
selectedItem
|
|
4499
|
+
selectedItem
|
|
4484
4500
|
});
|
|
4485
4501
|
}, [dispatch]);
|
|
4486
|
-
|
|
4502
|
+
const removeSelectedItem = preact.useCallback(selectedItem => {
|
|
4487
4503
|
dispatch({
|
|
4488
4504
|
type: FunctionRemoveSelectedItem,
|
|
4489
|
-
selectedItem
|
|
4505
|
+
selectedItem
|
|
4490
4506
|
});
|
|
4491
4507
|
}, [dispatch]);
|
|
4492
|
-
|
|
4508
|
+
const setSelectedItems = preact.useCallback(newSelectedItems => {
|
|
4493
4509
|
dispatch({
|
|
4494
4510
|
type: FunctionSetSelectedItems,
|
|
4495
4511
|
selectedItems: newSelectedItems
|
|
4496
4512
|
});
|
|
4497
4513
|
}, [dispatch]);
|
|
4498
|
-
|
|
4514
|
+
const setActiveIndex = preact.useCallback(newActiveIndex => {
|
|
4499
4515
|
dispatch({
|
|
4500
4516
|
type: FunctionSetActiveIndex,
|
|
4501
4517
|
activeIndex: newActiveIndex
|
|
4502
4518
|
});
|
|
4503
4519
|
}, [dispatch]);
|
|
4504
|
-
|
|
4520
|
+
const reset = preact.useCallback(() => {
|
|
4505
4521
|
dispatch({
|
|
4506
4522
|
type: FunctionReset
|
|
4507
4523
|
});
|
|
4508
4524
|
}, [dispatch]);
|
|
4509
4525
|
return {
|
|
4510
|
-
getSelectedItemProps
|
|
4511
|
-
getDropdownProps
|
|
4512
|
-
addSelectedItem
|
|
4513
|
-
removeSelectedItem
|
|
4514
|
-
setSelectedItems
|
|
4515
|
-
setActiveIndex
|
|
4516
|
-
reset
|
|
4517
|
-
selectedItems
|
|
4518
|
-
activeIndex
|
|
4526
|
+
getSelectedItemProps,
|
|
4527
|
+
getDropdownProps,
|
|
4528
|
+
addSelectedItem,
|
|
4529
|
+
removeSelectedItem,
|
|
4530
|
+
setSelectedItems,
|
|
4531
|
+
setActiveIndex,
|
|
4532
|
+
reset,
|
|
4533
|
+
selectedItems,
|
|
4534
|
+
activeIndex
|
|
4519
4535
|
};
|
|
4520
4536
|
}
|
|
4521
4537
|
|
|
4522
|
-
exports[
|
|
4538
|
+
exports["default"] = Downshift$1;
|
|
4523
4539
|
exports.resetIdCounter = resetIdCounter;
|
|
4524
4540
|
exports.useCombobox = useCombobox;
|
|
4525
4541
|
exports.useMultipleSelection = useMultipleSelection;
|
|
@@ -4527,5 +4543,5 @@
|
|
|
4527
4543
|
|
|
4528
4544
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4529
4545
|
|
|
4530
|
-
}))
|
|
4546
|
+
}));
|
|
4531
4547
|
//# sourceMappingURL=downshift.umd.js.map
|