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