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