downshift 6.1.7 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -9
- package/dist/downshift.cjs.js +1745 -1740
- package/dist/downshift.esm.js +1620 -1611
- package/dist/downshift.native.cjs.js +1730 -1723
- package/dist/downshift.umd.js +1657 -1678
- 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/dist/src/hooks/useSelect/stateChangeTypes.d.ts +11 -12
- package/dist/src/hooks/useSelect/utils.d.ts +0 -1
- package/dist/src/hooks/utils.d.ts +1 -2
- package/package.json +24 -11
- package/preact/dist/downshift.cjs.js +1709 -1704
- package/preact/dist/downshift.esm.js +1620 -1611
- package/preact/dist/downshift.umd.js +1709 -1752
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -23
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/typings/index.d.ts +16 -19
- package/CHANGELOG.md +0 -5
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"];
|
|
544
|
-
|
|
545
|
-
var Downshift = /*#__PURE__*/function () {
|
|
546
|
-
var Downshift = /*#__PURE__*/function (_Component) {
|
|
547
|
-
_inheritsLoose(Downshift, _Component);
|
|
539
|
+
/* eslint camelcase:0 */
|
|
548
540
|
|
|
549
|
-
|
|
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
|
-
|
|
917
|
-
_this.getToggleButtonProps = function (_temp3) {
|
|
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
902
|
|
|
926
|
-
|
|
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,19 +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
|
|
1907
|
-
circularNavigation: false,
|
|
1893
|
+
const defaultProps$3 = {
|
|
1894
|
+
itemToString,
|
|
1895
|
+
stateReducer,
|
|
1896
|
+
getA11ySelectionMessage,
|
|
1897
|
+
scrollIntoView,
|
|
1908
1898
|
environment:
|
|
1909
1899
|
/* istanbul ignore next (ssr) */
|
|
1910
1900
|
typeof window === 'undefined' ? {} : window
|
|
@@ -1915,10 +1905,10 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
|
1915
1905
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1916
1906
|
}
|
|
1917
1907
|
|
|
1918
|
-
|
|
1908
|
+
const defaultValue = props["default" + capitalizeString(propKey)];
|
|
1919
1909
|
|
|
1920
|
-
if (
|
|
1921
|
-
return
|
|
1910
|
+
if (defaultValue !== undefined) {
|
|
1911
|
+
return defaultValue;
|
|
1922
1912
|
}
|
|
1923
1913
|
|
|
1924
1914
|
return defaultStateValues[propKey];
|
|
@@ -1929,38 +1919,44 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1929
1919
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1930
1920
|
}
|
|
1931
1921
|
|
|
1932
|
-
|
|
1933
|
-
|
|
1922
|
+
const value = props[propKey];
|
|
1923
|
+
|
|
1924
|
+
if (value !== undefined) {
|
|
1925
|
+
return value;
|
|
1934
1926
|
}
|
|
1935
1927
|
|
|
1936
|
-
|
|
1928
|
+
const initialValue = props["initial" + capitalizeString(propKey)];
|
|
1937
1929
|
|
|
1938
|
-
if (
|
|
1939
|
-
return
|
|
1930
|
+
if (initialValue !== undefined) {
|
|
1931
|
+
return initialValue;
|
|
1940
1932
|
}
|
|
1941
1933
|
|
|
1942
1934
|
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1943
1935
|
}
|
|
1944
1936
|
|
|
1945
1937
|
function getInitialState$2(props) {
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1938
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1939
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
1940
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
1941
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
1950
1942
|
return {
|
|
1951
1943
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
1952
|
-
isOpen
|
|
1953
|
-
selectedItem
|
|
1954
|
-
inputValue
|
|
1944
|
+
isOpen,
|
|
1945
|
+
selectedItem,
|
|
1946
|
+
inputValue
|
|
1955
1947
|
};
|
|
1956
1948
|
}
|
|
1957
1949
|
|
|
1958
|
-
function getHighlightedIndexOnOpen(props, state, offset
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1950
|
+
function getHighlightedIndexOnOpen(props, state, offset) {
|
|
1951
|
+
const {
|
|
1952
|
+
items,
|
|
1953
|
+
initialHighlightedIndex,
|
|
1954
|
+
defaultHighlightedIndex
|
|
1955
|
+
} = props;
|
|
1956
|
+
const {
|
|
1957
|
+
selectedItem,
|
|
1958
|
+
highlightedIndex
|
|
1959
|
+
} = state;
|
|
1964
1960
|
|
|
1965
1961
|
if (items.length === 0) {
|
|
1966
1962
|
return -1;
|
|
@@ -1976,11 +1972,7 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
|
1976
1972
|
}
|
|
1977
1973
|
|
|
1978
1974
|
if (selectedItem) {
|
|
1979
|
-
|
|
1980
|
-
return items.indexOf(selectedItem);
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
return getNextWrappingIndex(offset, items.indexOf(selectedItem), items.length, getItemNodeFromIndex, false);
|
|
1975
|
+
return items.indexOf(selectedItem);
|
|
1984
1976
|
}
|
|
1985
1977
|
|
|
1986
1978
|
if (offset === 0) {
|
|
@@ -2001,39 +1993,35 @@ function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
|
2001
1993
|
|
|
2002
1994
|
|
|
2003
1995
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
2004
|
-
|
|
1996
|
+
const mouseAndTouchTrackersRef = useRef({
|
|
2005
1997
|
isMouseDown: false,
|
|
2006
1998
|
isTouchMove: false
|
|
2007
1999
|
});
|
|
2008
|
-
useEffect(
|
|
2000
|
+
useEffect(() => {
|
|
2009
2001
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
2010
2002
|
// as in downshift.js.
|
|
2011
|
-
|
|
2003
|
+
const onMouseDown = () => {
|
|
2012
2004
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
2013
2005
|
};
|
|
2014
2006
|
|
|
2015
|
-
|
|
2007
|
+
const onMouseUp = event => {
|
|
2016
2008
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
2017
2009
|
|
|
2018
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2019
|
-
return ref.current;
|
|
2020
|
-
}), environment)) {
|
|
2010
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
2021
2011
|
handleBlur();
|
|
2022
2012
|
}
|
|
2023
2013
|
};
|
|
2024
2014
|
|
|
2025
|
-
|
|
2015
|
+
const onTouchStart = () => {
|
|
2026
2016
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
2027
2017
|
};
|
|
2028
2018
|
|
|
2029
|
-
|
|
2019
|
+
const onTouchMove = () => {
|
|
2030
2020
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
2031
2021
|
};
|
|
2032
2022
|
|
|
2033
|
-
|
|
2034
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
2035
|
-
return ref.current;
|
|
2036
|
-
}), environment, false)) {
|
|
2023
|
+
const onTouchEnd = event => {
|
|
2024
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
2037
2025
|
handleBlur();
|
|
2038
2026
|
}
|
|
2039
2027
|
};
|
|
@@ -2057,9 +2045,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
2057
2045
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2058
2046
|
|
|
2059
2047
|
|
|
2060
|
-
|
|
2061
|
-
return noop;
|
|
2062
|
-
};
|
|
2048
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
2063
2049
|
/**
|
|
2064
2050
|
* Custom hook that checks if getter props are called correctly.
|
|
2065
2051
|
*
|
|
@@ -2071,20 +2057,20 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
2071
2057
|
|
|
2072
2058
|
|
|
2073
2059
|
if (process.env.NODE_ENV !== 'production') {
|
|
2074
|
-
useGetterPropsCalledChecker = function
|
|
2075
|
-
|
|
2060
|
+
useGetterPropsCalledChecker = function () {
|
|
2061
|
+
const isInitialMountRef = useRef(true);
|
|
2076
2062
|
|
|
2077
2063
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
2078
2064
|
propKeys[_key] = arguments[_key];
|
|
2079
2065
|
}
|
|
2080
2066
|
|
|
2081
|
-
|
|
2067
|
+
const getterPropsCalledRef = useRef(propKeys.reduce((acc, propKey) => {
|
|
2082
2068
|
acc[propKey] = {};
|
|
2083
2069
|
return acc;
|
|
2084
2070
|
}, {}));
|
|
2085
|
-
useEffect(
|
|
2086
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
2087
|
-
|
|
2071
|
+
useEffect(() => {
|
|
2072
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
2073
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
2088
2074
|
|
|
2089
2075
|
if (isInitialMountRef.current) {
|
|
2090
2076
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -2094,9 +2080,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2094
2080
|
}
|
|
2095
2081
|
}
|
|
2096
2082
|
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2083
|
+
const {
|
|
2084
|
+
suppressRefError,
|
|
2085
|
+
refKey,
|
|
2086
|
+
elementRef
|
|
2087
|
+
} = propCallInfo;
|
|
2100
2088
|
|
|
2101
2089
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
2102
2090
|
// eslint-disable-next-line no-console
|
|
@@ -2105,11 +2093,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2105
2093
|
});
|
|
2106
2094
|
isInitialMountRef.current = false;
|
|
2107
2095
|
});
|
|
2108
|
-
|
|
2096
|
+
const setGetterPropCallInfo = useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
2109
2097
|
getterPropsCalledRef.current[propKey] = {
|
|
2110
|
-
suppressRefError
|
|
2111
|
-
refKey
|
|
2112
|
-
elementRef
|
|
2098
|
+
suppressRefError,
|
|
2099
|
+
refKey,
|
|
2100
|
+
elementRef
|
|
2113
2101
|
};
|
|
2114
2102
|
}, []);
|
|
2115
2103
|
return setGetterPropCallInfo;
|
|
@@ -2117,39 +2105,41 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2117
2105
|
}
|
|
2118
2106
|
|
|
2119
2107
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2108
|
+
let {
|
|
2109
|
+
isInitialMount,
|
|
2110
|
+
highlightedIndex,
|
|
2111
|
+
items,
|
|
2112
|
+
environment,
|
|
2113
|
+
...rest
|
|
2114
|
+
} = _ref2;
|
|
2126
2115
|
// Sets a11y status message on changes in state.
|
|
2127
|
-
useEffect(
|
|
2116
|
+
useEffect(() => {
|
|
2128
2117
|
if (isInitialMount || false) {
|
|
2129
2118
|
return;
|
|
2130
2119
|
}
|
|
2131
2120
|
|
|
2132
|
-
updateA11yStatus(
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2121
|
+
updateA11yStatus(() => getA11yMessage({
|
|
2122
|
+
highlightedIndex,
|
|
2123
|
+
highlightedItem: items[highlightedIndex],
|
|
2124
|
+
resultCount: items.length,
|
|
2125
|
+
...rest
|
|
2126
|
+
}), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2139
2127
|
}, dependencyArray);
|
|
2140
2128
|
}
|
|
2141
2129
|
|
|
2142
2130
|
function useScrollIntoView(_ref3) {
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2131
|
+
let {
|
|
2132
|
+
highlightedIndex,
|
|
2133
|
+
isOpen,
|
|
2134
|
+
itemRefs,
|
|
2135
|
+
getItemNodeFromIndex,
|
|
2136
|
+
menuElement,
|
|
2137
|
+
scrollIntoView: scrollIntoViewProp
|
|
2138
|
+
} = _ref3;
|
|
2149
2139
|
// used not to scroll on highlight by mouse.
|
|
2150
|
-
|
|
2140
|
+
const shouldScrollRef = useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
2151
2141
|
|
|
2152
|
-
useIsomorphicLayoutEffect(
|
|
2142
|
+
useIsomorphicLayoutEffect(() => {
|
|
2153
2143
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
2154
2144
|
return;
|
|
2155
2145
|
}
|
|
@@ -2165,17 +2155,19 @@ function useScrollIntoView(_ref3) {
|
|
|
2165
2155
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
2166
2156
|
|
|
2167
2157
|
|
|
2168
|
-
|
|
2158
|
+
let useControlPropsValidator = noop;
|
|
2169
2159
|
/* istanbul ignore next */
|
|
2170
2160
|
|
|
2171
2161
|
if (process.env.NODE_ENV !== 'production') {
|
|
2172
|
-
useControlPropsValidator =
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2162
|
+
useControlPropsValidator = _ref4 => {
|
|
2163
|
+
let {
|
|
2164
|
+
isInitialMount,
|
|
2165
|
+
props,
|
|
2166
|
+
state
|
|
2167
|
+
} = _ref4;
|
|
2176
2168
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
2177
|
-
|
|
2178
|
-
useEffect(
|
|
2169
|
+
const prevPropsRef = useRef(props);
|
|
2170
|
+
useEffect(() => {
|
|
2179
2171
|
if (isInitialMount) {
|
|
2180
2172
|
return;
|
|
2181
2173
|
}
|
|
@@ -2186,12 +2178,12 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2186
2178
|
};
|
|
2187
2179
|
}
|
|
2188
2180
|
|
|
2189
|
-
/* eslint-disable complexity */
|
|
2190
|
-
|
|
2191
2181
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2182
|
+
const {
|
|
2183
|
+
type,
|
|
2184
|
+
props
|
|
2185
|
+
} = action;
|
|
2186
|
+
let changes;
|
|
2195
2187
|
|
|
2196
2188
|
switch (type) {
|
|
2197
2189
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -2252,7 +2244,9 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
2252
2244
|
throw new Error('Reducer called without proper action type.');
|
|
2253
2245
|
}
|
|
2254
2246
|
|
|
2255
|
-
return
|
|
2247
|
+
return { ...state,
|
|
2248
|
+
...changes
|
|
2249
|
+
};
|
|
2256
2250
|
}
|
|
2257
2251
|
/* eslint-enable complexity */
|
|
2258
2252
|
|
|
@@ -2279,7 +2273,6 @@ var propTypes$2 = {
|
|
|
2279
2273
|
itemToString: PropTypes.func,
|
|
2280
2274
|
getA11yStatusMessage: PropTypes.func,
|
|
2281
2275
|
getA11ySelectionMessage: PropTypes.func,
|
|
2282
|
-
circularNavigation: PropTypes.bool,
|
|
2283
2276
|
highlightedIndex: PropTypes.number,
|
|
2284
2277
|
defaultHighlightedIndex: PropTypes.number,
|
|
2285
2278
|
initialHighlightedIndex: PropTypes.number,
|
|
@@ -2326,7 +2319,7 @@ function getA11yStatusMessage(_a) {
|
|
|
2326
2319
|
return 'No results are available.';
|
|
2327
2320
|
}
|
|
2328
2321
|
if (resultCount !== previousResultCount) {
|
|
2329
|
-
return resultCount
|
|
2322
|
+
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
2323
|
}
|
|
2331
2324
|
return '';
|
|
2332
2325
|
}
|
|
@@ -2340,48 +2333,46 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
2340
2333
|
};
|
|
2341
2334
|
}
|
|
2342
2335
|
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
var FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 22;
|
|
2336
|
+
const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
|
|
2337
|
+
const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
|
|
2338
|
+
const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
|
|
2339
|
+
const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
|
|
2340
|
+
const ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
|
|
2341
|
+
const ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
|
|
2342
|
+
const ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
|
|
2343
|
+
const ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
|
|
2344
|
+
const ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
|
|
2345
|
+
const ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
|
|
2346
|
+
const ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
|
|
2347
|
+
const ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
|
|
2348
|
+
const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
|
|
2349
|
+
const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
|
|
2350
|
+
const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
|
|
2351
|
+
const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
|
|
2352
|
+
const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
|
|
2353
|
+
const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
|
|
2354
|
+
const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
|
|
2355
|
+
const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
|
|
2356
|
+
const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
|
|
2357
|
+
const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
|
|
2366
2358
|
|
|
2367
2359
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2368
2360
|
__proto__: null,
|
|
2369
|
-
MenuKeyDownArrowDown: MenuKeyDownArrowDown,
|
|
2370
|
-
MenuKeyDownArrowUp: MenuKeyDownArrowUp,
|
|
2371
|
-
MenuKeyDownEscape: MenuKeyDownEscape,
|
|
2372
|
-
MenuKeyDownHome: MenuKeyDownHome,
|
|
2373
|
-
MenuKeyDownEnd: MenuKeyDownEnd,
|
|
2374
|
-
MenuKeyDownEnter: MenuKeyDownEnter,
|
|
2375
|
-
MenuKeyDownSpaceButton: MenuKeyDownSpaceButton,
|
|
2376
|
-
MenuKeyDownCharacter: MenuKeyDownCharacter,
|
|
2377
|
-
MenuBlur: MenuBlur,
|
|
2378
|
-
MenuMouseLeave: MenuMouseLeave$1,
|
|
2379
|
-
ItemMouseMove: ItemMouseMove$1,
|
|
2380
|
-
ItemClick: ItemClick$1,
|
|
2381
2361
|
ToggleButtonClick: ToggleButtonClick$1,
|
|
2382
2362
|
ToggleButtonKeyDownArrowDown: ToggleButtonKeyDownArrowDown,
|
|
2383
2363
|
ToggleButtonKeyDownArrowUp: ToggleButtonKeyDownArrowUp,
|
|
2384
2364
|
ToggleButtonKeyDownCharacter: ToggleButtonKeyDownCharacter,
|
|
2365
|
+
ToggleButtonKeyDownEscape: ToggleButtonKeyDownEscape,
|
|
2366
|
+
ToggleButtonKeyDownHome: ToggleButtonKeyDownHome,
|
|
2367
|
+
ToggleButtonKeyDownEnd: ToggleButtonKeyDownEnd,
|
|
2368
|
+
ToggleButtonKeyDownEnter: ToggleButtonKeyDownEnter,
|
|
2369
|
+
ToggleButtonKeyDownSpaceButton: ToggleButtonKeyDownSpaceButton,
|
|
2370
|
+
ToggleButtonKeyDownPageUp: ToggleButtonKeyDownPageUp,
|
|
2371
|
+
ToggleButtonKeyDownPageDown: ToggleButtonKeyDownPageDown,
|
|
2372
|
+
ToggleButtonBlur: ToggleButtonBlur,
|
|
2373
|
+
MenuMouseLeave: MenuMouseLeave$1,
|
|
2374
|
+
ItemMouseMove: ItemMouseMove$1,
|
|
2375
|
+
ItemClick: ItemClick$1,
|
|
2385
2376
|
FunctionToggleMenu: FunctionToggleMenu$1,
|
|
2386
2377
|
FunctionOpenMenu: FunctionOpenMenu$1,
|
|
2387
2378
|
FunctionCloseMenu: FunctionCloseMenu$1,
|
|
@@ -2394,10 +2385,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2394
2385
|
/* eslint-disable complexity */
|
|
2395
2386
|
|
|
2396
2387
|
function downshiftSelectReducer(state, action) {
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2388
|
+
const {
|
|
2389
|
+
type,
|
|
2390
|
+
props,
|
|
2391
|
+
altKey
|
|
2392
|
+
} = action;
|
|
2393
|
+
let changes;
|
|
2401
2394
|
|
|
2402
2395
|
switch (type) {
|
|
2403
2396
|
case ItemClick$1:
|
|
@@ -2410,103 +2403,105 @@ function downshiftSelectReducer(state, action) {
|
|
|
2410
2403
|
|
|
2411
2404
|
case ToggleButtonKeyDownCharacter:
|
|
2412
2405
|
{
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2406
|
+
const lowercasedKey = action.key;
|
|
2407
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
2408
|
+
const prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
|
|
2409
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
2416
2410
|
keysSoFar: inputValue,
|
|
2417
|
-
highlightedIndex:
|
|
2411
|
+
highlightedIndex: prevHighlightedIndex,
|
|
2418
2412
|
items: props.items,
|
|
2419
2413
|
itemToString: props.itemToString,
|
|
2420
2414
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2421
2415
|
});
|
|
2422
|
-
changes =
|
|
2423
|
-
inputValue
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
}
|
|
2416
|
+
changes = {
|
|
2417
|
+
inputValue,
|
|
2418
|
+
highlightedIndex,
|
|
2419
|
+
isOpen: true
|
|
2420
|
+
};
|
|
2427
2421
|
}
|
|
2428
2422
|
break;
|
|
2429
2423
|
|
|
2430
2424
|
case ToggleButtonKeyDownArrowDown:
|
|
2431
|
-
|
|
2432
|
-
highlightedIndex
|
|
2433
|
-
|
|
2434
|
-
|
|
2425
|
+
{
|
|
2426
|
+
const highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
|
|
2427
|
+
changes = {
|
|
2428
|
+
highlightedIndex,
|
|
2429
|
+
isOpen: true
|
|
2430
|
+
};
|
|
2431
|
+
}
|
|
2435
2432
|
break;
|
|
2436
2433
|
|
|
2437
2434
|
case ToggleButtonKeyDownArrowUp:
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2435
|
+
if (state.isOpen && altKey) {
|
|
2436
|
+
changes = {
|
|
2437
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2438
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2439
|
+
...(state.highlightedIndex >= 0 && {
|
|
2440
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2441
|
+
})
|
|
2442
|
+
};
|
|
2443
|
+
} else {
|
|
2444
|
+
const highlightedIndex = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2445
|
+
changes = {
|
|
2446
|
+
highlightedIndex,
|
|
2447
|
+
isOpen: true
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2443
2450
|
|
|
2444
|
-
case MenuKeyDownEnter:
|
|
2445
|
-
case MenuKeyDownSpaceButton:
|
|
2446
|
-
changes = _extends({
|
|
2447
|
-
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2448
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2449
|
-
}, state.highlightedIndex >= 0 && {
|
|
2450
|
-
selectedItem: props.items[state.highlightedIndex]
|
|
2451
|
-
});
|
|
2452
2451
|
break;
|
|
2452
|
+
// only triggered when menu is open.
|
|
2453
2453
|
|
|
2454
|
-
case
|
|
2454
|
+
case ToggleButtonKeyDownEnter:
|
|
2455
|
+
case ToggleButtonKeyDownSpaceButton:
|
|
2455
2456
|
changes = {
|
|
2456
|
-
|
|
2457
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2458
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2459
|
+
...(state.highlightedIndex >= 0 && {
|
|
2460
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2461
|
+
})
|
|
2457
2462
|
};
|
|
2458
2463
|
break;
|
|
2459
2464
|
|
|
2460
|
-
case
|
|
2465
|
+
case ToggleButtonKeyDownHome:
|
|
2461
2466
|
changes = {
|
|
2462
|
-
highlightedIndex: getNextNonDisabledIndex(
|
|
2467
|
+
highlightedIndex: getNextNonDisabledIndex(1, 0, props.items.length, action.getItemNodeFromIndex, false),
|
|
2468
|
+
isOpen: true
|
|
2463
2469
|
};
|
|
2464
2470
|
break;
|
|
2465
2471
|
|
|
2466
|
-
case
|
|
2472
|
+
case ToggleButtonKeyDownEnd:
|
|
2467
2473
|
changes = {
|
|
2468
|
-
|
|
2469
|
-
|
|
2474
|
+
highlightedIndex: getNextNonDisabledIndex(-1, props.items.length - 1, props.items.length, action.getItemNodeFromIndex, false),
|
|
2475
|
+
isOpen: true
|
|
2470
2476
|
};
|
|
2471
2477
|
break;
|
|
2472
2478
|
|
|
2473
|
-
case
|
|
2479
|
+
case ToggleButtonKeyDownPageUp:
|
|
2474
2480
|
changes = {
|
|
2475
|
-
|
|
2476
|
-
highlightedIndex: -1
|
|
2481
|
+
highlightedIndex: getNextWrappingIndex(-10, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false)
|
|
2477
2482
|
};
|
|
2478
2483
|
break;
|
|
2479
2484
|
|
|
2480
|
-
case
|
|
2481
|
-
{
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
var _inputValue = "" + state.inputValue + _lowercasedKey;
|
|
2485
|
-
|
|
2486
|
-
var highlightedIndex = getItemIndexByCharacterKey({
|
|
2487
|
-
keysSoFar: _inputValue,
|
|
2488
|
-
highlightedIndex: state.highlightedIndex,
|
|
2489
|
-
items: props.items,
|
|
2490
|
-
itemToString: props.itemToString,
|
|
2491
|
-
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2492
|
-
});
|
|
2493
|
-
changes = _extends({
|
|
2494
|
-
inputValue: _inputValue
|
|
2495
|
-
}, highlightedIndex >= 0 && {
|
|
2496
|
-
highlightedIndex: highlightedIndex
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2485
|
+
case ToggleButtonKeyDownPageDown:
|
|
2486
|
+
changes = {
|
|
2487
|
+
highlightedIndex: getNextWrappingIndex(10, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false)
|
|
2488
|
+
};
|
|
2499
2489
|
break;
|
|
2500
2490
|
|
|
2501
|
-
case
|
|
2491
|
+
case ToggleButtonKeyDownEscape:
|
|
2502
2492
|
changes = {
|
|
2503
|
-
|
|
2493
|
+
isOpen: false,
|
|
2494
|
+
highlightedIndex: -1
|
|
2504
2495
|
};
|
|
2505
2496
|
break;
|
|
2506
2497
|
|
|
2507
|
-
case
|
|
2498
|
+
case ToggleButtonBlur:
|
|
2508
2499
|
changes = {
|
|
2509
|
-
|
|
2500
|
+
isOpen: false,
|
|
2501
|
+
highlightedIndex: -1,
|
|
2502
|
+
...(state.highlightedIndex >= 0 && {
|
|
2503
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2504
|
+
})
|
|
2510
2505
|
};
|
|
2511
2506
|
break;
|
|
2512
2507
|
|
|
@@ -2520,13 +2515,12 @@ function downshiftSelectReducer(state, action) {
|
|
|
2520
2515
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2521
2516
|
}
|
|
2522
2517
|
|
|
2523
|
-
return
|
|
2518
|
+
return { ...state,
|
|
2519
|
+
...changes
|
|
2520
|
+
};
|
|
2524
2521
|
}
|
|
2525
2522
|
/* eslint-enable complexity */
|
|
2526
2523
|
|
|
2527
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
|
|
2528
|
-
_excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
|
|
2529
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
|
|
2530
2524
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2531
2525
|
|
|
2532
2526
|
function useSelect(userProps) {
|
|
@@ -2536,91 +2530,88 @@ function useSelect(userProps) {
|
|
|
2536
2530
|
|
|
2537
2531
|
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
2538
2532
|
|
|
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
|
-
var latest = useLatestRef({
|
|
2575
|
-
state: state,
|
|
2576
|
-
props: props
|
|
2533
|
+
const props = { ...defaultProps$2,
|
|
2534
|
+
...userProps
|
|
2535
|
+
};
|
|
2536
|
+
const {
|
|
2537
|
+
items,
|
|
2538
|
+
scrollIntoView,
|
|
2539
|
+
environment,
|
|
2540
|
+
itemToString,
|
|
2541
|
+
getA11ySelectionMessage,
|
|
2542
|
+
getA11yStatusMessage
|
|
2543
|
+
} = props; // Initial state depending on controlled props.
|
|
2544
|
+
|
|
2545
|
+
const initialState = getInitialState$2(props);
|
|
2546
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
2547
|
+
const {
|
|
2548
|
+
isOpen,
|
|
2549
|
+
highlightedIndex,
|
|
2550
|
+
selectedItem,
|
|
2551
|
+
inputValue
|
|
2552
|
+
} = state; // Element efs.
|
|
2553
|
+
|
|
2554
|
+
const toggleButtonRef = useRef(null);
|
|
2555
|
+
const menuRef = useRef(null);
|
|
2556
|
+
const itemRefs = useRef({}); // used to keep the inputValue clearTimeout object between renders.
|
|
2557
|
+
|
|
2558
|
+
const clearTimeoutRef = useRef(null); // prevent id re-generation between renders.
|
|
2559
|
+
|
|
2560
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
2561
|
+
|
|
2562
|
+
const previousResultCountRef = useRef();
|
|
2563
|
+
const isInitialMountRef = useRef(true); // utility callback to get item element.
|
|
2564
|
+
|
|
2565
|
+
const latest = useLatestRef({
|
|
2566
|
+
state,
|
|
2567
|
+
props
|
|
2577
2568
|
}); // Some utils.
|
|
2578
2569
|
|
|
2579
|
-
|
|
2580
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2581
|
-
}, [elementIds]); // Effects.
|
|
2570
|
+
const getItemNodeFromIndex = useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
2582
2571
|
// Sets a11y status message on changes in state.
|
|
2583
2572
|
|
|
2584
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2573
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2585
2574
|
isInitialMount: isInitialMountRef.current,
|
|
2586
2575
|
previousResultCount: previousResultCountRef.current,
|
|
2587
|
-
items
|
|
2588
|
-
environment
|
|
2589
|
-
itemToString
|
|
2590
|
-
|
|
2576
|
+
items,
|
|
2577
|
+
environment,
|
|
2578
|
+
itemToString,
|
|
2579
|
+
...state
|
|
2580
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
2591
2581
|
|
|
2592
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2582
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2593
2583
|
isInitialMount: isInitialMountRef.current,
|
|
2594
2584
|
previousResultCount: previousResultCountRef.current,
|
|
2595
|
-
items
|
|
2596
|
-
environment
|
|
2597
|
-
itemToString
|
|
2598
|
-
|
|
2585
|
+
items,
|
|
2586
|
+
environment,
|
|
2587
|
+
itemToString,
|
|
2588
|
+
...state
|
|
2589
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
2599
2590
|
|
|
2600
|
-
|
|
2591
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2601
2592
|
menuElement: menuRef.current,
|
|
2602
|
-
highlightedIndex
|
|
2603
|
-
isOpen
|
|
2604
|
-
itemRefs
|
|
2605
|
-
scrollIntoView
|
|
2606
|
-
getItemNodeFromIndex
|
|
2593
|
+
highlightedIndex,
|
|
2594
|
+
isOpen,
|
|
2595
|
+
itemRefs,
|
|
2596
|
+
scrollIntoView,
|
|
2597
|
+
getItemNodeFromIndex
|
|
2607
2598
|
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2608
2599
|
|
|
2609
|
-
useEffect(
|
|
2600
|
+
useEffect(() => {
|
|
2610
2601
|
// init the clean function here as we need access to dispatch.
|
|
2611
|
-
clearTimeoutRef.current = debounce(
|
|
2602
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
2612
2603
|
outerDispatch({
|
|
2613
2604
|
type: FunctionSetInputValue$1,
|
|
2614
2605
|
inputValue: ''
|
|
2615
2606
|
});
|
|
2616
2607
|
}, 500); // Cancel any pending debounced calls on mount
|
|
2617
2608
|
|
|
2618
|
-
return
|
|
2609
|
+
return () => {
|
|
2619
2610
|
clearTimeoutRef.current.cancel();
|
|
2620
2611
|
};
|
|
2621
2612
|
}, []); // Invokes the keysSoFar callback set up above.
|
|
2622
2613
|
|
|
2623
|
-
useEffect(
|
|
2614
|
+
useEffect(() => {
|
|
2624
2615
|
if (!inputValue) {
|
|
2625
2616
|
return;
|
|
2626
2617
|
}
|
|
@@ -2629,43 +2620,10 @@ function useSelect(userProps) {
|
|
|
2629
2620
|
}, [dispatch, inputValue]);
|
|
2630
2621
|
useControlPropsValidator({
|
|
2631
2622
|
isInitialMount: isInitialMountRef.current,
|
|
2632
|
-
props
|
|
2633
|
-
state
|
|
2623
|
+
props,
|
|
2624
|
+
state
|
|
2634
2625
|
});
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
useEffect(function () {
|
|
2638
|
-
// Don't focus menu on first render.
|
|
2639
|
-
if (isInitialMountRef.current) {
|
|
2640
|
-
// Unless it was initialised as open.
|
|
2641
|
-
if ((initialIsOpen || defaultIsOpen || isOpen) && menuRef.current) {
|
|
2642
|
-
menuRef.current.focus();
|
|
2643
|
-
}
|
|
2644
|
-
|
|
2645
|
-
return;
|
|
2646
|
-
} // Focus menu on open.
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
if (isOpen) {
|
|
2650
|
-
// istanbul ignore else
|
|
2651
|
-
if (menuRef.current) {
|
|
2652
|
-
menuRef.current.focus();
|
|
2653
|
-
}
|
|
2654
|
-
|
|
2655
|
-
return;
|
|
2656
|
-
} // Focus toggleButton on close, but not if it was closed with (Shift+)Tab.
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
if (environment.document.activeElement === menuRef.current) {
|
|
2660
|
-
// istanbul ignore else
|
|
2661
|
-
if (toggleButtonRef.current) {
|
|
2662
|
-
shouldBlurRef.current = false;
|
|
2663
|
-
toggleButtonRef.current.focus();
|
|
2664
|
-
}
|
|
2665
|
-
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2666
|
-
|
|
2667
|
-
}, [isOpen]);
|
|
2668
|
-
useEffect(function () {
|
|
2626
|
+
useEffect(() => {
|
|
2669
2627
|
if (isInitialMountRef.current) {
|
|
2670
2628
|
return;
|
|
2671
2629
|
}
|
|
@@ -2673,244 +2631,239 @@ function useSelect(userProps) {
|
|
|
2673
2631
|
previousResultCountRef.current = items.length;
|
|
2674
2632
|
}); // Add mouse/touch events to document.
|
|
2675
2633
|
|
|
2676
|
-
|
|
2634
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
2677
2635
|
dispatch({
|
|
2678
|
-
type:
|
|
2636
|
+
type: ToggleButtonBlur
|
|
2679
2637
|
});
|
|
2680
2638
|
});
|
|
2681
|
-
|
|
2639
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
2682
2640
|
|
|
2683
|
-
useEffect(
|
|
2641
|
+
useEffect(() => {
|
|
2684
2642
|
isInitialMountRef.current = false;
|
|
2685
2643
|
}, []); // Reset itemRefs on close.
|
|
2686
2644
|
|
|
2687
|
-
useEffect(
|
|
2645
|
+
useEffect(() => {
|
|
2688
2646
|
if (!isOpen) {
|
|
2689
2647
|
itemRefs.current = {};
|
|
2690
2648
|
}
|
|
2691
2649
|
}, [isOpen]); // Event handler functions.
|
|
2692
2650
|
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2651
|
+
const toggleButtonKeyDownHandlers = useMemo(() => ({
|
|
2652
|
+
ArrowDown(event) {
|
|
2653
|
+
event.preventDefault();
|
|
2654
|
+
dispatch({
|
|
2655
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
2656
|
+
getItemNodeFromIndex,
|
|
2657
|
+
altKey: event.altKey
|
|
2658
|
+
});
|
|
2659
|
+
},
|
|
2660
|
+
|
|
2661
|
+
ArrowUp(event) {
|
|
2662
|
+
event.preventDefault();
|
|
2663
|
+
dispatch({
|
|
2664
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
2665
|
+
getItemNodeFromIndex,
|
|
2666
|
+
altKey: event.altKey
|
|
2667
|
+
});
|
|
2668
|
+
},
|
|
2669
|
+
|
|
2670
|
+
Home(event) {
|
|
2671
|
+
event.preventDefault();
|
|
2672
|
+
dispatch({
|
|
2673
|
+
type: ToggleButtonKeyDownHome,
|
|
2674
|
+
getItemNodeFromIndex
|
|
2675
|
+
});
|
|
2676
|
+
},
|
|
2677
|
+
|
|
2678
|
+
End(event) {
|
|
2679
|
+
event.preventDefault();
|
|
2680
|
+
dispatch({
|
|
2681
|
+
type: ToggleButtonKeyDownEnd,
|
|
2682
|
+
getItemNodeFromIndex
|
|
2683
|
+
});
|
|
2684
|
+
},
|
|
2685
|
+
|
|
2686
|
+
Escape() {
|
|
2687
|
+
if (latest.current.state.isOpen) {
|
|
2705
2688
|
dispatch({
|
|
2706
|
-
type:
|
|
2707
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
2708
|
-
shiftKey: event.shiftKey
|
|
2689
|
+
type: ToggleButtonKeyDownEscape
|
|
2709
2690
|
});
|
|
2710
2691
|
}
|
|
2711
|
-
}
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
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) {
|
|
2692
|
+
},
|
|
2693
|
+
|
|
2694
|
+
Enter(event) {
|
|
2695
|
+
if (latest.current.state.isOpen) {
|
|
2732
2696
|
event.preventDefault();
|
|
2733
2697
|
dispatch({
|
|
2734
|
-
type:
|
|
2735
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2698
|
+
type: ToggleButtonKeyDownEnter
|
|
2736
2699
|
});
|
|
2737
|
-
}
|
|
2738
|
-
|
|
2700
|
+
}
|
|
2701
|
+
},
|
|
2702
|
+
|
|
2703
|
+
PageUp(event) {
|
|
2704
|
+
if (latest.current.state.isOpen) {
|
|
2739
2705
|
event.preventDefault();
|
|
2740
2706
|
dispatch({
|
|
2741
|
-
type:
|
|
2742
|
-
getItemNodeFromIndex
|
|
2707
|
+
type: ToggleButtonKeyDownPageUp,
|
|
2708
|
+
getItemNodeFromIndex
|
|
2743
2709
|
});
|
|
2744
|
-
}
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
},
|
|
2750
|
-
Enter: function Enter(event) {
|
|
2710
|
+
}
|
|
2711
|
+
},
|
|
2712
|
+
|
|
2713
|
+
PageDown(event) {
|
|
2714
|
+
if (latest.current.state.isOpen) {
|
|
2751
2715
|
event.preventDefault();
|
|
2752
2716
|
dispatch({
|
|
2753
|
-
type:
|
|
2717
|
+
type: ToggleButtonKeyDownPageDown,
|
|
2718
|
+
getItemNodeFromIndex
|
|
2754
2719
|
});
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2720
|
+
}
|
|
2721
|
+
},
|
|
2722
|
+
|
|
2723
|
+
' '(event) {
|
|
2724
|
+
if (latest.current.state.isOpen) {
|
|
2757
2725
|
event.preventDefault();
|
|
2758
2726
|
dispatch({
|
|
2759
|
-
type:
|
|
2727
|
+
type: ToggleButtonKeyDownSpaceButton
|
|
2760
2728
|
});
|
|
2761
2729
|
}
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
}), [dispatch, getItemNodeFromIndex, latest]); // Action functions.
|
|
2764
2733
|
|
|
2765
|
-
|
|
2734
|
+
const toggleMenu = useCallback(() => {
|
|
2766
2735
|
dispatch({
|
|
2767
2736
|
type: FunctionToggleMenu$1
|
|
2768
2737
|
});
|
|
2769
2738
|
}, [dispatch]);
|
|
2770
|
-
|
|
2739
|
+
const closeMenu = useCallback(() => {
|
|
2771
2740
|
dispatch({
|
|
2772
2741
|
type: FunctionCloseMenu$1
|
|
2773
2742
|
});
|
|
2774
2743
|
}, [dispatch]);
|
|
2775
|
-
|
|
2744
|
+
const openMenu = useCallback(() => {
|
|
2776
2745
|
dispatch({
|
|
2777
2746
|
type: FunctionOpenMenu$1
|
|
2778
2747
|
});
|
|
2779
2748
|
}, [dispatch]);
|
|
2780
|
-
|
|
2749
|
+
const setHighlightedIndex = useCallback(newHighlightedIndex => {
|
|
2781
2750
|
dispatch({
|
|
2782
2751
|
type: FunctionSetHighlightedIndex$1,
|
|
2783
2752
|
highlightedIndex: newHighlightedIndex
|
|
2784
2753
|
});
|
|
2785
2754
|
}, [dispatch]);
|
|
2786
|
-
|
|
2755
|
+
const selectItem = useCallback(newSelectedItem => {
|
|
2787
2756
|
dispatch({
|
|
2788
2757
|
type: FunctionSelectItem$1,
|
|
2789
2758
|
selectedItem: newSelectedItem
|
|
2790
2759
|
});
|
|
2791
2760
|
}, [dispatch]);
|
|
2792
|
-
|
|
2761
|
+
const reset = useCallback(() => {
|
|
2793
2762
|
dispatch({
|
|
2794
2763
|
type: FunctionReset$2
|
|
2795
2764
|
});
|
|
2796
2765
|
}, [dispatch]);
|
|
2797
|
-
|
|
2766
|
+
const setInputValue = useCallback(newInputValue => {
|
|
2798
2767
|
dispatch({
|
|
2799
2768
|
type: FunctionSetInputValue$1,
|
|
2800
2769
|
inputValue: newInputValue
|
|
2801
2770
|
});
|
|
2802
2771
|
}, [dispatch]); // Getter functions.
|
|
2803
2772
|
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
2824
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
2825
|
-
|
|
2826
|
-
var latestState = latest.current.state;
|
|
2827
|
-
|
|
2828
|
-
var menuHandleKeyDown = function menuHandleKeyDown(event) {
|
|
2829
|
-
var key = normalizeArrowKey(event);
|
|
2830
|
-
|
|
2831
|
-
if (key && menuKeyDownHandlers[key]) {
|
|
2832
|
-
menuKeyDownHandlers[key](event);
|
|
2833
|
-
} else if (isAcceptedCharacterKey(key)) {
|
|
2834
|
-
dispatch({
|
|
2835
|
-
type: MenuKeyDownCharacter,
|
|
2836
|
-
key: key,
|
|
2837
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2838
|
-
});
|
|
2839
|
-
}
|
|
2840
|
-
};
|
|
2841
|
-
|
|
2842
|
-
var menuHandleBlur = function menuHandleBlur() {
|
|
2843
|
-
// if the blur was a result of selection, we don't trigger this action.
|
|
2844
|
-
if (shouldBlurRef.current === false) {
|
|
2845
|
-
shouldBlurRef.current = true;
|
|
2846
|
-
return;
|
|
2847
|
-
}
|
|
2848
|
-
|
|
2849
|
-
var shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
2850
|
-
/* istanbul ignore else */
|
|
2851
|
-
|
|
2852
|
-
if (shouldBlur) {
|
|
2853
|
-
dispatch({
|
|
2854
|
-
type: MenuBlur
|
|
2855
|
-
});
|
|
2856
|
-
}
|
|
2857
|
-
};
|
|
2858
|
-
|
|
2859
|
-
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
2773
|
+
const getLabelProps = useCallback(labelProps => ({
|
|
2774
|
+
id: elementIds.labelId,
|
|
2775
|
+
htmlFor: elementIds.toggleButtonId,
|
|
2776
|
+
...labelProps
|
|
2777
|
+
}), [elementIds]);
|
|
2778
|
+
const getMenuProps = useCallback(function (_temp, _temp2) {
|
|
2779
|
+
let {
|
|
2780
|
+
onMouseLeave,
|
|
2781
|
+
refKey = 'ref',
|
|
2782
|
+
onKeyDown,
|
|
2783
|
+
onBlur,
|
|
2784
|
+
ref,
|
|
2785
|
+
...rest
|
|
2786
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2787
|
+
let {
|
|
2788
|
+
suppressRefError = false
|
|
2789
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2790
|
+
|
|
2791
|
+
const menuHandleMouseLeave = () => {
|
|
2860
2792
|
dispatch({
|
|
2861
2793
|
type: MenuMouseLeave$1
|
|
2862
2794
|
});
|
|
2863
2795
|
};
|
|
2864
2796
|
|
|
2865
2797
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2866
|
-
return
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2798
|
+
return {
|
|
2799
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
2800
|
+
menuRef.current = menuNode;
|
|
2801
|
+
}),
|
|
2802
|
+
id: elementIds.menuId,
|
|
2803
|
+
role: 'listbox',
|
|
2804
|
+
'aria-labelledby': elementIds.labelId,
|
|
2805
|
+
tabIndex: -1,
|
|
2871
2806
|
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
2807
|
+
...rest
|
|
2808
|
+
};
|
|
2809
|
+
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2810
|
+
const getToggleButtonProps = useCallback(function (_temp3, _temp4) {
|
|
2811
|
+
let {
|
|
2812
|
+
onBlur,
|
|
2813
|
+
onClick,
|
|
2814
|
+
onKeyDown,
|
|
2815
|
+
refKey = 'ref',
|
|
2816
|
+
ref,
|
|
2817
|
+
...rest
|
|
2818
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2819
|
+
let {
|
|
2820
|
+
suppressRefError = false
|
|
2821
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2822
|
+
const latestState = latest.current.state;
|
|
2823
|
+
|
|
2824
|
+
const toggleButtonHandleClick = () => {
|
|
2892
2825
|
dispatch({
|
|
2893
2826
|
type: ToggleButtonClick$1
|
|
2894
2827
|
});
|
|
2895
2828
|
};
|
|
2896
2829
|
|
|
2897
|
-
|
|
2898
|
-
|
|
2830
|
+
const toggleButtonHandleBlur = () => {
|
|
2831
|
+
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
2832
|
+
dispatch({
|
|
2833
|
+
type: ToggleButtonBlur
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
|
|
2838
|
+
const toggleButtonHandleKeyDown = event => {
|
|
2839
|
+
const key = normalizeArrowKey(event);
|
|
2899
2840
|
|
|
2900
2841
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
2901
2842
|
toggleButtonKeyDownHandlers[key](event);
|
|
2902
2843
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2903
2844
|
dispatch({
|
|
2904
2845
|
type: ToggleButtonKeyDownCharacter,
|
|
2905
|
-
key
|
|
2906
|
-
getItemNodeFromIndex
|
|
2846
|
+
key,
|
|
2847
|
+
getItemNodeFromIndex
|
|
2907
2848
|
});
|
|
2908
2849
|
}
|
|
2909
2850
|
};
|
|
2910
2851
|
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2852
|
+
const toggleProps = {
|
|
2853
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
2854
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
2855
|
+
}),
|
|
2856
|
+
'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
|
|
2857
|
+
'aria-controls': elementIds.menuId,
|
|
2858
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
2859
|
+
'aria-haspopup': 'listbox',
|
|
2860
|
+
'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
|
|
2861
|
+
id: elementIds.toggleButtonId,
|
|
2862
|
+
role: 'combobox',
|
|
2863
|
+
tabIndex: 0,
|
|
2864
|
+
onBlur: callAllEventHandlers(onBlur, toggleButtonHandleBlur),
|
|
2865
|
+
...rest
|
|
2866
|
+
};
|
|
2914
2867
|
|
|
2915
2868
|
if (!rest.disabled) {
|
|
2916
2869
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
@@ -2919,25 +2872,25 @@ function useSelect(userProps) {
|
|
|
2919
2872
|
|
|
2920
2873
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2921
2874
|
return toggleProps;
|
|
2922
|
-
}, [
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2875
|
+
}, [latest, elementIds, setGetterPropCallInfo, dispatch, mouseAndTouchTrackersRef, toggleButtonKeyDownHandlers, getItemNodeFromIndex]);
|
|
2876
|
+
const getItemProps = useCallback(function (_temp5) {
|
|
2877
|
+
let {
|
|
2878
|
+
item: itemProp,
|
|
2879
|
+
index: indexProp,
|
|
2880
|
+
onMouseMove,
|
|
2881
|
+
onClick,
|
|
2882
|
+
refKey = 'ref',
|
|
2883
|
+
ref,
|
|
2884
|
+
...rest
|
|
2885
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
2886
|
+
const {
|
|
2887
|
+
state: latestState,
|
|
2888
|
+
props: latestProps
|
|
2889
|
+
} = latest.current;
|
|
2890
|
+
const item = itemProp != null ? itemProp : items[indexProp];
|
|
2891
|
+
const index = getItemIndex(indexProp, item, latestProps.items);
|
|
2892
|
+
|
|
2893
|
+
const itemHandleMouseMove = () => {
|
|
2941
2894
|
if (index === latestState.highlightedIndex) {
|
|
2942
2895
|
return;
|
|
2943
2896
|
}
|
|
@@ -2945,32 +2898,34 @@ function useSelect(userProps) {
|
|
|
2945
2898
|
shouldScrollRef.current = false;
|
|
2946
2899
|
dispatch({
|
|
2947
2900
|
type: ItemMouseMove$1,
|
|
2948
|
-
index
|
|
2901
|
+
index
|
|
2949
2902
|
});
|
|
2950
2903
|
};
|
|
2951
2904
|
|
|
2952
|
-
|
|
2905
|
+
const itemHandleClick = () => {
|
|
2953
2906
|
dispatch({
|
|
2954
2907
|
type: ItemClick$1,
|
|
2955
|
-
index
|
|
2908
|
+
index
|
|
2956
2909
|
});
|
|
2957
2910
|
};
|
|
2958
2911
|
|
|
2959
|
-
|
|
2912
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2960
2913
|
|
|
2961
2914
|
if (itemIndex < 0) {
|
|
2962
2915
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
2963
2916
|
}
|
|
2964
2917
|
|
|
2965
|
-
|
|
2918
|
+
const itemProps = {
|
|
2966
2919
|
role: 'option',
|
|
2967
|
-
'aria-selected': "" + (
|
|
2968
|
-
id: elementIds.getItemId(itemIndex)
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2920
|
+
'aria-selected': "" + (item === selectedItem),
|
|
2921
|
+
id: elementIds.getItemId(itemIndex),
|
|
2922
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
2923
|
+
if (itemNode) {
|
|
2924
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
2925
|
+
}
|
|
2926
|
+
}),
|
|
2927
|
+
...rest
|
|
2928
|
+
};
|
|
2974
2929
|
|
|
2975
2930
|
if (!rest.disabled) {
|
|
2976
2931
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
@@ -2978,49 +2933,49 @@ function useSelect(userProps) {
|
|
|
2978
2933
|
}
|
|
2979
2934
|
|
|
2980
2935
|
return itemProps;
|
|
2981
|
-
}, [
|
|
2936
|
+
}, [latest, items, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2982
2937
|
return {
|
|
2983
2938
|
// prop getters.
|
|
2984
|
-
getToggleButtonProps
|
|
2985
|
-
getLabelProps
|
|
2986
|
-
getMenuProps
|
|
2987
|
-
getItemProps
|
|
2939
|
+
getToggleButtonProps,
|
|
2940
|
+
getLabelProps,
|
|
2941
|
+
getMenuProps,
|
|
2942
|
+
getItemProps,
|
|
2988
2943
|
// actions.
|
|
2989
|
-
toggleMenu
|
|
2990
|
-
openMenu
|
|
2991
|
-
closeMenu
|
|
2992
|
-
setHighlightedIndex
|
|
2993
|
-
selectItem
|
|
2994
|
-
reset
|
|
2995
|
-
setInputValue
|
|
2944
|
+
toggleMenu,
|
|
2945
|
+
openMenu,
|
|
2946
|
+
closeMenu,
|
|
2947
|
+
setHighlightedIndex,
|
|
2948
|
+
selectItem,
|
|
2949
|
+
reset,
|
|
2950
|
+
setInputValue,
|
|
2996
2951
|
// state.
|
|
2997
|
-
highlightedIndex
|
|
2998
|
-
isOpen
|
|
2999
|
-
selectedItem
|
|
3000
|
-
inputValue
|
|
2952
|
+
highlightedIndex,
|
|
2953
|
+
isOpen,
|
|
2954
|
+
selectedItem,
|
|
2955
|
+
inputValue
|
|
3001
2956
|
};
|
|
3002
2957
|
}
|
|
3003
2958
|
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
2959
|
+
const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2960
|
+
const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2961
|
+
const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
2962
|
+
const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
|
|
2963
|
+
const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
|
|
2964
|
+
const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 5;
|
|
2965
|
+
const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 6;
|
|
2966
|
+
const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 7;
|
|
2967
|
+
const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 8;
|
|
2968
|
+
const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 9;
|
|
2969
|
+
const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 10;
|
|
2970
|
+
const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 11;
|
|
2971
|
+
const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 12;
|
|
2972
|
+
const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 13;
|
|
2973
|
+
const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 14;
|
|
2974
|
+
const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 15;
|
|
2975
|
+
const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 16;
|
|
2976
|
+
const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 17;
|
|
2977
|
+
const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 18;
|
|
2978
|
+
const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 19;
|
|
3024
2979
|
|
|
3025
2980
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
3026
2981
|
__proto__: null,
|
|
@@ -3047,20 +3002,24 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
3047
3002
|
});
|
|
3048
3003
|
|
|
3049
3004
|
function getInitialState$1(props) {
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3005
|
+
const initialState = getInitialState$2(props);
|
|
3006
|
+
const {
|
|
3007
|
+
selectedItem
|
|
3008
|
+
} = initialState;
|
|
3009
|
+
let {
|
|
3010
|
+
inputValue
|
|
3011
|
+
} = initialState;
|
|
3053
3012
|
|
|
3054
3013
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
3055
3014
|
inputValue = props.itemToString(selectedItem);
|
|
3056
3015
|
}
|
|
3057
3016
|
|
|
3058
|
-
return
|
|
3059
|
-
inputValue
|
|
3060
|
-
}
|
|
3017
|
+
return { ...initialState,
|
|
3018
|
+
inputValue
|
|
3019
|
+
};
|
|
3061
3020
|
}
|
|
3062
3021
|
|
|
3063
|
-
|
|
3022
|
+
const propTypes$1 = {
|
|
3064
3023
|
items: PropTypes.array.isRequired,
|
|
3065
3024
|
itemToString: PropTypes.func,
|
|
3066
3025
|
getA11yStatusMessage: PropTypes.func,
|
|
@@ -3114,14 +3073,10 @@ var propTypes$1 = {
|
|
|
3114
3073
|
*/
|
|
3115
3074
|
|
|
3116
3075
|
function useControlledReducer(reducer, initialState, props) {
|
|
3117
|
-
|
|
3076
|
+
const previousSelectedItemRef = useRef();
|
|
3077
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3118
3078
|
|
|
3119
|
-
|
|
3120
|
-
state = _useEnhancedReducer[0],
|
|
3121
|
-
dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
useEffect(function () {
|
|
3079
|
+
useEffect(() => {
|
|
3125
3080
|
if (isControlledProp(props, 'selectedItem')) {
|
|
3126
3081
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
3127
3082
|
dispatch({
|
|
@@ -3137,27 +3092,29 @@ function useControlledReducer(reducer, initialState, props) {
|
|
|
3137
3092
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
3138
3093
|
|
|
3139
3094
|
|
|
3140
|
-
|
|
3095
|
+
let validatePropTypes$1 = noop;
|
|
3141
3096
|
/* istanbul ignore next */
|
|
3142
3097
|
|
|
3143
3098
|
if (process.env.NODE_ENV !== 'production') {
|
|
3144
|
-
validatePropTypes$1 =
|
|
3099
|
+
validatePropTypes$1 = (options, caller) => {
|
|
3145
3100
|
PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
3146
3101
|
};
|
|
3147
3102
|
}
|
|
3148
3103
|
|
|
3149
|
-
|
|
3104
|
+
const defaultProps$1 = { ...defaultProps$3,
|
|
3150
3105
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
3151
3106
|
circularNavigation: true
|
|
3152
|
-
}
|
|
3107
|
+
};
|
|
3153
3108
|
|
|
3154
3109
|
/* eslint-disable complexity */
|
|
3155
3110
|
|
|
3156
3111
|
function downshiftUseComboboxReducer(state, action) {
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3112
|
+
const {
|
|
3113
|
+
type,
|
|
3114
|
+
props,
|
|
3115
|
+
shiftKey
|
|
3116
|
+
} = action;
|
|
3117
|
+
let changes;
|
|
3161
3118
|
|
|
3162
3119
|
switch (type) {
|
|
3163
3120
|
case ItemClick:
|
|
@@ -3198,22 +3155,24 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3198
3155
|
break;
|
|
3199
3156
|
|
|
3200
3157
|
case InputKeyDownEnter:
|
|
3201
|
-
changes =
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3158
|
+
changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
|
|
3159
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3160
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3161
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3162
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3163
|
+
})
|
|
3164
|
+
};
|
|
3207
3165
|
break;
|
|
3208
3166
|
|
|
3209
3167
|
case InputKeyDownEscape:
|
|
3210
|
-
changes =
|
|
3168
|
+
changes = {
|
|
3211
3169
|
isOpen: false,
|
|
3212
|
-
highlightedIndex: -1
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3170
|
+
highlightedIndex: -1,
|
|
3171
|
+
...(!state.isOpen && {
|
|
3172
|
+
selectedItem: null,
|
|
3173
|
+
inputValue: ''
|
|
3174
|
+
})
|
|
3175
|
+
};
|
|
3217
3176
|
break;
|
|
3218
3177
|
|
|
3219
3178
|
case InputKeyDownHome:
|
|
@@ -3229,13 +3188,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3229
3188
|
break;
|
|
3230
3189
|
|
|
3231
3190
|
case InputBlur:
|
|
3232
|
-
changes =
|
|
3191
|
+
changes = {
|
|
3233
3192
|
isOpen: false,
|
|
3234
|
-
highlightedIndex: -1
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3193
|
+
highlightedIndex: -1,
|
|
3194
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
3195
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
3196
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
3197
|
+
})
|
|
3198
|
+
};
|
|
3239
3199
|
break;
|
|
3240
3200
|
|
|
3241
3201
|
case InputChange:
|
|
@@ -3263,15 +3223,13 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
3263
3223
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
3264
3224
|
}
|
|
3265
3225
|
|
|
3266
|
-
return
|
|
3226
|
+
return { ...state,
|
|
3227
|
+
...changes
|
|
3228
|
+
};
|
|
3267
3229
|
}
|
|
3268
3230
|
/* eslint-enable complexity */
|
|
3269
3231
|
|
|
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"];
|
|
3232
|
+
/* eslint-disable max-statements */
|
|
3275
3233
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
3276
3234
|
|
|
3277
3235
|
function useCombobox(userProps) {
|
|
@@ -3281,87 +3239,88 @@ function useCombobox(userProps) {
|
|
|
3281
3239
|
|
|
3282
3240
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
3283
3241
|
|
|
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
|
-
|
|
3242
|
+
const props = { ...defaultProps$1,
|
|
3243
|
+
...userProps
|
|
3244
|
+
};
|
|
3245
|
+
const {
|
|
3246
|
+
initialIsOpen,
|
|
3247
|
+
defaultIsOpen,
|
|
3248
|
+
items,
|
|
3249
|
+
scrollIntoView,
|
|
3250
|
+
environment,
|
|
3251
|
+
getA11yStatusMessage,
|
|
3252
|
+
getA11ySelectionMessage,
|
|
3253
|
+
itemToString
|
|
3254
|
+
} = props; // Initial state depending on controlled props.
|
|
3255
|
+
|
|
3256
|
+
const initialState = getInitialState$1(props);
|
|
3257
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
3258
|
+
const {
|
|
3259
|
+
isOpen,
|
|
3260
|
+
highlightedIndex,
|
|
3261
|
+
selectedItem,
|
|
3262
|
+
inputValue
|
|
3263
|
+
} = state; // Element refs.
|
|
3264
|
+
|
|
3265
|
+
const menuRef = useRef(null);
|
|
3266
|
+
const itemRefs = useRef({});
|
|
3267
|
+
const inputRef = useRef(null);
|
|
3268
|
+
const toggleButtonRef = useRef(null);
|
|
3269
|
+
const comboboxRef = useRef(null);
|
|
3270
|
+
const isInitialMountRef = useRef(true); // prevent id re-generation between renders.
|
|
3271
|
+
|
|
3272
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
3273
|
+
|
|
3274
|
+
const previousResultCountRef = useRef(); // utility callback to get item element.
|
|
3275
|
+
|
|
3276
|
+
const latest = useLatestRef({
|
|
3277
|
+
state,
|
|
3278
|
+
props
|
|
3320
3279
|
});
|
|
3321
|
-
|
|
3322
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3323
|
-
}, [elementIds]); // Effects.
|
|
3280
|
+
const getItemNodeFromIndex = useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
3324
3281
|
// Sets a11y status message on changes in state.
|
|
3325
3282
|
|
|
3326
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
3283
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3327
3284
|
isInitialMount: isInitialMountRef.current,
|
|
3328
3285
|
previousResultCount: previousResultCountRef.current,
|
|
3329
|
-
items
|
|
3330
|
-
environment
|
|
3331
|
-
itemToString
|
|
3332
|
-
|
|
3286
|
+
items,
|
|
3287
|
+
environment,
|
|
3288
|
+
itemToString,
|
|
3289
|
+
...state
|
|
3290
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
3333
3291
|
|
|
3334
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
3292
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3335
3293
|
isInitialMount: isInitialMountRef.current,
|
|
3336
3294
|
previousResultCount: previousResultCountRef.current,
|
|
3337
|
-
items
|
|
3338
|
-
environment
|
|
3339
|
-
itemToString
|
|
3340
|
-
|
|
3295
|
+
items,
|
|
3296
|
+
environment,
|
|
3297
|
+
itemToString,
|
|
3298
|
+
...state
|
|
3299
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
3341
3300
|
|
|
3342
|
-
|
|
3301
|
+
const shouldScrollRef = useScrollIntoView({
|
|
3343
3302
|
menuElement: menuRef.current,
|
|
3344
|
-
highlightedIndex
|
|
3345
|
-
isOpen
|
|
3346
|
-
itemRefs
|
|
3347
|
-
scrollIntoView
|
|
3348
|
-
getItemNodeFromIndex
|
|
3303
|
+
highlightedIndex,
|
|
3304
|
+
isOpen,
|
|
3305
|
+
itemRefs,
|
|
3306
|
+
scrollIntoView,
|
|
3307
|
+
getItemNodeFromIndex
|
|
3349
3308
|
});
|
|
3350
3309
|
useControlPropsValidator({
|
|
3351
3310
|
isInitialMount: isInitialMountRef.current,
|
|
3352
|
-
props
|
|
3353
|
-
state
|
|
3311
|
+
props,
|
|
3312
|
+
state
|
|
3354
3313
|
}); // Focus the input on first render if required.
|
|
3355
3314
|
|
|
3356
|
-
useEffect(
|
|
3357
|
-
|
|
3315
|
+
useEffect(() => {
|
|
3316
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
3358
3317
|
|
|
3359
3318
|
if (focusOnOpen && inputRef.current) {
|
|
3360
3319
|
inputRef.current.focus();
|
|
3361
3320
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3362
3321
|
|
|
3363
3322
|
}, []);
|
|
3364
|
-
useEffect(
|
|
3323
|
+
useEffect(() => {
|
|
3365
3324
|
if (isInitialMountRef.current) {
|
|
3366
3325
|
return;
|
|
3367
3326
|
}
|
|
@@ -3369,147 +3328,151 @@ function useCombobox(userProps) {
|
|
|
3369
3328
|
previousResultCountRef.current = items.length;
|
|
3370
3329
|
}); // Add mouse/touch events to document.
|
|
3371
3330
|
|
|
3372
|
-
|
|
3331
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
|
|
3373
3332
|
dispatch({
|
|
3374
3333
|
type: InputBlur,
|
|
3375
3334
|
selectItem: false
|
|
3376
3335
|
});
|
|
3377
3336
|
});
|
|
3378
|
-
|
|
3337
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
3379
3338
|
|
|
3380
|
-
useEffect(
|
|
3339
|
+
useEffect(() => {
|
|
3381
3340
|
isInitialMountRef.current = false;
|
|
3382
3341
|
}, []); // Reset itemRefs on close.
|
|
3383
3342
|
|
|
3384
|
-
useEffect(
|
|
3343
|
+
useEffect(() => {
|
|
3385
3344
|
if (!isOpen) {
|
|
3386
3345
|
itemRefs.current = {};
|
|
3387
3346
|
}
|
|
3388
3347
|
}, [isOpen]);
|
|
3389
3348
|
/* Event handler functions */
|
|
3390
3349
|
|
|
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
|
-
}
|
|
3350
|
+
const inputKeyDownHandlers = useMemo(() => ({
|
|
3351
|
+
ArrowDown(event) {
|
|
3352
|
+
event.preventDefault();
|
|
3353
|
+
dispatch({
|
|
3354
|
+
type: InputKeyDownArrowDown,
|
|
3355
|
+
shiftKey: event.shiftKey,
|
|
3356
|
+
getItemNodeFromIndex
|
|
3357
|
+
});
|
|
3358
|
+
},
|
|
3413
3359
|
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
return;
|
|
3423
|
-
}
|
|
3360
|
+
ArrowUp(event) {
|
|
3361
|
+
event.preventDefault();
|
|
3362
|
+
dispatch({
|
|
3363
|
+
type: InputKeyDownArrowUp,
|
|
3364
|
+
shiftKey: event.shiftKey,
|
|
3365
|
+
getItemNodeFromIndex
|
|
3366
|
+
});
|
|
3367
|
+
},
|
|
3424
3368
|
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
});
|
|
3430
|
-
},
|
|
3431
|
-
Escape: function Escape() {
|
|
3432
|
-
var latestState = latest.current.state;
|
|
3369
|
+
Home(event) {
|
|
3370
|
+
if (!latest.current.state.isOpen) {
|
|
3371
|
+
return;
|
|
3372
|
+
}
|
|
3433
3373
|
|
|
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.
|
|
3374
|
+
event.preventDefault();
|
|
3375
|
+
dispatch({
|
|
3376
|
+
type: InputKeyDownHome,
|
|
3377
|
+
getItemNodeFromIndex
|
|
3378
|
+
});
|
|
3379
|
+
},
|
|
3442
3380
|
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3381
|
+
End(event) {
|
|
3382
|
+
if (!latest.current.state.isOpen) {
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3447
3385
|
|
|
3448
|
-
|
|
3386
|
+
event.preventDefault();
|
|
3387
|
+
dispatch({
|
|
3388
|
+
type: InputKeyDownEnd,
|
|
3389
|
+
getItemNodeFromIndex
|
|
3390
|
+
});
|
|
3391
|
+
},
|
|
3392
|
+
|
|
3393
|
+
Escape() {
|
|
3394
|
+
const latestState = latest.current.state;
|
|
3395
|
+
|
|
3396
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
3449
3397
|
dispatch({
|
|
3450
|
-
type:
|
|
3451
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3398
|
+
type: InputKeyDownEscape
|
|
3452
3399
|
});
|
|
3453
3400
|
}
|
|
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;
|
|
3401
|
+
},
|
|
3476
3402
|
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3403
|
+
Enter(event) {
|
|
3404
|
+
const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
3405
|
+
|
|
3406
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3407
|
+
) {
|
|
3408
|
+
return;
|
|
3409
|
+
}
|
|
3410
|
+
|
|
3411
|
+
event.preventDefault();
|
|
3481
3412
|
dispatch({
|
|
3482
|
-
type:
|
|
3413
|
+
type: InputKeyDownEnter,
|
|
3414
|
+
getItemNodeFromIndex
|
|
3483
3415
|
});
|
|
3484
|
-
}
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
}), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
3419
|
+
|
|
3420
|
+
const getLabelProps = useCallback(labelProps => ({
|
|
3421
|
+
id: elementIds.labelId,
|
|
3422
|
+
htmlFor: elementIds.inputId,
|
|
3423
|
+
...labelProps
|
|
3424
|
+
}), [elementIds]);
|
|
3425
|
+
const getMenuProps = useCallback(function (_temp, _temp2) {
|
|
3426
|
+
let {
|
|
3427
|
+
onMouseLeave,
|
|
3428
|
+
refKey = 'ref',
|
|
3429
|
+
ref,
|
|
3430
|
+
...rest
|
|
3431
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3432
|
+
let {
|
|
3433
|
+
suppressRefError = false
|
|
3434
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3435
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3436
|
+
return {
|
|
3437
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3438
|
+
menuRef.current = menuNode;
|
|
3439
|
+
}),
|
|
3440
|
+
id: elementIds.menuId,
|
|
3441
|
+
role: 'listbox',
|
|
3442
|
+
'aria-labelledby': elementIds.labelId,
|
|
3443
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
3444
|
+
dispatch({
|
|
3445
|
+
type: MenuMouseLeave
|
|
3446
|
+
});
|
|
3447
|
+
}),
|
|
3448
|
+
...rest
|
|
3449
|
+
};
|
|
3485
3450
|
}, [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);
|
|
3451
|
+
const getItemProps = useCallback(function (_temp3) {
|
|
3452
|
+
let {
|
|
3453
|
+
item,
|
|
3454
|
+
index,
|
|
3455
|
+
refKey = 'ref',
|
|
3456
|
+
ref,
|
|
3457
|
+
onMouseMove,
|
|
3458
|
+
onClick,
|
|
3459
|
+
onPress,
|
|
3460
|
+
...rest
|
|
3461
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3462
|
+
const {
|
|
3463
|
+
props: latestProps,
|
|
3464
|
+
state: latestState
|
|
3465
|
+
} = latest.current;
|
|
3466
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3504
3467
|
|
|
3505
3468
|
if (itemIndex < 0) {
|
|
3506
3469
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3507
3470
|
}
|
|
3508
3471
|
|
|
3509
|
-
|
|
3510
|
-
|
|
3472
|
+
const onSelectKey = 'onClick';
|
|
3473
|
+
const customClickHandler = onClick;
|
|
3511
3474
|
|
|
3512
|
-
|
|
3475
|
+
const itemHandleMouseMove = () => {
|
|
3513
3476
|
if (index === latestState.highlightedIndex) {
|
|
3514
3477
|
return;
|
|
3515
3478
|
}
|
|
@@ -3517,14 +3480,14 @@ function useCombobox(userProps) {
|
|
|
3517
3480
|
shouldScrollRef.current = false;
|
|
3518
3481
|
dispatch({
|
|
3519
3482
|
type: ItemMouseMove,
|
|
3520
|
-
index
|
|
3483
|
+
index
|
|
3521
3484
|
});
|
|
3522
3485
|
};
|
|
3523
3486
|
|
|
3524
|
-
|
|
3487
|
+
const itemHandleClick = () => {
|
|
3525
3488
|
dispatch({
|
|
3526
3489
|
type: ItemClick,
|
|
3527
|
-
index
|
|
3490
|
+
index
|
|
3528
3491
|
});
|
|
3529
3492
|
|
|
3530
3493
|
if (inputRef.current) {
|
|
@@ -3532,26 +3495,32 @@ function useCombobox(userProps) {
|
|
|
3532
3495
|
}
|
|
3533
3496
|
};
|
|
3534
3497
|
|
|
3535
|
-
return
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3498
|
+
return {
|
|
3499
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3500
|
+
if (itemNode) {
|
|
3501
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3502
|
+
}
|
|
3503
|
+
}),
|
|
3504
|
+
role: 'option',
|
|
3505
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
3506
|
+
id: elementIds.getItemId(itemIndex),
|
|
3507
|
+
...(!rest.disabled && {
|
|
3508
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3509
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
3510
|
+
}),
|
|
3511
|
+
...rest
|
|
3512
|
+
};
|
|
3542
3513
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3514
|
+
const getToggleButtonProps = useCallback(function (_temp4) {
|
|
3515
|
+
let {
|
|
3516
|
+
onClick,
|
|
3517
|
+
onPress,
|
|
3518
|
+
refKey = 'ref',
|
|
3519
|
+
ref,
|
|
3520
|
+
...rest
|
|
3521
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3522
|
+
|
|
3523
|
+
const toggleButtonHandleClick = () => {
|
|
3555
3524
|
dispatch({
|
|
3556
3525
|
type: ToggleButtonClick
|
|
3557
3526
|
});
|
|
@@ -3561,49 +3530,52 @@ function useCombobox(userProps) {
|
|
|
3561
3530
|
}
|
|
3562
3531
|
};
|
|
3563
3532
|
|
|
3564
|
-
return
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3533
|
+
return {
|
|
3534
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3535
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3536
|
+
}),
|
|
3537
|
+
id: elementIds.toggleButtonId,
|
|
3538
|
+
tabIndex: -1,
|
|
3539
|
+
...(!rest.disabled && { ...({
|
|
3540
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
3541
|
+
})
|
|
3542
|
+
}),
|
|
3543
|
+
...rest
|
|
3544
|
+
};
|
|
3569
3545
|
}, [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
|
-
|
|
3546
|
+
const getInputProps = useCallback(function (_temp5, _temp6) {
|
|
3547
|
+
let {
|
|
3548
|
+
onKeyDown,
|
|
3549
|
+
onChange,
|
|
3550
|
+
onInput,
|
|
3551
|
+
onBlur,
|
|
3552
|
+
onChangeText,
|
|
3553
|
+
refKey = 'ref',
|
|
3554
|
+
ref,
|
|
3555
|
+
...rest
|
|
3556
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3557
|
+
let {
|
|
3558
|
+
suppressRefError = false
|
|
3559
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
3588
3560
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3589
|
-
|
|
3561
|
+
const latestState = latest.current.state;
|
|
3590
3562
|
|
|
3591
|
-
|
|
3592
|
-
|
|
3563
|
+
const inputHandleKeyDown = event => {
|
|
3564
|
+
const key = normalizeArrowKey(event);
|
|
3593
3565
|
|
|
3594
3566
|
if (key && inputKeyDownHandlers[key]) {
|
|
3595
3567
|
inputKeyDownHandlers[key](event);
|
|
3596
3568
|
}
|
|
3597
3569
|
};
|
|
3598
3570
|
|
|
3599
|
-
|
|
3571
|
+
const inputHandleChange = event => {
|
|
3600
3572
|
dispatch({
|
|
3601
3573
|
type: InputChange,
|
|
3602
3574
|
inputValue: event.target.value
|
|
3603
3575
|
});
|
|
3604
3576
|
};
|
|
3605
3577
|
|
|
3606
|
-
|
|
3578
|
+
const inputHandleBlur = () => {
|
|
3607
3579
|
/* istanbul ignore else */
|
|
3608
3580
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3609
3581
|
dispatch({
|
|
@@ -3615,109 +3587,121 @@ function useCombobox(userProps) {
|
|
|
3615
3587
|
/* istanbul ignore next (preact) */
|
|
3616
3588
|
|
|
3617
3589
|
|
|
3618
|
-
|
|
3619
|
-
|
|
3590
|
+
const onChangeKey = 'onChange';
|
|
3591
|
+
let eventHandlers = {};
|
|
3620
3592
|
|
|
3621
3593
|
if (!rest.disabled) {
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3594
|
+
eventHandlers = {
|
|
3595
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
3596
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
3597
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
|
|
3598
|
+
};
|
|
3625
3599
|
}
|
|
3626
3600
|
|
|
3627
|
-
return
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3601
|
+
return {
|
|
3602
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
3603
|
+
inputRef.current = inputNode;
|
|
3604
|
+
}),
|
|
3605
|
+
id: elementIds.inputId,
|
|
3606
|
+
'aria-autocomplete': 'list',
|
|
3607
|
+
'aria-controls': elementIds.menuId,
|
|
3608
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
3609
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
3610
|
+
}),
|
|
3632
3611
|
'aria-labelledby': elementIds.labelId,
|
|
3633
3612
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
3634
3613
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
3635
3614
|
autoComplete: 'off',
|
|
3636
|
-
value: latestState.inputValue
|
|
3637
|
-
|
|
3615
|
+
value: latestState.inputValue,
|
|
3616
|
+
...eventHandlers,
|
|
3617
|
+
...rest
|
|
3618
|
+
};
|
|
3638
3619
|
}, [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
|
-
|
|
3620
|
+
const getComboboxProps = useCallback(function (_temp7, _temp8) {
|
|
3621
|
+
let {
|
|
3622
|
+
refKey = 'ref',
|
|
3623
|
+
ref,
|
|
3624
|
+
...rest
|
|
3625
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
3626
|
+
let {
|
|
3627
|
+
suppressRefError = false
|
|
3628
|
+
} = _temp8 === void 0 ? {} : _temp8;
|
|
3652
3629
|
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
3653
|
-
return
|
|
3654
|
-
|
|
3655
|
-
|
|
3630
|
+
return {
|
|
3631
|
+
[refKey]: handleRefs(ref, comboboxNode => {
|
|
3632
|
+
comboboxRef.current = comboboxNode;
|
|
3633
|
+
}),
|
|
3634
|
+
role: 'combobox',
|
|
3635
|
+
'aria-haspopup': 'listbox',
|
|
3636
|
+
'aria-owns': elementIds.menuId,
|
|
3637
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
3638
|
+
...rest
|
|
3639
|
+
};
|
|
3656
3640
|
}, [latest, setGetterPropCallInfo, elementIds]); // returns
|
|
3657
3641
|
|
|
3658
|
-
|
|
3642
|
+
const toggleMenu = useCallback(() => {
|
|
3659
3643
|
dispatch({
|
|
3660
3644
|
type: FunctionToggleMenu
|
|
3661
3645
|
});
|
|
3662
3646
|
}, [dispatch]);
|
|
3663
|
-
|
|
3647
|
+
const closeMenu = useCallback(() => {
|
|
3664
3648
|
dispatch({
|
|
3665
3649
|
type: FunctionCloseMenu
|
|
3666
3650
|
});
|
|
3667
3651
|
}, [dispatch]);
|
|
3668
|
-
|
|
3652
|
+
const openMenu = useCallback(() => {
|
|
3669
3653
|
dispatch({
|
|
3670
3654
|
type: FunctionOpenMenu
|
|
3671
3655
|
});
|
|
3672
3656
|
}, [dispatch]);
|
|
3673
|
-
|
|
3657
|
+
const setHighlightedIndex = useCallback(newHighlightedIndex => {
|
|
3674
3658
|
dispatch({
|
|
3675
3659
|
type: FunctionSetHighlightedIndex,
|
|
3676
3660
|
highlightedIndex: newHighlightedIndex
|
|
3677
3661
|
});
|
|
3678
3662
|
}, [dispatch]);
|
|
3679
|
-
|
|
3663
|
+
const selectItem = useCallback(newSelectedItem => {
|
|
3680
3664
|
dispatch({
|
|
3681
3665
|
type: FunctionSelectItem,
|
|
3682
3666
|
selectedItem: newSelectedItem
|
|
3683
3667
|
});
|
|
3684
3668
|
}, [dispatch]);
|
|
3685
|
-
|
|
3669
|
+
const setInputValue = useCallback(newInputValue => {
|
|
3686
3670
|
dispatch({
|
|
3687
3671
|
type: FunctionSetInputValue,
|
|
3688
3672
|
inputValue: newInputValue
|
|
3689
3673
|
});
|
|
3690
3674
|
}, [dispatch]);
|
|
3691
|
-
|
|
3675
|
+
const reset = useCallback(() => {
|
|
3692
3676
|
dispatch({
|
|
3693
3677
|
type: FunctionReset$1
|
|
3694
3678
|
});
|
|
3695
3679
|
}, [dispatch]);
|
|
3696
3680
|
return {
|
|
3697
3681
|
// prop getters.
|
|
3698
|
-
getItemProps
|
|
3699
|
-
getLabelProps
|
|
3700
|
-
getMenuProps
|
|
3701
|
-
getInputProps
|
|
3702
|
-
getComboboxProps
|
|
3703
|
-
getToggleButtonProps
|
|
3682
|
+
getItemProps,
|
|
3683
|
+
getLabelProps,
|
|
3684
|
+
getMenuProps,
|
|
3685
|
+
getInputProps,
|
|
3686
|
+
getComboboxProps,
|
|
3687
|
+
getToggleButtonProps,
|
|
3704
3688
|
// actions.
|
|
3705
|
-
toggleMenu
|
|
3706
|
-
openMenu
|
|
3707
|
-
closeMenu
|
|
3708
|
-
setHighlightedIndex
|
|
3709
|
-
setInputValue
|
|
3710
|
-
selectItem
|
|
3711
|
-
reset
|
|
3689
|
+
toggleMenu,
|
|
3690
|
+
openMenu,
|
|
3691
|
+
closeMenu,
|
|
3692
|
+
setHighlightedIndex,
|
|
3693
|
+
setInputValue,
|
|
3694
|
+
selectItem,
|
|
3695
|
+
reset,
|
|
3712
3696
|
// state.
|
|
3713
|
-
highlightedIndex
|
|
3714
|
-
isOpen
|
|
3715
|
-
selectedItem
|
|
3716
|
-
inputValue
|
|
3697
|
+
highlightedIndex,
|
|
3698
|
+
isOpen,
|
|
3699
|
+
selectedItem,
|
|
3700
|
+
inputValue
|
|
3717
3701
|
};
|
|
3718
3702
|
}
|
|
3719
3703
|
|
|
3720
|
-
|
|
3704
|
+
const defaultStateValues = {
|
|
3721
3705
|
activeIndex: -1,
|
|
3722
3706
|
selectedItems: []
|
|
3723
3707
|
};
|
|
@@ -3757,11 +3741,11 @@ function getDefaultValue(props, propKey) {
|
|
|
3757
3741
|
|
|
3758
3742
|
|
|
3759
3743
|
function getInitialState(props) {
|
|
3760
|
-
|
|
3761
|
-
|
|
3744
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
3745
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
3762
3746
|
return {
|
|
3763
|
-
activeIndex
|
|
3764
|
-
selectedItems
|
|
3747
|
+
activeIndex,
|
|
3748
|
+
selectedItems
|
|
3765
3749
|
};
|
|
3766
3750
|
}
|
|
3767
3751
|
/**
|
|
@@ -3780,10 +3764,12 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3780
3764
|
return false;
|
|
3781
3765
|
}
|
|
3782
3766
|
|
|
3783
|
-
|
|
3767
|
+
const element = event.target;
|
|
3784
3768
|
|
|
3785
3769
|
if (element instanceof HTMLInputElement && // if element is a text input
|
|
3786
|
-
element.value !== '' && (
|
|
3770
|
+
element.value !== '' && ( // and we have text in it
|
|
3771
|
+
// and cursor is either not at the start or is currently highlighting text.
|
|
3772
|
+
element.selectionStart !== 0 || element.selectionEnd !== 0)) {
|
|
3787
3773
|
return false;
|
|
3788
3774
|
}
|
|
3789
3775
|
|
|
@@ -3798,12 +3784,14 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3798
3784
|
|
|
3799
3785
|
|
|
3800
3786
|
function getA11yRemovalMessage(selectionParameters) {
|
|
3801
|
-
|
|
3802
|
-
|
|
3787
|
+
const {
|
|
3788
|
+
removedSelectedItem,
|
|
3789
|
+
itemToString: itemToStringLocal
|
|
3790
|
+
} = selectionParameters;
|
|
3803
3791
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
3804
3792
|
}
|
|
3805
3793
|
|
|
3806
|
-
|
|
3794
|
+
const propTypes = {
|
|
3807
3795
|
selectedItems: PropTypes.array,
|
|
3808
3796
|
initialSelectedItems: PropTypes.array,
|
|
3809
3797
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -3827,37 +3815,37 @@ var propTypes = {
|
|
|
3827
3815
|
})
|
|
3828
3816
|
})
|
|
3829
3817
|
};
|
|
3830
|
-
|
|
3818
|
+
const defaultProps = {
|
|
3831
3819
|
itemToString: defaultProps$3.itemToString,
|
|
3832
3820
|
stateReducer: defaultProps$3.stateReducer,
|
|
3833
3821
|
environment: defaultProps$3.environment,
|
|
3834
|
-
getA11yRemovalMessage
|
|
3822
|
+
getA11yRemovalMessage,
|
|
3835
3823
|
keyNavigationNext: 'ArrowRight',
|
|
3836
3824
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3837
3825
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
3838
3826
|
|
|
3839
|
-
|
|
3827
|
+
let validatePropTypes = noop;
|
|
3840
3828
|
/* istanbul ignore next */
|
|
3841
3829
|
|
|
3842
3830
|
if (process.env.NODE_ENV !== 'production') {
|
|
3843
|
-
validatePropTypes =
|
|
3831
|
+
validatePropTypes = (options, caller) => {
|
|
3844
3832
|
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3845
3833
|
};
|
|
3846
3834
|
}
|
|
3847
3835
|
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3836
|
+
const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
|
|
3837
|
+
const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
|
|
3838
|
+
const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
|
|
3839
|
+
const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
|
|
3840
|
+
const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
|
|
3841
|
+
const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
|
|
3842
|
+
const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
|
|
3843
|
+
const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
|
|
3844
|
+
const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
|
|
3845
|
+
const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
|
|
3846
|
+
const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
|
|
3847
|
+
const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3848
|
+
const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3861
3849
|
|
|
3862
3850
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3863
3851
|
__proto__: null,
|
|
@@ -3879,13 +3867,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3879
3867
|
/* eslint-disable complexity */
|
|
3880
3868
|
|
|
3881
3869
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3870
|
+
const {
|
|
3871
|
+
type,
|
|
3872
|
+
index,
|
|
3873
|
+
props,
|
|
3874
|
+
selectedItem
|
|
3875
|
+
} = action;
|
|
3876
|
+
const {
|
|
3877
|
+
activeIndex,
|
|
3878
|
+
selectedItems
|
|
3879
|
+
} = state;
|
|
3880
|
+
let changes;
|
|
3889
3881
|
|
|
3890
3882
|
switch (type) {
|
|
3891
3883
|
case SelectedItemClick:
|
|
@@ -3909,7 +3901,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3909
3901
|
case SelectedItemKeyDownBackspace:
|
|
3910
3902
|
case SelectedItemKeyDownDelete:
|
|
3911
3903
|
{
|
|
3912
|
-
|
|
3904
|
+
let newActiveIndex = activeIndex;
|
|
3913
3905
|
|
|
3914
3906
|
if (selectedItems.length === 1) {
|
|
3915
3907
|
newActiveIndex = -1;
|
|
@@ -3917,11 +3909,12 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3917
3909
|
newActiveIndex = selectedItems.length - 2;
|
|
3918
3910
|
}
|
|
3919
3911
|
|
|
3920
|
-
changes =
|
|
3921
|
-
selectedItems: [
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3912
|
+
changes = {
|
|
3913
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
3914
|
+
...{
|
|
3915
|
+
activeIndex: newActiveIndex
|
|
3916
|
+
}
|
|
3917
|
+
};
|
|
3925
3918
|
break;
|
|
3926
3919
|
}
|
|
3927
3920
|
|
|
@@ -3939,7 +3932,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3939
3932
|
|
|
3940
3933
|
case FunctionAddSelectedItem:
|
|
3941
3934
|
changes = {
|
|
3942
|
-
selectedItems: [
|
|
3935
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
3943
3936
|
};
|
|
3944
3937
|
break;
|
|
3945
3938
|
|
|
@@ -3951,26 +3944,30 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3951
3944
|
|
|
3952
3945
|
case FunctionRemoveSelectedItem:
|
|
3953
3946
|
{
|
|
3954
|
-
|
|
3955
|
-
|
|
3947
|
+
let newActiveIndex = activeIndex;
|
|
3948
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
3949
|
+
|
|
3950
|
+
if (selectedItemIndex >= 0) {
|
|
3951
|
+
if (selectedItems.length === 1) {
|
|
3952
|
+
newActiveIndex = -1;
|
|
3953
|
+
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
3954
|
+
newActiveIndex = selectedItems.length - 2;
|
|
3955
|
+
}
|
|
3956
3956
|
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3957
|
+
changes = {
|
|
3958
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
3959
|
+
activeIndex: newActiveIndex
|
|
3960
|
+
};
|
|
3961
3961
|
}
|
|
3962
3962
|
|
|
3963
|
-
changes = _extends({
|
|
3964
|
-
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
|
|
3965
|
-
}, {
|
|
3966
|
-
activeIndex: _newActiveIndex
|
|
3967
|
-
});
|
|
3968
3963
|
break;
|
|
3969
3964
|
}
|
|
3970
3965
|
|
|
3971
3966
|
case FunctionSetSelectedItems:
|
|
3972
3967
|
{
|
|
3973
|
-
|
|
3968
|
+
const {
|
|
3969
|
+
selectedItems: newSelectedItems
|
|
3970
|
+
} = action;
|
|
3974
3971
|
changes = {
|
|
3975
3972
|
selectedItems: newSelectedItems
|
|
3976
3973
|
};
|
|
@@ -3979,9 +3976,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3979
3976
|
|
|
3980
3977
|
case FunctionSetActiveIndex:
|
|
3981
3978
|
{
|
|
3982
|
-
|
|
3979
|
+
const {
|
|
3980
|
+
activeIndex: newActiveIndex
|
|
3981
|
+
} = action;
|
|
3983
3982
|
changes = {
|
|
3984
|
-
activeIndex:
|
|
3983
|
+
activeIndex: newActiveIndex
|
|
3985
3984
|
};
|
|
3986
3985
|
break;
|
|
3987
3986
|
}
|
|
@@ -3997,11 +3996,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3997
3996
|
throw new Error('Reducer called without proper action type.');
|
|
3998
3997
|
}
|
|
3999
3998
|
|
|
4000
|
-
return
|
|
3999
|
+
return { ...state,
|
|
4000
|
+
...changes
|
|
4001
|
+
};
|
|
4001
4002
|
}
|
|
4002
4003
|
|
|
4003
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
4004
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
4005
4004
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
4006
4005
|
|
|
4007
4006
|
function useMultipleSelection(userProps) {
|
|
@@ -4011,47 +4010,47 @@ function useMultipleSelection(userProps) {
|
|
|
4011
4010
|
|
|
4012
4011
|
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
4013
4012
|
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4013
|
+
const props = { ...defaultProps,
|
|
4014
|
+
...userProps
|
|
4015
|
+
};
|
|
4016
|
+
const {
|
|
4017
|
+
getA11yRemovalMessage,
|
|
4018
|
+
itemToString,
|
|
4019
|
+
environment,
|
|
4020
|
+
keyNavigationNext,
|
|
4021
|
+
keyNavigationPrevious
|
|
4022
|
+
} = props; // Reducer init.
|
|
4023
|
+
|
|
4024
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
4025
|
+
const {
|
|
4026
|
+
activeIndex,
|
|
4027
|
+
selectedItems
|
|
4028
|
+
} = state; // Refs.
|
|
4029
|
+
|
|
4030
|
+
const isInitialMountRef = useRef(true);
|
|
4031
|
+
const dropdownRef = useRef(null);
|
|
4032
|
+
const previousSelectedItemsRef = useRef(selectedItems);
|
|
4033
|
+
const selectedItemRefs = useRef();
|
|
4033
4034
|
selectedItemRefs.current = [];
|
|
4034
|
-
|
|
4035
|
-
state
|
|
4036
|
-
props
|
|
4035
|
+
const latest = useLatestRef({
|
|
4036
|
+
state,
|
|
4037
|
+
props
|
|
4037
4038
|
}); // Effects.
|
|
4038
4039
|
|
|
4039
4040
|
/* Sets a11y status message on changes in selectedItem. */
|
|
4040
4041
|
|
|
4041
|
-
useEffect(
|
|
4042
|
+
useEffect(() => {
|
|
4042
4043
|
if (isInitialMountRef.current) {
|
|
4043
4044
|
return;
|
|
4044
4045
|
}
|
|
4045
4046
|
|
|
4046
4047
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
4047
|
-
|
|
4048
|
-
return selectedItems.indexOf(item) < 0;
|
|
4049
|
-
});
|
|
4048
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
4050
4049
|
setStatus(getA11yRemovalMessage({
|
|
4051
|
-
itemToString
|
|
4050
|
+
itemToString,
|
|
4052
4051
|
resultCount: selectedItems.length,
|
|
4053
|
-
removedSelectedItem
|
|
4054
|
-
activeIndex
|
|
4052
|
+
removedSelectedItem,
|
|
4053
|
+
activeIndex,
|
|
4055
4054
|
activeSelectedItem: selectedItems[activeIndex]
|
|
4056
4055
|
}), environment.document);
|
|
4057
4056
|
}
|
|
@@ -4059,7 +4058,7 @@ function useMultipleSelection(userProps) {
|
|
|
4059
4058
|
previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4060
4059
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
4061
4060
|
|
|
4062
|
-
useEffect(
|
|
4061
|
+
useEffect(() => {
|
|
4063
4062
|
if (isInitialMountRef.current) {
|
|
4064
4063
|
return;
|
|
4065
4064
|
}
|
|
@@ -4072,177 +4071,187 @@ function useMultipleSelection(userProps) {
|
|
|
4072
4071
|
}, [activeIndex]);
|
|
4073
4072
|
useControlPropsValidator({
|
|
4074
4073
|
isInitialMount: isInitialMountRef.current,
|
|
4075
|
-
props
|
|
4076
|
-
state
|
|
4074
|
+
props,
|
|
4075
|
+
state
|
|
4077
4076
|
});
|
|
4078
|
-
|
|
4077
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
4079
4078
|
|
|
4080
|
-
useEffect(
|
|
4079
|
+
useEffect(() => {
|
|
4081
4080
|
isInitialMountRef.current = false;
|
|
4082
4081
|
}, []); // Event handler functions.
|
|
4083
4082
|
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
4083
|
+
const selectedItemKeyDownHandlers = useMemo(() => ({
|
|
4084
|
+
[keyNavigationPrevious]() {
|
|
4088
4085
|
dispatch({
|
|
4089
4086
|
type: SelectedItemKeyDownNavigationPrevious
|
|
4090
4087
|
});
|
|
4091
|
-
},
|
|
4088
|
+
},
|
|
4089
|
+
|
|
4090
|
+
[keyNavigationNext]() {
|
|
4092
4091
|
dispatch({
|
|
4093
4092
|
type: SelectedItemKeyDownNavigationNext
|
|
4094
4093
|
});
|
|
4095
|
-
},
|
|
4094
|
+
},
|
|
4095
|
+
|
|
4096
|
+
Delete() {
|
|
4096
4097
|
dispatch({
|
|
4097
4098
|
type: SelectedItemKeyDownDelete
|
|
4098
4099
|
});
|
|
4099
|
-
},
|
|
4100
|
+
},
|
|
4101
|
+
|
|
4102
|
+
Backspace() {
|
|
4100
4103
|
dispatch({
|
|
4101
4104
|
type: SelectedItemKeyDownBackspace
|
|
4102
4105
|
});
|
|
4103
|
-
}
|
|
4104
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4105
|
-
var dropdownKeyDownHandlers = useMemo(function () {
|
|
4106
|
-
var _ref2;
|
|
4106
|
+
}
|
|
4107
4107
|
|
|
4108
|
-
|
|
4108
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
4109
|
+
const dropdownKeyDownHandlers = useMemo(() => ({
|
|
4110
|
+
[keyNavigationPrevious](event) {
|
|
4109
4111
|
if (isKeyDownOperationPermitted(event)) {
|
|
4110
4112
|
dispatch({
|
|
4111
4113
|
type: DropdownKeyDownNavigationPrevious
|
|
4112
4114
|
});
|
|
4113
4115
|
}
|
|
4114
|
-
},
|
|
4116
|
+
},
|
|
4117
|
+
|
|
4118
|
+
Backspace(event) {
|
|
4115
4119
|
if (isKeyDownOperationPermitted(event)) {
|
|
4116
4120
|
dispatch({
|
|
4117
4121
|
type: DropdownKeyDownBackspace
|
|
4118
4122
|
});
|
|
4119
4123
|
}
|
|
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);
|
|
4124
|
+
}
|
|
4135
4125
|
|
|
4136
|
-
|
|
4137
|
-
|
|
4126
|
+
}), [dispatch, keyNavigationPrevious]); // Getter props.
|
|
4127
|
+
|
|
4128
|
+
const getSelectedItemProps = useCallback(function (_temp) {
|
|
4129
|
+
let {
|
|
4130
|
+
refKey = 'ref',
|
|
4131
|
+
ref,
|
|
4132
|
+
onClick,
|
|
4133
|
+
onKeyDown,
|
|
4134
|
+
selectedItem,
|
|
4135
|
+
index,
|
|
4136
|
+
...rest
|
|
4137
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4138
|
+
const {
|
|
4139
|
+
state: latestState
|
|
4140
|
+
} = latest.current;
|
|
4141
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
4138
4142
|
|
|
4139
4143
|
if (itemIndex < 0) {
|
|
4140
4144
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
4141
4145
|
}
|
|
4142
4146
|
|
|
4143
|
-
|
|
4147
|
+
const selectedItemHandleClick = () => {
|
|
4144
4148
|
dispatch({
|
|
4145
4149
|
type: SelectedItemClick,
|
|
4146
|
-
index
|
|
4150
|
+
index
|
|
4147
4151
|
});
|
|
4148
4152
|
};
|
|
4149
4153
|
|
|
4150
|
-
|
|
4151
|
-
|
|
4154
|
+
const selectedItemHandleKeyDown = event => {
|
|
4155
|
+
const key = normalizeArrowKey(event);
|
|
4152
4156
|
|
|
4153
4157
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
4154
4158
|
selectedItemKeyDownHandlers[key](event);
|
|
4155
4159
|
}
|
|
4156
4160
|
};
|
|
4157
4161
|
|
|
4158
|
-
return
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4162
|
+
return {
|
|
4163
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
4164
|
+
if (selectedItemNode) {
|
|
4165
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
4166
|
+
}
|
|
4167
|
+
}),
|
|
4168
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
4169
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
4170
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
4171
|
+
...rest
|
|
4172
|
+
};
|
|
4163
4173
|
}, [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
|
-
|
|
4174
|
+
const getDropdownProps = useCallback(function (_temp2, _temp3) {
|
|
4175
|
+
let {
|
|
4176
|
+
refKey = 'ref',
|
|
4177
|
+
ref,
|
|
4178
|
+
onKeyDown,
|
|
4179
|
+
onClick,
|
|
4180
|
+
preventKeyAction = false,
|
|
4181
|
+
...rest
|
|
4182
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4183
|
+
let {
|
|
4184
|
+
suppressRefError = false
|
|
4185
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4181
4186
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
4182
4187
|
|
|
4183
|
-
|
|
4184
|
-
|
|
4188
|
+
const dropdownHandleKeyDown = event => {
|
|
4189
|
+
const key = normalizeArrowKey(event);
|
|
4185
4190
|
|
|
4186
4191
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
4187
4192
|
dropdownKeyDownHandlers[key](event);
|
|
4188
4193
|
}
|
|
4189
4194
|
};
|
|
4190
4195
|
|
|
4191
|
-
|
|
4196
|
+
const dropdownHandleClick = () => {
|
|
4192
4197
|
dispatch({
|
|
4193
4198
|
type: DropdownClick
|
|
4194
4199
|
});
|
|
4195
4200
|
};
|
|
4196
4201
|
|
|
4197
|
-
return
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4202
|
+
return {
|
|
4203
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
4204
|
+
if (dropdownNode) {
|
|
4205
|
+
dropdownRef.current = dropdownNode;
|
|
4206
|
+
}
|
|
4207
|
+
}),
|
|
4208
|
+
...(!preventKeyAction && {
|
|
4209
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
4210
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
4211
|
+
}),
|
|
4212
|
+
...rest
|
|
4213
|
+
};
|
|
4205
4214
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
4206
4215
|
|
|
4207
|
-
|
|
4216
|
+
const addSelectedItem = useCallback(selectedItem => {
|
|
4208
4217
|
dispatch({
|
|
4209
4218
|
type: FunctionAddSelectedItem,
|
|
4210
|
-
selectedItem
|
|
4219
|
+
selectedItem
|
|
4211
4220
|
});
|
|
4212
4221
|
}, [dispatch]);
|
|
4213
|
-
|
|
4222
|
+
const removeSelectedItem = useCallback(selectedItem => {
|
|
4214
4223
|
dispatch({
|
|
4215
4224
|
type: FunctionRemoveSelectedItem,
|
|
4216
|
-
selectedItem
|
|
4225
|
+
selectedItem
|
|
4217
4226
|
});
|
|
4218
4227
|
}, [dispatch]);
|
|
4219
|
-
|
|
4228
|
+
const setSelectedItems = useCallback(newSelectedItems => {
|
|
4220
4229
|
dispatch({
|
|
4221
4230
|
type: FunctionSetSelectedItems,
|
|
4222
4231
|
selectedItems: newSelectedItems
|
|
4223
4232
|
});
|
|
4224
4233
|
}, [dispatch]);
|
|
4225
|
-
|
|
4234
|
+
const setActiveIndex = useCallback(newActiveIndex => {
|
|
4226
4235
|
dispatch({
|
|
4227
4236
|
type: FunctionSetActiveIndex,
|
|
4228
4237
|
activeIndex: newActiveIndex
|
|
4229
4238
|
});
|
|
4230
4239
|
}, [dispatch]);
|
|
4231
|
-
|
|
4240
|
+
const reset = useCallback(() => {
|
|
4232
4241
|
dispatch({
|
|
4233
4242
|
type: FunctionReset
|
|
4234
4243
|
});
|
|
4235
4244
|
}, [dispatch]);
|
|
4236
4245
|
return {
|
|
4237
|
-
getSelectedItemProps
|
|
4238
|
-
getDropdownProps
|
|
4239
|
-
addSelectedItem
|
|
4240
|
-
removeSelectedItem
|
|
4241
|
-
setSelectedItems
|
|
4242
|
-
setActiveIndex
|
|
4243
|
-
reset
|
|
4244
|
-
selectedItems
|
|
4245
|
-
activeIndex
|
|
4246
|
+
getSelectedItemProps,
|
|
4247
|
+
getDropdownProps,
|
|
4248
|
+
addSelectedItem,
|
|
4249
|
+
removeSelectedItem,
|
|
4250
|
+
setSelectedItems,
|
|
4251
|
+
setActiveIndex,
|
|
4252
|
+
reset,
|
|
4253
|
+
selectedItems,
|
|
4254
|
+
activeIndex
|
|
4246
4255
|
};
|
|
4247
4256
|
}
|
|
4248
4257
|
|