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,10 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
6
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
-
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
8
|
-
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
9
5
|
var preact = require('preact');
|
|
10
6
|
var reactIs = require('react-is');
|
|
11
7
|
var computeScrollIntoView = require('compute-scroll-into-view');
|
|
@@ -14,14 +10,10 @@ var PropTypes = require('prop-types');
|
|
|
14
10
|
|
|
15
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
12
|
|
|
17
|
-
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
18
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
19
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
20
|
-
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
21
13
|
var computeScrollIntoView__default = /*#__PURE__*/_interopDefaultLegacy(computeScrollIntoView);
|
|
22
14
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
let idCounter = 0;
|
|
25
17
|
/**
|
|
26
18
|
* Accepts a parameter and returns it if it's a function
|
|
27
19
|
* or a noop function if it's not. This allows us to
|
|
@@ -48,15 +40,17 @@ function scrollIntoView(node, menuNode) {
|
|
|
48
40
|
return;
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
|
|
43
|
+
const actions = computeScrollIntoView__default["default"](node, {
|
|
52
44
|
boundary: menuNode,
|
|
53
45
|
block: 'nearest',
|
|
54
46
|
scrollMode: 'if-needed'
|
|
55
47
|
});
|
|
56
|
-
actions.forEach(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
actions.forEach(_ref => {
|
|
49
|
+
let {
|
|
50
|
+
el,
|
|
51
|
+
top,
|
|
52
|
+
left
|
|
53
|
+
} = _ref;
|
|
60
54
|
el.scrollTop = top;
|
|
61
55
|
el.scrollLeft = left;
|
|
62
56
|
});
|
|
@@ -70,7 +64,7 @@ function scrollIntoView(node, menuNode) {
|
|
|
70
64
|
|
|
71
65
|
|
|
72
66
|
function isOrContainsNode(parent, child, environment) {
|
|
73
|
-
|
|
67
|
+
const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
74
68
|
return result;
|
|
75
69
|
}
|
|
76
70
|
/**
|
|
@@ -84,7 +78,7 @@ function isOrContainsNode(parent, child, environment) {
|
|
|
84
78
|
|
|
85
79
|
|
|
86
80
|
function debounce(fn, time) {
|
|
87
|
-
|
|
81
|
+
let timeoutId;
|
|
88
82
|
|
|
89
83
|
function cancel() {
|
|
90
84
|
if (timeoutId) {
|
|
@@ -98,9 +92,9 @@ function debounce(fn, time) {
|
|
|
98
92
|
}
|
|
99
93
|
|
|
100
94
|
cancel();
|
|
101
|
-
timeoutId = setTimeout(
|
|
95
|
+
timeoutId = setTimeout(() => {
|
|
102
96
|
timeoutId = null;
|
|
103
|
-
fn
|
|
97
|
+
fn(...args);
|
|
104
98
|
}, time);
|
|
105
99
|
}
|
|
106
100
|
|
|
@@ -126,9 +120,9 @@ function callAllEventHandlers() {
|
|
|
126
120
|
args[_key3 - 1] = arguments[_key3];
|
|
127
121
|
}
|
|
128
122
|
|
|
129
|
-
return fns.some(
|
|
123
|
+
return fns.some(fn => {
|
|
130
124
|
if (fn) {
|
|
131
|
-
fn
|
|
125
|
+
fn(event, ...args);
|
|
132
126
|
}
|
|
133
127
|
|
|
134
128
|
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
@@ -141,8 +135,8 @@ function handleRefs() {
|
|
|
141
135
|
refs[_key4] = arguments[_key4];
|
|
142
136
|
}
|
|
143
137
|
|
|
144
|
-
return
|
|
145
|
-
refs.forEach(
|
|
138
|
+
return node => {
|
|
139
|
+
refs.forEach(ref => {
|
|
146
140
|
if (typeof ref === 'function') {
|
|
147
141
|
ref(node);
|
|
148
142
|
} else if (ref) {
|
|
@@ -179,9 +173,11 @@ function resetIdCounter() {
|
|
|
179
173
|
|
|
180
174
|
|
|
181
175
|
function getA11yStatusMessage$1(_ref2) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
176
|
+
let {
|
|
177
|
+
isOpen,
|
|
178
|
+
resultCount,
|
|
179
|
+
previousResultCount
|
|
180
|
+
} = _ref2;
|
|
185
181
|
|
|
186
182
|
if (!isOpen) {
|
|
187
183
|
return '';
|
|
@@ -257,7 +253,7 @@ function requiredProp(fnName, propName) {
|
|
|
257
253
|
console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
|
|
258
254
|
}
|
|
259
255
|
|
|
260
|
-
|
|
256
|
+
const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
|
261
257
|
/**
|
|
262
258
|
* @param {Object} state the state object
|
|
263
259
|
* @return {Object} state that is relevant to downshift
|
|
@@ -268,8 +264,8 @@ function pickState(state) {
|
|
|
268
264
|
state = {};
|
|
269
265
|
}
|
|
270
266
|
|
|
271
|
-
|
|
272
|
-
stateKeys.forEach(
|
|
267
|
+
const result = {};
|
|
268
|
+
stateKeys.forEach(k => {
|
|
273
269
|
if (state.hasOwnProperty(k)) {
|
|
274
270
|
result[k] = state[k];
|
|
275
271
|
}
|
|
@@ -290,7 +286,7 @@ function pickState(state) {
|
|
|
290
286
|
|
|
291
287
|
|
|
292
288
|
function getState(state, props) {
|
|
293
|
-
return Object.keys(state).reduce(
|
|
289
|
+
return Object.keys(state).reduce((prevState, key) => {
|
|
294
290
|
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
295
291
|
return prevState;
|
|
296
292
|
}, {});
|
|
@@ -317,8 +313,10 @@ function isControlledProp(props, key) {
|
|
|
317
313
|
|
|
318
314
|
|
|
319
315
|
function normalizeArrowKey(event) {
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
const {
|
|
317
|
+
key,
|
|
318
|
+
keyCode
|
|
319
|
+
} = event;
|
|
322
320
|
/* istanbul ignore next (ie) */
|
|
323
321
|
|
|
324
322
|
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
@@ -359,13 +357,13 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
|
|
|
359
357
|
return -1;
|
|
360
358
|
}
|
|
361
359
|
|
|
362
|
-
|
|
360
|
+
const itemsLastIndex = itemCount - 1;
|
|
363
361
|
|
|
364
362
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
365
363
|
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
|
366
364
|
}
|
|
367
365
|
|
|
368
|
-
|
|
366
|
+
let newIndex = baseIndex + moveAmount;
|
|
369
367
|
|
|
370
368
|
if (newIndex < 0) {
|
|
371
369
|
newIndex = circular ? itemsLastIndex : 0;
|
|
@@ -373,7 +371,7 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
|
|
|
373
371
|
newIndex = circular ? 0 : itemsLastIndex;
|
|
374
372
|
}
|
|
375
373
|
|
|
376
|
-
|
|
374
|
+
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
|
|
377
375
|
|
|
378
376
|
if (nonDisabledNewIndex === -1) {
|
|
379
377
|
return baseIndex >= itemCount ? -1 : baseIndex;
|
|
@@ -394,22 +392,22 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
|
|
|
394
392
|
|
|
395
393
|
|
|
396
394
|
function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
|
|
397
|
-
|
|
395
|
+
const currentElementNode = getItemNodeFromIndex(baseIndex);
|
|
398
396
|
|
|
399
397
|
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
|
|
400
398
|
return baseIndex;
|
|
401
399
|
}
|
|
402
400
|
|
|
403
401
|
if (moveAmount > 0) {
|
|
404
|
-
for (
|
|
402
|
+
for (let index = baseIndex + 1; index < itemCount; index++) {
|
|
405
403
|
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
406
404
|
return index;
|
|
407
405
|
}
|
|
408
406
|
}
|
|
409
407
|
} else {
|
|
410
|
-
for (
|
|
411
|
-
if (!getItemNodeFromIndex(
|
|
412
|
-
return
|
|
408
|
+
for (let index = baseIndex - 1; index >= 0; index--) {
|
|
409
|
+
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
410
|
+
return index;
|
|
413
411
|
}
|
|
414
412
|
}
|
|
415
413
|
}
|
|
@@ -437,19 +435,17 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
|
|
|
437
435
|
checkActiveElement = true;
|
|
438
436
|
}
|
|
439
437
|
|
|
440
|
-
return downshiftElements.some(
|
|
441
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
442
|
-
});
|
|
438
|
+
return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
|
|
443
439
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
444
440
|
|
|
445
441
|
|
|
446
|
-
|
|
442
|
+
let validateControlledUnchanged = noop;
|
|
447
443
|
/* istanbul ignore next */
|
|
448
444
|
|
|
449
445
|
if (process.env.NODE_ENV !== 'production') {
|
|
450
|
-
validateControlledUnchanged =
|
|
451
|
-
|
|
452
|
-
Object.keys(state).forEach(
|
|
446
|
+
validateControlledUnchanged = (state, prevProps, nextProps) => {
|
|
447
|
+
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";
|
|
448
|
+
Object.keys(state).forEach(propKey => {
|
|
453
449
|
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
454
450
|
// eslint-disable-next-line no-console
|
|
455
451
|
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
@@ -461,7 +457,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
461
457
|
};
|
|
462
458
|
}
|
|
463
459
|
|
|
464
|
-
|
|
460
|
+
const cleanupStatus = debounce(documentProp => {
|
|
465
461
|
getStatusDiv(documentProp).textContent = '';
|
|
466
462
|
}, 500);
|
|
467
463
|
/**
|
|
@@ -470,7 +466,7 @@ var cleanupStatus = debounce(function (documentProp) {
|
|
|
470
466
|
*/
|
|
471
467
|
|
|
472
468
|
function setStatus(status, documentProp) {
|
|
473
|
-
|
|
469
|
+
const div = getStatusDiv(documentProp);
|
|
474
470
|
|
|
475
471
|
if (!status) {
|
|
476
472
|
return;
|
|
@@ -491,7 +487,7 @@ function getStatusDiv(documentProp) {
|
|
|
491
487
|
documentProp = document;
|
|
492
488
|
}
|
|
493
489
|
|
|
494
|
-
|
|
490
|
+
let statusDiv = documentProp.getElementById('a11y-status-message');
|
|
495
491
|
|
|
496
492
|
if (statusDiv) {
|
|
497
493
|
return statusDiv;
|
|
@@ -516,23 +512,23 @@ function getStatusDiv(documentProp) {
|
|
|
516
512
|
return statusDiv;
|
|
517
513
|
}
|
|
518
514
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
515
|
+
const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
516
|
+
const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
517
|
+
const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
518
|
+
const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
|
|
519
|
+
const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
|
|
520
|
+
const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
|
|
521
|
+
const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
|
|
522
|
+
const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
|
|
523
|
+
const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
|
|
524
|
+
const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
|
|
525
|
+
const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
|
|
526
|
+
const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
|
|
527
|
+
const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
|
|
528
|
+
const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
|
|
529
|
+
const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
|
|
530
|
+
const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
|
531
|
+
const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
|
536
532
|
|
|
537
533
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
538
534
|
__proto__: null,
|
|
@@ -555,58 +551,45 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
555
551
|
touchEnd: touchEnd
|
|
556
552
|
});
|
|
557
553
|
|
|
558
|
-
|
|
559
|
-
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
560
|
-
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
561
|
-
_excluded4$1 = ["refKey", "ref"],
|
|
562
|
-
_excluded5$1 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
554
|
+
/* eslint camelcase:0 */
|
|
563
555
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
function Downshift(_props) {
|
|
556
|
+
const Downshift = /*#__PURE__*/(() => {
|
|
557
|
+
class Downshift extends preact.Component {
|
|
558
|
+
constructor(_props) {
|
|
569
559
|
var _this;
|
|
570
560
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
_this.labelId = _this.props.labelId || _this.id + "-label";
|
|
578
|
-
_this.inputId = _this.props.inputId || _this.id + "-input";
|
|
561
|
+
super(_props);
|
|
562
|
+
_this = this;
|
|
563
|
+
this.id = this.props.id || "downshift-" + generateId();
|
|
564
|
+
this.menuId = this.props.menuId || this.id + "-menu";
|
|
565
|
+
this.labelId = this.props.labelId || this.id + "-label";
|
|
566
|
+
this.inputId = this.props.inputId || this.id + "-input";
|
|
579
567
|
|
|
580
|
-
|
|
581
|
-
return _this.id + "-item-" + index;
|
|
582
|
-
};
|
|
568
|
+
this.getItemId = this.props.getItemId || (index => this.id + "-item-" + index);
|
|
583
569
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
570
|
+
this.input = null;
|
|
571
|
+
this.items = [];
|
|
572
|
+
this.itemCount = null;
|
|
573
|
+
this.previousResultCount = 0;
|
|
574
|
+
this.timeoutIds = [];
|
|
589
575
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return i !== id;
|
|
594
|
-
});
|
|
576
|
+
this.internalSetTimeout = (fn, time) => {
|
|
577
|
+
const id = setTimeout(() => {
|
|
578
|
+
this.timeoutIds = this.timeoutIds.filter(i => i !== id);
|
|
595
579
|
fn();
|
|
596
580
|
}, time);
|
|
597
|
-
|
|
598
|
-
_this.timeoutIds.push(id);
|
|
581
|
+
this.timeoutIds.push(id);
|
|
599
582
|
};
|
|
600
583
|
|
|
601
|
-
|
|
602
|
-
|
|
584
|
+
this.setItemCount = count => {
|
|
585
|
+
this.itemCount = count;
|
|
603
586
|
};
|
|
604
587
|
|
|
605
|
-
|
|
606
|
-
|
|
588
|
+
this.unsetItemCount = () => {
|
|
589
|
+
this.itemCount = null;
|
|
607
590
|
};
|
|
608
591
|
|
|
609
|
-
|
|
592
|
+
this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
610
593
|
if (highlightedIndex === void 0) {
|
|
611
594
|
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
612
595
|
}
|
|
@@ -617,71 +600,72 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
617
600
|
|
|
618
601
|
otherStateToSet = pickState(otherStateToSet);
|
|
619
602
|
|
|
620
|
-
_this.internalSetState(
|
|
621
|
-
highlightedIndex
|
|
622
|
-
|
|
603
|
+
_this.internalSetState({
|
|
604
|
+
highlightedIndex,
|
|
605
|
+
...otherStateToSet
|
|
606
|
+
});
|
|
623
607
|
};
|
|
624
608
|
|
|
625
|
-
|
|
626
|
-
|
|
609
|
+
this.clearSelection = cb => {
|
|
610
|
+
this.internalSetState({
|
|
627
611
|
selectedItem: null,
|
|
628
612
|
inputValue: '',
|
|
629
|
-
highlightedIndex:
|
|
630
|
-
isOpen:
|
|
613
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
614
|
+
isOpen: this.props.defaultIsOpen
|
|
631
615
|
}, cb);
|
|
632
616
|
};
|
|
633
617
|
|
|
634
|
-
|
|
618
|
+
this.selectItem = (item, otherStateToSet, cb) => {
|
|
635
619
|
otherStateToSet = pickState(otherStateToSet);
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
620
|
+
this.internalSetState({
|
|
621
|
+
isOpen: this.props.defaultIsOpen,
|
|
622
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
640
623
|
selectedItem: item,
|
|
641
|
-
inputValue:
|
|
642
|
-
|
|
624
|
+
inputValue: this.props.itemToString(item),
|
|
625
|
+
...otherStateToSet
|
|
626
|
+
}, cb);
|
|
643
627
|
};
|
|
644
628
|
|
|
645
|
-
|
|
646
|
-
|
|
629
|
+
this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
|
|
630
|
+
const item = this.items[itemIndex];
|
|
647
631
|
|
|
648
632
|
if (item == null) {
|
|
649
633
|
return;
|
|
650
634
|
}
|
|
651
635
|
|
|
652
|
-
|
|
636
|
+
this.selectItem(item, otherStateToSet, cb);
|
|
653
637
|
};
|
|
654
638
|
|
|
655
|
-
|
|
656
|
-
return
|
|
639
|
+
this.selectHighlightedItem = (otherStateToSet, cb) => {
|
|
640
|
+
return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
|
|
657
641
|
};
|
|
658
642
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
643
|
+
this.internalSetState = (stateToSet, cb) => {
|
|
644
|
+
let isItemSelected, onChangeArg;
|
|
645
|
+
const onStateChangeArg = {};
|
|
646
|
+
const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
|
|
663
647
|
// so someone controlling the `inputValue` state gets notified of
|
|
664
648
|
// the input change as soon as possible. This avoids issues with
|
|
665
649
|
// preserving the cursor position.
|
|
666
650
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
667
651
|
|
|
668
652
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
669
|
-
|
|
653
|
+
this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
654
|
+
...stateToSet
|
|
655
|
+
});
|
|
670
656
|
}
|
|
671
657
|
|
|
672
|
-
return
|
|
673
|
-
state =
|
|
674
|
-
|
|
658
|
+
return this.setState(state => {
|
|
659
|
+
state = this.getState(state);
|
|
660
|
+
let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
|
|
675
661
|
|
|
676
|
-
newStateToSet =
|
|
662
|
+
newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
|
|
677
663
|
// what was selected before
|
|
678
664
|
// used to determine if onSelect and onChange callbacks should be called
|
|
679
665
|
|
|
680
666
|
isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
|
|
681
667
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
|
|
668
|
+
const nextState = {}; // this is just used to tell whether the state changed
|
|
685
669
|
// and we're trying to update that state. OR if the selection has changed and we're
|
|
686
670
|
// trying to update the selection
|
|
687
671
|
|
|
@@ -690,7 +674,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
690
674
|
}
|
|
691
675
|
|
|
692
676
|
newStateToSet.type = newStateToSet.type || unknown;
|
|
693
|
-
Object.keys(newStateToSet).forEach(
|
|
677
|
+
Object.keys(newStateToSet).forEach(key => {
|
|
694
678
|
// onStateChangeArg should only have the state that is
|
|
695
679
|
// actually changing
|
|
696
680
|
if (state[key] !== newStateToSet[key]) {
|
|
@@ -707,81 +691,84 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
707
691
|
return;
|
|
708
692
|
}
|
|
709
693
|
|
|
710
|
-
|
|
694
|
+
newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
|
|
711
695
|
|
|
712
|
-
if (!isControlledProp(
|
|
696
|
+
if (!isControlledProp(this.props, key)) {
|
|
713
697
|
nextState[key] = newStateToSet[key];
|
|
714
698
|
}
|
|
715
699
|
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
716
700
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
717
701
|
|
|
718
702
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
719
|
-
|
|
703
|
+
this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
704
|
+
...newStateToSet
|
|
705
|
+
});
|
|
720
706
|
}
|
|
721
707
|
|
|
722
708
|
return nextState;
|
|
723
|
-
},
|
|
709
|
+
}, () => {
|
|
724
710
|
// call the provided callback if it's a function
|
|
725
711
|
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
|
|
726
712
|
// we have relevant information to pass them.
|
|
727
713
|
|
|
728
|
-
|
|
714
|
+
const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
729
715
|
|
|
730
716
|
if (hasMoreStateThanType) {
|
|
731
|
-
|
|
717
|
+
this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
|
|
732
718
|
}
|
|
733
719
|
|
|
734
720
|
if (isItemSelected) {
|
|
735
|
-
|
|
721
|
+
this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
|
|
736
722
|
}
|
|
737
723
|
|
|
738
724
|
if (onChangeArg !== undefined) {
|
|
739
|
-
|
|
725
|
+
this.props.onChange(onChangeArg, this.getStateAndHelpers());
|
|
740
726
|
} // this is currently undocumented and therefore subject to change
|
|
741
727
|
// We'll try to not break it, but just be warned.
|
|
742
728
|
|
|
743
729
|
|
|
744
|
-
|
|
730
|
+
this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
|
|
745
731
|
});
|
|
746
732
|
};
|
|
747
733
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$4);
|
|
760
|
-
|
|
761
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
762
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
763
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
764
|
-
|
|
734
|
+
this.rootRef = node => this._rootNode = node;
|
|
735
|
+
|
|
736
|
+
this.getRootProps = function (_temp, _temp2) {
|
|
737
|
+
let {
|
|
738
|
+
refKey = 'ref',
|
|
739
|
+
ref,
|
|
740
|
+
...rest
|
|
741
|
+
} = _temp === void 0 ? {} : _temp;
|
|
742
|
+
let {
|
|
743
|
+
suppressRefError = false
|
|
744
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
765
745
|
// this is used in the render to know whether the user has called getRootProps.
|
|
766
746
|
// It uses that to know whether to apply the props automatically
|
|
767
747
|
_this.getRootProps.called = true;
|
|
768
748
|
_this.getRootProps.refKey = refKey;
|
|
769
749
|
_this.getRootProps.suppressRefError = suppressRefError;
|
|
770
750
|
|
|
771
|
-
|
|
772
|
-
|
|
751
|
+
const {
|
|
752
|
+
isOpen
|
|
753
|
+
} = _this.getState();
|
|
773
754
|
|
|
774
|
-
return
|
|
755
|
+
return {
|
|
756
|
+
[refKey]: handleRefs(ref, _this.rootRef),
|
|
757
|
+
role: 'combobox',
|
|
758
|
+
'aria-expanded': isOpen,
|
|
759
|
+
'aria-haspopup': 'listbox',
|
|
760
|
+
'aria-owns': isOpen ? _this.menuId : null,
|
|
761
|
+
'aria-labelledby': _this.labelId,
|
|
762
|
+
...rest
|
|
763
|
+
};
|
|
775
764
|
};
|
|
776
765
|
|
|
777
|
-
|
|
778
|
-
ArrowDown
|
|
779
|
-
var _this2 = this;
|
|
780
|
-
|
|
766
|
+
this.keyDownHandlers = {
|
|
767
|
+
ArrowDown(event) {
|
|
781
768
|
event.preventDefault();
|
|
782
769
|
|
|
783
770
|
if (this.getState().isOpen) {
|
|
784
|
-
|
|
771
|
+
const amount = event.shiftKey ? 5 : 1;
|
|
785
772
|
this.moveHighlightedIndex(amount, {
|
|
786
773
|
type: keyDownArrowDown
|
|
787
774
|
});
|
|
@@ -789,31 +776,27 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
789
776
|
this.internalSetState({
|
|
790
777
|
isOpen: true,
|
|
791
778
|
type: keyDownArrowDown
|
|
792
|
-
},
|
|
793
|
-
|
|
779
|
+
}, () => {
|
|
780
|
+
const itemCount = this.getItemCount();
|
|
794
781
|
|
|
795
782
|
if (itemCount > 0) {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
_this2.setHighlightedIndex(nextHighlightedIndex, {
|
|
783
|
+
const {
|
|
784
|
+
highlightedIndex
|
|
785
|
+
} = this.getState();
|
|
786
|
+
const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
787
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
804
788
|
type: keyDownArrowDown
|
|
805
789
|
});
|
|
806
790
|
}
|
|
807
791
|
});
|
|
808
792
|
}
|
|
809
793
|
},
|
|
810
|
-
ArrowUp: function ArrowUp(event) {
|
|
811
|
-
var _this3 = this;
|
|
812
794
|
|
|
795
|
+
ArrowUp(event) {
|
|
813
796
|
event.preventDefault();
|
|
814
797
|
|
|
815
798
|
if (this.getState().isOpen) {
|
|
816
|
-
|
|
799
|
+
const amount = event.shiftKey ? -5 : -1;
|
|
817
800
|
this.moveHighlightedIndex(amount, {
|
|
818
801
|
type: keyDownArrowUp
|
|
819
802
|
});
|
|
@@ -821,37 +804,36 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
821
804
|
this.internalSetState({
|
|
822
805
|
isOpen: true,
|
|
823
806
|
type: keyDownArrowUp
|
|
824
|
-
},
|
|
825
|
-
|
|
807
|
+
}, () => {
|
|
808
|
+
const itemCount = this.getItemCount();
|
|
826
809
|
|
|
827
810
|
if (itemCount > 0) {
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
_this3.setHighlightedIndex(nextHighlightedIndex, {
|
|
811
|
+
const {
|
|
812
|
+
highlightedIndex
|
|
813
|
+
} = this.getState();
|
|
814
|
+
const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
815
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
836
816
|
type: keyDownArrowUp
|
|
837
817
|
});
|
|
838
818
|
}
|
|
839
819
|
});
|
|
840
820
|
}
|
|
841
821
|
},
|
|
842
|
-
|
|
822
|
+
|
|
823
|
+
Enter(event) {
|
|
843
824
|
if (event.which === 229) {
|
|
844
825
|
return;
|
|
845
826
|
}
|
|
846
827
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
828
|
+
const {
|
|
829
|
+
isOpen,
|
|
830
|
+
highlightedIndex
|
|
831
|
+
} = this.getState();
|
|
850
832
|
|
|
851
833
|
if (isOpen && highlightedIndex != null) {
|
|
852
834
|
event.preventDefault();
|
|
853
|
-
|
|
854
|
-
|
|
835
|
+
const item = this.items[highlightedIndex];
|
|
836
|
+
const itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
855
837
|
|
|
856
838
|
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
857
839
|
return;
|
|
@@ -862,125 +844,131 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
862
844
|
});
|
|
863
845
|
}
|
|
864
846
|
},
|
|
865
|
-
|
|
847
|
+
|
|
848
|
+
Escape(event) {
|
|
866
849
|
event.preventDefault();
|
|
867
|
-
this.reset(
|
|
868
|
-
type: keyDownEscape
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
850
|
+
this.reset({
|
|
851
|
+
type: keyDownEscape,
|
|
852
|
+
...(!this.state.isOpen && {
|
|
853
|
+
selectedItem: null,
|
|
854
|
+
inputValue: ''
|
|
855
|
+
})
|
|
856
|
+
});
|
|
873
857
|
}
|
|
858
|
+
|
|
874
859
|
};
|
|
875
|
-
|
|
876
|
-
|
|
860
|
+
this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
|
|
861
|
+
|
|
862
|
+
' '(event) {
|
|
877
863
|
event.preventDefault();
|
|
878
864
|
this.toggleMenu({
|
|
879
865
|
type: keyDownSpaceButton
|
|
880
866
|
});
|
|
881
867
|
}
|
|
882
|
-
});
|
|
883
|
-
_this.inputKeyDownHandlers = _extends__default['default']({}, _this.keyDownHandlers, {
|
|
884
|
-
Home: function Home(event) {
|
|
885
|
-
var _this4 = this;
|
|
886
868
|
|
|
887
|
-
|
|
888
|
-
|
|
869
|
+
};
|
|
870
|
+
this.inputKeyDownHandlers = { ...this.keyDownHandlers,
|
|
871
|
+
|
|
872
|
+
Home(event) {
|
|
873
|
+
const {
|
|
874
|
+
isOpen
|
|
875
|
+
} = this.getState();
|
|
889
876
|
|
|
890
877
|
if (!isOpen) {
|
|
891
878
|
return;
|
|
892
879
|
}
|
|
893
880
|
|
|
894
881
|
event.preventDefault();
|
|
895
|
-
|
|
882
|
+
const itemCount = this.getItemCount();
|
|
896
883
|
|
|
897
884
|
if (itemCount <= 0 || !isOpen) {
|
|
898
885
|
return;
|
|
899
886
|
} // get next non-disabled starting downwards from 0 if that's disabled.
|
|
900
887
|
|
|
901
888
|
|
|
902
|
-
|
|
903
|
-
return _this4.getItemNodeFromIndex(index);
|
|
904
|
-
}, false);
|
|
889
|
+
const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
905
890
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
906
891
|
type: keyDownHome
|
|
907
892
|
});
|
|
908
893
|
},
|
|
909
|
-
End: function End(event) {
|
|
910
|
-
var _this5 = this;
|
|
911
894
|
|
|
912
|
-
|
|
913
|
-
|
|
895
|
+
End(event) {
|
|
896
|
+
const {
|
|
897
|
+
isOpen
|
|
898
|
+
} = this.getState();
|
|
914
899
|
|
|
915
900
|
if (!isOpen) {
|
|
916
901
|
return;
|
|
917
902
|
}
|
|
918
903
|
|
|
919
904
|
event.preventDefault();
|
|
920
|
-
|
|
905
|
+
const itemCount = this.getItemCount();
|
|
921
906
|
|
|
922
907
|
if (itemCount <= 0 || !isOpen) {
|
|
923
908
|
return;
|
|
924
909
|
} // get next non-disabled starting upwards from last index if that's disabled.
|
|
925
910
|
|
|
926
911
|
|
|
927
|
-
|
|
928
|
-
return _this5.getItemNodeFromIndex(index);
|
|
929
|
-
}, false);
|
|
912
|
+
const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
930
913
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
931
914
|
type: keyDownEnd
|
|
932
915
|
});
|
|
933
916
|
}
|
|
934
|
-
});
|
|
935
917
|
|
|
936
|
-
|
|
937
|
-
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
938
|
-
onClick = _ref3.onClick;
|
|
939
|
-
_ref3.onPress;
|
|
940
|
-
var onKeyDown = _ref3.onKeyDown,
|
|
941
|
-
onKeyUp = _ref3.onKeyUp,
|
|
942
|
-
onBlur = _ref3.onBlur,
|
|
943
|
-
rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded2$3);
|
|
944
|
-
|
|
945
|
-
var _this$getState5 = _this.getState(),
|
|
946
|
-
isOpen = _this$getState5.isOpen;
|
|
918
|
+
};
|
|
947
919
|
|
|
948
|
-
|
|
920
|
+
this.getToggleButtonProps = function (_temp3) {
|
|
921
|
+
let {
|
|
922
|
+
onClick,
|
|
923
|
+
onPress,
|
|
924
|
+
onKeyDown,
|
|
925
|
+
onKeyUp,
|
|
926
|
+
onBlur,
|
|
927
|
+
...rest
|
|
928
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
929
|
+
|
|
930
|
+
const {
|
|
931
|
+
isOpen
|
|
932
|
+
} = _this.getState();
|
|
933
|
+
|
|
934
|
+
const enabledEventHandlers = {
|
|
949
935
|
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
950
936
|
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
951
937
|
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
952
938
|
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
953
939
|
};
|
|
954
|
-
|
|
955
|
-
return
|
|
940
|
+
const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
941
|
+
return {
|
|
956
942
|
type: 'button',
|
|
957
943
|
role: 'button',
|
|
958
944
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
959
945
|
'aria-haspopup': true,
|
|
960
|
-
'data-toggle': true
|
|
961
|
-
|
|
946
|
+
'data-toggle': true,
|
|
947
|
+
...eventHandlers,
|
|
948
|
+
...rest
|
|
949
|
+
};
|
|
962
950
|
};
|
|
963
951
|
|
|
964
|
-
|
|
952
|
+
this.buttonHandleKeyUp = event => {
|
|
965
953
|
// Prevent click event from emitting in Firefox
|
|
966
954
|
event.preventDefault();
|
|
967
955
|
};
|
|
968
956
|
|
|
969
|
-
|
|
970
|
-
|
|
957
|
+
this.buttonHandleKeyDown = event => {
|
|
958
|
+
const key = normalizeArrowKey(event);
|
|
971
959
|
|
|
972
|
-
if (
|
|
973
|
-
|
|
960
|
+
if (this.buttonKeyDownHandlers[key]) {
|
|
961
|
+
this.buttonKeyDownHandlers[key].call(this, event);
|
|
974
962
|
}
|
|
975
963
|
};
|
|
976
964
|
|
|
977
|
-
|
|
965
|
+
this.buttonHandleClick = event => {
|
|
978
966
|
event.preventDefault(); // handle odd case for Safari and Firefox which
|
|
979
967
|
// don't give the button the focus properly.
|
|
980
968
|
|
|
981
969
|
/* istanbul ignore if (can't reasonably test this) */
|
|
982
970
|
|
|
983
|
-
if (
|
|
971
|
+
if (this.props.environment.document.activeElement === this.props.environment.document.body) {
|
|
984
972
|
event.target.focus();
|
|
985
973
|
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
986
974
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -988,69 +976,71 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
988
976
|
|
|
989
977
|
|
|
990
978
|
if (process.env.NODE_ENV === 'test') {
|
|
991
|
-
|
|
979
|
+
this.toggleMenu({
|
|
992
980
|
type: clickButton
|
|
993
981
|
});
|
|
994
982
|
} else {
|
|
995
983
|
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
});
|
|
1000
|
-
});
|
|
984
|
+
this.internalSetTimeout(() => this.toggleMenu({
|
|
985
|
+
type: clickButton
|
|
986
|
+
}));
|
|
1001
987
|
}
|
|
1002
988
|
};
|
|
1003
989
|
|
|
1004
|
-
|
|
1005
|
-
|
|
990
|
+
this.buttonHandleBlur = event => {
|
|
991
|
+
const blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
1006
992
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
1007
993
|
|
|
1008
|
-
|
|
1009
|
-
if (!
|
|
994
|
+
this.internalSetTimeout(() => {
|
|
995
|
+
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)
|
|
1010
996
|
) {
|
|
1011
|
-
|
|
997
|
+
this.reset({
|
|
1012
998
|
type: blurButton
|
|
1013
999
|
});
|
|
1014
1000
|
}
|
|
1015
1001
|
});
|
|
1016
1002
|
};
|
|
1017
1003
|
|
|
1018
|
-
|
|
1019
|
-
return
|
|
1020
|
-
htmlFor:
|
|
1021
|
-
id:
|
|
1022
|
-
|
|
1004
|
+
this.getLabelProps = props => {
|
|
1005
|
+
return {
|
|
1006
|
+
htmlFor: this.inputId,
|
|
1007
|
+
id: this.labelId,
|
|
1008
|
+
...props
|
|
1009
|
+
};
|
|
1023
1010
|
};
|
|
1024
1011
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1012
|
+
this.getInputProps = function (_temp4) {
|
|
1013
|
+
let {
|
|
1014
|
+
onKeyDown,
|
|
1015
|
+
onBlur,
|
|
1016
|
+
onChange,
|
|
1017
|
+
onInput,
|
|
1018
|
+
onChangeText,
|
|
1019
|
+
...rest
|
|
1020
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
1021
|
+
let onChangeKey;
|
|
1022
|
+
let eventHandlers = {};
|
|
1036
1023
|
/* istanbul ignore next (preact) */
|
|
1037
1024
|
|
|
1038
1025
|
{
|
|
1039
1026
|
onChangeKey = 'onInput';
|
|
1040
1027
|
}
|
|
1041
1028
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1029
|
+
const {
|
|
1030
|
+
inputValue,
|
|
1031
|
+
isOpen,
|
|
1032
|
+
highlightedIndex
|
|
1033
|
+
} = _this.getState();
|
|
1046
1034
|
|
|
1047
1035
|
if (!rest.disabled) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1036
|
+
eventHandlers = {
|
|
1037
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
|
|
1038
|
+
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
|
|
1039
|
+
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
1040
|
+
};
|
|
1051
1041
|
}
|
|
1052
1042
|
|
|
1053
|
-
return
|
|
1043
|
+
return {
|
|
1054
1044
|
'aria-autocomplete': 'list',
|
|
1055
1045
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
1056
1046
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -1059,77 +1049,79 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1059
1049
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
1060
1050
|
autoComplete: 'off',
|
|
1061
1051
|
value: inputValue,
|
|
1062
|
-
id: _this.inputId
|
|
1063
|
-
|
|
1052
|
+
id: _this.inputId,
|
|
1053
|
+
...eventHandlers,
|
|
1054
|
+
...rest
|
|
1055
|
+
};
|
|
1064
1056
|
};
|
|
1065
1057
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1058
|
+
this.inputHandleKeyDown = event => {
|
|
1059
|
+
const key = normalizeArrowKey(event);
|
|
1068
1060
|
|
|
1069
|
-
if (key &&
|
|
1070
|
-
|
|
1061
|
+
if (key && this.inputKeyDownHandlers[key]) {
|
|
1062
|
+
this.inputKeyDownHandlers[key].call(this, event);
|
|
1071
1063
|
}
|
|
1072
1064
|
};
|
|
1073
1065
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1066
|
+
this.inputHandleChange = event => {
|
|
1067
|
+
this.internalSetState({
|
|
1076
1068
|
type: changeInput,
|
|
1077
1069
|
isOpen: true,
|
|
1078
1070
|
inputValue: event.target.value,
|
|
1079
|
-
highlightedIndex:
|
|
1071
|
+
highlightedIndex: this.props.defaultHighlightedIndex
|
|
1080
1072
|
});
|
|
1081
1073
|
};
|
|
1082
1074
|
|
|
1083
|
-
|
|
1075
|
+
this.inputHandleBlur = () => {
|
|
1084
1076
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
1085
|
-
|
|
1086
|
-
|
|
1077
|
+
this.internalSetTimeout(() => {
|
|
1078
|
+
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);
|
|
1087
1079
|
|
|
1088
|
-
if (!
|
|
1089
|
-
|
|
1080
|
+
if (!this.isMouseDown && !downshiftButtonIsActive) {
|
|
1081
|
+
this.reset({
|
|
1090
1082
|
type: blurInput
|
|
1091
1083
|
});
|
|
1092
1084
|
}
|
|
1093
1085
|
});
|
|
1094
1086
|
};
|
|
1095
1087
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1088
|
+
this.menuRef = node => {
|
|
1089
|
+
this._menuNode = node;
|
|
1098
1090
|
};
|
|
1099
1091
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
1110
|
-
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
1111
|
-
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
1112
|
-
|
|
1092
|
+
this.getMenuProps = function (_temp5, _temp6) {
|
|
1093
|
+
let {
|
|
1094
|
+
refKey = 'ref',
|
|
1095
|
+
ref,
|
|
1096
|
+
...props
|
|
1097
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
1098
|
+
let {
|
|
1099
|
+
suppressRefError = false
|
|
1100
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
1113
1101
|
_this.getMenuProps.called = true;
|
|
1114
1102
|
_this.getMenuProps.refKey = refKey;
|
|
1115
1103
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
1116
|
-
return
|
|
1104
|
+
return {
|
|
1105
|
+
[refKey]: handleRefs(ref, _this.menuRef),
|
|
1106
|
+
role: 'listbox',
|
|
1107
|
+
'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
|
|
1108
|
+
id: _this.menuId,
|
|
1109
|
+
...props
|
|
1110
|
+
};
|
|
1117
1111
|
};
|
|
1118
1112
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
undefined : requiredProp('getItemProps', 'item') : _ref7$item,
|
|
1132
|
-
rest = _objectWithoutPropertiesLoose__default['default'](_ref7, _excluded5$1);
|
|
1113
|
+
this.getItemProps = function (_temp7) {
|
|
1114
|
+
let {
|
|
1115
|
+
onMouseMove,
|
|
1116
|
+
onMouseDown,
|
|
1117
|
+
onClick,
|
|
1118
|
+
onPress,
|
|
1119
|
+
index,
|
|
1120
|
+
item = process.env.NODE_ENV === 'production' ?
|
|
1121
|
+
/* istanbul ignore next */
|
|
1122
|
+
undefined : requiredProp('getItemProps', 'item'),
|
|
1123
|
+
...rest
|
|
1124
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
1133
1125
|
|
|
1134
1126
|
if (index === undefined) {
|
|
1135
1127
|
_this.items.push(item);
|
|
@@ -1139,13 +1131,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1139
1131
|
_this.items[index] = item;
|
|
1140
1132
|
}
|
|
1141
1133
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1134
|
+
const onSelectKey = 'onClick';
|
|
1135
|
+
const customClickHandler = onClick;
|
|
1136
|
+
const enabledEventHandlers = {
|
|
1145
1137
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
1146
1138
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
1147
1139
|
// can fire on DOM changes, interrupting keyboard navigation
|
|
1148
|
-
onMouseMove: callAllEventHandlers(onMouseMove,
|
|
1140
|
+
onMouseMove: callAllEventHandlers(onMouseMove, () => {
|
|
1149
1141
|
if (index === _this.getState().highlightedIndex) {
|
|
1150
1142
|
return;
|
|
1151
1143
|
}
|
|
@@ -1160,72 +1152,81 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1160
1152
|
|
|
1161
1153
|
_this.avoidScrolling = true;
|
|
1162
1154
|
|
|
1163
|
-
_this.internalSetTimeout(
|
|
1164
|
-
return _this.avoidScrolling = false;
|
|
1165
|
-
}, 250);
|
|
1155
|
+
_this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
|
|
1166
1156
|
}),
|
|
1167
|
-
onMouseDown: callAllEventHandlers(onMouseDown,
|
|
1157
|
+
onMouseDown: callAllEventHandlers(onMouseDown, event => {
|
|
1168
1158
|
// This prevents the activeElement from being changed
|
|
1169
1159
|
// to the item so it can remain with the current activeElement
|
|
1170
1160
|
// which is a more common use case.
|
|
1171
1161
|
event.preventDefault();
|
|
1162
|
+
}),
|
|
1163
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, () => {
|
|
1164
|
+
_this.selectItemAtIndex(index, {
|
|
1165
|
+
type: clickItem
|
|
1166
|
+
});
|
|
1172
1167
|
})
|
|
1173
|
-
}
|
|
1174
|
-
_this.selectItemAtIndex(index, {
|
|
1175
|
-
type: clickItem
|
|
1176
|
-
});
|
|
1177
|
-
}), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
|
|
1168
|
+
}; // Passing down the onMouseDown handler to prevent redirect
|
|
1178
1169
|
// of the activeElement if clicking on disabled items
|
|
1179
1170
|
|
|
1180
|
-
|
|
1171
|
+
const eventHandlers = rest.disabled ? {
|
|
1181
1172
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
1182
1173
|
} : enabledEventHandlers;
|
|
1183
|
-
return
|
|
1174
|
+
return {
|
|
1184
1175
|
id: _this.getItemId(index),
|
|
1185
1176
|
role: 'option',
|
|
1186
|
-
'aria-selected': _this.getState().highlightedIndex === index
|
|
1187
|
-
|
|
1177
|
+
'aria-selected': _this.getState().highlightedIndex === index,
|
|
1178
|
+
...eventHandlers,
|
|
1179
|
+
...rest
|
|
1180
|
+
};
|
|
1188
1181
|
};
|
|
1189
1182
|
|
|
1190
|
-
|
|
1191
|
-
|
|
1183
|
+
this.clearItems = () => {
|
|
1184
|
+
this.items = [];
|
|
1192
1185
|
};
|
|
1193
1186
|
|
|
1194
|
-
|
|
1187
|
+
this.reset = function (otherStateToSet, cb) {
|
|
1195
1188
|
if (otherStateToSet === void 0) {
|
|
1196
1189
|
otherStateToSet = {};
|
|
1197
1190
|
}
|
|
1198
1191
|
|
|
1199
1192
|
otherStateToSet = pickState(otherStateToSet);
|
|
1200
1193
|
|
|
1201
|
-
_this.internalSetState(
|
|
1202
|
-
|
|
1203
|
-
|
|
1194
|
+
_this.internalSetState(_ref => {
|
|
1195
|
+
let {
|
|
1196
|
+
selectedItem
|
|
1197
|
+
} = _ref;
|
|
1198
|
+
return {
|
|
1204
1199
|
isOpen: _this.props.defaultIsOpen,
|
|
1205
1200
|
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1206
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
1207
|
-
|
|
1201
|
+
inputValue: _this.props.itemToString(selectedItem),
|
|
1202
|
+
...otherStateToSet
|
|
1203
|
+
};
|
|
1208
1204
|
}, cb);
|
|
1209
1205
|
};
|
|
1210
1206
|
|
|
1211
|
-
|
|
1207
|
+
this.toggleMenu = function (otherStateToSet, cb) {
|
|
1212
1208
|
if (otherStateToSet === void 0) {
|
|
1213
1209
|
otherStateToSet = {};
|
|
1214
1210
|
}
|
|
1215
1211
|
|
|
1216
1212
|
otherStateToSet = pickState(otherStateToSet);
|
|
1217
1213
|
|
|
1218
|
-
_this.internalSetState(
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1214
|
+
_this.internalSetState(_ref2 => {
|
|
1215
|
+
let {
|
|
1216
|
+
isOpen
|
|
1217
|
+
} = _ref2;
|
|
1218
|
+
return {
|
|
1219
|
+
isOpen: !isOpen,
|
|
1220
|
+
...(isOpen && {
|
|
1221
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
1222
|
+
}),
|
|
1223
|
+
...otherStateToSet
|
|
1224
|
+
};
|
|
1225
|
+
}, () => {
|
|
1226
|
+
const {
|
|
1227
|
+
isOpen,
|
|
1228
|
+
highlightedIndex
|
|
1229
|
+
} = _this.getState();
|
|
1229
1230
|
|
|
1230
1231
|
if (isOpen) {
|
|
1231
1232
|
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
@@ -1237,70 +1238,63 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1237
1238
|
});
|
|
1238
1239
|
};
|
|
1239
1240
|
|
|
1240
|
-
|
|
1241
|
-
|
|
1241
|
+
this.openMenu = cb => {
|
|
1242
|
+
this.internalSetState({
|
|
1242
1243
|
isOpen: true
|
|
1243
1244
|
}, cb);
|
|
1244
1245
|
};
|
|
1245
1246
|
|
|
1246
|
-
|
|
1247
|
-
|
|
1247
|
+
this.closeMenu = cb => {
|
|
1248
|
+
this.internalSetState({
|
|
1248
1249
|
isOpen: false
|
|
1249
1250
|
}, cb);
|
|
1250
1251
|
};
|
|
1251
1252
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
_this.previousResultCount = resultCount;
|
|
1267
|
-
setStatus(status, _this.props.environment.document);
|
|
1253
|
+
this.updateStatus = debounce(() => {
|
|
1254
|
+
const state = this.getState();
|
|
1255
|
+
const item = this.items[state.highlightedIndex];
|
|
1256
|
+
const resultCount = this.getItemCount();
|
|
1257
|
+
const status = this.props.getA11yStatusMessage({
|
|
1258
|
+
itemToString: this.props.itemToString,
|
|
1259
|
+
previousResultCount: this.previousResultCount,
|
|
1260
|
+
resultCount,
|
|
1261
|
+
highlightedItem: item,
|
|
1262
|
+
...state
|
|
1263
|
+
});
|
|
1264
|
+
this.previousResultCount = resultCount;
|
|
1265
|
+
setStatus(status, this.props.environment.document);
|
|
1268
1266
|
}, 200);
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
var _state = _this.getState({
|
|
1267
|
+
// fancy destructuring + defaults + aliases
|
|
1268
|
+
// this basically says each value of state should either be set to
|
|
1269
|
+
// the initial value or the default value if the initial value is not provided
|
|
1270
|
+
const {
|
|
1271
|
+
defaultHighlightedIndex,
|
|
1272
|
+
initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
|
|
1273
|
+
defaultIsOpen,
|
|
1274
|
+
initialIsOpen: _isOpen = defaultIsOpen,
|
|
1275
|
+
initialInputValue: _inputValue = '',
|
|
1276
|
+
initialSelectedItem: _selectedItem = null
|
|
1277
|
+
} = this.props;
|
|
1278
|
+
|
|
1279
|
+
const _state = this.getState({
|
|
1283
1280
|
highlightedIndex: _highlightedIndex,
|
|
1284
1281
|
isOpen: _isOpen,
|
|
1285
1282
|
inputValue: _inputValue,
|
|
1286
1283
|
selectedItem: _selectedItem
|
|
1287
1284
|
});
|
|
1288
1285
|
|
|
1289
|
-
if (_state.selectedItem != null &&
|
|
1290
|
-
_state.inputValue =
|
|
1286
|
+
if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
|
|
1287
|
+
_state.inputValue = this.props.itemToString(_state.selectedItem);
|
|
1291
1288
|
}
|
|
1292
1289
|
|
|
1293
|
-
|
|
1294
|
-
return _this;
|
|
1290
|
+
this.state = _state;
|
|
1295
1291
|
}
|
|
1296
1292
|
|
|
1297
|
-
var _proto = Downshift.prototype;
|
|
1298
|
-
|
|
1299
1293
|
/**
|
|
1300
1294
|
* Clear all running timeouts
|
|
1301
1295
|
*/
|
|
1302
|
-
|
|
1303
|
-
this.timeoutIds.forEach(
|
|
1296
|
+
internalClearTimeouts() {
|
|
1297
|
+
this.timeoutIds.forEach(id => {
|
|
1304
1298
|
clearTimeout(id);
|
|
1305
1299
|
});
|
|
1306
1300
|
this.timeoutIds = [];
|
|
@@ -1314,22 +1308,22 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1314
1308
|
* @param {Object} stateToMerge defaults to this.state
|
|
1315
1309
|
* @return {Object} the state
|
|
1316
1310
|
*/
|
|
1317
|
-
;
|
|
1318
1311
|
|
|
1319
|
-
|
|
1312
|
+
|
|
1313
|
+
getState(stateToMerge) {
|
|
1320
1314
|
if (stateToMerge === void 0) {
|
|
1321
1315
|
stateToMerge = this.state;
|
|
1322
1316
|
}
|
|
1323
1317
|
|
|
1324
1318
|
return getState(stateToMerge, this.props);
|
|
1325
|
-
}
|
|
1319
|
+
}
|
|
1326
1320
|
|
|
1327
|
-
|
|
1321
|
+
getItemCount() {
|
|
1328
1322
|
// things read better this way. They're in priority order:
|
|
1329
1323
|
// 1. `this.itemCount`
|
|
1330
1324
|
// 2. `this.props.itemCount`
|
|
1331
1325
|
// 3. `this.items.length`
|
|
1332
|
-
|
|
1326
|
+
let itemCount = this.items.length;
|
|
1333
1327
|
|
|
1334
1328
|
if (this.itemCount != null) {
|
|
1335
1329
|
itemCount = this.itemCount;
|
|
@@ -1338,102 +1332,102 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1338
1332
|
}
|
|
1339
1333
|
|
|
1340
1334
|
return itemCount;
|
|
1341
|
-
}
|
|
1335
|
+
}
|
|
1342
1336
|
|
|
1343
|
-
|
|
1337
|
+
getItemNodeFromIndex(index) {
|
|
1344
1338
|
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
1345
|
-
}
|
|
1339
|
+
}
|
|
1346
1340
|
|
|
1347
|
-
|
|
1341
|
+
scrollHighlightedItemIntoView() {
|
|
1348
1342
|
/* istanbul ignore else (react-native) */
|
|
1349
1343
|
{
|
|
1350
|
-
|
|
1344
|
+
const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
1351
1345
|
this.props.scrollIntoView(node, this._menuNode);
|
|
1352
1346
|
}
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
_proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
|
1356
|
-
var _this6 = this;
|
|
1357
|
-
|
|
1358
|
-
var itemCount = this.getItemCount();
|
|
1347
|
+
}
|
|
1359
1348
|
|
|
1360
|
-
|
|
1361
|
-
|
|
1349
|
+
moveHighlightedIndex(amount, otherStateToSet) {
|
|
1350
|
+
const itemCount = this.getItemCount();
|
|
1351
|
+
const {
|
|
1352
|
+
highlightedIndex
|
|
1353
|
+
} = this.getState();
|
|
1362
1354
|
|
|
1363
1355
|
if (itemCount > 0) {
|
|
1364
|
-
|
|
1365
|
-
return _this6.getItemNodeFromIndex(index);
|
|
1366
|
-
});
|
|
1356
|
+
const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
1367
1357
|
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
1368
1358
|
}
|
|
1369
|
-
}
|
|
1359
|
+
}
|
|
1370
1360
|
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1361
|
+
getStateAndHelpers() {
|
|
1362
|
+
const {
|
|
1363
|
+
highlightedIndex,
|
|
1364
|
+
inputValue,
|
|
1365
|
+
selectedItem,
|
|
1366
|
+
isOpen
|
|
1367
|
+
} = this.getState();
|
|
1368
|
+
const {
|
|
1369
|
+
itemToString
|
|
1370
|
+
} = this.props;
|
|
1371
|
+
const {
|
|
1372
|
+
id
|
|
1373
|
+
} = this;
|
|
1374
|
+
const {
|
|
1375
|
+
getRootProps,
|
|
1376
|
+
getToggleButtonProps,
|
|
1377
|
+
getLabelProps,
|
|
1378
|
+
getMenuProps,
|
|
1379
|
+
getInputProps,
|
|
1380
|
+
getItemProps,
|
|
1381
|
+
openMenu,
|
|
1382
|
+
closeMenu,
|
|
1383
|
+
toggleMenu,
|
|
1384
|
+
selectItem,
|
|
1385
|
+
selectItemAtIndex,
|
|
1386
|
+
selectHighlightedItem,
|
|
1387
|
+
setHighlightedIndex,
|
|
1388
|
+
clearSelection,
|
|
1389
|
+
clearItems,
|
|
1390
|
+
reset,
|
|
1391
|
+
setItemCount,
|
|
1392
|
+
unsetItemCount,
|
|
1393
|
+
internalSetState: setState
|
|
1394
|
+
} = this;
|
|
1399
1395
|
return {
|
|
1400
1396
|
// prop getters
|
|
1401
|
-
getRootProps
|
|
1402
|
-
getToggleButtonProps
|
|
1403
|
-
getLabelProps
|
|
1404
|
-
getMenuProps
|
|
1405
|
-
getInputProps
|
|
1406
|
-
getItemProps
|
|
1397
|
+
getRootProps,
|
|
1398
|
+
getToggleButtonProps,
|
|
1399
|
+
getLabelProps,
|
|
1400
|
+
getMenuProps,
|
|
1401
|
+
getInputProps,
|
|
1402
|
+
getItemProps,
|
|
1407
1403
|
// actions
|
|
1408
|
-
reset
|
|
1409
|
-
openMenu
|
|
1410
|
-
closeMenu
|
|
1411
|
-
toggleMenu
|
|
1412
|
-
selectItem
|
|
1413
|
-
selectItemAtIndex
|
|
1414
|
-
selectHighlightedItem
|
|
1415
|
-
setHighlightedIndex
|
|
1416
|
-
clearSelection
|
|
1417
|
-
clearItems
|
|
1418
|
-
setItemCount
|
|
1419
|
-
unsetItemCount
|
|
1420
|
-
setState
|
|
1404
|
+
reset,
|
|
1405
|
+
openMenu,
|
|
1406
|
+
closeMenu,
|
|
1407
|
+
toggleMenu,
|
|
1408
|
+
selectItem,
|
|
1409
|
+
selectItemAtIndex,
|
|
1410
|
+
selectHighlightedItem,
|
|
1411
|
+
setHighlightedIndex,
|
|
1412
|
+
clearSelection,
|
|
1413
|
+
clearItems,
|
|
1414
|
+
setItemCount,
|
|
1415
|
+
unsetItemCount,
|
|
1416
|
+
setState,
|
|
1421
1417
|
// props
|
|
1422
|
-
itemToString
|
|
1418
|
+
itemToString,
|
|
1423
1419
|
// derived
|
|
1424
|
-
id
|
|
1420
|
+
id,
|
|
1425
1421
|
// state
|
|
1426
|
-
highlightedIndex
|
|
1427
|
-
inputValue
|
|
1428
|
-
isOpen
|
|
1429
|
-
selectedItem
|
|
1422
|
+
highlightedIndex,
|
|
1423
|
+
inputValue,
|
|
1424
|
+
isOpen,
|
|
1425
|
+
selectedItem
|
|
1430
1426
|
};
|
|
1431
1427
|
} //////////////////////////// ROOT
|
|
1432
|
-
;
|
|
1433
1428
|
|
|
1434
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
1435
|
-
var _this7 = this;
|
|
1436
1429
|
|
|
1430
|
+
componentDidMount() {
|
|
1437
1431
|
/* istanbul ignore if (react-native) */
|
|
1438
1432
|
if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
1439
1433
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
@@ -1447,22 +1441,20 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1447
1441
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
1448
1442
|
// this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
|
|
1449
1443
|
// trigger hiding the menu.
|
|
1450
|
-
|
|
1451
|
-
|
|
1444
|
+
const onMouseDown = () => {
|
|
1445
|
+
this.isMouseDown = true;
|
|
1452
1446
|
};
|
|
1453
1447
|
|
|
1454
|
-
|
|
1455
|
-
|
|
1448
|
+
const onMouseUp = event => {
|
|
1449
|
+
this.isMouseDown = false; // if the target element or the activeElement is within a downshift node
|
|
1456
1450
|
// then we don't want to reset downshift
|
|
1457
1451
|
|
|
1458
|
-
|
|
1452
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
|
|
1459
1453
|
|
|
1460
|
-
if (!contextWithinDownshift &&
|
|
1461
|
-
|
|
1454
|
+
if (!contextWithinDownshift && this.getState().isOpen) {
|
|
1455
|
+
this.reset({
|
|
1462
1456
|
type: mouseUp
|
|
1463
|
-
},
|
|
1464
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
1465
|
-
});
|
|
1457
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
1466
1458
|
}
|
|
1467
1459
|
}; // Touching an element in iOS gives focus and hover states, but touching out of
|
|
1468
1460
|
// the element will remove hover, and persist the focus state, resulting in the
|
|
@@ -1472,38 +1464,36 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1472
1464
|
// but not if the user is swiping
|
|
1473
1465
|
|
|
1474
1466
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1467
|
+
const onTouchStart = () => {
|
|
1468
|
+
this.isTouchMove = false;
|
|
1477
1469
|
};
|
|
1478
1470
|
|
|
1479
|
-
|
|
1480
|
-
|
|
1471
|
+
const onTouchMove = () => {
|
|
1472
|
+
this.isTouchMove = true;
|
|
1481
1473
|
};
|
|
1482
1474
|
|
|
1483
|
-
|
|
1484
|
-
|
|
1475
|
+
const onTouchEnd = event => {
|
|
1476
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
|
|
1485
1477
|
|
|
1486
|
-
if (!
|
|
1487
|
-
|
|
1478
|
+
if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
|
|
1479
|
+
this.reset({
|
|
1488
1480
|
type: touchEnd
|
|
1489
|
-
},
|
|
1490
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
1491
|
-
});
|
|
1481
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
1492
1482
|
}
|
|
1493
1483
|
};
|
|
1494
1484
|
|
|
1495
|
-
|
|
1485
|
+
const {
|
|
1486
|
+
environment
|
|
1487
|
+
} = this.props;
|
|
1496
1488
|
environment.addEventListener('mousedown', onMouseDown);
|
|
1497
1489
|
environment.addEventListener('mouseup', onMouseUp);
|
|
1498
1490
|
environment.addEventListener('touchstart', onTouchStart);
|
|
1499
1491
|
environment.addEventListener('touchmove', onTouchMove);
|
|
1500
1492
|
environment.addEventListener('touchend', onTouchEnd);
|
|
1501
1493
|
|
|
1502
|
-
this.cleanup =
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
_this7.updateStatus.cancel();
|
|
1506
|
-
|
|
1494
|
+
this.cleanup = () => {
|
|
1495
|
+
this.internalClearTimeouts();
|
|
1496
|
+
this.updateStatus.cancel();
|
|
1507
1497
|
environment.removeEventListener('mousedown', onMouseDown);
|
|
1508
1498
|
environment.removeEventListener('mouseup', onMouseUp);
|
|
1509
1499
|
environment.removeEventListener('touchstart', onTouchStart);
|
|
@@ -1511,21 +1501,21 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1511
1501
|
environment.removeEventListener('touchend', onTouchEnd);
|
|
1512
1502
|
};
|
|
1513
1503
|
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
_proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
|
1517
|
-
var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
|
1518
|
-
currentHighlightedIndex = _ref10.highlightedIndex;
|
|
1519
|
-
|
|
1520
|
-
var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
|
1521
|
-
prevHighlightedIndex = _ref11.highlightedIndex;
|
|
1504
|
+
}
|
|
1522
1505
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1506
|
+
shouldScroll(prevState, prevProps) {
|
|
1507
|
+
const {
|
|
1508
|
+
highlightedIndex: currentHighlightedIndex
|
|
1509
|
+
} = this.props.highlightedIndex === undefined ? this.getState() : this.props;
|
|
1510
|
+
const {
|
|
1511
|
+
highlightedIndex: prevHighlightedIndex
|
|
1512
|
+
} = prevProps.highlightedIndex === undefined ? prevState : prevProps;
|
|
1513
|
+
const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
1514
|
+
const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
1525
1515
|
return scrollWhenOpen || scrollWhenNavigating;
|
|
1526
|
-
}
|
|
1516
|
+
}
|
|
1527
1517
|
|
|
1528
|
-
|
|
1518
|
+
componentDidUpdate(prevProps, prevState) {
|
|
1529
1519
|
if (process.env.NODE_ENV !== 'production') {
|
|
1530
1520
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
1531
1521
|
/* istanbul ignore if (react-native) */
|
|
@@ -1551,14 +1541,14 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1551
1541
|
{
|
|
1552
1542
|
this.updateStatus();
|
|
1553
1543
|
}
|
|
1554
|
-
}
|
|
1544
|
+
}
|
|
1555
1545
|
|
|
1556
|
-
|
|
1546
|
+
componentWillUnmount() {
|
|
1557
1547
|
this.cleanup(); // avoids memory leak
|
|
1558
|
-
}
|
|
1548
|
+
}
|
|
1559
1549
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1550
|
+
render() {
|
|
1551
|
+
const children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
|
|
1562
1552
|
// we clear this out each render and it will be populated again as
|
|
1563
1553
|
// getItemProps is called.
|
|
1564
1554
|
|
|
@@ -1578,7 +1568,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1578
1568
|
this.getLabelProps.called = false; // and something similar for getInputProps
|
|
1579
1569
|
|
|
1580
1570
|
this.getInputProps.called = false;
|
|
1581
|
-
|
|
1571
|
+
const element = unwrapArray(children(this.getStateAndHelpers()));
|
|
1582
1572
|
|
|
1583
1573
|
if (!element) {
|
|
1584
1574
|
return null;
|
|
@@ -1607,16 +1597,15 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1607
1597
|
|
|
1608
1598
|
|
|
1609
1599
|
return undefined;
|
|
1610
|
-
}
|
|
1600
|
+
}
|
|
1611
1601
|
|
|
1612
|
-
|
|
1613
|
-
}(preact.Component);
|
|
1602
|
+
}
|
|
1614
1603
|
|
|
1615
1604
|
Downshift.defaultProps = {
|
|
1616
1605
|
defaultHighlightedIndex: null,
|
|
1617
1606
|
defaultIsOpen: false,
|
|
1618
1607
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
1619
|
-
itemToString:
|
|
1608
|
+
itemToString: i => {
|
|
1620
1609
|
if (i == null) {
|
|
1621
1610
|
return '';
|
|
1622
1611
|
}
|
|
@@ -1634,26 +1623,24 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1634
1623
|
onChange: noop,
|
|
1635
1624
|
onSelect: noop,
|
|
1636
1625
|
onOuterClick: noop,
|
|
1637
|
-
selectedItemChanged:
|
|
1638
|
-
return prevItem !== item;
|
|
1639
|
-
},
|
|
1626
|
+
selectedItemChanged: (prevItem, item) => prevItem !== item,
|
|
1640
1627
|
environment:
|
|
1641
1628
|
/* istanbul ignore next (ssr) */
|
|
1642
1629
|
typeof window === 'undefined' ? {} : window,
|
|
1643
|
-
stateReducer:
|
|
1644
|
-
return stateToSet;
|
|
1645
|
-
},
|
|
1630
|
+
stateReducer: (state, stateToSet) => stateToSet,
|
|
1646
1631
|
suppressRefError: false,
|
|
1647
|
-
scrollIntoView
|
|
1632
|
+
scrollIntoView
|
|
1648
1633
|
};
|
|
1649
1634
|
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
1650
1635
|
return Downshift;
|
|
1651
|
-
}();
|
|
1636
|
+
})();
|
|
1652
1637
|
|
|
1653
1638
|
var Downshift$1 = Downshift;
|
|
1654
1639
|
|
|
1655
|
-
function validateGetMenuPropsCalledCorrectly(node,
|
|
1656
|
-
|
|
1640
|
+
function validateGetMenuPropsCalledCorrectly(node, _ref3) {
|
|
1641
|
+
let {
|
|
1642
|
+
refKey
|
|
1643
|
+
} = _ref3;
|
|
1657
1644
|
|
|
1658
1645
|
if (!node) {
|
|
1659
1646
|
// eslint-disable-next-line no-console
|
|
@@ -1661,10 +1648,12 @@ function validateGetMenuPropsCalledCorrectly(node, _ref12) {
|
|
|
1661
1648
|
}
|
|
1662
1649
|
}
|
|
1663
1650
|
|
|
1664
|
-
function validateGetRootPropsCalledCorrectly(element,
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1651
|
+
function validateGetRootPropsCalledCorrectly(element, _ref4) {
|
|
1652
|
+
let {
|
|
1653
|
+
refKey
|
|
1654
|
+
} = _ref4;
|
|
1655
|
+
const refKeySpecified = refKey !== 'ref';
|
|
1656
|
+
const isComposite = !isDOMElement(element);
|
|
1668
1657
|
|
|
1669
1658
|
if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
|
|
1670
1659
|
// eslint-disable-next-line no-console
|
|
@@ -1680,8 +1669,7 @@ function validateGetRootPropsCalledCorrectly(element, _ref13) {
|
|
|
1680
1669
|
}
|
|
1681
1670
|
}
|
|
1682
1671
|
|
|
1683
|
-
|
|
1684
|
-
var dropdownDefaultStateValues = {
|
|
1672
|
+
const dropdownDefaultStateValues = {
|
|
1685
1673
|
highlightedIndex: -1,
|
|
1686
1674
|
isOpen: false,
|
|
1687
1675
|
selectedItem: null,
|
|
@@ -1689,10 +1677,12 @@ var dropdownDefaultStateValues = {
|
|
|
1689
1677
|
};
|
|
1690
1678
|
|
|
1691
1679
|
function callOnChangeProps(action, state, newState) {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1680
|
+
const {
|
|
1681
|
+
props,
|
|
1682
|
+
type
|
|
1683
|
+
} = action;
|
|
1684
|
+
const changes = {};
|
|
1685
|
+
Object.keys(state).forEach(key => {
|
|
1696
1686
|
invokeOnChangeHandler(key, action, state, newState);
|
|
1697
1687
|
|
|
1698
1688
|
if (newState[key] !== state[key]) {
|
|
@@ -1701,21 +1691,25 @@ function callOnChangeProps(action, state, newState) {
|
|
|
1701
1691
|
});
|
|
1702
1692
|
|
|
1703
1693
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
1704
|
-
props.onStateChange(
|
|
1705
|
-
type
|
|
1706
|
-
|
|
1694
|
+
props.onStateChange({
|
|
1695
|
+
type,
|
|
1696
|
+
...changes
|
|
1697
|
+
});
|
|
1707
1698
|
}
|
|
1708
1699
|
}
|
|
1709
1700
|
|
|
1710
1701
|
function invokeOnChangeHandler(key, action, state, newState) {
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1702
|
+
const {
|
|
1703
|
+
props,
|
|
1704
|
+
type
|
|
1705
|
+
} = action;
|
|
1706
|
+
const handler = "on" + capitalizeString(key) + "Change";
|
|
1714
1707
|
|
|
1715
1708
|
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
1716
|
-
props[handler](
|
|
1717
|
-
type
|
|
1718
|
-
|
|
1709
|
+
props[handler]({
|
|
1710
|
+
type,
|
|
1711
|
+
...newState
|
|
1712
|
+
});
|
|
1719
1713
|
}
|
|
1720
1714
|
}
|
|
1721
1715
|
/**
|
|
@@ -1739,8 +1733,10 @@ function stateReducer(s, a) {
|
|
|
1739
1733
|
|
|
1740
1734
|
|
|
1741
1735
|
function getA11ySelectionMessage(selectionParameters) {
|
|
1742
|
-
|
|
1743
|
-
|
|
1736
|
+
const {
|
|
1737
|
+
selectedItem,
|
|
1738
|
+
itemToString: itemToStringLocal
|
|
1739
|
+
} = selectionParameters;
|
|
1744
1740
|
return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
|
|
1745
1741
|
}
|
|
1746
1742
|
/**
|
|
@@ -1748,26 +1744,25 @@ function getA11ySelectionMessage(selectionParameters) {
|
|
|
1748
1744
|
*/
|
|
1749
1745
|
|
|
1750
1746
|
|
|
1751
|
-
|
|
1747
|
+
const updateA11yStatus = debounce((getA11yMessage, document) => {
|
|
1752
1748
|
setStatus(getA11yMessage(), document);
|
|
1753
1749
|
}, 200); // istanbul ignore next
|
|
1754
1750
|
|
|
1755
|
-
|
|
1751
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? preact.useLayoutEffect : preact.useEffect;
|
|
1756
1752
|
|
|
1757
1753
|
function useElementIds(_ref) {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1754
|
+
let {
|
|
1755
|
+
id = "downshift-" + generateId(),
|
|
1756
|
+
labelId,
|
|
1757
|
+
menuId,
|
|
1758
|
+
getItemId,
|
|
1759
|
+
toggleButtonId,
|
|
1760
|
+
inputId
|
|
1761
|
+
} = _ref;
|
|
1762
|
+
const elementIdsRef = preact.useRef({
|
|
1766
1763
|
labelId: labelId || id + "-label",
|
|
1767
1764
|
menuId: menuId || id + "-menu",
|
|
1768
|
-
getItemId: getItemId ||
|
|
1769
|
-
return id + "-item-" + index;
|
|
1770
|
-
},
|
|
1765
|
+
getItemId: getItemId || (index => id + "-item-" + index),
|
|
1771
1766
|
toggleButtonId: toggleButtonId || id + "-toggle-button",
|
|
1772
1767
|
inputId: inputId || id + "-input"
|
|
1773
1768
|
});
|
|
@@ -1799,7 +1794,7 @@ function capitalizeString(string) {
|
|
|
1799
1794
|
}
|
|
1800
1795
|
|
|
1801
1796
|
function useLatestRef(val) {
|
|
1802
|
-
|
|
1797
|
+
const ref = preact.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
|
|
1803
1798
|
// the value during render (so it's not idempotent). However, the places this
|
|
1804
1799
|
// hook is used is to support memoizing callbacks which will be called
|
|
1805
1800
|
// *during* render, so we need the latest values *during* render.
|
|
@@ -1821,30 +1816,25 @@ function useLatestRef(val) {
|
|
|
1821
1816
|
|
|
1822
1817
|
|
|
1823
1818
|
function useEnhancedReducer(reducer, initialState, props) {
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1819
|
+
const prevStateRef = preact.useRef();
|
|
1820
|
+
const actionRef = preact.useRef();
|
|
1821
|
+
const enhancedReducer = preact.useCallback((state, action) => {
|
|
1827
1822
|
actionRef.current = action;
|
|
1828
1823
|
state = getState(state, action.props);
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
changes
|
|
1832
|
-
})
|
|
1824
|
+
const changes = reducer(state, action);
|
|
1825
|
+
const newState = action.props.stateReducer(state, { ...action,
|
|
1826
|
+
changes
|
|
1827
|
+
});
|
|
1833
1828
|
return newState;
|
|
1834
1829
|
}, [reducer]);
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
props: propsRef.current
|
|
1844
|
-
}, action));
|
|
1845
|
-
}, [propsRef]);
|
|
1846
|
-
var action = actionRef.current;
|
|
1847
|
-
preact.useEffect(function () {
|
|
1830
|
+
const [state, dispatch] = preact.useReducer(enhancedReducer, initialState);
|
|
1831
|
+
const propsRef = useLatestRef(props);
|
|
1832
|
+
const dispatchWithProps = preact.useCallback(action => dispatch({
|
|
1833
|
+
props: propsRef.current,
|
|
1834
|
+
...action
|
|
1835
|
+
}), [propsRef]);
|
|
1836
|
+
const action = actionRef.current;
|
|
1837
|
+
preact.useEffect(() => {
|
|
1848
1838
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
1849
1839
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
1850
1840
|
}
|
|
@@ -1865,18 +1855,15 @@ function useEnhancedReducer(reducer, initialState, props) {
|
|
|
1865
1855
|
|
|
1866
1856
|
|
|
1867
1857
|
function useControlledReducer$1(reducer, initialState, props) {
|
|
1868
|
-
|
|
1869
|
-
state = _useEnhancedReducer[0],
|
|
1870
|
-
dispatch = _useEnhancedReducer[1];
|
|
1871
|
-
|
|
1858
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
|
|
1872
1859
|
return [getState(state, props), dispatch];
|
|
1873
1860
|
}
|
|
1874
1861
|
|
|
1875
|
-
|
|
1876
|
-
itemToString
|
|
1877
|
-
stateReducer
|
|
1878
|
-
getA11ySelectionMessage
|
|
1879
|
-
scrollIntoView
|
|
1862
|
+
const defaultProps$3 = {
|
|
1863
|
+
itemToString,
|
|
1864
|
+
stateReducer,
|
|
1865
|
+
getA11ySelectionMessage,
|
|
1866
|
+
scrollIntoView,
|
|
1880
1867
|
circularNavigation: false,
|
|
1881
1868
|
environment:
|
|
1882
1869
|
/* istanbul ignore next (ssr) */
|
|
@@ -1888,7 +1875,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
|
1888
1875
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1889
1876
|
}
|
|
1890
1877
|
|
|
1891
|
-
|
|
1878
|
+
const defaultPropKey = "default" + capitalizeString(propKey);
|
|
1892
1879
|
|
|
1893
1880
|
if (defaultPropKey in props) {
|
|
1894
1881
|
return props[defaultPropKey];
|
|
@@ -1906,7 +1893,7 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1906
1893
|
return props[propKey];
|
|
1907
1894
|
}
|
|
1908
1895
|
|
|
1909
|
-
|
|
1896
|
+
const initialPropKey = "initial" + capitalizeString(propKey);
|
|
1910
1897
|
|
|
1911
1898
|
if (initialPropKey in props) {
|
|
1912
1899
|
return props[initialPropKey];
|
|
@@ -1916,24 +1903,28 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1916
1903
|
}
|
|
1917
1904
|
|
|
1918
1905
|
function getInitialState$2(props) {
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1906
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1907
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
1908
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
1909
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
1923
1910
|
return {
|
|
1924
1911
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
1925
|
-
isOpen
|
|
1926
|
-
selectedItem
|
|
1927
|
-
inputValue
|
|
1912
|
+
isOpen,
|
|
1913
|
+
selectedItem,
|
|
1914
|
+
inputValue
|
|
1928
1915
|
};
|
|
1929
1916
|
}
|
|
1930
1917
|
|
|
1931
1918
|
function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1919
|
+
const {
|
|
1920
|
+
items,
|
|
1921
|
+
initialHighlightedIndex,
|
|
1922
|
+
defaultHighlightedIndex
|
|
1923
|
+
} = props;
|
|
1924
|
+
const {
|
|
1925
|
+
selectedItem,
|
|
1926
|
+
highlightedIndex
|
|
1927
|
+
} = state;
|
|
1937
1928
|
|
|
1938
1929
|
if (items.length === 0) {
|
|
1939
1930
|
return -1;
|
|
@@ -1974,39 +1965,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
|
1974
1965
|
|
|
1975
1966
|
|
|
1976
1967
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
1977
|
-
|
|
1968
|
+
const mouseAndTouchTrackersRef = preact.useRef({
|
|
1978
1969
|
isMouseDown: false,
|
|
1979
1970
|
isTouchMove: false
|
|
1980
1971
|
});
|
|
1981
|
-
preact.useEffect(
|
|
1972
|
+
preact.useEffect(() => {
|
|
1982
1973
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
1983
1974
|
// as in downshift.js.
|
|
1984
|
-
|
|
1975
|
+
const onMouseDown = () => {
|
|
1985
1976
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
1986
1977
|
};
|
|
1987
1978
|
|
|
1988
|
-
|
|
1979
|
+
const onMouseUp = event => {
|
|
1989
1980
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
1990
1981
|
|
|
1991
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
1992
|
-
return ref.current;
|
|
1993
|
-
}), environment)) {
|
|
1982
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
1994
1983
|
handleBlur();
|
|
1995
1984
|
}
|
|
1996
1985
|
};
|
|
1997
1986
|
|
|
1998
|
-
|
|
1987
|
+
const onTouchStart = () => {
|
|
1999
1988
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
2000
1989
|
};
|
|
2001
1990
|
|
|
2002
|
-
|
|
1991
|
+
const onTouchMove = () => {
|
|
2003
1992
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
2004
1993
|
};
|
|
2005
1994
|
|
|
2006
|
-
|
|
2007
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2008
|
-
return ref.current;
|
|
2009
|
-
}), environment, false)) {
|
|
1995
|
+
const onTouchEnd = event => {
|
|
1996
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
2010
1997
|
handleBlur();
|
|
2011
1998
|
}
|
|
2012
1999
|
};
|
|
@@ -2030,9 +2017,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
2030
2017
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2031
2018
|
|
|
2032
2019
|
|
|
2033
|
-
|
|
2034
|
-
return noop;
|
|
2035
|
-
};
|
|
2020
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
2036
2021
|
/**
|
|
2037
2022
|
* Custom hook that checks if getter props are called correctly.
|
|
2038
2023
|
*
|
|
@@ -2044,20 +2029,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
2044
2029
|
|
|
2045
2030
|
|
|
2046
2031
|
if (process.env.NODE_ENV !== 'production') {
|
|
2047
|
-
useGetterPropsCalledChecker = function
|
|
2048
|
-
|
|
2032
|
+
useGetterPropsCalledChecker = function () {
|
|
2033
|
+
const isInitialMountRef = preact.useRef(true);
|
|
2049
2034
|
|
|
2050
2035
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2051
2036
|
propKeys[_key] = arguments[_key];
|
|
2052
2037
|
}
|
|
2053
2038
|
|
|
2054
|
-
|
|
2039
|
+
const getterPropsCalledRef = preact.useRef(propKeys.reduce((acc, propKey) => {
|
|
2055
2040
|
acc[propKey] = {};
|
|
2056
2041
|
return acc;
|
|
2057
2042
|
}, {}));
|
|
2058
|
-
preact.useEffect(
|
|
2059
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
2060
|
-
|
|
2043
|
+
preact.useEffect(() => {
|
|
2044
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
2045
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
2061
2046
|
|
|
2062
2047
|
if (isInitialMountRef.current) {
|
|
2063
2048
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -2067,9 +2052,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2067
2052
|
}
|
|
2068
2053
|
}
|
|
2069
2054
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2055
|
+
const {
|
|
2056
|
+
suppressRefError,
|
|
2057
|
+
refKey,
|
|
2058
|
+
elementRef
|
|
2059
|
+
} = propCallInfo;
|
|
2073
2060
|
|
|
2074
2061
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
2075
2062
|
// eslint-disable-next-line no-console
|
|
@@ -2078,11 +2065,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2078
2065
|
});
|
|
2079
2066
|
isInitialMountRef.current = false;
|
|
2080
2067
|
});
|
|
2081
|
-
|
|
2068
|
+
const setGetterPropCallInfo = preact.useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
2082
2069
|
getterPropsCalledRef.current[propKey] = {
|
|
2083
|
-
suppressRefError
|
|
2084
|
-
refKey
|
|
2085
|
-
elementRef
|
|
2070
|
+
suppressRefError,
|
|
2071
|
+
refKey,
|
|
2072
|
+
elementRef
|
|
2086
2073
|
};
|
|
2087
2074
|
}, []);
|
|
2088
2075
|
return setGetterPropCallInfo;
|
|
@@ -2090,39 +2077,41 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2090
2077
|
}
|
|
2091
2078
|
|
|
2092
2079
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2080
|
+
let {
|
|
2081
|
+
isInitialMount,
|
|
2082
|
+
highlightedIndex,
|
|
2083
|
+
items,
|
|
2084
|
+
environment,
|
|
2085
|
+
...rest
|
|
2086
|
+
} = _ref2;
|
|
2099
2087
|
// Sets a11y status message on changes in state.
|
|
2100
|
-
preact.useEffect(
|
|
2088
|
+
preact.useEffect(() => {
|
|
2101
2089
|
if (isInitialMount || false) {
|
|
2102
2090
|
return;
|
|
2103
2091
|
}
|
|
2104
2092
|
|
|
2105
|
-
updateA11yStatus(
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2093
|
+
updateA11yStatus(() => getA11yMessage({
|
|
2094
|
+
highlightedIndex,
|
|
2095
|
+
highlightedItem: items[highlightedIndex],
|
|
2096
|
+
resultCount: items.length,
|
|
2097
|
+
...rest
|
|
2098
|
+
}), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2112
2099
|
}, dependencyArray);
|
|
2113
2100
|
}
|
|
2114
2101
|
|
|
2115
2102
|
function useScrollIntoView(_ref3) {
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2103
|
+
let {
|
|
2104
|
+
highlightedIndex,
|
|
2105
|
+
isOpen,
|
|
2106
|
+
itemRefs,
|
|
2107
|
+
getItemNodeFromIndex,
|
|
2108
|
+
menuElement,
|
|
2109
|
+
scrollIntoView: scrollIntoViewProp
|
|
2110
|
+
} = _ref3;
|
|
2122
2111
|
// used not to scroll on highlight by mouse.
|
|
2123
|
-
|
|
2112
|
+
const shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
2124
2113
|
|
|
2125
|
-
useIsomorphicLayoutEffect(
|
|
2114
|
+
useIsomorphicLayoutEffect(() => {
|
|
2126
2115
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2127
2116
|
return;
|
|
2128
2117
|
}
|
|
@@ -2138,17 +2127,19 @@ function useScrollIntoView(_ref3) {
|
|
|
2138
2127
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
2139
2128
|
|
|
2140
2129
|
|
|
2141
|
-
|
|
2130
|
+
let useControlPropsValidator = noop;
|
|
2142
2131
|
/* istanbul ignore next */
|
|
2143
2132
|
|
|
2144
2133
|
if (process.env.NODE_ENV !== 'production') {
|
|
2145
|
-
useControlPropsValidator =
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2134
|
+
useControlPropsValidator = _ref4 => {
|
|
2135
|
+
let {
|
|
2136
|
+
isInitialMount,
|
|
2137
|
+
props,
|
|
2138
|
+
state
|
|
2139
|
+
} = _ref4;
|
|
2149
2140
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
2150
|
-
|
|
2151
|
-
preact.useEffect(
|
|
2141
|
+
const prevPropsRef = preact.useRef(props);
|
|
2142
|
+
preact.useEffect(() => {
|
|
2152
2143
|
if (isInitialMount) {
|
|
2153
2144
|
return;
|
|
2154
2145
|
}
|
|
@@ -2162,9 +2153,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2162
2153
|
/* eslint-disable complexity */
|
|
2163
2154
|
|
|
2164
2155
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2156
|
+
const {
|
|
2157
|
+
type,
|
|
2158
|
+
props
|
|
2159
|
+
} = action;
|
|
2160
|
+
let changes;
|
|
2168
2161
|
|
|
2169
2162
|
switch (type) {
|
|
2170
2163
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -2225,7 +2218,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2225
2218
|
throw new Error('Reducer called without proper action type.');
|
|
2226
2219
|
}
|
|
2227
2220
|
|
|
2228
|
-
return
|
|
2221
|
+
return { ...state,
|
|
2222
|
+
...changes
|
|
2223
|
+
};
|
|
2229
2224
|
}
|
|
2230
2225
|
/* eslint-enable complexity */
|
|
2231
2226
|
|
|
@@ -2248,37 +2243,37 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2248
2243
|
return highlightedIndex;
|
|
2249
2244
|
}
|
|
2250
2245
|
var propTypes$2 = {
|
|
2251
|
-
items: PropTypes__default[
|
|
2252
|
-
itemToString: PropTypes__default[
|
|
2253
|
-
getA11yStatusMessage: PropTypes__default[
|
|
2254
|
-
getA11ySelectionMessage: PropTypes__default[
|
|
2255
|
-
circularNavigation: PropTypes__default[
|
|
2256
|
-
highlightedIndex: PropTypes__default[
|
|
2257
|
-
defaultHighlightedIndex: PropTypes__default[
|
|
2258
|
-
initialHighlightedIndex: PropTypes__default[
|
|
2259
|
-
isOpen: PropTypes__default[
|
|
2260
|
-
defaultIsOpen: PropTypes__default[
|
|
2261
|
-
initialIsOpen: PropTypes__default[
|
|
2262
|
-
selectedItem: PropTypes__default[
|
|
2263
|
-
initialSelectedItem: PropTypes__default[
|
|
2264
|
-
defaultSelectedItem: PropTypes__default[
|
|
2265
|
-
id: PropTypes__default[
|
|
2266
|
-
labelId: PropTypes__default[
|
|
2267
|
-
menuId: PropTypes__default[
|
|
2268
|
-
getItemId: PropTypes__default[
|
|
2269
|
-
toggleButtonId: PropTypes__default[
|
|
2270
|
-
stateReducer: PropTypes__default[
|
|
2271
|
-
onSelectedItemChange: PropTypes__default[
|
|
2272
|
-
onHighlightedIndexChange: PropTypes__default[
|
|
2273
|
-
onStateChange: PropTypes__default[
|
|
2274
|
-
onIsOpenChange: PropTypes__default[
|
|
2275
|
-
environment: PropTypes__default[
|
|
2276
|
-
addEventListener: PropTypes__default[
|
|
2277
|
-
removeEventListener: PropTypes__default[
|
|
2278
|
-
document: PropTypes__default[
|
|
2279
|
-
getElementById: PropTypes__default[
|
|
2280
|
-
activeElement: PropTypes__default[
|
|
2281
|
-
body: PropTypes__default[
|
|
2246
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
2247
|
+
itemToString: PropTypes__default["default"].func,
|
|
2248
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
2249
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
2250
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
2251
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
2252
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
2253
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
2254
|
+
isOpen: PropTypes__default["default"].bool,
|
|
2255
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
2256
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
2257
|
+
selectedItem: PropTypes__default["default"].any,
|
|
2258
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
2259
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
2260
|
+
id: PropTypes__default["default"].string,
|
|
2261
|
+
labelId: PropTypes__default["default"].string,
|
|
2262
|
+
menuId: PropTypes__default["default"].string,
|
|
2263
|
+
getItemId: PropTypes__default["default"].func,
|
|
2264
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
2265
|
+
stateReducer: PropTypes__default["default"].func,
|
|
2266
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
2267
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
2268
|
+
onStateChange: PropTypes__default["default"].func,
|
|
2269
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
2270
|
+
environment: PropTypes__default["default"].shape({
|
|
2271
|
+
addEventListener: PropTypes__default["default"].func,
|
|
2272
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
2273
|
+
document: PropTypes__default["default"].shape({
|
|
2274
|
+
getElementById: PropTypes__default["default"].func,
|
|
2275
|
+
activeElement: PropTypes__default["default"].any,
|
|
2276
|
+
body: PropTypes__default["default"].any
|
|
2282
2277
|
})
|
|
2283
2278
|
})
|
|
2284
2279
|
};
|
|
@@ -2299,7 +2294,7 @@ function getA11yStatusMessage(_a) {
|
|
|
2299
2294
|
return 'No results are available.';
|
|
2300
2295
|
}
|
|
2301
2296
|
if (resultCount !== previousResultCount) {
|
|
2302
|
-
return resultCount
|
|
2297
|
+
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.");
|
|
2303
2298
|
}
|
|
2304
2299
|
return '';
|
|
2305
2300
|
}
|
|
@@ -2309,33 +2304,33 @@ var validatePropTypes$2 = noop;
|
|
|
2309
2304
|
/* istanbul ignore next */
|
|
2310
2305
|
if (process.env.NODE_ENV !== 'production') {
|
|
2311
2306
|
validatePropTypes$2 = function (options, caller) {
|
|
2312
|
-
PropTypes__default[
|
|
2307
|
+
PropTypes__default["default"].checkPropTypes(propTypes$2, options, 'prop', caller.name);
|
|
2313
2308
|
};
|
|
2314
2309
|
}
|
|
2315
2310
|
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2311
|
+
const MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
|
|
2312
|
+
const MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
|
|
2313
|
+
const MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
|
|
2314
|
+
const MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
|
|
2315
|
+
const MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
|
|
2316
|
+
const MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
|
|
2317
|
+
const MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
|
|
2318
|
+
const MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
|
|
2319
|
+
const MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
|
|
2320
|
+
const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
|
|
2321
|
+
const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
|
|
2322
|
+
const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
|
|
2323
|
+
const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
|
|
2324
|
+
const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
|
|
2325
|
+
const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
|
|
2326
|
+
const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
|
|
2327
|
+
const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
|
|
2328
|
+
const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
|
|
2329
|
+
const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
|
|
2330
|
+
const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
|
|
2331
|
+
const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
|
|
2332
|
+
const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
|
|
2333
|
+
const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
|
|
2339
2334
|
|
|
2340
2335
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2341
2336
|
__proto__: null,
|
|
@@ -2367,10 +2362,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2367
2362
|
/* eslint-disable complexity */
|
|
2368
2363
|
|
|
2369
2364
|
function downshiftSelectReducer(state, action) {
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2365
|
+
const {
|
|
2366
|
+
type,
|
|
2367
|
+
props,
|
|
2368
|
+
shiftKey
|
|
2369
|
+
} = action;
|
|
2370
|
+
let changes;
|
|
2374
2371
|
|
|
2375
2372
|
switch (type) {
|
|
2376
2373
|
case ItemClick$1:
|
|
@@ -2383,20 +2380,21 @@ function downshiftSelectReducer(state, action) {
|
|
|
2383
2380
|
|
|
2384
2381
|
case ToggleButtonKeyDownCharacter:
|
|
2385
2382
|
{
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2383
|
+
const lowercasedKey = action.key;
|
|
2384
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2385
|
+
const itemIndex = getItemIndexByCharacterKey({
|
|
2389
2386
|
keysSoFar: inputValue,
|
|
2390
2387
|
highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
|
|
2391
2388
|
items: props.items,
|
|
2392
2389
|
itemToString: props.itemToString,
|
|
2393
2390
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2394
2391
|
});
|
|
2395
|
-
changes =
|
|
2396
|
-
inputValue
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2392
|
+
changes = {
|
|
2393
|
+
inputValue,
|
|
2394
|
+
...(itemIndex >= 0 && {
|
|
2395
|
+
selectedItem: props.items[itemIndex]
|
|
2396
|
+
})
|
|
2397
|
+
};
|
|
2400
2398
|
}
|
|
2401
2399
|
break;
|
|
2402
2400
|
|
|
@@ -2416,12 +2414,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2416
2414
|
|
|
2417
2415
|
case MenuKeyDownEnter:
|
|
2418
2416
|
case MenuKeyDownSpaceButton:
|
|
2419
|
-
changes =
|
|
2417
|
+
changes = {
|
|
2420
2418
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2421
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2419
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2420
|
+
...(state.highlightedIndex >= 0 && {
|
|
2421
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2422
|
+
})
|
|
2423
|
+
};
|
|
2425
2424
|
break;
|
|
2426
2425
|
|
|
2427
2426
|
case MenuKeyDownHome:
|
|
@@ -2452,22 +2451,21 @@ function downshiftSelectReducer(state, action) {
|
|
|
2452
2451
|
|
|
2453
2452
|
case MenuKeyDownCharacter:
|
|
2454
2453
|
{
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
var highlightedIndex = getItemIndexByCharacterKey({
|
|
2460
|
-
keysSoFar: _inputValue,
|
|
2454
|
+
const lowercasedKey = action.key;
|
|
2455
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2456
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
2457
|
+
keysSoFar: inputValue,
|
|
2461
2458
|
highlightedIndex: state.highlightedIndex,
|
|
2462
2459
|
items: props.items,
|
|
2463
2460
|
itemToString: props.itemToString,
|
|
2464
2461
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2465
2462
|
});
|
|
2466
|
-
changes =
|
|
2467
|
-
inputValue
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2463
|
+
changes = {
|
|
2464
|
+
inputValue,
|
|
2465
|
+
...(highlightedIndex >= 0 && {
|
|
2466
|
+
highlightedIndex
|
|
2467
|
+
})
|
|
2468
|
+
};
|
|
2471
2469
|
}
|
|
2472
2470
|
break;
|
|
2473
2471
|
|
|
@@ -2493,13 +2491,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2493
2491
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2494
2492
|
}
|
|
2495
2493
|
|
|
2496
|
-
return
|
|
2494
|
+
return { ...state,
|
|
2495
|
+
...changes
|
|
2496
|
+
};
|
|
2497
2497
|
}
|
|
2498
2498
|
/* eslint-enable complexity */
|
|
2499
2499
|
|
|
2500
|
-
|
|
2501
|
-
_excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
|
|
2502
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
|
|
2500
|
+
/* eslint-disable max-statements */
|
|
2503
2501
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2504
2502
|
|
|
2505
2503
|
function useSelect(userProps) {
|
|
@@ -2509,91 +2507,92 @@ function useSelect(userProps) {
|
|
|
2509
2507
|
|
|
2510
2508
|
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
2511
2509
|
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2510
|
+
const props = { ...defaultProps$2,
|
|
2511
|
+
...userProps
|
|
2512
|
+
};
|
|
2513
|
+
const {
|
|
2514
|
+
items,
|
|
2515
|
+
scrollIntoView,
|
|
2516
|
+
environment,
|
|
2517
|
+
initialIsOpen,
|
|
2518
|
+
defaultIsOpen,
|
|
2519
|
+
itemToString,
|
|
2520
|
+
getA11ySelectionMessage,
|
|
2521
|
+
getA11yStatusMessage
|
|
2522
|
+
} = props; // Initial state depending on controlled props.
|
|
2523
|
+
|
|
2524
|
+
const initialState = getInitialState$2(props);
|
|
2525
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
2526
|
+
const {
|
|
2527
|
+
isOpen,
|
|
2528
|
+
highlightedIndex,
|
|
2529
|
+
selectedItem,
|
|
2530
|
+
inputValue
|
|
2531
|
+
} = state; // Element efs.
|
|
2532
|
+
|
|
2533
|
+
const toggleButtonRef = preact.useRef(null);
|
|
2534
|
+
const menuRef = preact.useRef(null);
|
|
2535
|
+
const itemRefs = preact.useRef({}); // used not to trigger menu blur action in some scenarios.
|
|
2536
|
+
|
|
2537
|
+
const shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
2538
|
+
|
|
2539
|
+
const clearTimeoutRef = preact.useRef(null); // prevent id re-generation between renders.
|
|
2540
|
+
|
|
2541
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
2542
|
+
|
|
2543
|
+
const previousResultCountRef = preact.useRef();
|
|
2544
|
+
const isInitialMountRef = preact.useRef(true); // utility callback to get item element.
|
|
2545
|
+
|
|
2546
|
+
const latest = useLatestRef({
|
|
2547
|
+
state,
|
|
2548
|
+
props
|
|
2550
2549
|
}); // Some utils.
|
|
2551
2550
|
|
|
2552
|
-
|
|
2553
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2554
|
-
}, [elementIds]); // Effects.
|
|
2551
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
2555
2552
|
// Sets a11y status message on changes in state.
|
|
2556
2553
|
|
|
2557
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2554
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2558
2555
|
isInitialMount: isInitialMountRef.current,
|
|
2559
2556
|
previousResultCount: previousResultCountRef.current,
|
|
2560
|
-
items
|
|
2561
|
-
environment
|
|
2562
|
-
itemToString
|
|
2563
|
-
|
|
2557
|
+
items,
|
|
2558
|
+
environment,
|
|
2559
|
+
itemToString,
|
|
2560
|
+
...state
|
|
2561
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
2564
2562
|
|
|
2565
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2563
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2566
2564
|
isInitialMount: isInitialMountRef.current,
|
|
2567
2565
|
previousResultCount: previousResultCountRef.current,
|
|
2568
|
-
items
|
|
2569
|
-
environment
|
|
2570
|
-
itemToString
|
|
2571
|
-
|
|
2566
|
+
items,
|
|
2567
|
+
environment,
|
|
2568
|
+
itemToString,
|
|
2569
|
+
...state
|
|
2570
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
2572
2571
|
|
|
2573
|
-
|
|
2572
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2574
2573
|
menuElement: menuRef.current,
|
|
2575
|
-
highlightedIndex
|
|
2576
|
-
isOpen
|
|
2577
|
-
itemRefs
|
|
2578
|
-
scrollIntoView
|
|
2579
|
-
getItemNodeFromIndex
|
|
2574
|
+
highlightedIndex,
|
|
2575
|
+
isOpen,
|
|
2576
|
+
itemRefs,
|
|
2577
|
+
scrollIntoView,
|
|
2578
|
+
getItemNodeFromIndex
|
|
2580
2579
|
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2581
2580
|
|
|
2582
|
-
preact.useEffect(
|
|
2581
|
+
preact.useEffect(() => {
|
|
2583
2582
|
// init the clean function here as we need access to dispatch.
|
|
2584
|
-
clearTimeoutRef.current = debounce(
|
|
2583
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
2585
2584
|
outerDispatch({
|
|
2586
2585
|
type: FunctionSetInputValue$1,
|
|
2587
2586
|
inputValue: ''
|
|
2588
2587
|
});
|
|
2589
2588
|
}, 500); // Cancel any pending debounced calls on mount
|
|
2590
2589
|
|
|
2591
|
-
return
|
|
2590
|
+
return () => {
|
|
2592
2591
|
clearTimeoutRef.current.cancel();
|
|
2593
2592
|
};
|
|
2594
2593
|
}, []); // Invokes the keysSoFar callback set up above.
|
|
2595
2594
|
|
|
2596
|
-
preact.useEffect(
|
|
2595
|
+
preact.useEffect(() => {
|
|
2597
2596
|
if (!inputValue) {
|
|
2598
2597
|
return;
|
|
2599
2598
|
}
|
|
@@ -2602,12 +2601,12 @@ function useSelect(userProps) {
|
|
|
2602
2601
|
}, [dispatch, inputValue]);
|
|
2603
2602
|
useControlPropsValidator({
|
|
2604
2603
|
isInitialMount: isInitialMountRef.current,
|
|
2605
|
-
props
|
|
2606
|
-
state
|
|
2604
|
+
props,
|
|
2605
|
+
state
|
|
2607
2606
|
});
|
|
2608
2607
|
/* Controls the focus on the menu or the toggle button. */
|
|
2609
2608
|
|
|
2610
|
-
preact.useEffect(
|
|
2609
|
+
preact.useEffect(() => {
|
|
2611
2610
|
// Don't focus menu on first render.
|
|
2612
2611
|
if (isInitialMountRef.current) {
|
|
2613
2612
|
// Unless it was initialised as open.
|
|
@@ -2638,7 +2637,7 @@ function useSelect(userProps) {
|
|
|
2638
2637
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2639
2638
|
|
|
2640
2639
|
}, [isOpen]);
|
|
2641
|
-
preact.useEffect(
|
|
2640
|
+
preact.useEffect(() => {
|
|
2642
2641
|
if (isInitialMountRef.current) {
|
|
2643
2642
|
return;
|
|
2644
2643
|
}
|
|
@@ -2646,180 +2645,180 @@ function useSelect(userProps) {
|
|
|
2646
2645
|
previousResultCountRef.current = items.length;
|
|
2647
2646
|
}); // Add mouse/touch events to document.
|
|
2648
2647
|
|
|
2649
|
-
|
|
2648
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
2650
2649
|
dispatch({
|
|
2651
2650
|
type: MenuBlur
|
|
2652
2651
|
});
|
|
2653
2652
|
});
|
|
2654
|
-
|
|
2653
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
2655
2654
|
|
|
2656
|
-
preact.useEffect(
|
|
2655
|
+
preact.useEffect(() => {
|
|
2657
2656
|
isInitialMountRef.current = false;
|
|
2658
2657
|
}, []); // Reset itemRefs on close.
|
|
2659
2658
|
|
|
2660
|
-
preact.useEffect(
|
|
2659
|
+
preact.useEffect(() => {
|
|
2661
2660
|
if (!isOpen) {
|
|
2662
2661
|
itemRefs.current = {};
|
|
2663
2662
|
}
|
|
2664
2663
|
}, [isOpen]); // Event handler functions.
|
|
2665
2664
|
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
},
|
|
2676
|
-
ArrowUp: function ArrowUp(event) {
|
|
2677
|
-
event.preventDefault();
|
|
2678
|
-
dispatch({
|
|
2679
|
-
type: ToggleButtonKeyDownArrowUp,
|
|
2680
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
2681
|
-
shiftKey: event.shiftKey
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
};
|
|
2685
|
-
}, [dispatch, getItemNodeFromIndex]);
|
|
2686
|
-
var menuKeyDownHandlers = preact.useMemo(function () {
|
|
2687
|
-
return {
|
|
2688
|
-
ArrowDown: function ArrowDown(event) {
|
|
2689
|
-
event.preventDefault();
|
|
2690
|
-
dispatch({
|
|
2691
|
-
type: MenuKeyDownArrowDown,
|
|
2692
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
2693
|
-
shiftKey: event.shiftKey
|
|
2694
|
-
});
|
|
2695
|
-
},
|
|
2696
|
-
ArrowUp: function ArrowUp(event) {
|
|
2697
|
-
event.preventDefault();
|
|
2698
|
-
dispatch({
|
|
2699
|
-
type: MenuKeyDownArrowUp,
|
|
2700
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
2701
|
-
shiftKey: event.shiftKey
|
|
2702
|
-
});
|
|
2703
|
-
},
|
|
2704
|
-
Home: function Home(event) {
|
|
2705
|
-
event.preventDefault();
|
|
2706
|
-
dispatch({
|
|
2707
|
-
type: MenuKeyDownHome,
|
|
2708
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2709
|
-
});
|
|
2710
|
-
},
|
|
2711
|
-
End: function End(event) {
|
|
2712
|
-
event.preventDefault();
|
|
2713
|
-
dispatch({
|
|
2714
|
-
type: MenuKeyDownEnd,
|
|
2715
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2716
|
-
});
|
|
2717
|
-
},
|
|
2718
|
-
Escape: function Escape() {
|
|
2719
|
-
dispatch({
|
|
2720
|
-
type: MenuKeyDownEscape
|
|
2721
|
-
});
|
|
2722
|
-
},
|
|
2723
|
-
Enter: function Enter(event) {
|
|
2724
|
-
event.preventDefault();
|
|
2725
|
-
dispatch({
|
|
2726
|
-
type: MenuKeyDownEnter
|
|
2727
|
-
});
|
|
2728
|
-
},
|
|
2729
|
-
' ': function _(event) {
|
|
2730
|
-
event.preventDefault();
|
|
2731
|
-
dispatch({
|
|
2732
|
-
type: MenuKeyDownSpaceButton
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
};
|
|
2736
|
-
}, [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
2665
|
+
const toggleButtonKeyDownHandlers = preact.useMemo(() => ({
|
|
2666
|
+
ArrowDown(event) {
|
|
2667
|
+
event.preventDefault();
|
|
2668
|
+
dispatch({
|
|
2669
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
2670
|
+
getItemNodeFromIndex,
|
|
2671
|
+
shiftKey: event.shiftKey
|
|
2672
|
+
});
|
|
2673
|
+
},
|
|
2737
2674
|
|
|
2738
|
-
|
|
2675
|
+
ArrowUp(event) {
|
|
2676
|
+
event.preventDefault();
|
|
2677
|
+
dispatch({
|
|
2678
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
2679
|
+
getItemNodeFromIndex,
|
|
2680
|
+
shiftKey: event.shiftKey
|
|
2681
|
+
});
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
}), [dispatch, getItemNodeFromIndex]);
|
|
2685
|
+
const menuKeyDownHandlers = preact.useMemo(() => ({
|
|
2686
|
+
ArrowDown(event) {
|
|
2687
|
+
event.preventDefault();
|
|
2688
|
+
dispatch({
|
|
2689
|
+
type: MenuKeyDownArrowDown,
|
|
2690
|
+
getItemNodeFromIndex,
|
|
2691
|
+
shiftKey: event.shiftKey
|
|
2692
|
+
});
|
|
2693
|
+
},
|
|
2694
|
+
|
|
2695
|
+
ArrowUp(event) {
|
|
2696
|
+
event.preventDefault();
|
|
2697
|
+
dispatch({
|
|
2698
|
+
type: MenuKeyDownArrowUp,
|
|
2699
|
+
getItemNodeFromIndex,
|
|
2700
|
+
shiftKey: event.shiftKey
|
|
2701
|
+
});
|
|
2702
|
+
},
|
|
2703
|
+
|
|
2704
|
+
Home(event) {
|
|
2705
|
+
event.preventDefault();
|
|
2706
|
+
dispatch({
|
|
2707
|
+
type: MenuKeyDownHome,
|
|
2708
|
+
getItemNodeFromIndex
|
|
2709
|
+
});
|
|
2710
|
+
},
|
|
2711
|
+
|
|
2712
|
+
End(event) {
|
|
2713
|
+
event.preventDefault();
|
|
2714
|
+
dispatch({
|
|
2715
|
+
type: MenuKeyDownEnd,
|
|
2716
|
+
getItemNodeFromIndex
|
|
2717
|
+
});
|
|
2718
|
+
},
|
|
2719
|
+
|
|
2720
|
+
Escape() {
|
|
2721
|
+
dispatch({
|
|
2722
|
+
type: MenuKeyDownEscape
|
|
2723
|
+
});
|
|
2724
|
+
},
|
|
2725
|
+
|
|
2726
|
+
Enter(event) {
|
|
2727
|
+
event.preventDefault();
|
|
2728
|
+
dispatch({
|
|
2729
|
+
type: MenuKeyDownEnter
|
|
2730
|
+
});
|
|
2731
|
+
},
|
|
2732
|
+
|
|
2733
|
+
' '(event) {
|
|
2734
|
+
event.preventDefault();
|
|
2735
|
+
dispatch({
|
|
2736
|
+
type: MenuKeyDownSpaceButton
|
|
2737
|
+
});
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
}), [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
2741
|
+
|
|
2742
|
+
const toggleMenu = preact.useCallback(() => {
|
|
2739
2743
|
dispatch({
|
|
2740
2744
|
type: FunctionToggleMenu$1
|
|
2741
2745
|
});
|
|
2742
2746
|
}, [dispatch]);
|
|
2743
|
-
|
|
2747
|
+
const closeMenu = preact.useCallback(() => {
|
|
2744
2748
|
dispatch({
|
|
2745
2749
|
type: FunctionCloseMenu$1
|
|
2746
2750
|
});
|
|
2747
2751
|
}, [dispatch]);
|
|
2748
|
-
|
|
2752
|
+
const openMenu = preact.useCallback(() => {
|
|
2749
2753
|
dispatch({
|
|
2750
2754
|
type: FunctionOpenMenu$1
|
|
2751
2755
|
});
|
|
2752
2756
|
}, [dispatch]);
|
|
2753
|
-
|
|
2757
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
2754
2758
|
dispatch({
|
|
2755
2759
|
type: FunctionSetHighlightedIndex$1,
|
|
2756
2760
|
highlightedIndex: newHighlightedIndex
|
|
2757
2761
|
});
|
|
2758
2762
|
}, [dispatch]);
|
|
2759
|
-
|
|
2763
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
2760
2764
|
dispatch({
|
|
2761
2765
|
type: FunctionSelectItem$1,
|
|
2762
2766
|
selectedItem: newSelectedItem
|
|
2763
2767
|
});
|
|
2764
2768
|
}, [dispatch]);
|
|
2765
|
-
|
|
2769
|
+
const reset = preact.useCallback(() => {
|
|
2766
2770
|
dispatch({
|
|
2767
2771
|
type: FunctionReset$2
|
|
2768
2772
|
});
|
|
2769
2773
|
}, [dispatch]);
|
|
2770
|
-
|
|
2774
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
2771
2775
|
dispatch({
|
|
2772
2776
|
type: FunctionSetInputValue$1,
|
|
2773
2777
|
inputValue: newInputValue
|
|
2774
2778
|
});
|
|
2775
2779
|
}, [dispatch]); // Getter functions.
|
|
2776
2780
|
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
var latestState = latest.current.state;
|
|
2800
|
-
|
|
2801
|
-
var menuHandleKeyDown = function menuHandleKeyDown(event) {
|
|
2802
|
-
var key = normalizeArrowKey(event);
|
|
2781
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
2782
|
+
id: elementIds.labelId,
|
|
2783
|
+
htmlFor: elementIds.toggleButtonId,
|
|
2784
|
+
...labelProps
|
|
2785
|
+
}), [elementIds]);
|
|
2786
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
2787
|
+
let {
|
|
2788
|
+
onMouseLeave,
|
|
2789
|
+
refKey = 'ref',
|
|
2790
|
+
onKeyDown,
|
|
2791
|
+
onBlur,
|
|
2792
|
+
ref,
|
|
2793
|
+
...rest
|
|
2794
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2795
|
+
let {
|
|
2796
|
+
suppressRefError = false
|
|
2797
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2798
|
+
const latestState = latest.current.state;
|
|
2799
|
+
|
|
2800
|
+
const menuHandleKeyDown = event => {
|
|
2801
|
+
const key = normalizeArrowKey(event);
|
|
2803
2802
|
|
|
2804
2803
|
if (key && menuKeyDownHandlers[key]) {
|
|
2805
2804
|
menuKeyDownHandlers[key](event);
|
|
2806
2805
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2807
2806
|
dispatch({
|
|
2808
2807
|
type: MenuKeyDownCharacter,
|
|
2809
|
-
key
|
|
2810
|
-
getItemNodeFromIndex
|
|
2808
|
+
key,
|
|
2809
|
+
getItemNodeFromIndex
|
|
2811
2810
|
});
|
|
2812
2811
|
}
|
|
2813
2812
|
};
|
|
2814
2813
|
|
|
2815
|
-
|
|
2814
|
+
const menuHandleBlur = () => {
|
|
2816
2815
|
// if the blur was a result of selection, we don't trigger this action.
|
|
2817
2816
|
if (shouldBlurRef.current === false) {
|
|
2818
2817
|
shouldBlurRef.current = true;
|
|
2819
2818
|
return;
|
|
2820
2819
|
}
|
|
2821
2820
|
|
|
2822
|
-
|
|
2821
|
+
const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
2823
2822
|
/* istanbul ignore else */
|
|
2824
2823
|
|
|
2825
2824
|
if (shouldBlur) {
|
|
@@ -2829,61 +2828,72 @@ function useSelect(userProps) {
|
|
|
2829
2828
|
}
|
|
2830
2829
|
};
|
|
2831
2830
|
|
|
2832
|
-
|
|
2831
|
+
const menuHandleMouseLeave = () => {
|
|
2833
2832
|
dispatch({
|
|
2834
2833
|
type: MenuMouseLeave$1
|
|
2835
2834
|
});
|
|
2836
2835
|
};
|
|
2837
2836
|
|
|
2838
2837
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2839
|
-
return
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2838
|
+
return {
|
|
2839
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
2840
|
+
menuRef.current = menuNode;
|
|
2841
|
+
}),
|
|
2842
|
+
id: elementIds.menuId,
|
|
2843
|
+
role: 'listbox',
|
|
2844
|
+
'aria-labelledby': elementIds.labelId,
|
|
2845
|
+
tabIndex: -1,
|
|
2846
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
2847
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
2848
|
+
}),
|
|
2844
2849
|
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
2845
2850
|
onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
|
2846
|
-
onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
|
2847
|
-
|
|
2851
|
+
onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
|
|
2852
|
+
...rest
|
|
2853
|
+
};
|
|
2848
2854
|
}, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
|
|
2863
|
-
|
|
2864
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
2855
|
+
const getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
|
|
2856
|
+
let {
|
|
2857
|
+
onClick,
|
|
2858
|
+
onKeyDown,
|
|
2859
|
+
refKey = 'ref',
|
|
2860
|
+
ref,
|
|
2861
|
+
...rest
|
|
2862
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2863
|
+
let {
|
|
2864
|
+
suppressRefError = false
|
|
2865
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2866
|
+
|
|
2867
|
+
const toggleButtonHandleClick = () => {
|
|
2865
2868
|
dispatch({
|
|
2866
2869
|
type: ToggleButtonClick$1
|
|
2867
2870
|
});
|
|
2868
2871
|
};
|
|
2869
2872
|
|
|
2870
|
-
|
|
2871
|
-
|
|
2873
|
+
const toggleButtonHandleKeyDown = event => {
|
|
2874
|
+
const key = normalizeArrowKey(event);
|
|
2872
2875
|
|
|
2873
2876
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
2874
2877
|
toggleButtonKeyDownHandlers[key](event);
|
|
2875
2878
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2876
2879
|
dispatch({
|
|
2877
2880
|
type: ToggleButtonKeyDownCharacter,
|
|
2878
|
-
key
|
|
2879
|
-
getItemNodeFromIndex
|
|
2881
|
+
key,
|
|
2882
|
+
getItemNodeFromIndex
|
|
2880
2883
|
});
|
|
2881
2884
|
}
|
|
2882
2885
|
};
|
|
2883
2886
|
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
+
const toggleProps = {
|
|
2888
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
2889
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
2890
|
+
}),
|
|
2891
|
+
id: elementIds.toggleButtonId,
|
|
2892
|
+
'aria-haspopup': 'listbox',
|
|
2893
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
2894
|
+
'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
|
|
2895
|
+
...rest
|
|
2896
|
+
};
|
|
2887
2897
|
|
|
2888
2898
|
if (!rest.disabled) {
|
|
2889
2899
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
@@ -2893,24 +2903,22 @@ function useSelect(userProps) {
|
|
|
2893
2903
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2894
2904
|
return toggleProps;
|
|
2895
2905
|
}, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
2906
|
+
const getItemProps = preact.useCallback(function (_temp5) {
|
|
2907
|
+
let {
|
|
2908
|
+
item,
|
|
2909
|
+
index,
|
|
2910
|
+
onMouseMove,
|
|
2911
|
+
onClick,
|
|
2912
|
+
refKey = 'ref',
|
|
2913
|
+
ref,
|
|
2914
|
+
...rest
|
|
2915
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
2916
|
+
const {
|
|
2917
|
+
state: latestState,
|
|
2918
|
+
props: latestProps
|
|
2919
|
+
} = latest.current;
|
|
2920
|
+
|
|
2921
|
+
const itemHandleMouseMove = () => {
|
|
2914
2922
|
if (index === latestState.highlightedIndex) {
|
|
2915
2923
|
return;
|
|
2916
2924
|
}
|
|
@@ -2918,32 +2926,34 @@ function useSelect(userProps) {
|
|
|
2918
2926
|
shouldScrollRef.current = false;
|
|
2919
2927
|
dispatch({
|
|
2920
2928
|
type: ItemMouseMove$1,
|
|
2921
|
-
index
|
|
2929
|
+
index
|
|
2922
2930
|
});
|
|
2923
2931
|
};
|
|
2924
2932
|
|
|
2925
|
-
|
|
2933
|
+
const itemHandleClick = () => {
|
|
2926
2934
|
dispatch({
|
|
2927
2935
|
type: ItemClick$1,
|
|
2928
|
-
index
|
|
2936
|
+
index
|
|
2929
2937
|
});
|
|
2930
2938
|
};
|
|
2931
2939
|
|
|
2932
|
-
|
|
2940
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2933
2941
|
|
|
2934
2942
|
if (itemIndex < 0) {
|
|
2935
2943
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
2936
2944
|
}
|
|
2937
2945
|
|
|
2938
|
-
|
|
2946
|
+
const itemProps = {
|
|
2939
2947
|
role: 'option',
|
|
2940
2948
|
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
2941
|
-
id: elementIds.getItemId(itemIndex)
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2949
|
+
id: elementIds.getItemId(itemIndex),
|
|
2950
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
2951
|
+
if (itemNode) {
|
|
2952
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
2953
|
+
}
|
|
2954
|
+
}),
|
|
2955
|
+
...rest
|
|
2956
|
+
};
|
|
2947
2957
|
|
|
2948
2958
|
if (!rest.disabled) {
|
|
2949
2959
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
@@ -2954,46 +2964,46 @@ function useSelect(userProps) {
|
|
|
2954
2964
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
2955
2965
|
return {
|
|
2956
2966
|
// prop getters.
|
|
2957
|
-
getToggleButtonProps
|
|
2958
|
-
getLabelProps
|
|
2959
|
-
getMenuProps
|
|
2960
|
-
getItemProps
|
|
2967
|
+
getToggleButtonProps,
|
|
2968
|
+
getLabelProps,
|
|
2969
|
+
getMenuProps,
|
|
2970
|
+
getItemProps,
|
|
2961
2971
|
// actions.
|
|
2962
|
-
toggleMenu
|
|
2963
|
-
openMenu
|
|
2964
|
-
closeMenu
|
|
2965
|
-
setHighlightedIndex
|
|
2966
|
-
selectItem
|
|
2967
|
-
reset
|
|
2968
|
-
setInputValue
|
|
2972
|
+
toggleMenu,
|
|
2973
|
+
openMenu,
|
|
2974
|
+
closeMenu,
|
|
2975
|
+
setHighlightedIndex,
|
|
2976
|
+
selectItem,
|
|
2977
|
+
reset,
|
|
2978
|
+
setInputValue,
|
|
2969
2979
|
// state.
|
|
2970
|
-
highlightedIndex
|
|
2971
|
-
isOpen
|
|
2972
|
-
selectedItem
|
|
2973
|
-
inputValue
|
|
2980
|
+
highlightedIndex,
|
|
2981
|
+
isOpen,
|
|
2982
|
+
selectedItem,
|
|
2983
|
+
inputValue
|
|
2974
2984
|
};
|
|
2975
2985
|
}
|
|
2976
2986
|
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2987
|
+
const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2988
|
+
const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2989
|
+
const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
2990
|
+
const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
|
|
2991
|
+
const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
|
|
2992
|
+
const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
|
|
2993
|
+
const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
|
|
2994
|
+
const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
|
|
2995
|
+
const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
|
|
2996
|
+
const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
|
|
2997
|
+
const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
|
|
2998
|
+
const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
|
|
2999
|
+
const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
|
|
3000
|
+
const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
|
|
3001
|
+
const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
|
|
3002
|
+
const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
|
|
3003
|
+
const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
|
|
3004
|
+
const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
|
|
3005
|
+
const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
|
|
3006
|
+
const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
|
|
2997
3007
|
|
|
2998
3008
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2999
3009
|
__proto__: null,
|
|
@@ -3020,56 +3030,60 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3020
3030
|
});
|
|
3021
3031
|
|
|
3022
3032
|
function getInitialState$1(props) {
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3033
|
+
const initialState = getInitialState$2(props);
|
|
3034
|
+
const {
|
|
3035
|
+
selectedItem
|
|
3036
|
+
} = initialState;
|
|
3037
|
+
let {
|
|
3038
|
+
inputValue
|
|
3039
|
+
} = initialState;
|
|
3026
3040
|
|
|
3027
3041
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3028
3042
|
inputValue = props.itemToString(selectedItem);
|
|
3029
3043
|
}
|
|
3030
3044
|
|
|
3031
|
-
return
|
|
3032
|
-
inputValue
|
|
3033
|
-
}
|
|
3045
|
+
return { ...initialState,
|
|
3046
|
+
inputValue
|
|
3047
|
+
};
|
|
3034
3048
|
}
|
|
3035
3049
|
|
|
3036
|
-
|
|
3037
|
-
items: PropTypes__default[
|
|
3038
|
-
itemToString: PropTypes__default[
|
|
3039
|
-
getA11yStatusMessage: PropTypes__default[
|
|
3040
|
-
getA11ySelectionMessage: PropTypes__default[
|
|
3041
|
-
circularNavigation: PropTypes__default[
|
|
3042
|
-
highlightedIndex: PropTypes__default[
|
|
3043
|
-
defaultHighlightedIndex: PropTypes__default[
|
|
3044
|
-
initialHighlightedIndex: PropTypes__default[
|
|
3045
|
-
isOpen: PropTypes__default[
|
|
3046
|
-
defaultIsOpen: PropTypes__default[
|
|
3047
|
-
initialIsOpen: PropTypes__default[
|
|
3048
|
-
selectedItem: PropTypes__default[
|
|
3049
|
-
initialSelectedItem: PropTypes__default[
|
|
3050
|
-
defaultSelectedItem: PropTypes__default[
|
|
3051
|
-
inputValue: PropTypes__default[
|
|
3052
|
-
defaultInputValue: PropTypes__default[
|
|
3053
|
-
initialInputValue: PropTypes__default[
|
|
3054
|
-
id: PropTypes__default[
|
|
3055
|
-
labelId: PropTypes__default[
|
|
3056
|
-
menuId: PropTypes__default[
|
|
3057
|
-
getItemId: PropTypes__default[
|
|
3058
|
-
inputId: PropTypes__default[
|
|
3059
|
-
toggleButtonId: PropTypes__default[
|
|
3060
|
-
stateReducer: PropTypes__default[
|
|
3061
|
-
onSelectedItemChange: PropTypes__default[
|
|
3062
|
-
onHighlightedIndexChange: PropTypes__default[
|
|
3063
|
-
onStateChange: PropTypes__default[
|
|
3064
|
-
onIsOpenChange: PropTypes__default[
|
|
3065
|
-
onInputValueChange: PropTypes__default[
|
|
3066
|
-
environment: PropTypes__default[
|
|
3067
|
-
addEventListener: PropTypes__default[
|
|
3068
|
-
removeEventListener: PropTypes__default[
|
|
3069
|
-
document: PropTypes__default[
|
|
3070
|
-
getElementById: PropTypes__default[
|
|
3071
|
-
activeElement: PropTypes__default[
|
|
3072
|
-
body: PropTypes__default[
|
|
3050
|
+
const propTypes$1 = {
|
|
3051
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
3052
|
+
itemToString: PropTypes__default["default"].func,
|
|
3053
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
3054
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
3055
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
3056
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
3057
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
3058
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
3059
|
+
isOpen: PropTypes__default["default"].bool,
|
|
3060
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
3061
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
3062
|
+
selectedItem: PropTypes__default["default"].any,
|
|
3063
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
3064
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
3065
|
+
inputValue: PropTypes__default["default"].string,
|
|
3066
|
+
defaultInputValue: PropTypes__default["default"].string,
|
|
3067
|
+
initialInputValue: PropTypes__default["default"].string,
|
|
3068
|
+
id: PropTypes__default["default"].string,
|
|
3069
|
+
labelId: PropTypes__default["default"].string,
|
|
3070
|
+
menuId: PropTypes__default["default"].string,
|
|
3071
|
+
getItemId: PropTypes__default["default"].func,
|
|
3072
|
+
inputId: PropTypes__default["default"].string,
|
|
3073
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
3074
|
+
stateReducer: PropTypes__default["default"].func,
|
|
3075
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
3076
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
3077
|
+
onStateChange: PropTypes__default["default"].func,
|
|
3078
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
3079
|
+
onInputValueChange: PropTypes__default["default"].func,
|
|
3080
|
+
environment: PropTypes__default["default"].shape({
|
|
3081
|
+
addEventListener: PropTypes__default["default"].func,
|
|
3082
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
3083
|
+
document: PropTypes__default["default"].shape({
|
|
3084
|
+
getElementById: PropTypes__default["default"].func,
|
|
3085
|
+
activeElement: PropTypes__default["default"].any,
|
|
3086
|
+
body: PropTypes__default["default"].any
|
|
3073
3087
|
})
|
|
3074
3088
|
})
|
|
3075
3089
|
};
|
|
@@ -3087,14 +3101,10 @@ var propTypes$1 = {
|
|
|
3087
3101
|
*/
|
|
3088
3102
|
|
|
3089
3103
|
function useControlledReducer(reducer, initialState, props) {
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
3093
|
-
state = _useEnhancedReducer[0],
|
|
3094
|
-
dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3095
|
-
|
|
3104
|
+
const previousSelectedItemRef = preact.useRef();
|
|
3105
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3096
3106
|
|
|
3097
|
-
preact.useEffect(
|
|
3107
|
+
preact.useEffect(() => {
|
|
3098
3108
|
if (isControlledProp(props, 'selectedItem')) {
|
|
3099
3109
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
3100
3110
|
dispatch({
|
|
@@ -3110,27 +3120,29 @@ function useControlledReducer(reducer, initialState, props) {
|
|
|
3110
3120
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
3111
3121
|
|
|
3112
3122
|
|
|
3113
|
-
|
|
3123
|
+
let validatePropTypes$1 = noop;
|
|
3114
3124
|
/* istanbul ignore next */
|
|
3115
3125
|
|
|
3116
3126
|
if (process.env.NODE_ENV !== 'production') {
|
|
3117
|
-
validatePropTypes$1 =
|
|
3118
|
-
PropTypes__default[
|
|
3127
|
+
validatePropTypes$1 = (options, caller) => {
|
|
3128
|
+
PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
3119
3129
|
};
|
|
3120
3130
|
}
|
|
3121
3131
|
|
|
3122
|
-
|
|
3132
|
+
const defaultProps$1 = { ...defaultProps$3,
|
|
3123
3133
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
3124
3134
|
circularNavigation: true
|
|
3125
|
-
}
|
|
3135
|
+
};
|
|
3126
3136
|
|
|
3127
3137
|
/* eslint-disable complexity */
|
|
3128
3138
|
|
|
3129
3139
|
function downshiftUseComboboxReducer(state, action) {
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3140
|
+
const {
|
|
3141
|
+
type,
|
|
3142
|
+
props,
|
|
3143
|
+
shiftKey
|
|
3144
|
+
} = action;
|
|
3145
|
+
let changes;
|
|
3134
3146
|
|
|
3135
3147
|
switch (type) {
|
|
3136
3148
|
case ItemClick:
|
|
@@ -3171,22 +3183,24 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3171
3183
|
break;
|
|
3172
3184
|
|
|
3173
3185
|
case InputKeyDownEnter:
|
|
3174
|
-
changes =
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3186
|
+
changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
|
|
3187
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3188
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3189
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3190
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3191
|
+
})
|
|
3192
|
+
};
|
|
3180
3193
|
break;
|
|
3181
3194
|
|
|
3182
3195
|
case InputKeyDownEscape:
|
|
3183
|
-
changes =
|
|
3196
|
+
changes = {
|
|
3184
3197
|
isOpen: false,
|
|
3185
|
-
highlightedIndex: -1
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3198
|
+
highlightedIndex: -1,
|
|
3199
|
+
...(!state.isOpen && {
|
|
3200
|
+
selectedItem: null,
|
|
3201
|
+
inputValue: ''
|
|
3202
|
+
})
|
|
3203
|
+
};
|
|
3190
3204
|
break;
|
|
3191
3205
|
|
|
3192
3206
|
case InputKeyDownHome:
|
|
@@ -3202,13 +3216,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3202
3216
|
break;
|
|
3203
3217
|
|
|
3204
3218
|
case InputBlur:
|
|
3205
|
-
changes =
|
|
3219
|
+
changes = {
|
|
3206
3220
|
isOpen: false,
|
|
3207
|
-
highlightedIndex: -1
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3221
|
+
highlightedIndex: -1,
|
|
3222
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
3223
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3224
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3225
|
+
})
|
|
3226
|
+
};
|
|
3212
3227
|
break;
|
|
3213
3228
|
|
|
3214
3229
|
case InputChange:
|
|
@@ -3236,15 +3251,13 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3236
3251
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
3237
3252
|
}
|
|
3238
3253
|
|
|
3239
|
-
return
|
|
3254
|
+
return { ...state,
|
|
3255
|
+
...changes
|
|
3256
|
+
};
|
|
3240
3257
|
}
|
|
3241
3258
|
/* eslint-enable complexity */
|
|
3242
3259
|
|
|
3243
|
-
|
|
3244
|
-
_excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"],
|
|
3245
|
-
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
3246
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"],
|
|
3247
|
-
_excluded5 = ["refKey", "ref"];
|
|
3260
|
+
/* eslint-disable max-statements */
|
|
3248
3261
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
3249
3262
|
|
|
3250
3263
|
function useCombobox(userProps) {
|
|
@@ -3254,87 +3267,88 @@ function useCombobox(userProps) {
|
|
|
3254
3267
|
|
|
3255
3268
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
3256
3269
|
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3270
|
+
const props = { ...defaultProps$1,
|
|
3271
|
+
...userProps
|
|
3272
|
+
};
|
|
3273
|
+
const {
|
|
3274
|
+
initialIsOpen,
|
|
3275
|
+
defaultIsOpen,
|
|
3276
|
+
items,
|
|
3277
|
+
scrollIntoView,
|
|
3278
|
+
environment,
|
|
3279
|
+
getA11yStatusMessage,
|
|
3280
|
+
getA11ySelectionMessage,
|
|
3281
|
+
itemToString
|
|
3282
|
+
} = props; // Initial state depending on controlled props.
|
|
3283
|
+
|
|
3284
|
+
const initialState = getInitialState$1(props);
|
|
3285
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
3286
|
+
const {
|
|
3287
|
+
isOpen,
|
|
3288
|
+
highlightedIndex,
|
|
3289
|
+
selectedItem,
|
|
3290
|
+
inputValue
|
|
3291
|
+
} = state; // Element refs.
|
|
3292
|
+
|
|
3293
|
+
const menuRef = preact.useRef(null);
|
|
3294
|
+
const itemRefs = preact.useRef({});
|
|
3295
|
+
const inputRef = preact.useRef(null);
|
|
3296
|
+
const toggleButtonRef = preact.useRef(null);
|
|
3297
|
+
const comboboxRef = preact.useRef(null);
|
|
3298
|
+
const isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
|
|
3299
|
+
|
|
3300
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
3301
|
+
|
|
3302
|
+
const previousResultCountRef = preact.useRef(); // utility callback to get item element.
|
|
3303
|
+
|
|
3304
|
+
const latest = useLatestRef({
|
|
3305
|
+
state,
|
|
3306
|
+
props
|
|
3293
3307
|
});
|
|
3294
|
-
|
|
3295
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3296
|
-
}, [elementIds]); // Effects.
|
|
3308
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
3297
3309
|
// Sets a11y status message on changes in state.
|
|
3298
3310
|
|
|
3299
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
3311
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3300
3312
|
isInitialMount: isInitialMountRef.current,
|
|
3301
3313
|
previousResultCount: previousResultCountRef.current,
|
|
3302
|
-
items
|
|
3303
|
-
environment
|
|
3304
|
-
itemToString
|
|
3305
|
-
|
|
3314
|
+
items,
|
|
3315
|
+
environment,
|
|
3316
|
+
itemToString,
|
|
3317
|
+
...state
|
|
3318
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
3306
3319
|
|
|
3307
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
3320
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3308
3321
|
isInitialMount: isInitialMountRef.current,
|
|
3309
3322
|
previousResultCount: previousResultCountRef.current,
|
|
3310
|
-
items
|
|
3311
|
-
environment
|
|
3312
|
-
itemToString
|
|
3313
|
-
|
|
3323
|
+
items,
|
|
3324
|
+
environment,
|
|
3325
|
+
itemToString,
|
|
3326
|
+
...state
|
|
3327
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
3314
3328
|
|
|
3315
|
-
|
|
3329
|
+
const shouldScrollRef = useScrollIntoView({
|
|
3316
3330
|
menuElement: menuRef.current,
|
|
3317
|
-
highlightedIndex
|
|
3318
|
-
isOpen
|
|
3319
|
-
itemRefs
|
|
3320
|
-
scrollIntoView
|
|
3321
|
-
getItemNodeFromIndex
|
|
3331
|
+
highlightedIndex,
|
|
3332
|
+
isOpen,
|
|
3333
|
+
itemRefs,
|
|
3334
|
+
scrollIntoView,
|
|
3335
|
+
getItemNodeFromIndex
|
|
3322
3336
|
});
|
|
3323
3337
|
useControlPropsValidator({
|
|
3324
3338
|
isInitialMount: isInitialMountRef.current,
|
|
3325
|
-
props
|
|
3326
|
-
state
|
|
3339
|
+
props,
|
|
3340
|
+
state
|
|
3327
3341
|
}); // Focus the input on first render if required.
|
|
3328
3342
|
|
|
3329
|
-
preact.useEffect(
|
|
3330
|
-
|
|
3343
|
+
preact.useEffect(() => {
|
|
3344
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
3331
3345
|
|
|
3332
3346
|
if (focusOnOpen && inputRef.current) {
|
|
3333
3347
|
inputRef.current.focus();
|
|
3334
3348
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3335
3349
|
|
|
3336
3350
|
}, []);
|
|
3337
|
-
preact.useEffect(
|
|
3351
|
+
preact.useEffect(() => {
|
|
3338
3352
|
if (isInitialMountRef.current) {
|
|
3339
3353
|
return;
|
|
3340
3354
|
}
|
|
@@ -3342,147 +3356,151 @@ function useCombobox(userProps) {
|
|
|
3342
3356
|
previousResultCountRef.current = items.length;
|
|
3343
3357
|
}); // Add mouse/touch events to document.
|
|
3344
3358
|
|
|
3345
|
-
|
|
3359
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
|
|
3346
3360
|
dispatch({
|
|
3347
3361
|
type: InputBlur,
|
|
3348
3362
|
selectItem: false
|
|
3349
3363
|
});
|
|
3350
3364
|
});
|
|
3351
|
-
|
|
3365
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
3352
3366
|
|
|
3353
|
-
preact.useEffect(
|
|
3367
|
+
preact.useEffect(() => {
|
|
3354
3368
|
isInitialMountRef.current = false;
|
|
3355
3369
|
}, []); // Reset itemRefs on close.
|
|
3356
3370
|
|
|
3357
|
-
preact.useEffect(
|
|
3371
|
+
preact.useEffect(() => {
|
|
3358
3372
|
if (!isOpen) {
|
|
3359
3373
|
itemRefs.current = {};
|
|
3360
3374
|
}
|
|
3361
3375
|
}, [isOpen]);
|
|
3362
3376
|
/* Event handler functions */
|
|
3363
3377
|
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
},
|
|
3374
|
-
ArrowUp: function ArrowUp(event) {
|
|
3375
|
-
event.preventDefault();
|
|
3376
|
-
dispatch({
|
|
3377
|
-
type: InputKeyDownArrowUp,
|
|
3378
|
-
shiftKey: event.shiftKey,
|
|
3379
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3380
|
-
});
|
|
3381
|
-
},
|
|
3382
|
-
Home: function Home(event) {
|
|
3383
|
-
if (!latest.current.state.isOpen) {
|
|
3384
|
-
return;
|
|
3385
|
-
}
|
|
3378
|
+
const inputKeyDownHandlers = preact.useMemo(() => ({
|
|
3379
|
+
ArrowDown(event) {
|
|
3380
|
+
event.preventDefault();
|
|
3381
|
+
dispatch({
|
|
3382
|
+
type: InputKeyDownArrowDown,
|
|
3383
|
+
shiftKey: event.shiftKey,
|
|
3384
|
+
getItemNodeFromIndex
|
|
3385
|
+
});
|
|
3386
|
+
},
|
|
3386
3387
|
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
return;
|
|
3396
|
-
}
|
|
3388
|
+
ArrowUp(event) {
|
|
3389
|
+
event.preventDefault();
|
|
3390
|
+
dispatch({
|
|
3391
|
+
type: InputKeyDownArrowUp,
|
|
3392
|
+
shiftKey: event.shiftKey,
|
|
3393
|
+
getItemNodeFromIndex
|
|
3394
|
+
});
|
|
3395
|
+
},
|
|
3397
3396
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
});
|
|
3403
|
-
},
|
|
3404
|
-
Escape: function Escape() {
|
|
3405
|
-
var latestState = latest.current.state;
|
|
3397
|
+
Home(event) {
|
|
3398
|
+
if (!latest.current.state.isOpen) {
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3406
3401
|
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
Enter: function Enter(event) {
|
|
3414
|
-
var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3402
|
+
event.preventDefault();
|
|
3403
|
+
dispatch({
|
|
3404
|
+
type: InputKeyDownHome,
|
|
3405
|
+
getItemNodeFromIndex
|
|
3406
|
+
});
|
|
3407
|
+
},
|
|
3415
3408
|
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3409
|
+
End(event) {
|
|
3410
|
+
if (!latest.current.state.isOpen) {
|
|
3411
|
+
return;
|
|
3412
|
+
}
|
|
3420
3413
|
|
|
3421
|
-
|
|
3414
|
+
event.preventDefault();
|
|
3415
|
+
dispatch({
|
|
3416
|
+
type: InputKeyDownEnd,
|
|
3417
|
+
getItemNodeFromIndex
|
|
3418
|
+
});
|
|
3419
|
+
},
|
|
3420
|
+
|
|
3421
|
+
Escape() {
|
|
3422
|
+
const latestState = latest.current.state;
|
|
3423
|
+
|
|
3424
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
3422
3425
|
dispatch({
|
|
3423
|
-
type:
|
|
3424
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3426
|
+
type: InputKeyDownEscape
|
|
3425
3427
|
});
|
|
3426
3428
|
}
|
|
3427
|
-
}
|
|
3428
|
-
}, [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3429
|
-
|
|
3430
|
-
var getLabelProps = preact.useCallback(function (labelProps) {
|
|
3431
|
-
return _extends__default['default']({
|
|
3432
|
-
id: elementIds.labelId,
|
|
3433
|
-
htmlFor: elementIds.inputId
|
|
3434
|
-
}, labelProps);
|
|
3435
|
-
}, [elementIds]);
|
|
3436
|
-
var getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3437
|
-
var _extends2;
|
|
3438
|
-
|
|
3439
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
3440
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
3441
|
-
_ref$refKey = _ref.refKey,
|
|
3442
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
3443
|
-
ref = _ref.ref,
|
|
3444
|
-
rest = _objectWithoutPropertiesLoose__default['default'](_ref, _excluded$1);
|
|
3445
|
-
|
|
3446
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
3447
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3448
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3429
|
+
},
|
|
3449
3430
|
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3431
|
+
Enter(event) {
|
|
3432
|
+
const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3433
|
+
|
|
3434
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3435
|
+
) {
|
|
3436
|
+
return;
|
|
3437
|
+
}
|
|
3438
|
+
|
|
3439
|
+
event.preventDefault();
|
|
3454
3440
|
dispatch({
|
|
3455
|
-
type:
|
|
3441
|
+
type: InputKeyDownEnter,
|
|
3442
|
+
getItemNodeFromIndex
|
|
3456
3443
|
});
|
|
3457
|
-
}
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
}), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3447
|
+
|
|
3448
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
3449
|
+
id: elementIds.labelId,
|
|
3450
|
+
htmlFor: elementIds.inputId,
|
|
3451
|
+
...labelProps
|
|
3452
|
+
}), [elementIds]);
|
|
3453
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3454
|
+
let {
|
|
3455
|
+
onMouseLeave,
|
|
3456
|
+
refKey = 'ref',
|
|
3457
|
+
ref,
|
|
3458
|
+
...rest
|
|
3459
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3460
|
+
let {
|
|
3461
|
+
suppressRefError = false
|
|
3462
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3463
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3464
|
+
return {
|
|
3465
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3466
|
+
menuRef.current = menuNode;
|
|
3467
|
+
}),
|
|
3468
|
+
id: elementIds.menuId,
|
|
3469
|
+
role: 'listbox',
|
|
3470
|
+
'aria-labelledby': elementIds.labelId,
|
|
3471
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
3472
|
+
dispatch({
|
|
3473
|
+
type: MenuMouseLeave
|
|
3474
|
+
});
|
|
3475
|
+
}),
|
|
3476
|
+
...rest
|
|
3477
|
+
};
|
|
3458
3478
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
latestState = _latest$current.state;
|
|
3476
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3479
|
+
const getItemProps = preact.useCallback(function (_temp3) {
|
|
3480
|
+
let {
|
|
3481
|
+
item,
|
|
3482
|
+
index,
|
|
3483
|
+
refKey = 'ref',
|
|
3484
|
+
ref,
|
|
3485
|
+
onMouseMove,
|
|
3486
|
+
onClick,
|
|
3487
|
+
onPress,
|
|
3488
|
+
...rest
|
|
3489
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3490
|
+
const {
|
|
3491
|
+
props: latestProps,
|
|
3492
|
+
state: latestState
|
|
3493
|
+
} = latest.current;
|
|
3494
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3477
3495
|
|
|
3478
3496
|
if (itemIndex < 0) {
|
|
3479
3497
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3480
3498
|
}
|
|
3481
3499
|
|
|
3482
|
-
|
|
3483
|
-
|
|
3500
|
+
const onSelectKey = 'onClick';
|
|
3501
|
+
const customClickHandler = onClick;
|
|
3484
3502
|
|
|
3485
|
-
|
|
3503
|
+
const itemHandleMouseMove = () => {
|
|
3486
3504
|
if (index === latestState.highlightedIndex) {
|
|
3487
3505
|
return;
|
|
3488
3506
|
}
|
|
@@ -3490,14 +3508,14 @@ function useCombobox(userProps) {
|
|
|
3490
3508
|
shouldScrollRef.current = false;
|
|
3491
3509
|
dispatch({
|
|
3492
3510
|
type: ItemMouseMove,
|
|
3493
|
-
index
|
|
3511
|
+
index
|
|
3494
3512
|
});
|
|
3495
3513
|
};
|
|
3496
3514
|
|
|
3497
|
-
|
|
3515
|
+
const itemHandleClick = () => {
|
|
3498
3516
|
dispatch({
|
|
3499
3517
|
type: ItemClick,
|
|
3500
|
-
index
|
|
3518
|
+
index
|
|
3501
3519
|
});
|
|
3502
3520
|
|
|
3503
3521
|
if (inputRef.current) {
|
|
@@ -3505,26 +3523,32 @@ function useCombobox(userProps) {
|
|
|
3505
3523
|
}
|
|
3506
3524
|
};
|
|
3507
3525
|
|
|
3508
|
-
return
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3526
|
+
return {
|
|
3527
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3528
|
+
if (itemNode) {
|
|
3529
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3530
|
+
}
|
|
3531
|
+
}),
|
|
3532
|
+
role: 'option',
|
|
3533
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
3534
|
+
id: elementIds.getItemId(itemIndex),
|
|
3535
|
+
...(!rest.disabled && {
|
|
3536
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3537
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
3538
|
+
}),
|
|
3539
|
+
...rest
|
|
3540
|
+
};
|
|
3515
3541
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3542
|
+
const getToggleButtonProps = preact.useCallback(function (_temp4) {
|
|
3543
|
+
let {
|
|
3544
|
+
onClick,
|
|
3545
|
+
onPress,
|
|
3546
|
+
refKey = 'ref',
|
|
3547
|
+
ref,
|
|
3548
|
+
...rest
|
|
3549
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3550
|
+
|
|
3551
|
+
const toggleButtonHandleClick = () => {
|
|
3528
3552
|
dispatch({
|
|
3529
3553
|
type: ToggleButtonClick
|
|
3530
3554
|
});
|
|
@@ -3534,49 +3558,52 @@ function useCombobox(userProps) {
|
|
|
3534
3558
|
}
|
|
3535
3559
|
};
|
|
3536
3560
|
|
|
3537
|
-
return
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3561
|
+
return {
|
|
3562
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3563
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3564
|
+
}),
|
|
3565
|
+
id: elementIds.toggleButtonId,
|
|
3566
|
+
tabIndex: -1,
|
|
3567
|
+
...(!rest.disabled && { ...({
|
|
3568
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3569
|
+
})
|
|
3570
|
+
}),
|
|
3571
|
+
...rest
|
|
3572
|
+
};
|
|
3542
3573
|
}, [dispatch, latest, elementIds]);
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
var _ref7 = _temp6 === void 0 ? {} : _temp6,
|
|
3558
|
-
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
3559
|
-
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3560
|
-
|
|
3574
|
+
const getInputProps = preact.useCallback(function (_temp5, _temp6) {
|
|
3575
|
+
let {
|
|
3576
|
+
onKeyDown,
|
|
3577
|
+
onChange,
|
|
3578
|
+
onInput,
|
|
3579
|
+
onBlur,
|
|
3580
|
+
onChangeText,
|
|
3581
|
+
refKey = 'ref',
|
|
3582
|
+
ref,
|
|
3583
|
+
...rest
|
|
3584
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3585
|
+
let {
|
|
3586
|
+
suppressRefError = false
|
|
3587
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
3561
3588
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3562
|
-
|
|
3589
|
+
const latestState = latest.current.state;
|
|
3563
3590
|
|
|
3564
|
-
|
|
3565
|
-
|
|
3591
|
+
const inputHandleKeyDown = event => {
|
|
3592
|
+
const key = normalizeArrowKey(event);
|
|
3566
3593
|
|
|
3567
3594
|
if (key && inputKeyDownHandlers[key]) {
|
|
3568
3595
|
inputKeyDownHandlers[key](event);
|
|
3569
3596
|
}
|
|
3570
3597
|
};
|
|
3571
3598
|
|
|
3572
|
-
|
|
3599
|
+
const inputHandleChange = event => {
|
|
3573
3600
|
dispatch({
|
|
3574
3601
|
type: InputChange,
|
|
3575
3602
|
inputValue: event.target.value
|
|
3576
3603
|
});
|
|
3577
3604
|
};
|
|
3578
3605
|
|
|
3579
|
-
|
|
3606
|
+
const inputHandleBlur = () => {
|
|
3580
3607
|
/* istanbul ignore else */
|
|
3581
3608
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3582
3609
|
dispatch({
|
|
@@ -3588,109 +3615,121 @@ function useCombobox(userProps) {
|
|
|
3588
3615
|
/* istanbul ignore next (preact) */
|
|
3589
3616
|
|
|
3590
3617
|
|
|
3591
|
-
|
|
3592
|
-
|
|
3618
|
+
const onChangeKey = 'onInput' ;
|
|
3619
|
+
let eventHandlers = {};
|
|
3593
3620
|
|
|
3594
3621
|
if (!rest.disabled) {
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3622
|
+
eventHandlers = {
|
|
3623
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
3624
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
3625
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
|
|
3626
|
+
};
|
|
3598
3627
|
}
|
|
3599
3628
|
|
|
3600
|
-
return
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3629
|
+
return {
|
|
3630
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
3631
|
+
inputRef.current = inputNode;
|
|
3632
|
+
}),
|
|
3633
|
+
id: elementIds.inputId,
|
|
3634
|
+
'aria-autocomplete': 'list',
|
|
3635
|
+
'aria-controls': elementIds.menuId,
|
|
3636
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3637
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
3638
|
+
}),
|
|
3605
3639
|
'aria-labelledby': elementIds.labelId,
|
|
3606
3640
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
3607
3641
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
3608
3642
|
autoComplete: 'off',
|
|
3609
|
-
value: latestState.inputValue
|
|
3610
|
-
|
|
3643
|
+
value: latestState.inputValue,
|
|
3644
|
+
...eventHandlers,
|
|
3645
|
+
...rest
|
|
3646
|
+
};
|
|
3611
3647
|
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
var _ref9 = _temp8 === void 0 ? {} : _temp8,
|
|
3622
|
-
_ref9$suppressRefErro = _ref9.suppressRefError,
|
|
3623
|
-
suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
|
|
3624
|
-
|
|
3648
|
+
const getComboboxProps = preact.useCallback(function (_temp7, _temp8) {
|
|
3649
|
+
let {
|
|
3650
|
+
refKey = 'ref',
|
|
3651
|
+
ref,
|
|
3652
|
+
...rest
|
|
3653
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
3654
|
+
let {
|
|
3655
|
+
suppressRefError = false
|
|
3656
|
+
} = _temp8 === void 0 ? {} : _temp8;
|
|
3625
3657
|
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
3626
|
-
return
|
|
3627
|
-
|
|
3628
|
-
|
|
3658
|
+
return {
|
|
3659
|
+
[refKey]: handleRefs(ref, comboboxNode => {
|
|
3660
|
+
comboboxRef.current = comboboxNode;
|
|
3661
|
+
}),
|
|
3662
|
+
role: 'combobox',
|
|
3663
|
+
'aria-haspopup': 'listbox',
|
|
3664
|
+
'aria-owns': elementIds.menuId,
|
|
3665
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
3666
|
+
...rest
|
|
3667
|
+
};
|
|
3629
3668
|
}, [latest, setGetterPropCallInfo, elementIds]); // returns
|
|
3630
3669
|
|
|
3631
|
-
|
|
3670
|
+
const toggleMenu = preact.useCallback(() => {
|
|
3632
3671
|
dispatch({
|
|
3633
3672
|
type: FunctionToggleMenu
|
|
3634
3673
|
});
|
|
3635
3674
|
}, [dispatch]);
|
|
3636
|
-
|
|
3675
|
+
const closeMenu = preact.useCallback(() => {
|
|
3637
3676
|
dispatch({
|
|
3638
3677
|
type: FunctionCloseMenu
|
|
3639
3678
|
});
|
|
3640
3679
|
}, [dispatch]);
|
|
3641
|
-
|
|
3680
|
+
const openMenu = preact.useCallback(() => {
|
|
3642
3681
|
dispatch({
|
|
3643
3682
|
type: FunctionOpenMenu
|
|
3644
3683
|
});
|
|
3645
3684
|
}, [dispatch]);
|
|
3646
|
-
|
|
3685
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
3647
3686
|
dispatch({
|
|
3648
3687
|
type: FunctionSetHighlightedIndex,
|
|
3649
3688
|
highlightedIndex: newHighlightedIndex
|
|
3650
3689
|
});
|
|
3651
3690
|
}, [dispatch]);
|
|
3652
|
-
|
|
3691
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
3653
3692
|
dispatch({
|
|
3654
3693
|
type: FunctionSelectItem,
|
|
3655
3694
|
selectedItem: newSelectedItem
|
|
3656
3695
|
});
|
|
3657
3696
|
}, [dispatch]);
|
|
3658
|
-
|
|
3697
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
3659
3698
|
dispatch({
|
|
3660
3699
|
type: FunctionSetInputValue,
|
|
3661
3700
|
inputValue: newInputValue
|
|
3662
3701
|
});
|
|
3663
3702
|
}, [dispatch]);
|
|
3664
|
-
|
|
3703
|
+
const reset = preact.useCallback(() => {
|
|
3665
3704
|
dispatch({
|
|
3666
3705
|
type: FunctionReset$1
|
|
3667
3706
|
});
|
|
3668
3707
|
}, [dispatch]);
|
|
3669
3708
|
return {
|
|
3670
3709
|
// prop getters.
|
|
3671
|
-
getItemProps
|
|
3672
|
-
getLabelProps
|
|
3673
|
-
getMenuProps
|
|
3674
|
-
getInputProps
|
|
3675
|
-
getComboboxProps
|
|
3676
|
-
getToggleButtonProps
|
|
3710
|
+
getItemProps,
|
|
3711
|
+
getLabelProps,
|
|
3712
|
+
getMenuProps,
|
|
3713
|
+
getInputProps,
|
|
3714
|
+
getComboboxProps,
|
|
3715
|
+
getToggleButtonProps,
|
|
3677
3716
|
// actions.
|
|
3678
|
-
toggleMenu
|
|
3679
|
-
openMenu
|
|
3680
|
-
closeMenu
|
|
3681
|
-
setHighlightedIndex
|
|
3682
|
-
setInputValue
|
|
3683
|
-
selectItem
|
|
3684
|
-
reset
|
|
3717
|
+
toggleMenu,
|
|
3718
|
+
openMenu,
|
|
3719
|
+
closeMenu,
|
|
3720
|
+
setHighlightedIndex,
|
|
3721
|
+
setInputValue,
|
|
3722
|
+
selectItem,
|
|
3723
|
+
reset,
|
|
3685
3724
|
// state.
|
|
3686
|
-
highlightedIndex
|
|
3687
|
-
isOpen
|
|
3688
|
-
selectedItem
|
|
3689
|
-
inputValue
|
|
3725
|
+
highlightedIndex,
|
|
3726
|
+
isOpen,
|
|
3727
|
+
selectedItem,
|
|
3728
|
+
inputValue
|
|
3690
3729
|
};
|
|
3691
3730
|
}
|
|
3692
3731
|
|
|
3693
|
-
|
|
3732
|
+
const defaultStateValues = {
|
|
3694
3733
|
activeIndex: -1,
|
|
3695
3734
|
selectedItems: []
|
|
3696
3735
|
};
|
|
@@ -3730,11 +3769,11 @@ function getDefaultValue(props, propKey) {
|
|
|
3730
3769
|
|
|
3731
3770
|
|
|
3732
3771
|
function getInitialState(props) {
|
|
3733
|
-
|
|
3734
|
-
|
|
3772
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
3773
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
3735
3774
|
return {
|
|
3736
|
-
activeIndex
|
|
3737
|
-
selectedItems
|
|
3775
|
+
activeIndex,
|
|
3776
|
+
selectedItems
|
|
3738
3777
|
};
|
|
3739
3778
|
}
|
|
3740
3779
|
/**
|
|
@@ -3753,10 +3792,12 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3753
3792
|
return false;
|
|
3754
3793
|
}
|
|
3755
3794
|
|
|
3756
|
-
|
|
3795
|
+
const element = event.target;
|
|
3757
3796
|
|
|
3758
3797
|
if (element instanceof HTMLInputElement && // if element is a text input
|
|
3759
|
-
element.value !== '' && (
|
|
3798
|
+
element.value !== '' && ( // and we have text in it
|
|
3799
|
+
// and cursor is either not at the start or is currently highlighting text.
|
|
3800
|
+
element.selectionStart !== 0 || element.selectionEnd !== 0)) {
|
|
3760
3801
|
return false;
|
|
3761
3802
|
}
|
|
3762
3803
|
|
|
@@ -3771,66 +3812,68 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3771
3812
|
|
|
3772
3813
|
|
|
3773
3814
|
function getA11yRemovalMessage(selectionParameters) {
|
|
3774
|
-
|
|
3775
|
-
|
|
3815
|
+
const {
|
|
3816
|
+
removedSelectedItem,
|
|
3817
|
+
itemToString: itemToStringLocal
|
|
3818
|
+
} = selectionParameters;
|
|
3776
3819
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3777
3820
|
}
|
|
3778
3821
|
|
|
3779
|
-
|
|
3780
|
-
selectedItems: PropTypes__default[
|
|
3781
|
-
initialSelectedItems: PropTypes__default[
|
|
3782
|
-
defaultSelectedItems: PropTypes__default[
|
|
3783
|
-
itemToString: PropTypes__default[
|
|
3784
|
-
getA11yRemovalMessage: PropTypes__default[
|
|
3785
|
-
stateReducer: PropTypes__default[
|
|
3786
|
-
activeIndex: PropTypes__default[
|
|
3787
|
-
initialActiveIndex: PropTypes__default[
|
|
3788
|
-
defaultActiveIndex: PropTypes__default[
|
|
3789
|
-
onActiveIndexChange: PropTypes__default[
|
|
3790
|
-
onSelectedItemsChange: PropTypes__default[
|
|
3791
|
-
keyNavigationNext: PropTypes__default[
|
|
3792
|
-
keyNavigationPrevious: PropTypes__default[
|
|
3793
|
-
environment: PropTypes__default[
|
|
3794
|
-
addEventListener: PropTypes__default[
|
|
3795
|
-
removeEventListener: PropTypes__default[
|
|
3796
|
-
document: PropTypes__default[
|
|
3797
|
-
getElementById: PropTypes__default[
|
|
3798
|
-
activeElement: PropTypes__default[
|
|
3799
|
-
body: PropTypes__default[
|
|
3822
|
+
const propTypes = {
|
|
3823
|
+
selectedItems: PropTypes__default["default"].array,
|
|
3824
|
+
initialSelectedItems: PropTypes__default["default"].array,
|
|
3825
|
+
defaultSelectedItems: PropTypes__default["default"].array,
|
|
3826
|
+
itemToString: PropTypes__default["default"].func,
|
|
3827
|
+
getA11yRemovalMessage: PropTypes__default["default"].func,
|
|
3828
|
+
stateReducer: PropTypes__default["default"].func,
|
|
3829
|
+
activeIndex: PropTypes__default["default"].number,
|
|
3830
|
+
initialActiveIndex: PropTypes__default["default"].number,
|
|
3831
|
+
defaultActiveIndex: PropTypes__default["default"].number,
|
|
3832
|
+
onActiveIndexChange: PropTypes__default["default"].func,
|
|
3833
|
+
onSelectedItemsChange: PropTypes__default["default"].func,
|
|
3834
|
+
keyNavigationNext: PropTypes__default["default"].string,
|
|
3835
|
+
keyNavigationPrevious: PropTypes__default["default"].string,
|
|
3836
|
+
environment: PropTypes__default["default"].shape({
|
|
3837
|
+
addEventListener: PropTypes__default["default"].func,
|
|
3838
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
3839
|
+
document: PropTypes__default["default"].shape({
|
|
3840
|
+
getElementById: PropTypes__default["default"].func,
|
|
3841
|
+
activeElement: PropTypes__default["default"].any,
|
|
3842
|
+
body: PropTypes__default["default"].any
|
|
3800
3843
|
})
|
|
3801
3844
|
})
|
|
3802
3845
|
};
|
|
3803
|
-
|
|
3846
|
+
const defaultProps = {
|
|
3804
3847
|
itemToString: defaultProps$3.itemToString,
|
|
3805
3848
|
stateReducer: defaultProps$3.stateReducer,
|
|
3806
3849
|
environment: defaultProps$3.environment,
|
|
3807
|
-
getA11yRemovalMessage
|
|
3850
|
+
getA11yRemovalMessage,
|
|
3808
3851
|
keyNavigationNext: 'ArrowRight',
|
|
3809
3852
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3810
3853
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
3811
3854
|
|
|
3812
|
-
|
|
3855
|
+
let validatePropTypes = noop;
|
|
3813
3856
|
/* istanbul ignore next */
|
|
3814
3857
|
|
|
3815
3858
|
if (process.env.NODE_ENV !== 'production') {
|
|
3816
|
-
validatePropTypes =
|
|
3817
|
-
PropTypes__default[
|
|
3859
|
+
validatePropTypes = (options, caller) => {
|
|
3860
|
+
PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3818
3861
|
};
|
|
3819
3862
|
}
|
|
3820
3863
|
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3864
|
+
const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
|
|
3865
|
+
const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
|
|
3866
|
+
const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
|
|
3867
|
+
const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
|
|
3868
|
+
const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
|
|
3869
|
+
const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
|
|
3870
|
+
const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
|
|
3871
|
+
const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
|
|
3872
|
+
const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
|
|
3873
|
+
const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
|
|
3874
|
+
const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
|
|
3875
|
+
const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3876
|
+
const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3834
3877
|
|
|
3835
3878
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3836
3879
|
__proto__: null,
|
|
@@ -3852,13 +3895,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3852
3895
|
/* eslint-disable complexity */
|
|
3853
3896
|
|
|
3854
3897
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3898
|
+
const {
|
|
3899
|
+
type,
|
|
3900
|
+
index,
|
|
3901
|
+
props,
|
|
3902
|
+
selectedItem
|
|
3903
|
+
} = action;
|
|
3904
|
+
const {
|
|
3905
|
+
activeIndex,
|
|
3906
|
+
selectedItems
|
|
3907
|
+
} = state;
|
|
3908
|
+
let changes;
|
|
3862
3909
|
|
|
3863
3910
|
switch (type) {
|
|
3864
3911
|
case SelectedItemClick:
|
|
@@ -3882,7 +3929,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3882
3929
|
case SelectedItemKeyDownBackspace:
|
|
3883
3930
|
case SelectedItemKeyDownDelete:
|
|
3884
3931
|
{
|
|
3885
|
-
|
|
3932
|
+
let newActiveIndex = activeIndex;
|
|
3886
3933
|
|
|
3887
3934
|
if (selectedItems.length === 1) {
|
|
3888
3935
|
newActiveIndex = -1;
|
|
@@ -3890,11 +3937,12 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3890
3937
|
newActiveIndex = selectedItems.length - 2;
|
|
3891
3938
|
}
|
|
3892
3939
|
|
|
3893
|
-
changes =
|
|
3894
|
-
selectedItems: [
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3940
|
+
changes = {
|
|
3941
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
3942
|
+
...{
|
|
3943
|
+
activeIndex: newActiveIndex
|
|
3944
|
+
}
|
|
3945
|
+
};
|
|
3898
3946
|
break;
|
|
3899
3947
|
}
|
|
3900
3948
|
|
|
@@ -3912,7 +3960,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3912
3960
|
|
|
3913
3961
|
case FunctionAddSelectedItem:
|
|
3914
3962
|
changes = {
|
|
3915
|
-
selectedItems: [
|
|
3963
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
3916
3964
|
};
|
|
3917
3965
|
break;
|
|
3918
3966
|
|
|
@@ -3924,26 +3972,30 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3924
3972
|
|
|
3925
3973
|
case FunctionRemoveSelectedItem:
|
|
3926
3974
|
{
|
|
3927
|
-
|
|
3928
|
-
|
|
3975
|
+
let newActiveIndex = activeIndex;
|
|
3976
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
3977
|
+
|
|
3978
|
+
if (selectedItemIndex >= 0) {
|
|
3979
|
+
if (selectedItems.length === 1) {
|
|
3980
|
+
newActiveIndex = -1;
|
|
3981
|
+
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
3982
|
+
newActiveIndex = selectedItems.length - 2;
|
|
3983
|
+
}
|
|
3929
3984
|
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3985
|
+
changes = {
|
|
3986
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
3987
|
+
activeIndex: newActiveIndex
|
|
3988
|
+
};
|
|
3934
3989
|
}
|
|
3935
3990
|
|
|
3936
|
-
changes = _extends__default['default']({
|
|
3937
|
-
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
|
|
3938
|
-
}, {
|
|
3939
|
-
activeIndex: _newActiveIndex
|
|
3940
|
-
});
|
|
3941
3991
|
break;
|
|
3942
3992
|
}
|
|
3943
3993
|
|
|
3944
3994
|
case FunctionSetSelectedItems:
|
|
3945
3995
|
{
|
|
3946
|
-
|
|
3996
|
+
const {
|
|
3997
|
+
selectedItems: newSelectedItems
|
|
3998
|
+
} = action;
|
|
3947
3999
|
changes = {
|
|
3948
4000
|
selectedItems: newSelectedItems
|
|
3949
4001
|
};
|
|
@@ -3952,9 +4004,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3952
4004
|
|
|
3953
4005
|
case FunctionSetActiveIndex:
|
|
3954
4006
|
{
|
|
3955
|
-
|
|
4007
|
+
const {
|
|
4008
|
+
activeIndex: newActiveIndex
|
|
4009
|
+
} = action;
|
|
3956
4010
|
changes = {
|
|
3957
|
-
activeIndex:
|
|
4011
|
+
activeIndex: newActiveIndex
|
|
3958
4012
|
};
|
|
3959
4013
|
break;
|
|
3960
4014
|
}
|
|
@@ -3970,11 +4024,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3970
4024
|
throw new Error('Reducer called without proper action type.');
|
|
3971
4025
|
}
|
|
3972
4026
|
|
|
3973
|
-
return
|
|
4027
|
+
return { ...state,
|
|
4028
|
+
...changes
|
|
4029
|
+
};
|
|
3974
4030
|
}
|
|
3975
4031
|
|
|
3976
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
3977
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
3978
4032
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
3979
4033
|
|
|
3980
4034
|
function useMultipleSelection(userProps) {
|
|
@@ -3984,47 +4038,47 @@ function useMultipleSelection(userProps) {
|
|
|
3984
4038
|
|
|
3985
4039
|
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
3986
4040
|
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4041
|
+
const props = { ...defaultProps,
|
|
4042
|
+
...userProps
|
|
4043
|
+
};
|
|
4044
|
+
const {
|
|
4045
|
+
getA11yRemovalMessage,
|
|
4046
|
+
itemToString,
|
|
4047
|
+
environment,
|
|
4048
|
+
keyNavigationNext,
|
|
4049
|
+
keyNavigationPrevious
|
|
4050
|
+
} = props; // Reducer init.
|
|
4051
|
+
|
|
4052
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
4053
|
+
const {
|
|
4054
|
+
activeIndex,
|
|
4055
|
+
selectedItems
|
|
4056
|
+
} = state; // Refs.
|
|
4057
|
+
|
|
4058
|
+
const isInitialMountRef = preact.useRef(true);
|
|
4059
|
+
const dropdownRef = preact.useRef(null);
|
|
4060
|
+
const previousSelectedItemsRef = preact.useRef(selectedItems);
|
|
4061
|
+
const selectedItemRefs = preact.useRef();
|
|
4006
4062
|
selectedItemRefs.current = [];
|
|
4007
|
-
|
|
4008
|
-
state
|
|
4009
|
-
props
|
|
4063
|
+
const latest = useLatestRef({
|
|
4064
|
+
state,
|
|
4065
|
+
props
|
|
4010
4066
|
}); // Effects.
|
|
4011
4067
|
|
|
4012
4068
|
/* Sets a11y status message on changes in selectedItem. */
|
|
4013
4069
|
|
|
4014
|
-
preact.useEffect(
|
|
4070
|
+
preact.useEffect(() => {
|
|
4015
4071
|
if (isInitialMountRef.current) {
|
|
4016
4072
|
return;
|
|
4017
4073
|
}
|
|
4018
4074
|
|
|
4019
4075
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
4020
|
-
|
|
4021
|
-
return selectedItems.indexOf(item) < 0;
|
|
4022
|
-
});
|
|
4076
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
4023
4077
|
setStatus(getA11yRemovalMessage({
|
|
4024
|
-
itemToString
|
|
4078
|
+
itemToString,
|
|
4025
4079
|
resultCount: selectedItems.length,
|
|
4026
|
-
removedSelectedItem
|
|
4027
|
-
activeIndex
|
|
4080
|
+
removedSelectedItem,
|
|
4081
|
+
activeIndex,
|
|
4028
4082
|
activeSelectedItem: selectedItems[activeIndex]
|
|
4029
4083
|
}), environment.document);
|
|
4030
4084
|
}
|
|
@@ -4032,7 +4086,7 @@ function useMultipleSelection(userProps) {
|
|
|
4032
4086
|
previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4033
4087
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
4034
4088
|
|
|
4035
|
-
preact.useEffect(
|
|
4089
|
+
preact.useEffect(() => {
|
|
4036
4090
|
if (isInitialMountRef.current) {
|
|
4037
4091
|
return;
|
|
4038
4092
|
}
|
|
@@ -4045,181 +4099,191 @@ function useMultipleSelection(userProps) {
|
|
|
4045
4099
|
}, [activeIndex]);
|
|
4046
4100
|
useControlPropsValidator({
|
|
4047
4101
|
isInitialMount: isInitialMountRef.current,
|
|
4048
|
-
props
|
|
4049
|
-
state
|
|
4102
|
+
props,
|
|
4103
|
+
state
|
|
4050
4104
|
});
|
|
4051
|
-
|
|
4105
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
4052
4106
|
|
|
4053
|
-
preact.useEffect(
|
|
4107
|
+
preact.useEffect(() => {
|
|
4054
4108
|
isInitialMountRef.current = false;
|
|
4055
4109
|
}, []); // Event handler functions.
|
|
4056
4110
|
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
4111
|
+
const selectedItemKeyDownHandlers = preact.useMemo(() => ({
|
|
4112
|
+
[keyNavigationPrevious]() {
|
|
4061
4113
|
dispatch({
|
|
4062
4114
|
type: SelectedItemKeyDownNavigationPrevious
|
|
4063
4115
|
});
|
|
4064
|
-
},
|
|
4116
|
+
},
|
|
4117
|
+
|
|
4118
|
+
[keyNavigationNext]() {
|
|
4065
4119
|
dispatch({
|
|
4066
4120
|
type: SelectedItemKeyDownNavigationNext
|
|
4067
4121
|
});
|
|
4068
|
-
},
|
|
4122
|
+
},
|
|
4123
|
+
|
|
4124
|
+
Delete() {
|
|
4069
4125
|
dispatch({
|
|
4070
4126
|
type: SelectedItemKeyDownDelete
|
|
4071
4127
|
});
|
|
4072
|
-
},
|
|
4128
|
+
},
|
|
4129
|
+
|
|
4130
|
+
Backspace() {
|
|
4073
4131
|
dispatch({
|
|
4074
4132
|
type: SelectedItemKeyDownBackspace
|
|
4075
4133
|
});
|
|
4076
|
-
}
|
|
4077
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4078
|
-
var dropdownKeyDownHandlers = preact.useMemo(function () {
|
|
4079
|
-
var _ref2;
|
|
4134
|
+
}
|
|
4080
4135
|
|
|
4081
|
-
|
|
4136
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4137
|
+
const dropdownKeyDownHandlers = preact.useMemo(() => ({
|
|
4138
|
+
[keyNavigationPrevious](event) {
|
|
4082
4139
|
if (isKeyDownOperationPermitted(event)) {
|
|
4083
4140
|
dispatch({
|
|
4084
4141
|
type: DropdownKeyDownNavigationPrevious
|
|
4085
4142
|
});
|
|
4086
4143
|
}
|
|
4087
|
-
},
|
|
4144
|
+
},
|
|
4145
|
+
|
|
4146
|
+
Backspace(event) {
|
|
4088
4147
|
if (isKeyDownOperationPermitted(event)) {
|
|
4089
4148
|
dispatch({
|
|
4090
4149
|
type: DropdownKeyDownBackspace
|
|
4091
4150
|
});
|
|
4092
4151
|
}
|
|
4093
|
-
}
|
|
4094
|
-
}, [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4095
|
-
|
|
4096
|
-
var getSelectedItemProps = preact.useCallback(function (_temp) {
|
|
4097
|
-
var _extends2;
|
|
4098
|
-
|
|
4099
|
-
var _ref3 = _temp === void 0 ? {} : _temp,
|
|
4100
|
-
_ref3$refKey = _ref3.refKey,
|
|
4101
|
-
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4102
|
-
ref = _ref3.ref,
|
|
4103
|
-
onClick = _ref3.onClick,
|
|
4104
|
-
onKeyDown = _ref3.onKeyDown,
|
|
4105
|
-
selectedItem = _ref3.selectedItem,
|
|
4106
|
-
index = _ref3.index,
|
|
4107
|
-
rest = _objectWithoutPropertiesLoose__default['default'](_ref3, _excluded);
|
|
4152
|
+
}
|
|
4108
4153
|
|
|
4109
|
-
|
|
4110
|
-
|
|
4154
|
+
}), [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4155
|
+
|
|
4156
|
+
const getSelectedItemProps = preact.useCallback(function (_temp) {
|
|
4157
|
+
let {
|
|
4158
|
+
refKey = 'ref',
|
|
4159
|
+
ref,
|
|
4160
|
+
onClick,
|
|
4161
|
+
onKeyDown,
|
|
4162
|
+
selectedItem,
|
|
4163
|
+
index,
|
|
4164
|
+
...rest
|
|
4165
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4166
|
+
const {
|
|
4167
|
+
state: latestState
|
|
4168
|
+
} = latest.current;
|
|
4169
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
4111
4170
|
|
|
4112
4171
|
if (itemIndex < 0) {
|
|
4113
4172
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
4114
4173
|
}
|
|
4115
4174
|
|
|
4116
|
-
|
|
4175
|
+
const selectedItemHandleClick = () => {
|
|
4117
4176
|
dispatch({
|
|
4118
4177
|
type: SelectedItemClick,
|
|
4119
|
-
index
|
|
4178
|
+
index
|
|
4120
4179
|
});
|
|
4121
4180
|
};
|
|
4122
4181
|
|
|
4123
|
-
|
|
4124
|
-
|
|
4182
|
+
const selectedItemHandleKeyDown = event => {
|
|
4183
|
+
const key = normalizeArrowKey(event);
|
|
4125
4184
|
|
|
4126
4185
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
4127
4186
|
selectedItemKeyDownHandlers[key](event);
|
|
4128
4187
|
}
|
|
4129
4188
|
};
|
|
4130
4189
|
|
|
4131
|
-
return
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4190
|
+
return {
|
|
4191
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
4192
|
+
if (selectedItemNode) {
|
|
4193
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
4194
|
+
}
|
|
4195
|
+
}),
|
|
4196
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
4197
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
4198
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
4199
|
+
...rest
|
|
4200
|
+
};
|
|
4136
4201
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
4151
|
-
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
4152
|
-
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
4153
|
-
|
|
4202
|
+
const getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
|
|
4203
|
+
let {
|
|
4204
|
+
refKey = 'ref',
|
|
4205
|
+
ref,
|
|
4206
|
+
onKeyDown,
|
|
4207
|
+
onClick,
|
|
4208
|
+
preventKeyAction = false,
|
|
4209
|
+
...rest
|
|
4210
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4211
|
+
let {
|
|
4212
|
+
suppressRefError = false
|
|
4213
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4154
4214
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
4155
4215
|
|
|
4156
|
-
|
|
4157
|
-
|
|
4216
|
+
const dropdownHandleKeyDown = event => {
|
|
4217
|
+
const key = normalizeArrowKey(event);
|
|
4158
4218
|
|
|
4159
4219
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
4160
4220
|
dropdownKeyDownHandlers[key](event);
|
|
4161
4221
|
}
|
|
4162
4222
|
};
|
|
4163
4223
|
|
|
4164
|
-
|
|
4224
|
+
const dropdownHandleClick = () => {
|
|
4165
4225
|
dispatch({
|
|
4166
4226
|
type: DropdownClick
|
|
4167
4227
|
});
|
|
4168
4228
|
};
|
|
4169
4229
|
|
|
4170
|
-
return
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4230
|
+
return {
|
|
4231
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
4232
|
+
if (dropdownNode) {
|
|
4233
|
+
dropdownRef.current = dropdownNode;
|
|
4234
|
+
}
|
|
4235
|
+
}),
|
|
4236
|
+
...(!preventKeyAction && {
|
|
4237
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
4238
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
4239
|
+
}),
|
|
4240
|
+
...rest
|
|
4241
|
+
};
|
|
4178
4242
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
4179
4243
|
|
|
4180
|
-
|
|
4244
|
+
const addSelectedItem = preact.useCallback(selectedItem => {
|
|
4181
4245
|
dispatch({
|
|
4182
4246
|
type: FunctionAddSelectedItem,
|
|
4183
|
-
selectedItem
|
|
4247
|
+
selectedItem
|
|
4184
4248
|
});
|
|
4185
4249
|
}, [dispatch]);
|
|
4186
|
-
|
|
4250
|
+
const removeSelectedItem = preact.useCallback(selectedItem => {
|
|
4187
4251
|
dispatch({
|
|
4188
4252
|
type: FunctionRemoveSelectedItem,
|
|
4189
|
-
selectedItem
|
|
4253
|
+
selectedItem
|
|
4190
4254
|
});
|
|
4191
4255
|
}, [dispatch]);
|
|
4192
|
-
|
|
4256
|
+
const setSelectedItems = preact.useCallback(newSelectedItems => {
|
|
4193
4257
|
dispatch({
|
|
4194
4258
|
type: FunctionSetSelectedItems,
|
|
4195
4259
|
selectedItems: newSelectedItems
|
|
4196
4260
|
});
|
|
4197
4261
|
}, [dispatch]);
|
|
4198
|
-
|
|
4262
|
+
const setActiveIndex = preact.useCallback(newActiveIndex => {
|
|
4199
4263
|
dispatch({
|
|
4200
4264
|
type: FunctionSetActiveIndex,
|
|
4201
4265
|
activeIndex: newActiveIndex
|
|
4202
4266
|
});
|
|
4203
4267
|
}, [dispatch]);
|
|
4204
|
-
|
|
4268
|
+
const reset = preact.useCallback(() => {
|
|
4205
4269
|
dispatch({
|
|
4206
4270
|
type: FunctionReset
|
|
4207
4271
|
});
|
|
4208
4272
|
}, [dispatch]);
|
|
4209
4273
|
return {
|
|
4210
|
-
getSelectedItemProps
|
|
4211
|
-
getDropdownProps
|
|
4212
|
-
addSelectedItem
|
|
4213
|
-
removeSelectedItem
|
|
4214
|
-
setSelectedItems
|
|
4215
|
-
setActiveIndex
|
|
4216
|
-
reset
|
|
4217
|
-
selectedItems
|
|
4218
|
-
activeIndex
|
|
4274
|
+
getSelectedItemProps,
|
|
4275
|
+
getDropdownProps,
|
|
4276
|
+
addSelectedItem,
|
|
4277
|
+
removeSelectedItem,
|
|
4278
|
+
setSelectedItems,
|
|
4279
|
+
setActiveIndex,
|
|
4280
|
+
reset,
|
|
4281
|
+
selectedItems,
|
|
4282
|
+
activeIndex
|
|
4219
4283
|
};
|
|
4220
4284
|
}
|
|
4221
4285
|
|
|
4222
|
-
exports[
|
|
4286
|
+
exports["default"] = Downshift$1;
|
|
4223
4287
|
exports.resetIdCounter = resetIdCounter;
|
|
4224
4288
|
exports.useCombobox = useCombobox;
|
|
4225
4289
|
exports.useMultipleSelection = useMultipleSelection;
|