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