downshift 6.1.6 → 6.1.9
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 +15 -9
- package/dist/downshift.cjs.js +1703 -1637
- package/dist/downshift.esm.js +1577 -1507
- package/dist/downshift.native.cjs.js +1688 -1620
- package/dist/downshift.umd.js +1614 -1574
- 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 +1667 -1601
- package/preact/dist/downshift.esm.js +1577 -1507
- package/preact/dist/downshift.umd.js +1667 -1649
- 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
|
@@ -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,10 +1875,10 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
|
1888
1875
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1889
1876
|
}
|
|
1890
1877
|
|
|
1891
|
-
|
|
1878
|
+
const defaultValue = props["default" + capitalizeString(propKey)];
|
|
1892
1879
|
|
|
1893
|
-
if (
|
|
1894
|
-
return
|
|
1880
|
+
if (defaultValue !== undefined) {
|
|
1881
|
+
return defaultValue;
|
|
1895
1882
|
}
|
|
1896
1883
|
|
|
1897
1884
|
return defaultStateValues[propKey];
|
|
@@ -1902,38 +1889,44 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1902
1889
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1903
1890
|
}
|
|
1904
1891
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1892
|
+
const value = props[propKey];
|
|
1893
|
+
|
|
1894
|
+
if (value !== undefined) {
|
|
1895
|
+
return value;
|
|
1907
1896
|
}
|
|
1908
1897
|
|
|
1909
|
-
|
|
1898
|
+
const initialValue = props["initial" + capitalizeString(propKey)];
|
|
1910
1899
|
|
|
1911
|
-
if (
|
|
1912
|
-
return
|
|
1900
|
+
if (initialValue !== undefined) {
|
|
1901
|
+
return initialValue;
|
|
1913
1902
|
}
|
|
1914
1903
|
|
|
1915
1904
|
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1916
1905
|
}
|
|
1917
1906
|
|
|
1918
1907
|
function getInitialState$2(props) {
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1908
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1909
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
1910
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
1911
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
1923
1912
|
return {
|
|
1924
1913
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
1925
|
-
isOpen
|
|
1926
|
-
selectedItem
|
|
1927
|
-
inputValue
|
|
1914
|
+
isOpen,
|
|
1915
|
+
selectedItem,
|
|
1916
|
+
inputValue
|
|
1928
1917
|
};
|
|
1929
1918
|
}
|
|
1930
1919
|
|
|
1931
1920
|
function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1921
|
+
const {
|
|
1922
|
+
items,
|
|
1923
|
+
initialHighlightedIndex,
|
|
1924
|
+
defaultHighlightedIndex
|
|
1925
|
+
} = props;
|
|
1926
|
+
const {
|
|
1927
|
+
selectedItem,
|
|
1928
|
+
highlightedIndex
|
|
1929
|
+
} = state;
|
|
1937
1930
|
|
|
1938
1931
|
if (items.length === 0) {
|
|
1939
1932
|
return -1;
|
|
@@ -1974,39 +1967,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
|
1974
1967
|
|
|
1975
1968
|
|
|
1976
1969
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
1977
|
-
|
|
1970
|
+
const mouseAndTouchTrackersRef = preact.useRef({
|
|
1978
1971
|
isMouseDown: false,
|
|
1979
1972
|
isTouchMove: false
|
|
1980
1973
|
});
|
|
1981
|
-
preact.useEffect(
|
|
1974
|
+
preact.useEffect(() => {
|
|
1982
1975
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
1983
1976
|
// as in downshift.js.
|
|
1984
|
-
|
|
1977
|
+
const onMouseDown = () => {
|
|
1985
1978
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
1986
1979
|
};
|
|
1987
1980
|
|
|
1988
|
-
|
|
1981
|
+
const onMouseUp = event => {
|
|
1989
1982
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
1990
1983
|
|
|
1991
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
1992
|
-
return ref.current;
|
|
1993
|
-
}), environment)) {
|
|
1984
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
1994
1985
|
handleBlur();
|
|
1995
1986
|
}
|
|
1996
1987
|
};
|
|
1997
1988
|
|
|
1998
|
-
|
|
1989
|
+
const onTouchStart = () => {
|
|
1999
1990
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
2000
1991
|
};
|
|
2001
1992
|
|
|
2002
|
-
|
|
1993
|
+
const onTouchMove = () => {
|
|
2003
1994
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
2004
1995
|
};
|
|
2005
1996
|
|
|
2006
|
-
|
|
2007
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2008
|
-
return ref.current;
|
|
2009
|
-
}), environment, false)) {
|
|
1997
|
+
const onTouchEnd = event => {
|
|
1998
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
2010
1999
|
handleBlur();
|
|
2011
2000
|
}
|
|
2012
2001
|
};
|
|
@@ -2030,9 +2019,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
2030
2019
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2031
2020
|
|
|
2032
2021
|
|
|
2033
|
-
|
|
2034
|
-
return noop;
|
|
2035
|
-
};
|
|
2022
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
2036
2023
|
/**
|
|
2037
2024
|
* Custom hook that checks if getter props are called correctly.
|
|
2038
2025
|
*
|
|
@@ -2044,20 +2031,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
2044
2031
|
|
|
2045
2032
|
|
|
2046
2033
|
if (process.env.NODE_ENV !== 'production') {
|
|
2047
|
-
useGetterPropsCalledChecker = function
|
|
2048
|
-
|
|
2034
|
+
useGetterPropsCalledChecker = function () {
|
|
2035
|
+
const isInitialMountRef = preact.useRef(true);
|
|
2049
2036
|
|
|
2050
2037
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2051
2038
|
propKeys[_key] = arguments[_key];
|
|
2052
2039
|
}
|
|
2053
2040
|
|
|
2054
|
-
|
|
2041
|
+
const getterPropsCalledRef = preact.useRef(propKeys.reduce((acc, propKey) => {
|
|
2055
2042
|
acc[propKey] = {};
|
|
2056
2043
|
return acc;
|
|
2057
2044
|
}, {}));
|
|
2058
|
-
preact.useEffect(
|
|
2059
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
2060
|
-
|
|
2045
|
+
preact.useEffect(() => {
|
|
2046
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
2047
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
2061
2048
|
|
|
2062
2049
|
if (isInitialMountRef.current) {
|
|
2063
2050
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -2067,9 +2054,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2067
2054
|
}
|
|
2068
2055
|
}
|
|
2069
2056
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2057
|
+
const {
|
|
2058
|
+
suppressRefError,
|
|
2059
|
+
refKey,
|
|
2060
|
+
elementRef
|
|
2061
|
+
} = propCallInfo;
|
|
2073
2062
|
|
|
2074
2063
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
2075
2064
|
// eslint-disable-next-line no-console
|
|
@@ -2078,11 +2067,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2078
2067
|
});
|
|
2079
2068
|
isInitialMountRef.current = false;
|
|
2080
2069
|
});
|
|
2081
|
-
|
|
2070
|
+
const setGetterPropCallInfo = preact.useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
2082
2071
|
getterPropsCalledRef.current[propKey] = {
|
|
2083
|
-
suppressRefError
|
|
2084
|
-
refKey
|
|
2085
|
-
elementRef
|
|
2072
|
+
suppressRefError,
|
|
2073
|
+
refKey,
|
|
2074
|
+
elementRef
|
|
2086
2075
|
};
|
|
2087
2076
|
}, []);
|
|
2088
2077
|
return setGetterPropCallInfo;
|
|
@@ -2090,39 +2079,41 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2090
2079
|
}
|
|
2091
2080
|
|
|
2092
2081
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2082
|
+
let {
|
|
2083
|
+
isInitialMount,
|
|
2084
|
+
highlightedIndex,
|
|
2085
|
+
items,
|
|
2086
|
+
environment,
|
|
2087
|
+
...rest
|
|
2088
|
+
} = _ref2;
|
|
2099
2089
|
// Sets a11y status message on changes in state.
|
|
2100
|
-
preact.useEffect(
|
|
2090
|
+
preact.useEffect(() => {
|
|
2101
2091
|
if (isInitialMount || false) {
|
|
2102
2092
|
return;
|
|
2103
2093
|
}
|
|
2104
2094
|
|
|
2105
|
-
updateA11yStatus(
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2095
|
+
updateA11yStatus(() => getA11yMessage({
|
|
2096
|
+
highlightedIndex,
|
|
2097
|
+
highlightedItem: items[highlightedIndex],
|
|
2098
|
+
resultCount: items.length,
|
|
2099
|
+
...rest
|
|
2100
|
+
}), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2112
2101
|
}, dependencyArray);
|
|
2113
2102
|
}
|
|
2114
2103
|
|
|
2115
2104
|
function useScrollIntoView(_ref3) {
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2105
|
+
let {
|
|
2106
|
+
highlightedIndex,
|
|
2107
|
+
isOpen,
|
|
2108
|
+
itemRefs,
|
|
2109
|
+
getItemNodeFromIndex,
|
|
2110
|
+
menuElement,
|
|
2111
|
+
scrollIntoView: scrollIntoViewProp
|
|
2112
|
+
} = _ref3;
|
|
2122
2113
|
// used not to scroll on highlight by mouse.
|
|
2123
|
-
|
|
2114
|
+
const shouldScrollRef = preact.useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
2124
2115
|
|
|
2125
|
-
useIsomorphicLayoutEffect(
|
|
2116
|
+
useIsomorphicLayoutEffect(() => {
|
|
2126
2117
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2127
2118
|
return;
|
|
2128
2119
|
}
|
|
@@ -2138,17 +2129,19 @@ function useScrollIntoView(_ref3) {
|
|
|
2138
2129
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
2139
2130
|
|
|
2140
2131
|
|
|
2141
|
-
|
|
2132
|
+
let useControlPropsValidator = noop;
|
|
2142
2133
|
/* istanbul ignore next */
|
|
2143
2134
|
|
|
2144
2135
|
if (process.env.NODE_ENV !== 'production') {
|
|
2145
|
-
useControlPropsValidator =
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2136
|
+
useControlPropsValidator = _ref4 => {
|
|
2137
|
+
let {
|
|
2138
|
+
isInitialMount,
|
|
2139
|
+
props,
|
|
2140
|
+
state
|
|
2141
|
+
} = _ref4;
|
|
2149
2142
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
2150
|
-
|
|
2151
|
-
preact.useEffect(
|
|
2143
|
+
const prevPropsRef = preact.useRef(props);
|
|
2144
|
+
preact.useEffect(() => {
|
|
2152
2145
|
if (isInitialMount) {
|
|
2153
2146
|
return;
|
|
2154
2147
|
}
|
|
@@ -2162,9 +2155,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2162
2155
|
/* eslint-disable complexity */
|
|
2163
2156
|
|
|
2164
2157
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2158
|
+
const {
|
|
2159
|
+
type,
|
|
2160
|
+
props
|
|
2161
|
+
} = action;
|
|
2162
|
+
let changes;
|
|
2168
2163
|
|
|
2169
2164
|
switch (type) {
|
|
2170
2165
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -2225,7 +2220,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2225
2220
|
throw new Error('Reducer called without proper action type.');
|
|
2226
2221
|
}
|
|
2227
2222
|
|
|
2228
|
-
return
|
|
2223
|
+
return { ...state,
|
|
2224
|
+
...changes
|
|
2225
|
+
};
|
|
2229
2226
|
}
|
|
2230
2227
|
/* eslint-enable complexity */
|
|
2231
2228
|
|
|
@@ -2248,37 +2245,37 @@ function getItemIndexByCharacterKey(_a) {
|
|
|
2248
2245
|
return highlightedIndex;
|
|
2249
2246
|
}
|
|
2250
2247
|
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[
|
|
2248
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
2249
|
+
itemToString: PropTypes__default["default"].func,
|
|
2250
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
2251
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
2252
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
2253
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
2254
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
2255
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
2256
|
+
isOpen: PropTypes__default["default"].bool,
|
|
2257
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
2258
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
2259
|
+
selectedItem: PropTypes__default["default"].any,
|
|
2260
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
2261
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
2262
|
+
id: PropTypes__default["default"].string,
|
|
2263
|
+
labelId: PropTypes__default["default"].string,
|
|
2264
|
+
menuId: PropTypes__default["default"].string,
|
|
2265
|
+
getItemId: PropTypes__default["default"].func,
|
|
2266
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
2267
|
+
stateReducer: PropTypes__default["default"].func,
|
|
2268
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
2269
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
2270
|
+
onStateChange: PropTypes__default["default"].func,
|
|
2271
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
2272
|
+
environment: PropTypes__default["default"].shape({
|
|
2273
|
+
addEventListener: PropTypes__default["default"].func,
|
|
2274
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
2275
|
+
document: PropTypes__default["default"].shape({
|
|
2276
|
+
getElementById: PropTypes__default["default"].func,
|
|
2277
|
+
activeElement: PropTypes__default["default"].any,
|
|
2278
|
+
body: PropTypes__default["default"].any
|
|
2282
2279
|
})
|
|
2283
2280
|
})
|
|
2284
2281
|
};
|
|
@@ -2299,7 +2296,7 @@ function getA11yStatusMessage(_a) {
|
|
|
2299
2296
|
return 'No results are available.';
|
|
2300
2297
|
}
|
|
2301
2298
|
if (resultCount !== previousResultCount) {
|
|
2302
|
-
return resultCount
|
|
2299
|
+
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
2300
|
}
|
|
2304
2301
|
return '';
|
|
2305
2302
|
}
|
|
@@ -2309,33 +2306,33 @@ var validatePropTypes$2 = noop;
|
|
|
2309
2306
|
/* istanbul ignore next */
|
|
2310
2307
|
if (process.env.NODE_ENV !== 'production') {
|
|
2311
2308
|
validatePropTypes$2 = function (options, caller) {
|
|
2312
|
-
PropTypes__default[
|
|
2309
|
+
PropTypes__default["default"].checkPropTypes(propTypes$2, options, 'prop', caller.name);
|
|
2313
2310
|
};
|
|
2314
2311
|
}
|
|
2315
2312
|
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2313
|
+
const MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
|
|
2314
|
+
const MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
|
|
2315
|
+
const MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
|
|
2316
|
+
const MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
|
|
2317
|
+
const MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
|
|
2318
|
+
const MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
|
|
2319
|
+
const MenuKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__menu_keydown_space_button__' : 6;
|
|
2320
|
+
const MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 7;
|
|
2321
|
+
const MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 8;
|
|
2322
|
+
const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 9;
|
|
2323
|
+
const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 10;
|
|
2324
|
+
const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 11;
|
|
2325
|
+
const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 12;
|
|
2326
|
+
const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 13;
|
|
2327
|
+
const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 14;
|
|
2328
|
+
const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 15;
|
|
2329
|
+
const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 16;
|
|
2330
|
+
const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 17;
|
|
2331
|
+
const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 18;
|
|
2332
|
+
const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 19;
|
|
2333
|
+
const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 20;
|
|
2334
|
+
const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 21;
|
|
2335
|
+
const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
|
|
2339
2336
|
|
|
2340
2337
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2341
2338
|
__proto__: null,
|
|
@@ -2367,10 +2364,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2367
2364
|
/* eslint-disable complexity */
|
|
2368
2365
|
|
|
2369
2366
|
function downshiftSelectReducer(state, action) {
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2367
|
+
const {
|
|
2368
|
+
type,
|
|
2369
|
+
props,
|
|
2370
|
+
shiftKey
|
|
2371
|
+
} = action;
|
|
2372
|
+
let changes;
|
|
2374
2373
|
|
|
2375
2374
|
switch (type) {
|
|
2376
2375
|
case ItemClick$1:
|
|
@@ -2383,20 +2382,21 @@ function downshiftSelectReducer(state, action) {
|
|
|
2383
2382
|
|
|
2384
2383
|
case ToggleButtonKeyDownCharacter:
|
|
2385
2384
|
{
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2385
|
+
const lowercasedKey = action.key;
|
|
2386
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2387
|
+
const itemIndex = getItemIndexByCharacterKey({
|
|
2389
2388
|
keysSoFar: inputValue,
|
|
2390
2389
|
highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
|
|
2391
2390
|
items: props.items,
|
|
2392
2391
|
itemToString: props.itemToString,
|
|
2393
2392
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2394
2393
|
});
|
|
2395
|
-
changes =
|
|
2396
|
-
inputValue
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2394
|
+
changes = {
|
|
2395
|
+
inputValue,
|
|
2396
|
+
...(itemIndex >= 0 && {
|
|
2397
|
+
selectedItem: props.items[itemIndex]
|
|
2398
|
+
})
|
|
2399
|
+
};
|
|
2400
2400
|
}
|
|
2401
2401
|
break;
|
|
2402
2402
|
|
|
@@ -2416,12 +2416,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2416
2416
|
|
|
2417
2417
|
case MenuKeyDownEnter:
|
|
2418
2418
|
case MenuKeyDownSpaceButton:
|
|
2419
|
-
changes =
|
|
2419
|
+
changes = {
|
|
2420
2420
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2421
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2421
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2422
|
+
...(state.highlightedIndex >= 0 && {
|
|
2423
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2424
|
+
})
|
|
2425
|
+
};
|
|
2425
2426
|
break;
|
|
2426
2427
|
|
|
2427
2428
|
case MenuKeyDownHome:
|
|
@@ -2452,22 +2453,21 @@ function downshiftSelectReducer(state, action) {
|
|
|
2452
2453
|
|
|
2453
2454
|
case MenuKeyDownCharacter:
|
|
2454
2455
|
{
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
var highlightedIndex = getItemIndexByCharacterKey({
|
|
2460
|
-
keysSoFar: _inputValue,
|
|
2456
|
+
const lowercasedKey = action.key;
|
|
2457
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2458
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
2459
|
+
keysSoFar: inputValue,
|
|
2461
2460
|
highlightedIndex: state.highlightedIndex,
|
|
2462
2461
|
items: props.items,
|
|
2463
2462
|
itemToString: props.itemToString,
|
|
2464
2463
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2465
2464
|
});
|
|
2466
|
-
changes =
|
|
2467
|
-
inputValue
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2465
|
+
changes = {
|
|
2466
|
+
inputValue,
|
|
2467
|
+
...(highlightedIndex >= 0 && {
|
|
2468
|
+
highlightedIndex
|
|
2469
|
+
})
|
|
2470
|
+
};
|
|
2471
2471
|
}
|
|
2472
2472
|
break;
|
|
2473
2473
|
|
|
@@ -2493,13 +2493,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2493
2493
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2494
2494
|
}
|
|
2495
2495
|
|
|
2496
|
-
return
|
|
2496
|
+
return { ...state,
|
|
2497
|
+
...changes
|
|
2498
|
+
};
|
|
2497
2499
|
}
|
|
2498
2500
|
/* eslint-enable complexity */
|
|
2499
2501
|
|
|
2500
|
-
|
|
2501
|
-
_excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
|
|
2502
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
|
|
2502
|
+
/* eslint-disable max-statements */
|
|
2503
2503
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2504
2504
|
|
|
2505
2505
|
function useSelect(userProps) {
|
|
@@ -2509,91 +2509,92 @@ function useSelect(userProps) {
|
|
|
2509
2509
|
|
|
2510
2510
|
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
2511
2511
|
|
|
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
|
-
|
|
2512
|
+
const props = { ...defaultProps$2,
|
|
2513
|
+
...userProps
|
|
2514
|
+
};
|
|
2515
|
+
const {
|
|
2516
|
+
items,
|
|
2517
|
+
scrollIntoView,
|
|
2518
|
+
environment,
|
|
2519
|
+
initialIsOpen,
|
|
2520
|
+
defaultIsOpen,
|
|
2521
|
+
itemToString,
|
|
2522
|
+
getA11ySelectionMessage,
|
|
2523
|
+
getA11yStatusMessage
|
|
2524
|
+
} = props; // Initial state depending on controlled props.
|
|
2525
|
+
|
|
2526
|
+
const initialState = getInitialState$2(props);
|
|
2527
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
2528
|
+
const {
|
|
2529
|
+
isOpen,
|
|
2530
|
+
highlightedIndex,
|
|
2531
|
+
selectedItem,
|
|
2532
|
+
inputValue
|
|
2533
|
+
} = state; // Element efs.
|
|
2534
|
+
|
|
2535
|
+
const toggleButtonRef = preact.useRef(null);
|
|
2536
|
+
const menuRef = preact.useRef(null);
|
|
2537
|
+
const itemRefs = preact.useRef({}); // used not to trigger menu blur action in some scenarios.
|
|
2538
|
+
|
|
2539
|
+
const shouldBlurRef = preact.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
2540
|
+
|
|
2541
|
+
const clearTimeoutRef = preact.useRef(null); // prevent id re-generation between renders.
|
|
2542
|
+
|
|
2543
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
2544
|
+
|
|
2545
|
+
const previousResultCountRef = preact.useRef();
|
|
2546
|
+
const isInitialMountRef = preact.useRef(true); // utility callback to get item element.
|
|
2547
|
+
|
|
2548
|
+
const latest = useLatestRef({
|
|
2549
|
+
state,
|
|
2550
|
+
props
|
|
2550
2551
|
}); // Some utils.
|
|
2551
2552
|
|
|
2552
|
-
|
|
2553
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2554
|
-
}, [elementIds]); // Effects.
|
|
2553
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
2555
2554
|
// Sets a11y status message on changes in state.
|
|
2556
2555
|
|
|
2557
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2556
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2558
2557
|
isInitialMount: isInitialMountRef.current,
|
|
2559
2558
|
previousResultCount: previousResultCountRef.current,
|
|
2560
|
-
items
|
|
2561
|
-
environment
|
|
2562
|
-
itemToString
|
|
2563
|
-
|
|
2559
|
+
items,
|
|
2560
|
+
environment,
|
|
2561
|
+
itemToString,
|
|
2562
|
+
...state
|
|
2563
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
2564
2564
|
|
|
2565
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2565
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2566
2566
|
isInitialMount: isInitialMountRef.current,
|
|
2567
2567
|
previousResultCount: previousResultCountRef.current,
|
|
2568
|
-
items
|
|
2569
|
-
environment
|
|
2570
|
-
itemToString
|
|
2571
|
-
|
|
2568
|
+
items,
|
|
2569
|
+
environment,
|
|
2570
|
+
itemToString,
|
|
2571
|
+
...state
|
|
2572
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
2572
2573
|
|
|
2573
|
-
|
|
2574
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2574
2575
|
menuElement: menuRef.current,
|
|
2575
|
-
highlightedIndex
|
|
2576
|
-
isOpen
|
|
2577
|
-
itemRefs
|
|
2578
|
-
scrollIntoView
|
|
2579
|
-
getItemNodeFromIndex
|
|
2576
|
+
highlightedIndex,
|
|
2577
|
+
isOpen,
|
|
2578
|
+
itemRefs,
|
|
2579
|
+
scrollIntoView,
|
|
2580
|
+
getItemNodeFromIndex
|
|
2580
2581
|
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2581
2582
|
|
|
2582
|
-
preact.useEffect(
|
|
2583
|
+
preact.useEffect(() => {
|
|
2583
2584
|
// init the clean function here as we need access to dispatch.
|
|
2584
|
-
clearTimeoutRef.current = debounce(
|
|
2585
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
2585
2586
|
outerDispatch({
|
|
2586
2587
|
type: FunctionSetInputValue$1,
|
|
2587
2588
|
inputValue: ''
|
|
2588
2589
|
});
|
|
2589
2590
|
}, 500); // Cancel any pending debounced calls on mount
|
|
2590
2591
|
|
|
2591
|
-
return
|
|
2592
|
+
return () => {
|
|
2592
2593
|
clearTimeoutRef.current.cancel();
|
|
2593
2594
|
};
|
|
2594
2595
|
}, []); // Invokes the keysSoFar callback set up above.
|
|
2595
2596
|
|
|
2596
|
-
preact.useEffect(
|
|
2597
|
+
preact.useEffect(() => {
|
|
2597
2598
|
if (!inputValue) {
|
|
2598
2599
|
return;
|
|
2599
2600
|
}
|
|
@@ -2602,12 +2603,12 @@ function useSelect(userProps) {
|
|
|
2602
2603
|
}, [dispatch, inputValue]);
|
|
2603
2604
|
useControlPropsValidator({
|
|
2604
2605
|
isInitialMount: isInitialMountRef.current,
|
|
2605
|
-
props
|
|
2606
|
-
state
|
|
2606
|
+
props,
|
|
2607
|
+
state
|
|
2607
2608
|
});
|
|
2608
2609
|
/* Controls the focus on the menu or the toggle button. */
|
|
2609
2610
|
|
|
2610
|
-
preact.useEffect(
|
|
2611
|
+
preact.useEffect(() => {
|
|
2611
2612
|
// Don't focus menu on first render.
|
|
2612
2613
|
if (isInitialMountRef.current) {
|
|
2613
2614
|
// Unless it was initialised as open.
|
|
@@ -2638,7 +2639,7 @@ function useSelect(userProps) {
|
|
|
2638
2639
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2639
2640
|
|
|
2640
2641
|
}, [isOpen]);
|
|
2641
|
-
preact.useEffect(
|
|
2642
|
+
preact.useEffect(() => {
|
|
2642
2643
|
if (isInitialMountRef.current) {
|
|
2643
2644
|
return;
|
|
2644
2645
|
}
|
|
@@ -2646,180 +2647,180 @@ function useSelect(userProps) {
|
|
|
2646
2647
|
previousResultCountRef.current = items.length;
|
|
2647
2648
|
}); // Add mouse/touch events to document.
|
|
2648
2649
|
|
|
2649
|
-
|
|
2650
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
2650
2651
|
dispatch({
|
|
2651
2652
|
type: MenuBlur
|
|
2652
2653
|
});
|
|
2653
2654
|
});
|
|
2654
|
-
|
|
2655
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
2655
2656
|
|
|
2656
|
-
preact.useEffect(
|
|
2657
|
+
preact.useEffect(() => {
|
|
2657
2658
|
isInitialMountRef.current = false;
|
|
2658
2659
|
}, []); // Reset itemRefs on close.
|
|
2659
2660
|
|
|
2660
|
-
preact.useEffect(
|
|
2661
|
+
preact.useEffect(() => {
|
|
2661
2662
|
if (!isOpen) {
|
|
2662
2663
|
itemRefs.current = {};
|
|
2663
2664
|
}
|
|
2664
2665
|
}, [isOpen]); // Event handler functions.
|
|
2665
2666
|
|
|
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.
|
|
2667
|
+
const toggleButtonKeyDownHandlers = preact.useMemo(() => ({
|
|
2668
|
+
ArrowDown(event) {
|
|
2669
|
+
event.preventDefault();
|
|
2670
|
+
dispatch({
|
|
2671
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
2672
|
+
getItemNodeFromIndex,
|
|
2673
|
+
shiftKey: event.shiftKey
|
|
2674
|
+
});
|
|
2675
|
+
},
|
|
2737
2676
|
|
|
2738
|
-
|
|
2677
|
+
ArrowUp(event) {
|
|
2678
|
+
event.preventDefault();
|
|
2679
|
+
dispatch({
|
|
2680
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
2681
|
+
getItemNodeFromIndex,
|
|
2682
|
+
shiftKey: event.shiftKey
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
}), [dispatch, getItemNodeFromIndex]);
|
|
2687
|
+
const menuKeyDownHandlers = preact.useMemo(() => ({
|
|
2688
|
+
ArrowDown(event) {
|
|
2689
|
+
event.preventDefault();
|
|
2690
|
+
dispatch({
|
|
2691
|
+
type: MenuKeyDownArrowDown,
|
|
2692
|
+
getItemNodeFromIndex,
|
|
2693
|
+
shiftKey: event.shiftKey
|
|
2694
|
+
});
|
|
2695
|
+
},
|
|
2696
|
+
|
|
2697
|
+
ArrowUp(event) {
|
|
2698
|
+
event.preventDefault();
|
|
2699
|
+
dispatch({
|
|
2700
|
+
type: MenuKeyDownArrowUp,
|
|
2701
|
+
getItemNodeFromIndex,
|
|
2702
|
+
shiftKey: event.shiftKey
|
|
2703
|
+
});
|
|
2704
|
+
},
|
|
2705
|
+
|
|
2706
|
+
Home(event) {
|
|
2707
|
+
event.preventDefault();
|
|
2708
|
+
dispatch({
|
|
2709
|
+
type: MenuKeyDownHome,
|
|
2710
|
+
getItemNodeFromIndex
|
|
2711
|
+
});
|
|
2712
|
+
},
|
|
2713
|
+
|
|
2714
|
+
End(event) {
|
|
2715
|
+
event.preventDefault();
|
|
2716
|
+
dispatch({
|
|
2717
|
+
type: MenuKeyDownEnd,
|
|
2718
|
+
getItemNodeFromIndex
|
|
2719
|
+
});
|
|
2720
|
+
},
|
|
2721
|
+
|
|
2722
|
+
Escape() {
|
|
2723
|
+
dispatch({
|
|
2724
|
+
type: MenuKeyDownEscape
|
|
2725
|
+
});
|
|
2726
|
+
},
|
|
2727
|
+
|
|
2728
|
+
Enter(event) {
|
|
2729
|
+
event.preventDefault();
|
|
2730
|
+
dispatch({
|
|
2731
|
+
type: MenuKeyDownEnter
|
|
2732
|
+
});
|
|
2733
|
+
},
|
|
2734
|
+
|
|
2735
|
+
' '(event) {
|
|
2736
|
+
event.preventDefault();
|
|
2737
|
+
dispatch({
|
|
2738
|
+
type: MenuKeyDownSpaceButton
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
}), [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
2743
|
+
|
|
2744
|
+
const toggleMenu = preact.useCallback(() => {
|
|
2739
2745
|
dispatch({
|
|
2740
2746
|
type: FunctionToggleMenu$1
|
|
2741
2747
|
});
|
|
2742
2748
|
}, [dispatch]);
|
|
2743
|
-
|
|
2749
|
+
const closeMenu = preact.useCallback(() => {
|
|
2744
2750
|
dispatch({
|
|
2745
2751
|
type: FunctionCloseMenu$1
|
|
2746
2752
|
});
|
|
2747
2753
|
}, [dispatch]);
|
|
2748
|
-
|
|
2754
|
+
const openMenu = preact.useCallback(() => {
|
|
2749
2755
|
dispatch({
|
|
2750
2756
|
type: FunctionOpenMenu$1
|
|
2751
2757
|
});
|
|
2752
2758
|
}, [dispatch]);
|
|
2753
|
-
|
|
2759
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
2754
2760
|
dispatch({
|
|
2755
2761
|
type: FunctionSetHighlightedIndex$1,
|
|
2756
2762
|
highlightedIndex: newHighlightedIndex
|
|
2757
2763
|
});
|
|
2758
2764
|
}, [dispatch]);
|
|
2759
|
-
|
|
2765
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
2760
2766
|
dispatch({
|
|
2761
2767
|
type: FunctionSelectItem$1,
|
|
2762
2768
|
selectedItem: newSelectedItem
|
|
2763
2769
|
});
|
|
2764
2770
|
}, [dispatch]);
|
|
2765
|
-
|
|
2771
|
+
const reset = preact.useCallback(() => {
|
|
2766
2772
|
dispatch({
|
|
2767
2773
|
type: FunctionReset$2
|
|
2768
2774
|
});
|
|
2769
2775
|
}, [dispatch]);
|
|
2770
|
-
|
|
2776
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
2771
2777
|
dispatch({
|
|
2772
2778
|
type: FunctionSetInputValue$1,
|
|
2773
2779
|
inputValue: newInputValue
|
|
2774
2780
|
});
|
|
2775
2781
|
}, [dispatch]); // Getter functions.
|
|
2776
2782
|
|
|
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);
|
|
2783
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
2784
|
+
id: elementIds.labelId,
|
|
2785
|
+
htmlFor: elementIds.toggleButtonId,
|
|
2786
|
+
...labelProps
|
|
2787
|
+
}), [elementIds]);
|
|
2788
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
2789
|
+
let {
|
|
2790
|
+
onMouseLeave,
|
|
2791
|
+
refKey = 'ref',
|
|
2792
|
+
onKeyDown,
|
|
2793
|
+
onBlur,
|
|
2794
|
+
ref,
|
|
2795
|
+
...rest
|
|
2796
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2797
|
+
let {
|
|
2798
|
+
suppressRefError = false
|
|
2799
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2800
|
+
const latestState = latest.current.state;
|
|
2801
|
+
|
|
2802
|
+
const menuHandleKeyDown = event => {
|
|
2803
|
+
const key = normalizeArrowKey(event);
|
|
2803
2804
|
|
|
2804
2805
|
if (key && menuKeyDownHandlers[key]) {
|
|
2805
2806
|
menuKeyDownHandlers[key](event);
|
|
2806
2807
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2807
2808
|
dispatch({
|
|
2808
2809
|
type: MenuKeyDownCharacter,
|
|
2809
|
-
key
|
|
2810
|
-
getItemNodeFromIndex
|
|
2810
|
+
key,
|
|
2811
|
+
getItemNodeFromIndex
|
|
2811
2812
|
});
|
|
2812
2813
|
}
|
|
2813
2814
|
};
|
|
2814
2815
|
|
|
2815
|
-
|
|
2816
|
+
const menuHandleBlur = () => {
|
|
2816
2817
|
// if the blur was a result of selection, we don't trigger this action.
|
|
2817
2818
|
if (shouldBlurRef.current === false) {
|
|
2818
2819
|
shouldBlurRef.current = true;
|
|
2819
2820
|
return;
|
|
2820
2821
|
}
|
|
2821
2822
|
|
|
2822
|
-
|
|
2823
|
+
const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
2823
2824
|
/* istanbul ignore else */
|
|
2824
2825
|
|
|
2825
2826
|
if (shouldBlur) {
|
|
@@ -2829,61 +2830,72 @@ function useSelect(userProps) {
|
|
|
2829
2830
|
}
|
|
2830
2831
|
};
|
|
2831
2832
|
|
|
2832
|
-
|
|
2833
|
+
const menuHandleMouseLeave = () => {
|
|
2833
2834
|
dispatch({
|
|
2834
2835
|
type: MenuMouseLeave$1
|
|
2835
2836
|
});
|
|
2836
2837
|
};
|
|
2837
2838
|
|
|
2838
2839
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2839
|
-
return
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2840
|
+
return {
|
|
2841
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
2842
|
+
menuRef.current = menuNode;
|
|
2843
|
+
}),
|
|
2844
|
+
id: elementIds.menuId,
|
|
2845
|
+
role: 'listbox',
|
|
2846
|
+
'aria-labelledby': elementIds.labelId,
|
|
2847
|
+
tabIndex: -1,
|
|
2848
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
2849
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
2850
|
+
}),
|
|
2844
2851
|
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
2845
2852
|
onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
|
2846
|
-
onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
|
2847
|
-
|
|
2853
|
+
onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
|
|
2854
|
+
...rest
|
|
2855
|
+
};
|
|
2848
2856
|
}, [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() {
|
|
2857
|
+
const getToggleButtonProps = preact.useCallback(function (_temp3, _temp4) {
|
|
2858
|
+
let {
|
|
2859
|
+
onClick,
|
|
2860
|
+
onKeyDown,
|
|
2861
|
+
refKey = 'ref',
|
|
2862
|
+
ref,
|
|
2863
|
+
...rest
|
|
2864
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2865
|
+
let {
|
|
2866
|
+
suppressRefError = false
|
|
2867
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2868
|
+
|
|
2869
|
+
const toggleButtonHandleClick = () => {
|
|
2865
2870
|
dispatch({
|
|
2866
2871
|
type: ToggleButtonClick$1
|
|
2867
2872
|
});
|
|
2868
2873
|
};
|
|
2869
2874
|
|
|
2870
|
-
|
|
2871
|
-
|
|
2875
|
+
const toggleButtonHandleKeyDown = event => {
|
|
2876
|
+
const key = normalizeArrowKey(event);
|
|
2872
2877
|
|
|
2873
2878
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
2874
2879
|
toggleButtonKeyDownHandlers[key](event);
|
|
2875
2880
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2876
2881
|
dispatch({
|
|
2877
2882
|
type: ToggleButtonKeyDownCharacter,
|
|
2878
|
-
key
|
|
2879
|
-
getItemNodeFromIndex
|
|
2883
|
+
key,
|
|
2884
|
+
getItemNodeFromIndex
|
|
2880
2885
|
});
|
|
2881
2886
|
}
|
|
2882
2887
|
};
|
|
2883
2888
|
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2889
|
+
const toggleProps = {
|
|
2890
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
2891
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
2892
|
+
}),
|
|
2893
|
+
id: elementIds.toggleButtonId,
|
|
2894
|
+
'aria-haspopup': 'listbox',
|
|
2895
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
2896
|
+
'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
|
|
2897
|
+
...rest
|
|
2898
|
+
};
|
|
2887
2899
|
|
|
2888
2900
|
if (!rest.disabled) {
|
|
2889
2901
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
@@ -2893,24 +2905,22 @@ function useSelect(userProps) {
|
|
|
2893
2905
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2894
2906
|
return toggleProps;
|
|
2895
2907
|
}, [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() {
|
|
2908
|
+
const getItemProps = preact.useCallback(function (_temp5) {
|
|
2909
|
+
let {
|
|
2910
|
+
item,
|
|
2911
|
+
index,
|
|
2912
|
+
onMouseMove,
|
|
2913
|
+
onClick,
|
|
2914
|
+
refKey = 'ref',
|
|
2915
|
+
ref,
|
|
2916
|
+
...rest
|
|
2917
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
2918
|
+
const {
|
|
2919
|
+
state: latestState,
|
|
2920
|
+
props: latestProps
|
|
2921
|
+
} = latest.current;
|
|
2922
|
+
|
|
2923
|
+
const itemHandleMouseMove = () => {
|
|
2914
2924
|
if (index === latestState.highlightedIndex) {
|
|
2915
2925
|
return;
|
|
2916
2926
|
}
|
|
@@ -2918,32 +2928,34 @@ function useSelect(userProps) {
|
|
|
2918
2928
|
shouldScrollRef.current = false;
|
|
2919
2929
|
dispatch({
|
|
2920
2930
|
type: ItemMouseMove$1,
|
|
2921
|
-
index
|
|
2931
|
+
index
|
|
2922
2932
|
});
|
|
2923
2933
|
};
|
|
2924
2934
|
|
|
2925
|
-
|
|
2935
|
+
const itemHandleClick = () => {
|
|
2926
2936
|
dispatch({
|
|
2927
2937
|
type: ItemClick$1,
|
|
2928
|
-
index
|
|
2938
|
+
index
|
|
2929
2939
|
});
|
|
2930
2940
|
};
|
|
2931
2941
|
|
|
2932
|
-
|
|
2942
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2933
2943
|
|
|
2934
2944
|
if (itemIndex < 0) {
|
|
2935
2945
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
2936
2946
|
}
|
|
2937
2947
|
|
|
2938
|
-
|
|
2948
|
+
const itemProps = {
|
|
2939
2949
|
role: 'option',
|
|
2940
2950
|
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
2941
|
-
id: elementIds.getItemId(itemIndex)
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2951
|
+
id: elementIds.getItemId(itemIndex),
|
|
2952
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
2953
|
+
if (itemNode) {
|
|
2954
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
2955
|
+
}
|
|
2956
|
+
}),
|
|
2957
|
+
...rest
|
|
2958
|
+
};
|
|
2947
2959
|
|
|
2948
2960
|
if (!rest.disabled) {
|
|
2949
2961
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
@@ -2954,46 +2966,46 @@ function useSelect(userProps) {
|
|
|
2954
2966
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
2955
2967
|
return {
|
|
2956
2968
|
// prop getters.
|
|
2957
|
-
getToggleButtonProps
|
|
2958
|
-
getLabelProps
|
|
2959
|
-
getMenuProps
|
|
2960
|
-
getItemProps
|
|
2969
|
+
getToggleButtonProps,
|
|
2970
|
+
getLabelProps,
|
|
2971
|
+
getMenuProps,
|
|
2972
|
+
getItemProps,
|
|
2961
2973
|
// actions.
|
|
2962
|
-
toggleMenu
|
|
2963
|
-
openMenu
|
|
2964
|
-
closeMenu
|
|
2965
|
-
setHighlightedIndex
|
|
2966
|
-
selectItem
|
|
2967
|
-
reset
|
|
2968
|
-
setInputValue
|
|
2974
|
+
toggleMenu,
|
|
2975
|
+
openMenu,
|
|
2976
|
+
closeMenu,
|
|
2977
|
+
setHighlightedIndex,
|
|
2978
|
+
selectItem,
|
|
2979
|
+
reset,
|
|
2980
|
+
setInputValue,
|
|
2969
2981
|
// state.
|
|
2970
|
-
highlightedIndex
|
|
2971
|
-
isOpen
|
|
2972
|
-
selectedItem
|
|
2973
|
-
inputValue
|
|
2982
|
+
highlightedIndex,
|
|
2983
|
+
isOpen,
|
|
2984
|
+
selectedItem,
|
|
2985
|
+
inputValue
|
|
2974
2986
|
};
|
|
2975
2987
|
}
|
|
2976
2988
|
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2989
|
+
const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2990
|
+
const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2991
|
+
const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
2992
|
+
const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
|
|
2993
|
+
const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
|
|
2994
|
+
const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
|
|
2995
|
+
const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
|
|
2996
|
+
const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
|
|
2997
|
+
const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
|
|
2998
|
+
const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
|
|
2999
|
+
const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
|
|
3000
|
+
const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
|
|
3001
|
+
const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
|
|
3002
|
+
const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
|
|
3003
|
+
const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
|
|
3004
|
+
const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
|
|
3005
|
+
const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
|
|
3006
|
+
const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
|
|
3007
|
+
const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
|
|
3008
|
+
const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
|
|
2997
3009
|
|
|
2998
3010
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2999
3011
|
__proto__: null,
|
|
@@ -3020,56 +3032,60 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3020
3032
|
});
|
|
3021
3033
|
|
|
3022
3034
|
function getInitialState$1(props) {
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3035
|
+
const initialState = getInitialState$2(props);
|
|
3036
|
+
const {
|
|
3037
|
+
selectedItem
|
|
3038
|
+
} = initialState;
|
|
3039
|
+
let {
|
|
3040
|
+
inputValue
|
|
3041
|
+
} = initialState;
|
|
3026
3042
|
|
|
3027
3043
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3028
3044
|
inputValue = props.itemToString(selectedItem);
|
|
3029
3045
|
}
|
|
3030
3046
|
|
|
3031
|
-
return
|
|
3032
|
-
inputValue
|
|
3033
|
-
}
|
|
3047
|
+
return { ...initialState,
|
|
3048
|
+
inputValue
|
|
3049
|
+
};
|
|
3034
3050
|
}
|
|
3035
3051
|
|
|
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[
|
|
3052
|
+
const propTypes$1 = {
|
|
3053
|
+
items: PropTypes__default["default"].array.isRequired,
|
|
3054
|
+
itemToString: PropTypes__default["default"].func,
|
|
3055
|
+
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
3056
|
+
getA11ySelectionMessage: PropTypes__default["default"].func,
|
|
3057
|
+
circularNavigation: PropTypes__default["default"].bool,
|
|
3058
|
+
highlightedIndex: PropTypes__default["default"].number,
|
|
3059
|
+
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
3060
|
+
initialHighlightedIndex: PropTypes__default["default"].number,
|
|
3061
|
+
isOpen: PropTypes__default["default"].bool,
|
|
3062
|
+
defaultIsOpen: PropTypes__default["default"].bool,
|
|
3063
|
+
initialIsOpen: PropTypes__default["default"].bool,
|
|
3064
|
+
selectedItem: PropTypes__default["default"].any,
|
|
3065
|
+
initialSelectedItem: PropTypes__default["default"].any,
|
|
3066
|
+
defaultSelectedItem: PropTypes__default["default"].any,
|
|
3067
|
+
inputValue: PropTypes__default["default"].string,
|
|
3068
|
+
defaultInputValue: PropTypes__default["default"].string,
|
|
3069
|
+
initialInputValue: PropTypes__default["default"].string,
|
|
3070
|
+
id: PropTypes__default["default"].string,
|
|
3071
|
+
labelId: PropTypes__default["default"].string,
|
|
3072
|
+
menuId: PropTypes__default["default"].string,
|
|
3073
|
+
getItemId: PropTypes__default["default"].func,
|
|
3074
|
+
inputId: PropTypes__default["default"].string,
|
|
3075
|
+
toggleButtonId: PropTypes__default["default"].string,
|
|
3076
|
+
stateReducer: PropTypes__default["default"].func,
|
|
3077
|
+
onSelectedItemChange: PropTypes__default["default"].func,
|
|
3078
|
+
onHighlightedIndexChange: PropTypes__default["default"].func,
|
|
3079
|
+
onStateChange: PropTypes__default["default"].func,
|
|
3080
|
+
onIsOpenChange: PropTypes__default["default"].func,
|
|
3081
|
+
onInputValueChange: PropTypes__default["default"].func,
|
|
3082
|
+
environment: PropTypes__default["default"].shape({
|
|
3083
|
+
addEventListener: PropTypes__default["default"].func,
|
|
3084
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
3085
|
+
document: PropTypes__default["default"].shape({
|
|
3086
|
+
getElementById: PropTypes__default["default"].func,
|
|
3087
|
+
activeElement: PropTypes__default["default"].any,
|
|
3088
|
+
body: PropTypes__default["default"].any
|
|
3073
3089
|
})
|
|
3074
3090
|
})
|
|
3075
3091
|
};
|
|
@@ -3087,14 +3103,10 @@ var propTypes$1 = {
|
|
|
3087
3103
|
*/
|
|
3088
3104
|
|
|
3089
3105
|
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.
|
|
3106
|
+
const previousSelectedItemRef = preact.useRef();
|
|
3107
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3095
3108
|
|
|
3096
|
-
|
|
3097
|
-
preact.useEffect(function () {
|
|
3109
|
+
preact.useEffect(() => {
|
|
3098
3110
|
if (isControlledProp(props, 'selectedItem')) {
|
|
3099
3111
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
3100
3112
|
dispatch({
|
|
@@ -3110,27 +3122,29 @@ function useControlledReducer(reducer, initialState, props) {
|
|
|
3110
3122
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
3111
3123
|
|
|
3112
3124
|
|
|
3113
|
-
|
|
3125
|
+
let validatePropTypes$1 = noop;
|
|
3114
3126
|
/* istanbul ignore next */
|
|
3115
3127
|
|
|
3116
3128
|
if (process.env.NODE_ENV !== 'production') {
|
|
3117
|
-
validatePropTypes$1 =
|
|
3118
|
-
PropTypes__default[
|
|
3129
|
+
validatePropTypes$1 = (options, caller) => {
|
|
3130
|
+
PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
3119
3131
|
};
|
|
3120
3132
|
}
|
|
3121
3133
|
|
|
3122
|
-
|
|
3134
|
+
const defaultProps$1 = { ...defaultProps$3,
|
|
3123
3135
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
3124
3136
|
circularNavigation: true
|
|
3125
|
-
}
|
|
3137
|
+
};
|
|
3126
3138
|
|
|
3127
3139
|
/* eslint-disable complexity */
|
|
3128
3140
|
|
|
3129
3141
|
function downshiftUseComboboxReducer(state, action) {
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3142
|
+
const {
|
|
3143
|
+
type,
|
|
3144
|
+
props,
|
|
3145
|
+
shiftKey
|
|
3146
|
+
} = action;
|
|
3147
|
+
let changes;
|
|
3134
3148
|
|
|
3135
3149
|
switch (type) {
|
|
3136
3150
|
case ItemClick:
|
|
@@ -3171,22 +3185,24 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3171
3185
|
break;
|
|
3172
3186
|
|
|
3173
3187
|
case InputKeyDownEnter:
|
|
3174
|
-
changes =
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3188
|
+
changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
|
|
3189
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3190
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3191
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3192
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3193
|
+
})
|
|
3194
|
+
};
|
|
3180
3195
|
break;
|
|
3181
3196
|
|
|
3182
3197
|
case InputKeyDownEscape:
|
|
3183
|
-
changes =
|
|
3198
|
+
changes = {
|
|
3184
3199
|
isOpen: false,
|
|
3185
|
-
highlightedIndex: -1
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3200
|
+
highlightedIndex: -1,
|
|
3201
|
+
...(!state.isOpen && {
|
|
3202
|
+
selectedItem: null,
|
|
3203
|
+
inputValue: ''
|
|
3204
|
+
})
|
|
3205
|
+
};
|
|
3190
3206
|
break;
|
|
3191
3207
|
|
|
3192
3208
|
case InputKeyDownHome:
|
|
@@ -3202,13 +3218,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3202
3218
|
break;
|
|
3203
3219
|
|
|
3204
3220
|
case InputBlur:
|
|
3205
|
-
changes =
|
|
3221
|
+
changes = {
|
|
3206
3222
|
isOpen: false,
|
|
3207
|
-
highlightedIndex: -1
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3223
|
+
highlightedIndex: -1,
|
|
3224
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
3225
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3226
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3227
|
+
})
|
|
3228
|
+
};
|
|
3212
3229
|
break;
|
|
3213
3230
|
|
|
3214
3231
|
case InputChange:
|
|
@@ -3236,15 +3253,13 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3236
3253
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
3237
3254
|
}
|
|
3238
3255
|
|
|
3239
|
-
return
|
|
3256
|
+
return { ...state,
|
|
3257
|
+
...changes
|
|
3258
|
+
};
|
|
3240
3259
|
}
|
|
3241
3260
|
/* eslint-enable complexity */
|
|
3242
3261
|
|
|
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"];
|
|
3262
|
+
/* eslint-disable max-statements */
|
|
3248
3263
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
3249
3264
|
|
|
3250
3265
|
function useCombobox(userProps) {
|
|
@@ -3254,87 +3269,88 @@ function useCombobox(userProps) {
|
|
|
3254
3269
|
|
|
3255
3270
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
3256
3271
|
|
|
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
|
-
|
|
3272
|
+
const props = { ...defaultProps$1,
|
|
3273
|
+
...userProps
|
|
3274
|
+
};
|
|
3275
|
+
const {
|
|
3276
|
+
initialIsOpen,
|
|
3277
|
+
defaultIsOpen,
|
|
3278
|
+
items,
|
|
3279
|
+
scrollIntoView,
|
|
3280
|
+
environment,
|
|
3281
|
+
getA11yStatusMessage,
|
|
3282
|
+
getA11ySelectionMessage,
|
|
3283
|
+
itemToString
|
|
3284
|
+
} = props; // Initial state depending on controlled props.
|
|
3285
|
+
|
|
3286
|
+
const initialState = getInitialState$1(props);
|
|
3287
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
3288
|
+
const {
|
|
3289
|
+
isOpen,
|
|
3290
|
+
highlightedIndex,
|
|
3291
|
+
selectedItem,
|
|
3292
|
+
inputValue
|
|
3293
|
+
} = state; // Element refs.
|
|
3294
|
+
|
|
3295
|
+
const menuRef = preact.useRef(null);
|
|
3296
|
+
const itemRefs = preact.useRef({});
|
|
3297
|
+
const inputRef = preact.useRef(null);
|
|
3298
|
+
const toggleButtonRef = preact.useRef(null);
|
|
3299
|
+
const comboboxRef = preact.useRef(null);
|
|
3300
|
+
const isInitialMountRef = preact.useRef(true); // prevent id re-generation between renders.
|
|
3301
|
+
|
|
3302
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
3303
|
+
|
|
3304
|
+
const previousResultCountRef = preact.useRef(); // utility callback to get item element.
|
|
3305
|
+
|
|
3306
|
+
const latest = useLatestRef({
|
|
3307
|
+
state,
|
|
3308
|
+
props
|
|
3293
3309
|
});
|
|
3294
|
-
|
|
3295
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3296
|
-
}, [elementIds]); // Effects.
|
|
3310
|
+
const getItemNodeFromIndex = preact.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
3297
3311
|
// Sets a11y status message on changes in state.
|
|
3298
3312
|
|
|
3299
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
3313
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3300
3314
|
isInitialMount: isInitialMountRef.current,
|
|
3301
3315
|
previousResultCount: previousResultCountRef.current,
|
|
3302
|
-
items
|
|
3303
|
-
environment
|
|
3304
|
-
itemToString
|
|
3305
|
-
|
|
3316
|
+
items,
|
|
3317
|
+
environment,
|
|
3318
|
+
itemToString,
|
|
3319
|
+
...state
|
|
3320
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
3306
3321
|
|
|
3307
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
3322
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3308
3323
|
isInitialMount: isInitialMountRef.current,
|
|
3309
3324
|
previousResultCount: previousResultCountRef.current,
|
|
3310
|
-
items
|
|
3311
|
-
environment
|
|
3312
|
-
itemToString
|
|
3313
|
-
|
|
3325
|
+
items,
|
|
3326
|
+
environment,
|
|
3327
|
+
itemToString,
|
|
3328
|
+
...state
|
|
3329
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
3314
3330
|
|
|
3315
|
-
|
|
3331
|
+
const shouldScrollRef = useScrollIntoView({
|
|
3316
3332
|
menuElement: menuRef.current,
|
|
3317
|
-
highlightedIndex
|
|
3318
|
-
isOpen
|
|
3319
|
-
itemRefs
|
|
3320
|
-
scrollIntoView
|
|
3321
|
-
getItemNodeFromIndex
|
|
3333
|
+
highlightedIndex,
|
|
3334
|
+
isOpen,
|
|
3335
|
+
itemRefs,
|
|
3336
|
+
scrollIntoView,
|
|
3337
|
+
getItemNodeFromIndex
|
|
3322
3338
|
});
|
|
3323
3339
|
useControlPropsValidator({
|
|
3324
3340
|
isInitialMount: isInitialMountRef.current,
|
|
3325
|
-
props
|
|
3326
|
-
state
|
|
3341
|
+
props,
|
|
3342
|
+
state
|
|
3327
3343
|
}); // Focus the input on first render if required.
|
|
3328
3344
|
|
|
3329
|
-
preact.useEffect(
|
|
3330
|
-
|
|
3345
|
+
preact.useEffect(() => {
|
|
3346
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
3331
3347
|
|
|
3332
3348
|
if (focusOnOpen && inputRef.current) {
|
|
3333
3349
|
inputRef.current.focus();
|
|
3334
3350
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3335
3351
|
|
|
3336
3352
|
}, []);
|
|
3337
|
-
preact.useEffect(
|
|
3353
|
+
preact.useEffect(() => {
|
|
3338
3354
|
if (isInitialMountRef.current) {
|
|
3339
3355
|
return;
|
|
3340
3356
|
}
|
|
@@ -3342,147 +3358,151 @@ function useCombobox(userProps) {
|
|
|
3342
3358
|
previousResultCountRef.current = items.length;
|
|
3343
3359
|
}); // Add mouse/touch events to document.
|
|
3344
3360
|
|
|
3345
|
-
|
|
3361
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
|
|
3346
3362
|
dispatch({
|
|
3347
3363
|
type: InputBlur,
|
|
3348
3364
|
selectItem: false
|
|
3349
3365
|
});
|
|
3350
3366
|
});
|
|
3351
|
-
|
|
3367
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
3352
3368
|
|
|
3353
|
-
preact.useEffect(
|
|
3369
|
+
preact.useEffect(() => {
|
|
3354
3370
|
isInitialMountRef.current = false;
|
|
3355
3371
|
}, []); // Reset itemRefs on close.
|
|
3356
3372
|
|
|
3357
|
-
preact.useEffect(
|
|
3373
|
+
preact.useEffect(() => {
|
|
3358
3374
|
if (!isOpen) {
|
|
3359
3375
|
itemRefs.current = {};
|
|
3360
3376
|
}
|
|
3361
3377
|
}, [isOpen]);
|
|
3362
3378
|
/* Event handler functions */
|
|
3363
3379
|
|
|
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
|
-
}
|
|
3380
|
+
const inputKeyDownHandlers = preact.useMemo(() => ({
|
|
3381
|
+
ArrowDown(event) {
|
|
3382
|
+
event.preventDefault();
|
|
3383
|
+
dispatch({
|
|
3384
|
+
type: InputKeyDownArrowDown,
|
|
3385
|
+
shiftKey: event.shiftKey,
|
|
3386
|
+
getItemNodeFromIndex
|
|
3387
|
+
});
|
|
3388
|
+
},
|
|
3386
3389
|
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
return;
|
|
3396
|
-
}
|
|
3390
|
+
ArrowUp(event) {
|
|
3391
|
+
event.preventDefault();
|
|
3392
|
+
dispatch({
|
|
3393
|
+
type: InputKeyDownArrowUp,
|
|
3394
|
+
shiftKey: event.shiftKey,
|
|
3395
|
+
getItemNodeFromIndex
|
|
3396
|
+
});
|
|
3397
|
+
},
|
|
3397
3398
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
});
|
|
3403
|
-
},
|
|
3404
|
-
Escape: function Escape() {
|
|
3405
|
-
var latestState = latest.current.state;
|
|
3399
|
+
Home(event) {
|
|
3400
|
+
if (!latest.current.state.isOpen) {
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3406
3403
|
|
|
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.
|
|
3404
|
+
event.preventDefault();
|
|
3405
|
+
dispatch({
|
|
3406
|
+
type: InputKeyDownHome,
|
|
3407
|
+
getItemNodeFromIndex
|
|
3408
|
+
});
|
|
3409
|
+
},
|
|
3415
3410
|
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3411
|
+
End(event) {
|
|
3412
|
+
if (!latest.current.state.isOpen) {
|
|
3413
|
+
return;
|
|
3414
|
+
}
|
|
3420
3415
|
|
|
3421
|
-
|
|
3416
|
+
event.preventDefault();
|
|
3417
|
+
dispatch({
|
|
3418
|
+
type: InputKeyDownEnd,
|
|
3419
|
+
getItemNodeFromIndex
|
|
3420
|
+
});
|
|
3421
|
+
},
|
|
3422
|
+
|
|
3423
|
+
Escape() {
|
|
3424
|
+
const latestState = latest.current.state;
|
|
3425
|
+
|
|
3426
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
3422
3427
|
dispatch({
|
|
3423
|
-
type:
|
|
3424
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3428
|
+
type: InputKeyDownEscape
|
|
3425
3429
|
});
|
|
3426
3430
|
}
|
|
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;
|
|
3431
|
+
},
|
|
3449
3432
|
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3433
|
+
Enter(event) {
|
|
3434
|
+
const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3435
|
+
|
|
3436
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3437
|
+
) {
|
|
3438
|
+
return;
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
event.preventDefault();
|
|
3454
3442
|
dispatch({
|
|
3455
|
-
type:
|
|
3443
|
+
type: InputKeyDownEnter,
|
|
3444
|
+
getItemNodeFromIndex
|
|
3456
3445
|
});
|
|
3457
|
-
}
|
|
3446
|
+
}
|
|
3447
|
+
|
|
3448
|
+
}), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3449
|
+
|
|
3450
|
+
const getLabelProps = preact.useCallback(labelProps => ({
|
|
3451
|
+
id: elementIds.labelId,
|
|
3452
|
+
htmlFor: elementIds.inputId,
|
|
3453
|
+
...labelProps
|
|
3454
|
+
}), [elementIds]);
|
|
3455
|
+
const getMenuProps = preact.useCallback(function (_temp, _temp2) {
|
|
3456
|
+
let {
|
|
3457
|
+
onMouseLeave,
|
|
3458
|
+
refKey = 'ref',
|
|
3459
|
+
ref,
|
|
3460
|
+
...rest
|
|
3461
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3462
|
+
let {
|
|
3463
|
+
suppressRefError = false
|
|
3464
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3465
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3466
|
+
return {
|
|
3467
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3468
|
+
menuRef.current = menuNode;
|
|
3469
|
+
}),
|
|
3470
|
+
id: elementIds.menuId,
|
|
3471
|
+
role: 'listbox',
|
|
3472
|
+
'aria-labelledby': elementIds.labelId,
|
|
3473
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
3474
|
+
dispatch({
|
|
3475
|
+
type: MenuMouseLeave
|
|
3476
|
+
});
|
|
3477
|
+
}),
|
|
3478
|
+
...rest
|
|
3479
|
+
};
|
|
3458
3480
|
}, [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);
|
|
3481
|
+
const getItemProps = preact.useCallback(function (_temp3) {
|
|
3482
|
+
let {
|
|
3483
|
+
item,
|
|
3484
|
+
index,
|
|
3485
|
+
refKey = 'ref',
|
|
3486
|
+
ref,
|
|
3487
|
+
onMouseMove,
|
|
3488
|
+
onClick,
|
|
3489
|
+
onPress,
|
|
3490
|
+
...rest
|
|
3491
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3492
|
+
const {
|
|
3493
|
+
props: latestProps,
|
|
3494
|
+
state: latestState
|
|
3495
|
+
} = latest.current;
|
|
3496
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3477
3497
|
|
|
3478
3498
|
if (itemIndex < 0) {
|
|
3479
3499
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3480
3500
|
}
|
|
3481
3501
|
|
|
3482
|
-
|
|
3483
|
-
|
|
3502
|
+
const onSelectKey = 'onClick';
|
|
3503
|
+
const customClickHandler = onClick;
|
|
3484
3504
|
|
|
3485
|
-
|
|
3505
|
+
const itemHandleMouseMove = () => {
|
|
3486
3506
|
if (index === latestState.highlightedIndex) {
|
|
3487
3507
|
return;
|
|
3488
3508
|
}
|
|
@@ -3490,14 +3510,14 @@ function useCombobox(userProps) {
|
|
|
3490
3510
|
shouldScrollRef.current = false;
|
|
3491
3511
|
dispatch({
|
|
3492
3512
|
type: ItemMouseMove,
|
|
3493
|
-
index
|
|
3513
|
+
index
|
|
3494
3514
|
});
|
|
3495
3515
|
};
|
|
3496
3516
|
|
|
3497
|
-
|
|
3517
|
+
const itemHandleClick = () => {
|
|
3498
3518
|
dispatch({
|
|
3499
3519
|
type: ItemClick,
|
|
3500
|
-
index
|
|
3520
|
+
index
|
|
3501
3521
|
});
|
|
3502
3522
|
|
|
3503
3523
|
if (inputRef.current) {
|
|
@@ -3505,26 +3525,32 @@ function useCombobox(userProps) {
|
|
|
3505
3525
|
}
|
|
3506
3526
|
};
|
|
3507
3527
|
|
|
3508
|
-
return
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3528
|
+
return {
|
|
3529
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3530
|
+
if (itemNode) {
|
|
3531
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3532
|
+
}
|
|
3533
|
+
}),
|
|
3534
|
+
role: 'option',
|
|
3535
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
3536
|
+
id: elementIds.getItemId(itemIndex),
|
|
3537
|
+
...(!rest.disabled && {
|
|
3538
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3539
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
3540
|
+
}),
|
|
3541
|
+
...rest
|
|
3542
|
+
};
|
|
3515
3543
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3544
|
+
const getToggleButtonProps = preact.useCallback(function (_temp4) {
|
|
3545
|
+
let {
|
|
3546
|
+
onClick,
|
|
3547
|
+
onPress,
|
|
3548
|
+
refKey = 'ref',
|
|
3549
|
+
ref,
|
|
3550
|
+
...rest
|
|
3551
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3552
|
+
|
|
3553
|
+
const toggleButtonHandleClick = () => {
|
|
3528
3554
|
dispatch({
|
|
3529
3555
|
type: ToggleButtonClick
|
|
3530
3556
|
});
|
|
@@ -3534,49 +3560,52 @@ function useCombobox(userProps) {
|
|
|
3534
3560
|
}
|
|
3535
3561
|
};
|
|
3536
3562
|
|
|
3537
|
-
return
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3563
|
+
return {
|
|
3564
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3565
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3566
|
+
}),
|
|
3567
|
+
id: elementIds.toggleButtonId,
|
|
3568
|
+
tabIndex: -1,
|
|
3569
|
+
...(!rest.disabled && { ...({
|
|
3570
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3571
|
+
})
|
|
3572
|
+
}),
|
|
3573
|
+
...rest
|
|
3574
|
+
};
|
|
3542
3575
|
}, [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
|
-
|
|
3576
|
+
const getInputProps = preact.useCallback(function (_temp5, _temp6) {
|
|
3577
|
+
let {
|
|
3578
|
+
onKeyDown,
|
|
3579
|
+
onChange,
|
|
3580
|
+
onInput,
|
|
3581
|
+
onBlur,
|
|
3582
|
+
onChangeText,
|
|
3583
|
+
refKey = 'ref',
|
|
3584
|
+
ref,
|
|
3585
|
+
...rest
|
|
3586
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3587
|
+
let {
|
|
3588
|
+
suppressRefError = false
|
|
3589
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
3561
3590
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3562
|
-
|
|
3591
|
+
const latestState = latest.current.state;
|
|
3563
3592
|
|
|
3564
|
-
|
|
3565
|
-
|
|
3593
|
+
const inputHandleKeyDown = event => {
|
|
3594
|
+
const key = normalizeArrowKey(event);
|
|
3566
3595
|
|
|
3567
3596
|
if (key && inputKeyDownHandlers[key]) {
|
|
3568
3597
|
inputKeyDownHandlers[key](event);
|
|
3569
3598
|
}
|
|
3570
3599
|
};
|
|
3571
3600
|
|
|
3572
|
-
|
|
3601
|
+
const inputHandleChange = event => {
|
|
3573
3602
|
dispatch({
|
|
3574
3603
|
type: InputChange,
|
|
3575
3604
|
inputValue: event.target.value
|
|
3576
3605
|
});
|
|
3577
3606
|
};
|
|
3578
3607
|
|
|
3579
|
-
|
|
3608
|
+
const inputHandleBlur = () => {
|
|
3580
3609
|
/* istanbul ignore else */
|
|
3581
3610
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3582
3611
|
dispatch({
|
|
@@ -3588,109 +3617,121 @@ function useCombobox(userProps) {
|
|
|
3588
3617
|
/* istanbul ignore next (preact) */
|
|
3589
3618
|
|
|
3590
3619
|
|
|
3591
|
-
|
|
3592
|
-
|
|
3620
|
+
const onChangeKey = 'onInput' ;
|
|
3621
|
+
let eventHandlers = {};
|
|
3593
3622
|
|
|
3594
3623
|
if (!rest.disabled) {
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3624
|
+
eventHandlers = {
|
|
3625
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
3626
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
3627
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
|
|
3628
|
+
};
|
|
3598
3629
|
}
|
|
3599
3630
|
|
|
3600
|
-
return
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3631
|
+
return {
|
|
3632
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
3633
|
+
inputRef.current = inputNode;
|
|
3634
|
+
}),
|
|
3635
|
+
id: elementIds.inputId,
|
|
3636
|
+
'aria-autocomplete': 'list',
|
|
3637
|
+
'aria-controls': elementIds.menuId,
|
|
3638
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3639
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
3640
|
+
}),
|
|
3605
3641
|
'aria-labelledby': elementIds.labelId,
|
|
3606
3642
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
3607
3643
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
3608
3644
|
autoComplete: 'off',
|
|
3609
|
-
value: latestState.inputValue
|
|
3610
|
-
|
|
3645
|
+
value: latestState.inputValue,
|
|
3646
|
+
...eventHandlers,
|
|
3647
|
+
...rest
|
|
3648
|
+
};
|
|
3611
3649
|
}, [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
|
-
|
|
3650
|
+
const getComboboxProps = preact.useCallback(function (_temp7, _temp8) {
|
|
3651
|
+
let {
|
|
3652
|
+
refKey = 'ref',
|
|
3653
|
+
ref,
|
|
3654
|
+
...rest
|
|
3655
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
3656
|
+
let {
|
|
3657
|
+
suppressRefError = false
|
|
3658
|
+
} = _temp8 === void 0 ? {} : _temp8;
|
|
3625
3659
|
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
3626
|
-
return
|
|
3627
|
-
|
|
3628
|
-
|
|
3660
|
+
return {
|
|
3661
|
+
[refKey]: handleRefs(ref, comboboxNode => {
|
|
3662
|
+
comboboxRef.current = comboboxNode;
|
|
3663
|
+
}),
|
|
3664
|
+
role: 'combobox',
|
|
3665
|
+
'aria-haspopup': 'listbox',
|
|
3666
|
+
'aria-owns': elementIds.menuId,
|
|
3667
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
3668
|
+
...rest
|
|
3669
|
+
};
|
|
3629
3670
|
}, [latest, setGetterPropCallInfo, elementIds]); // returns
|
|
3630
3671
|
|
|
3631
|
-
|
|
3672
|
+
const toggleMenu = preact.useCallback(() => {
|
|
3632
3673
|
dispatch({
|
|
3633
3674
|
type: FunctionToggleMenu
|
|
3634
3675
|
});
|
|
3635
3676
|
}, [dispatch]);
|
|
3636
|
-
|
|
3677
|
+
const closeMenu = preact.useCallback(() => {
|
|
3637
3678
|
dispatch({
|
|
3638
3679
|
type: FunctionCloseMenu
|
|
3639
3680
|
});
|
|
3640
3681
|
}, [dispatch]);
|
|
3641
|
-
|
|
3682
|
+
const openMenu = preact.useCallback(() => {
|
|
3642
3683
|
dispatch({
|
|
3643
3684
|
type: FunctionOpenMenu
|
|
3644
3685
|
});
|
|
3645
3686
|
}, [dispatch]);
|
|
3646
|
-
|
|
3687
|
+
const setHighlightedIndex = preact.useCallback(newHighlightedIndex => {
|
|
3647
3688
|
dispatch({
|
|
3648
3689
|
type: FunctionSetHighlightedIndex,
|
|
3649
3690
|
highlightedIndex: newHighlightedIndex
|
|
3650
3691
|
});
|
|
3651
3692
|
}, [dispatch]);
|
|
3652
|
-
|
|
3693
|
+
const selectItem = preact.useCallback(newSelectedItem => {
|
|
3653
3694
|
dispatch({
|
|
3654
3695
|
type: FunctionSelectItem,
|
|
3655
3696
|
selectedItem: newSelectedItem
|
|
3656
3697
|
});
|
|
3657
3698
|
}, [dispatch]);
|
|
3658
|
-
|
|
3699
|
+
const setInputValue = preact.useCallback(newInputValue => {
|
|
3659
3700
|
dispatch({
|
|
3660
3701
|
type: FunctionSetInputValue,
|
|
3661
3702
|
inputValue: newInputValue
|
|
3662
3703
|
});
|
|
3663
3704
|
}, [dispatch]);
|
|
3664
|
-
|
|
3705
|
+
const reset = preact.useCallback(() => {
|
|
3665
3706
|
dispatch({
|
|
3666
3707
|
type: FunctionReset$1
|
|
3667
3708
|
});
|
|
3668
3709
|
}, [dispatch]);
|
|
3669
3710
|
return {
|
|
3670
3711
|
// prop getters.
|
|
3671
|
-
getItemProps
|
|
3672
|
-
getLabelProps
|
|
3673
|
-
getMenuProps
|
|
3674
|
-
getInputProps
|
|
3675
|
-
getComboboxProps
|
|
3676
|
-
getToggleButtonProps
|
|
3712
|
+
getItemProps,
|
|
3713
|
+
getLabelProps,
|
|
3714
|
+
getMenuProps,
|
|
3715
|
+
getInputProps,
|
|
3716
|
+
getComboboxProps,
|
|
3717
|
+
getToggleButtonProps,
|
|
3677
3718
|
// actions.
|
|
3678
|
-
toggleMenu
|
|
3679
|
-
openMenu
|
|
3680
|
-
closeMenu
|
|
3681
|
-
setHighlightedIndex
|
|
3682
|
-
setInputValue
|
|
3683
|
-
selectItem
|
|
3684
|
-
reset
|
|
3719
|
+
toggleMenu,
|
|
3720
|
+
openMenu,
|
|
3721
|
+
closeMenu,
|
|
3722
|
+
setHighlightedIndex,
|
|
3723
|
+
setInputValue,
|
|
3724
|
+
selectItem,
|
|
3725
|
+
reset,
|
|
3685
3726
|
// state.
|
|
3686
|
-
highlightedIndex
|
|
3687
|
-
isOpen
|
|
3688
|
-
selectedItem
|
|
3689
|
-
inputValue
|
|
3727
|
+
highlightedIndex,
|
|
3728
|
+
isOpen,
|
|
3729
|
+
selectedItem,
|
|
3730
|
+
inputValue
|
|
3690
3731
|
};
|
|
3691
3732
|
}
|
|
3692
3733
|
|
|
3693
|
-
|
|
3734
|
+
const defaultStateValues = {
|
|
3694
3735
|
activeIndex: -1,
|
|
3695
3736
|
selectedItems: []
|
|
3696
3737
|
};
|
|
@@ -3730,11 +3771,11 @@ function getDefaultValue(props, propKey) {
|
|
|
3730
3771
|
|
|
3731
3772
|
|
|
3732
3773
|
function getInitialState(props) {
|
|
3733
|
-
|
|
3734
|
-
|
|
3774
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
3775
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
3735
3776
|
return {
|
|
3736
|
-
activeIndex
|
|
3737
|
-
selectedItems
|
|
3777
|
+
activeIndex,
|
|
3778
|
+
selectedItems
|
|
3738
3779
|
};
|
|
3739
3780
|
}
|
|
3740
3781
|
/**
|
|
@@ -3753,10 +3794,12 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3753
3794
|
return false;
|
|
3754
3795
|
}
|
|
3755
3796
|
|
|
3756
|
-
|
|
3797
|
+
const element = event.target;
|
|
3757
3798
|
|
|
3758
3799
|
if (element instanceof HTMLInputElement && // if element is a text input
|
|
3759
|
-
element.value !== '' && (
|
|
3800
|
+
element.value !== '' && ( // and we have text in it
|
|
3801
|
+
// and cursor is either not at the start or is currently highlighting text.
|
|
3802
|
+
element.selectionStart !== 0 || element.selectionEnd !== 0)) {
|
|
3760
3803
|
return false;
|
|
3761
3804
|
}
|
|
3762
3805
|
|
|
@@ -3771,66 +3814,68 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3771
3814
|
|
|
3772
3815
|
|
|
3773
3816
|
function getA11yRemovalMessage(selectionParameters) {
|
|
3774
|
-
|
|
3775
|
-
|
|
3817
|
+
const {
|
|
3818
|
+
removedSelectedItem,
|
|
3819
|
+
itemToString: itemToStringLocal
|
|
3820
|
+
} = selectionParameters;
|
|
3776
3821
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3777
3822
|
}
|
|
3778
3823
|
|
|
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[
|
|
3824
|
+
const propTypes = {
|
|
3825
|
+
selectedItems: PropTypes__default["default"].array,
|
|
3826
|
+
initialSelectedItems: PropTypes__default["default"].array,
|
|
3827
|
+
defaultSelectedItems: PropTypes__default["default"].array,
|
|
3828
|
+
itemToString: PropTypes__default["default"].func,
|
|
3829
|
+
getA11yRemovalMessage: PropTypes__default["default"].func,
|
|
3830
|
+
stateReducer: PropTypes__default["default"].func,
|
|
3831
|
+
activeIndex: PropTypes__default["default"].number,
|
|
3832
|
+
initialActiveIndex: PropTypes__default["default"].number,
|
|
3833
|
+
defaultActiveIndex: PropTypes__default["default"].number,
|
|
3834
|
+
onActiveIndexChange: PropTypes__default["default"].func,
|
|
3835
|
+
onSelectedItemsChange: PropTypes__default["default"].func,
|
|
3836
|
+
keyNavigationNext: PropTypes__default["default"].string,
|
|
3837
|
+
keyNavigationPrevious: PropTypes__default["default"].string,
|
|
3838
|
+
environment: PropTypes__default["default"].shape({
|
|
3839
|
+
addEventListener: PropTypes__default["default"].func,
|
|
3840
|
+
removeEventListener: PropTypes__default["default"].func,
|
|
3841
|
+
document: PropTypes__default["default"].shape({
|
|
3842
|
+
getElementById: PropTypes__default["default"].func,
|
|
3843
|
+
activeElement: PropTypes__default["default"].any,
|
|
3844
|
+
body: PropTypes__default["default"].any
|
|
3800
3845
|
})
|
|
3801
3846
|
})
|
|
3802
3847
|
};
|
|
3803
|
-
|
|
3848
|
+
const defaultProps = {
|
|
3804
3849
|
itemToString: defaultProps$3.itemToString,
|
|
3805
3850
|
stateReducer: defaultProps$3.stateReducer,
|
|
3806
3851
|
environment: defaultProps$3.environment,
|
|
3807
|
-
getA11yRemovalMessage
|
|
3852
|
+
getA11yRemovalMessage,
|
|
3808
3853
|
keyNavigationNext: 'ArrowRight',
|
|
3809
3854
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3810
3855
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
3811
3856
|
|
|
3812
|
-
|
|
3857
|
+
let validatePropTypes = noop;
|
|
3813
3858
|
/* istanbul ignore next */
|
|
3814
3859
|
|
|
3815
3860
|
if (process.env.NODE_ENV !== 'production') {
|
|
3816
|
-
validatePropTypes =
|
|
3817
|
-
PropTypes__default[
|
|
3861
|
+
validatePropTypes = (options, caller) => {
|
|
3862
|
+
PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3818
3863
|
};
|
|
3819
3864
|
}
|
|
3820
3865
|
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3866
|
+
const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
|
|
3867
|
+
const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
|
|
3868
|
+
const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
|
|
3869
|
+
const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
|
|
3870
|
+
const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
|
|
3871
|
+
const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
|
|
3872
|
+
const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
|
|
3873
|
+
const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
|
|
3874
|
+
const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
|
|
3875
|
+
const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
|
|
3876
|
+
const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
|
|
3877
|
+
const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3878
|
+
const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3834
3879
|
|
|
3835
3880
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3836
3881
|
__proto__: null,
|
|
@@ -3852,13 +3897,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3852
3897
|
/* eslint-disable complexity */
|
|
3853
3898
|
|
|
3854
3899
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3900
|
+
const {
|
|
3901
|
+
type,
|
|
3902
|
+
index,
|
|
3903
|
+
props,
|
|
3904
|
+
selectedItem
|
|
3905
|
+
} = action;
|
|
3906
|
+
const {
|
|
3907
|
+
activeIndex,
|
|
3908
|
+
selectedItems
|
|
3909
|
+
} = state;
|
|
3910
|
+
let changes;
|
|
3862
3911
|
|
|
3863
3912
|
switch (type) {
|
|
3864
3913
|
case SelectedItemClick:
|
|
@@ -3882,7 +3931,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3882
3931
|
case SelectedItemKeyDownBackspace:
|
|
3883
3932
|
case SelectedItemKeyDownDelete:
|
|
3884
3933
|
{
|
|
3885
|
-
|
|
3934
|
+
let newActiveIndex = activeIndex;
|
|
3886
3935
|
|
|
3887
3936
|
if (selectedItems.length === 1) {
|
|
3888
3937
|
newActiveIndex = -1;
|
|
@@ -3890,11 +3939,12 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3890
3939
|
newActiveIndex = selectedItems.length - 2;
|
|
3891
3940
|
}
|
|
3892
3941
|
|
|
3893
|
-
changes =
|
|
3894
|
-
selectedItems: [
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3942
|
+
changes = {
|
|
3943
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
3944
|
+
...{
|
|
3945
|
+
activeIndex: newActiveIndex
|
|
3946
|
+
}
|
|
3947
|
+
};
|
|
3898
3948
|
break;
|
|
3899
3949
|
}
|
|
3900
3950
|
|
|
@@ -3912,7 +3962,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3912
3962
|
|
|
3913
3963
|
case FunctionAddSelectedItem:
|
|
3914
3964
|
changes = {
|
|
3915
|
-
selectedItems: [
|
|
3965
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
3916
3966
|
};
|
|
3917
3967
|
break;
|
|
3918
3968
|
|
|
@@ -3924,26 +3974,30 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3924
3974
|
|
|
3925
3975
|
case FunctionRemoveSelectedItem:
|
|
3926
3976
|
{
|
|
3927
|
-
|
|
3928
|
-
|
|
3977
|
+
let newActiveIndex = activeIndex;
|
|
3978
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
3979
|
+
|
|
3980
|
+
if (selectedItemIndex >= 0) {
|
|
3981
|
+
if (selectedItems.length === 1) {
|
|
3982
|
+
newActiveIndex = -1;
|
|
3983
|
+
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
3984
|
+
newActiveIndex = selectedItems.length - 2;
|
|
3985
|
+
}
|
|
3929
3986
|
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3987
|
+
changes = {
|
|
3988
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
3989
|
+
activeIndex: newActiveIndex
|
|
3990
|
+
};
|
|
3934
3991
|
}
|
|
3935
3992
|
|
|
3936
|
-
changes = _extends__default['default']({
|
|
3937
|
-
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
|
|
3938
|
-
}, {
|
|
3939
|
-
activeIndex: _newActiveIndex
|
|
3940
|
-
});
|
|
3941
3993
|
break;
|
|
3942
3994
|
}
|
|
3943
3995
|
|
|
3944
3996
|
case FunctionSetSelectedItems:
|
|
3945
3997
|
{
|
|
3946
|
-
|
|
3998
|
+
const {
|
|
3999
|
+
selectedItems: newSelectedItems
|
|
4000
|
+
} = action;
|
|
3947
4001
|
changes = {
|
|
3948
4002
|
selectedItems: newSelectedItems
|
|
3949
4003
|
};
|
|
@@ -3952,9 +4006,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3952
4006
|
|
|
3953
4007
|
case FunctionSetActiveIndex:
|
|
3954
4008
|
{
|
|
3955
|
-
|
|
4009
|
+
const {
|
|
4010
|
+
activeIndex: newActiveIndex
|
|
4011
|
+
} = action;
|
|
3956
4012
|
changes = {
|
|
3957
|
-
activeIndex:
|
|
4013
|
+
activeIndex: newActiveIndex
|
|
3958
4014
|
};
|
|
3959
4015
|
break;
|
|
3960
4016
|
}
|
|
@@ -3970,11 +4026,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3970
4026
|
throw new Error('Reducer called without proper action type.');
|
|
3971
4027
|
}
|
|
3972
4028
|
|
|
3973
|
-
return
|
|
4029
|
+
return { ...state,
|
|
4030
|
+
...changes
|
|
4031
|
+
};
|
|
3974
4032
|
}
|
|
3975
4033
|
|
|
3976
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
3977
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
3978
4034
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
3979
4035
|
|
|
3980
4036
|
function useMultipleSelection(userProps) {
|
|
@@ -3984,47 +4040,47 @@ function useMultipleSelection(userProps) {
|
|
|
3984
4040
|
|
|
3985
4041
|
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
3986
4042
|
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4043
|
+
const props = { ...defaultProps,
|
|
4044
|
+
...userProps
|
|
4045
|
+
};
|
|
4046
|
+
const {
|
|
4047
|
+
getA11yRemovalMessage,
|
|
4048
|
+
itemToString,
|
|
4049
|
+
environment,
|
|
4050
|
+
keyNavigationNext,
|
|
4051
|
+
keyNavigationPrevious
|
|
4052
|
+
} = props; // Reducer init.
|
|
4053
|
+
|
|
4054
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
4055
|
+
const {
|
|
4056
|
+
activeIndex,
|
|
4057
|
+
selectedItems
|
|
4058
|
+
} = state; // Refs.
|
|
4059
|
+
|
|
4060
|
+
const isInitialMountRef = preact.useRef(true);
|
|
4061
|
+
const dropdownRef = preact.useRef(null);
|
|
4062
|
+
const previousSelectedItemsRef = preact.useRef(selectedItems);
|
|
4063
|
+
const selectedItemRefs = preact.useRef();
|
|
4006
4064
|
selectedItemRefs.current = [];
|
|
4007
|
-
|
|
4008
|
-
state
|
|
4009
|
-
props
|
|
4065
|
+
const latest = useLatestRef({
|
|
4066
|
+
state,
|
|
4067
|
+
props
|
|
4010
4068
|
}); // Effects.
|
|
4011
4069
|
|
|
4012
4070
|
/* Sets a11y status message on changes in selectedItem. */
|
|
4013
4071
|
|
|
4014
|
-
preact.useEffect(
|
|
4072
|
+
preact.useEffect(() => {
|
|
4015
4073
|
if (isInitialMountRef.current) {
|
|
4016
4074
|
return;
|
|
4017
4075
|
}
|
|
4018
4076
|
|
|
4019
4077
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
4020
|
-
|
|
4021
|
-
return selectedItems.indexOf(item) < 0;
|
|
4022
|
-
});
|
|
4078
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
4023
4079
|
setStatus(getA11yRemovalMessage({
|
|
4024
|
-
itemToString
|
|
4080
|
+
itemToString,
|
|
4025
4081
|
resultCount: selectedItems.length,
|
|
4026
|
-
removedSelectedItem
|
|
4027
|
-
activeIndex
|
|
4082
|
+
removedSelectedItem,
|
|
4083
|
+
activeIndex,
|
|
4028
4084
|
activeSelectedItem: selectedItems[activeIndex]
|
|
4029
4085
|
}), environment.document);
|
|
4030
4086
|
}
|
|
@@ -4032,7 +4088,7 @@ function useMultipleSelection(userProps) {
|
|
|
4032
4088
|
previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4033
4089
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
4034
4090
|
|
|
4035
|
-
preact.useEffect(
|
|
4091
|
+
preact.useEffect(() => {
|
|
4036
4092
|
if (isInitialMountRef.current) {
|
|
4037
4093
|
return;
|
|
4038
4094
|
}
|
|
@@ -4045,181 +4101,191 @@ function useMultipleSelection(userProps) {
|
|
|
4045
4101
|
}, [activeIndex]);
|
|
4046
4102
|
useControlPropsValidator({
|
|
4047
4103
|
isInitialMount: isInitialMountRef.current,
|
|
4048
|
-
props
|
|
4049
|
-
state
|
|
4104
|
+
props,
|
|
4105
|
+
state
|
|
4050
4106
|
});
|
|
4051
|
-
|
|
4107
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
4052
4108
|
|
|
4053
|
-
preact.useEffect(
|
|
4109
|
+
preact.useEffect(() => {
|
|
4054
4110
|
isInitialMountRef.current = false;
|
|
4055
4111
|
}, []); // Event handler functions.
|
|
4056
4112
|
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
4113
|
+
const selectedItemKeyDownHandlers = preact.useMemo(() => ({
|
|
4114
|
+
[keyNavigationPrevious]() {
|
|
4061
4115
|
dispatch({
|
|
4062
4116
|
type: SelectedItemKeyDownNavigationPrevious
|
|
4063
4117
|
});
|
|
4064
|
-
},
|
|
4118
|
+
},
|
|
4119
|
+
|
|
4120
|
+
[keyNavigationNext]() {
|
|
4065
4121
|
dispatch({
|
|
4066
4122
|
type: SelectedItemKeyDownNavigationNext
|
|
4067
4123
|
});
|
|
4068
|
-
},
|
|
4124
|
+
},
|
|
4125
|
+
|
|
4126
|
+
Delete() {
|
|
4069
4127
|
dispatch({
|
|
4070
4128
|
type: SelectedItemKeyDownDelete
|
|
4071
4129
|
});
|
|
4072
|
-
},
|
|
4130
|
+
},
|
|
4131
|
+
|
|
4132
|
+
Backspace() {
|
|
4073
4133
|
dispatch({
|
|
4074
4134
|
type: SelectedItemKeyDownBackspace
|
|
4075
4135
|
});
|
|
4076
|
-
}
|
|
4077
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4078
|
-
var dropdownKeyDownHandlers = preact.useMemo(function () {
|
|
4079
|
-
var _ref2;
|
|
4136
|
+
}
|
|
4080
4137
|
|
|
4081
|
-
|
|
4138
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4139
|
+
const dropdownKeyDownHandlers = preact.useMemo(() => ({
|
|
4140
|
+
[keyNavigationPrevious](event) {
|
|
4082
4141
|
if (isKeyDownOperationPermitted(event)) {
|
|
4083
4142
|
dispatch({
|
|
4084
4143
|
type: DropdownKeyDownNavigationPrevious
|
|
4085
4144
|
});
|
|
4086
4145
|
}
|
|
4087
|
-
},
|
|
4146
|
+
},
|
|
4147
|
+
|
|
4148
|
+
Backspace(event) {
|
|
4088
4149
|
if (isKeyDownOperationPermitted(event)) {
|
|
4089
4150
|
dispatch({
|
|
4090
4151
|
type: DropdownKeyDownBackspace
|
|
4091
4152
|
});
|
|
4092
4153
|
}
|
|
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);
|
|
4154
|
+
}
|
|
4108
4155
|
|
|
4109
|
-
|
|
4110
|
-
|
|
4156
|
+
}), [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4157
|
+
|
|
4158
|
+
const getSelectedItemProps = preact.useCallback(function (_temp) {
|
|
4159
|
+
let {
|
|
4160
|
+
refKey = 'ref',
|
|
4161
|
+
ref,
|
|
4162
|
+
onClick,
|
|
4163
|
+
onKeyDown,
|
|
4164
|
+
selectedItem,
|
|
4165
|
+
index,
|
|
4166
|
+
...rest
|
|
4167
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4168
|
+
const {
|
|
4169
|
+
state: latestState
|
|
4170
|
+
} = latest.current;
|
|
4171
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
4111
4172
|
|
|
4112
4173
|
if (itemIndex < 0) {
|
|
4113
4174
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
4114
4175
|
}
|
|
4115
4176
|
|
|
4116
|
-
|
|
4177
|
+
const selectedItemHandleClick = () => {
|
|
4117
4178
|
dispatch({
|
|
4118
4179
|
type: SelectedItemClick,
|
|
4119
|
-
index
|
|
4180
|
+
index
|
|
4120
4181
|
});
|
|
4121
4182
|
};
|
|
4122
4183
|
|
|
4123
|
-
|
|
4124
|
-
|
|
4184
|
+
const selectedItemHandleKeyDown = event => {
|
|
4185
|
+
const key = normalizeArrowKey(event);
|
|
4125
4186
|
|
|
4126
4187
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
4127
4188
|
selectedItemKeyDownHandlers[key](event);
|
|
4128
4189
|
}
|
|
4129
4190
|
};
|
|
4130
4191
|
|
|
4131
|
-
return
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4192
|
+
return {
|
|
4193
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
4194
|
+
if (selectedItemNode) {
|
|
4195
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
4196
|
+
}
|
|
4197
|
+
}),
|
|
4198
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
4199
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
4200
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
4201
|
+
...rest
|
|
4202
|
+
};
|
|
4136
4203
|
}, [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
|
-
|
|
4204
|
+
const getDropdownProps = preact.useCallback(function (_temp2, _temp3) {
|
|
4205
|
+
let {
|
|
4206
|
+
refKey = 'ref',
|
|
4207
|
+
ref,
|
|
4208
|
+
onKeyDown,
|
|
4209
|
+
onClick,
|
|
4210
|
+
preventKeyAction = false,
|
|
4211
|
+
...rest
|
|
4212
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4213
|
+
let {
|
|
4214
|
+
suppressRefError = false
|
|
4215
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4154
4216
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
4155
4217
|
|
|
4156
|
-
|
|
4157
|
-
|
|
4218
|
+
const dropdownHandleKeyDown = event => {
|
|
4219
|
+
const key = normalizeArrowKey(event);
|
|
4158
4220
|
|
|
4159
4221
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
4160
4222
|
dropdownKeyDownHandlers[key](event);
|
|
4161
4223
|
}
|
|
4162
4224
|
};
|
|
4163
4225
|
|
|
4164
|
-
|
|
4226
|
+
const dropdownHandleClick = () => {
|
|
4165
4227
|
dispatch({
|
|
4166
4228
|
type: DropdownClick
|
|
4167
4229
|
});
|
|
4168
4230
|
};
|
|
4169
4231
|
|
|
4170
|
-
return
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4232
|
+
return {
|
|
4233
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
4234
|
+
if (dropdownNode) {
|
|
4235
|
+
dropdownRef.current = dropdownNode;
|
|
4236
|
+
}
|
|
4237
|
+
}),
|
|
4238
|
+
...(!preventKeyAction && {
|
|
4239
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
4240
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
4241
|
+
}),
|
|
4242
|
+
...rest
|
|
4243
|
+
};
|
|
4178
4244
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
4179
4245
|
|
|
4180
|
-
|
|
4246
|
+
const addSelectedItem = preact.useCallback(selectedItem => {
|
|
4181
4247
|
dispatch({
|
|
4182
4248
|
type: FunctionAddSelectedItem,
|
|
4183
|
-
selectedItem
|
|
4249
|
+
selectedItem
|
|
4184
4250
|
});
|
|
4185
4251
|
}, [dispatch]);
|
|
4186
|
-
|
|
4252
|
+
const removeSelectedItem = preact.useCallback(selectedItem => {
|
|
4187
4253
|
dispatch({
|
|
4188
4254
|
type: FunctionRemoveSelectedItem,
|
|
4189
|
-
selectedItem
|
|
4255
|
+
selectedItem
|
|
4190
4256
|
});
|
|
4191
4257
|
}, [dispatch]);
|
|
4192
|
-
|
|
4258
|
+
const setSelectedItems = preact.useCallback(newSelectedItems => {
|
|
4193
4259
|
dispatch({
|
|
4194
4260
|
type: FunctionSetSelectedItems,
|
|
4195
4261
|
selectedItems: newSelectedItems
|
|
4196
4262
|
});
|
|
4197
4263
|
}, [dispatch]);
|
|
4198
|
-
|
|
4264
|
+
const setActiveIndex = preact.useCallback(newActiveIndex => {
|
|
4199
4265
|
dispatch({
|
|
4200
4266
|
type: FunctionSetActiveIndex,
|
|
4201
4267
|
activeIndex: newActiveIndex
|
|
4202
4268
|
});
|
|
4203
4269
|
}, [dispatch]);
|
|
4204
|
-
|
|
4270
|
+
const reset = preact.useCallback(() => {
|
|
4205
4271
|
dispatch({
|
|
4206
4272
|
type: FunctionReset
|
|
4207
4273
|
});
|
|
4208
4274
|
}, [dispatch]);
|
|
4209
4275
|
return {
|
|
4210
|
-
getSelectedItemProps
|
|
4211
|
-
getDropdownProps
|
|
4212
|
-
addSelectedItem
|
|
4213
|
-
removeSelectedItem
|
|
4214
|
-
setSelectedItems
|
|
4215
|
-
setActiveIndex
|
|
4216
|
-
reset
|
|
4217
|
-
selectedItems
|
|
4218
|
-
activeIndex
|
|
4276
|
+
getSelectedItemProps,
|
|
4277
|
+
getDropdownProps,
|
|
4278
|
+
addSelectedItem,
|
|
4279
|
+
removeSelectedItem,
|
|
4280
|
+
setSelectedItems,
|
|
4281
|
+
setActiveIndex,
|
|
4282
|
+
reset,
|
|
4283
|
+
selectedItems,
|
|
4284
|
+
activeIndex
|
|
4219
4285
|
};
|
|
4220
4286
|
}
|
|
4221
4287
|
|
|
4222
|
-
exports[
|
|
4288
|
+
exports["default"] = Downshift$1;
|
|
4223
4289
|
exports.resetIdCounter = resetIdCounter;
|
|
4224
4290
|
exports.useCombobox = useCombobox;
|
|
4225
4291
|
exports.useMultipleSelection = useMultipleSelection;
|