downshift 7.1.2 → 7.1.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/downshift.cjs.js +1574 -1437
- package/dist/downshift.esm.js +1574 -1433
- package/dist/downshift.native.cjs.js +1558 -1421
- package/dist/downshift.umd.js +1569 -1473
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +2 -3
- package/preact/dist/downshift.cjs.js +1574 -1437
- package/preact/dist/downshift.esm.js +1574 -1433
- package/preact/dist/downshift.umd.js +1572 -1476
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -9
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/CHANGELOG.md +0 -5
|
@@ -2,26 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
6
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
7
|
-
var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
|
|
8
|
-
var _inheritsLoose = require('@babel/runtime/helpers/inheritsLoose');
|
|
9
5
|
var PropTypes = require('prop-types');
|
|
10
6
|
var react = require('react');
|
|
11
7
|
var reactIs = require('react-is');
|
|
12
|
-
var
|
|
8
|
+
var compute = require('compute-scroll-into-view');
|
|
13
9
|
var tslib = require('tslib');
|
|
14
10
|
|
|
15
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
12
|
|
|
17
|
-
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
18
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
19
|
-
var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
|
|
20
|
-
var _inheritsLoose__default = /*#__PURE__*/_interopDefaultLegacy(_inheritsLoose);
|
|
21
13
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
22
|
-
var
|
|
14
|
+
var compute__default = /*#__PURE__*/_interopDefaultLegacy(compute);
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
let idCounter = 0;
|
|
25
17
|
|
|
26
18
|
/**
|
|
27
19
|
* Accepts a parameter and returns it if it's a function
|
|
@@ -45,15 +37,17 @@ function scrollIntoView(node, menuNode) {
|
|
|
45
37
|
if (!node) {
|
|
46
38
|
return;
|
|
47
39
|
}
|
|
48
|
-
|
|
40
|
+
const actions = compute__default["default"](node, {
|
|
49
41
|
boundary: menuNode,
|
|
50
42
|
block: 'nearest',
|
|
51
43
|
scrollMode: 'if-needed'
|
|
52
44
|
});
|
|
53
|
-
actions.forEach(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
actions.forEach(_ref => {
|
|
46
|
+
let {
|
|
47
|
+
el,
|
|
48
|
+
top,
|
|
49
|
+
left
|
|
50
|
+
} = _ref;
|
|
57
51
|
el.scrollTop = top;
|
|
58
52
|
el.scrollLeft = left;
|
|
59
53
|
});
|
|
@@ -66,7 +60,7 @@ function scrollIntoView(node, menuNode) {
|
|
|
66
60
|
* @return {Boolean} whether the parent is the child or the child is in the parent
|
|
67
61
|
*/
|
|
68
62
|
function isOrContainsNode(parent, child, environment) {
|
|
69
|
-
|
|
63
|
+
const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
70
64
|
return result;
|
|
71
65
|
}
|
|
72
66
|
|
|
@@ -79,7 +73,7 @@ function isOrContainsNode(parent, child, environment) {
|
|
|
79
73
|
* @return {Function} the debounced function
|
|
80
74
|
*/
|
|
81
75
|
function debounce(fn, time) {
|
|
82
|
-
|
|
76
|
+
let timeoutId;
|
|
83
77
|
function cancel() {
|
|
84
78
|
if (timeoutId) {
|
|
85
79
|
clearTimeout(timeoutId);
|
|
@@ -90,9 +84,9 @@ function debounce(fn, time) {
|
|
|
90
84
|
args[_key] = arguments[_key];
|
|
91
85
|
}
|
|
92
86
|
cancel();
|
|
93
|
-
timeoutId = setTimeout(
|
|
87
|
+
timeoutId = setTimeout(() => {
|
|
94
88
|
timeoutId = null;
|
|
95
|
-
fn
|
|
89
|
+
fn(...args);
|
|
96
90
|
}, time);
|
|
97
91
|
}
|
|
98
92
|
wrapper.cancel = cancel;
|
|
@@ -114,9 +108,9 @@ function callAllEventHandlers() {
|
|
|
114
108
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
115
109
|
args[_key3 - 1] = arguments[_key3];
|
|
116
110
|
}
|
|
117
|
-
return fns.some(
|
|
111
|
+
return fns.some(fn => {
|
|
118
112
|
if (fn) {
|
|
119
|
-
fn
|
|
113
|
+
fn(event, ...args);
|
|
120
114
|
}
|
|
121
115
|
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
122
116
|
});
|
|
@@ -126,8 +120,8 @@ function handleRefs() {
|
|
|
126
120
|
for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
127
121
|
refs[_key4] = arguments[_key4];
|
|
128
122
|
}
|
|
129
|
-
return
|
|
130
|
-
refs.forEach(
|
|
123
|
+
return node => {
|
|
124
|
+
refs.forEach(ref => {
|
|
131
125
|
if (typeof ref === 'function') {
|
|
132
126
|
ref(node);
|
|
133
127
|
} else if (ref) {
|
|
@@ -161,9 +155,11 @@ function resetIdCounter() {
|
|
|
161
155
|
* @return {String} the a11y status message
|
|
162
156
|
*/
|
|
163
157
|
function getA11yStatusMessage$1(_ref2) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
let {
|
|
159
|
+
isOpen,
|
|
160
|
+
resultCount,
|
|
161
|
+
previousResultCount
|
|
162
|
+
} = _ref2;
|
|
167
163
|
if (!isOpen) {
|
|
168
164
|
return '';
|
|
169
165
|
}
|
|
@@ -171,7 +167,7 @@ function getA11yStatusMessage$1(_ref2) {
|
|
|
171
167
|
return 'No results are available.';
|
|
172
168
|
}
|
|
173
169
|
if (resultCount !== previousResultCount) {
|
|
174
|
-
return resultCount
|
|
170
|
+
return `${resultCount} result${resultCount === 1 ? ' is' : 's are'} available, use up and down arrow keys to navigate. Press Enter key to select.`;
|
|
175
171
|
}
|
|
176
172
|
return '';
|
|
177
173
|
}
|
|
@@ -218,9 +214,9 @@ function getElementProps(element) {
|
|
|
218
214
|
*/
|
|
219
215
|
function requiredProp(fnName, propName) {
|
|
220
216
|
// eslint-disable-next-line no-console
|
|
221
|
-
console.error(
|
|
217
|
+
console.error(`The property "${propName}" is required in "${fnName}"`);
|
|
222
218
|
}
|
|
223
|
-
|
|
219
|
+
const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
|
224
220
|
/**
|
|
225
221
|
* @param {Object} state the state object
|
|
226
222
|
* @return {Object} state that is relevant to downshift
|
|
@@ -229,8 +225,8 @@ function pickState(state) {
|
|
|
229
225
|
if (state === void 0) {
|
|
230
226
|
state = {};
|
|
231
227
|
}
|
|
232
|
-
|
|
233
|
-
stateKeys.forEach(
|
|
228
|
+
const result = {};
|
|
229
|
+
stateKeys.forEach(k => {
|
|
234
230
|
if (state.hasOwnProperty(k)) {
|
|
235
231
|
result[k] = state[k];
|
|
236
232
|
}
|
|
@@ -250,7 +246,7 @@ function pickState(state) {
|
|
|
250
246
|
* @returns {Object} The merged controlled state.
|
|
251
247
|
*/
|
|
252
248
|
function getState(state, props) {
|
|
253
|
-
return Object.keys(state).reduce(
|
|
249
|
+
return Object.keys(state).reduce((prevState, key) => {
|
|
254
250
|
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
255
251
|
return prevState;
|
|
256
252
|
}, {});
|
|
@@ -275,11 +271,13 @@ function isControlledProp(props, key) {
|
|
|
275
271
|
* @return {String} keyboard key
|
|
276
272
|
*/
|
|
277
273
|
function normalizeArrowKey(event) {
|
|
278
|
-
|
|
279
|
-
|
|
274
|
+
const {
|
|
275
|
+
key,
|
|
276
|
+
keyCode
|
|
277
|
+
} = event;
|
|
280
278
|
/* istanbul ignore next (ie) */
|
|
281
279
|
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
282
|
-
return
|
|
280
|
+
return `Arrow${key}`;
|
|
283
281
|
}
|
|
284
282
|
return key;
|
|
285
283
|
}
|
|
@@ -311,17 +309,17 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
|
|
|
311
309
|
if (itemCount === 0) {
|
|
312
310
|
return -1;
|
|
313
311
|
}
|
|
314
|
-
|
|
312
|
+
const itemsLastIndex = itemCount - 1;
|
|
315
313
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
316
314
|
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
|
317
315
|
}
|
|
318
|
-
|
|
316
|
+
let newIndex = baseIndex + moveAmount;
|
|
319
317
|
if (newIndex < 0) {
|
|
320
318
|
newIndex = circular ? itemsLastIndex : 0;
|
|
321
319
|
} else if (newIndex > itemsLastIndex) {
|
|
322
320
|
newIndex = circular ? 0 : itemsLastIndex;
|
|
323
321
|
}
|
|
324
|
-
|
|
322
|
+
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
|
|
325
323
|
if (nonDisabledNewIndex === -1) {
|
|
326
324
|
return baseIndex >= itemCount ? -1 : baseIndex;
|
|
327
325
|
}
|
|
@@ -339,20 +337,20 @@ function getNextWrappingIndex(moveAmount, baseIndex, itemCount, getItemNodeFromI
|
|
|
339
337
|
* @returns {number} The new index. Returns baseIndex if item is not disabled. Returns next non-disabled item otherwise. If no non-disabled found it will return -1.
|
|
340
338
|
*/
|
|
341
339
|
function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
|
|
342
|
-
|
|
340
|
+
const currentElementNode = getItemNodeFromIndex(baseIndex);
|
|
343
341
|
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
|
|
344
342
|
return baseIndex;
|
|
345
343
|
}
|
|
346
344
|
if (moveAmount > 0) {
|
|
347
|
-
for (
|
|
345
|
+
for (let index = baseIndex + 1; index < itemCount; index++) {
|
|
348
346
|
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
349
347
|
return index;
|
|
350
348
|
}
|
|
351
349
|
}
|
|
352
350
|
} else {
|
|
353
|
-
for (
|
|
354
|
-
if (!getItemNodeFromIndex(
|
|
355
|
-
return
|
|
351
|
+
for (let index = baseIndex - 1; index >= 0; index--) {
|
|
352
|
+
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
353
|
+
return index;
|
|
356
354
|
}
|
|
357
355
|
}
|
|
358
356
|
}
|
|
@@ -376,30 +374,28 @@ function targetWithinDownshift(target, downshiftElements, environment, checkActi
|
|
|
376
374
|
if (checkActiveElement === void 0) {
|
|
377
375
|
checkActiveElement = true;
|
|
378
376
|
}
|
|
379
|
-
return downshiftElements.some(
|
|
380
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
381
|
-
});
|
|
377
|
+
return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
|
|
382
378
|
}
|
|
383
379
|
|
|
384
380
|
// eslint-disable-next-line import/no-mutable-exports
|
|
385
|
-
|
|
381
|
+
let validateControlledUnchanged = noop;
|
|
386
382
|
/* istanbul ignore next */
|
|
387
383
|
if (process.env.NODE_ENV !== 'production') {
|
|
388
|
-
validateControlledUnchanged =
|
|
389
|
-
|
|
390
|
-
Object.keys(state).forEach(
|
|
384
|
+
validateControlledUnchanged = (state, prevProps, nextProps) => {
|
|
385
|
+
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`;
|
|
386
|
+
Object.keys(state).forEach(propKey => {
|
|
391
387
|
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
392
388
|
// eslint-disable-next-line no-console
|
|
393
|
-
console.error(
|
|
389
|
+
console.error(`downshift: A component has changed the controlled prop "${propKey}" to be uncontrolled. ${warningDescription}`);
|
|
394
390
|
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
395
391
|
// eslint-disable-next-line no-console
|
|
396
|
-
console.error(
|
|
392
|
+
console.error(`downshift: A component has changed the uncontrolled prop "${propKey}" to be controlled. ${warningDescription}`);
|
|
397
393
|
}
|
|
398
394
|
});
|
|
399
395
|
};
|
|
400
396
|
}
|
|
401
397
|
|
|
402
|
-
|
|
398
|
+
const cleanupStatus = debounce(documentProp => {
|
|
403
399
|
getStatusDiv(documentProp).textContent = '';
|
|
404
400
|
}, 500);
|
|
405
401
|
|
|
@@ -408,7 +404,7 @@ var cleanupStatus = debounce(function (documentProp) {
|
|
|
408
404
|
* @param {Object} documentProp document passed by the user.
|
|
409
405
|
*/
|
|
410
406
|
function setStatus(status, documentProp) {
|
|
411
|
-
|
|
407
|
+
const div = getStatusDiv(documentProp);
|
|
412
408
|
if (!status) {
|
|
413
409
|
return;
|
|
414
410
|
}
|
|
@@ -425,7 +421,7 @@ function getStatusDiv(documentProp) {
|
|
|
425
421
|
if (documentProp === void 0) {
|
|
426
422
|
documentProp = document;
|
|
427
423
|
}
|
|
428
|
-
|
|
424
|
+
let statusDiv = documentProp.getElementById('a11y-status-message');
|
|
429
425
|
if (statusDiv) {
|
|
430
426
|
return statusDiv;
|
|
431
427
|
}
|
|
@@ -448,23 +444,23 @@ function getStatusDiv(documentProp) {
|
|
|
448
444
|
return statusDiv;
|
|
449
445
|
}
|
|
450
446
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
447
|
+
const unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
|
448
|
+
const mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
|
449
|
+
const itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
|
450
|
+
const keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
|
|
451
|
+
const keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
|
|
452
|
+
const keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
|
|
453
|
+
const keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
|
|
454
|
+
const keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
|
|
455
|
+
const keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
|
|
456
|
+
const clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
|
|
457
|
+
const blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
|
|
458
|
+
const changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
|
|
459
|
+
const keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
|
|
460
|
+
const clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
|
|
461
|
+
const blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
|
|
462
|
+
const controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
|
463
|
+
const touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
|
468
464
|
|
|
469
465
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
470
466
|
__proto__: null,
|
|
@@ -487,48 +483,37 @@ var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
|
487
483
|
touchEnd: touchEnd
|
|
488
484
|
});
|
|
489
485
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
495
|
-
var Downshift = /*#__PURE__*/function () {
|
|
496
|
-
var Downshift = /*#__PURE__*/function (_Component) {
|
|
497
|
-
_inheritsLoose__default["default"](Downshift, _Component);
|
|
498
|
-
function Downshift(_props) {
|
|
486
|
+
/* eslint camelcase:0 */
|
|
487
|
+
const Downshift = /*#__PURE__*/(() => {
|
|
488
|
+
class Downshift extends react.Component {
|
|
489
|
+
constructor(_props) {
|
|
499
490
|
var _this;
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
_this.timeoutIds = [];
|
|
516
|
-
_this.internalSetTimeout = function (fn, time) {
|
|
517
|
-
var id = setTimeout(function () {
|
|
518
|
-
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
519
|
-
return i !== id;
|
|
520
|
-
});
|
|
491
|
+
super(_props);
|
|
492
|
+
_this = this;
|
|
493
|
+
this.id = this.props.id || `downshift-${generateId()}`;
|
|
494
|
+
this.menuId = this.props.menuId || `${this.id}-menu`;
|
|
495
|
+
this.labelId = this.props.labelId || `${this.id}-label`;
|
|
496
|
+
this.inputId = this.props.inputId || `${this.id}-input`;
|
|
497
|
+
this.getItemId = this.props.getItemId || (index => `${this.id}-item-${index}`);
|
|
498
|
+
this.input = null;
|
|
499
|
+
this.items = [];
|
|
500
|
+
this.itemCount = null;
|
|
501
|
+
this.previousResultCount = 0;
|
|
502
|
+
this.timeoutIds = [];
|
|
503
|
+
this.internalSetTimeout = (fn, time) => {
|
|
504
|
+
const id = setTimeout(() => {
|
|
505
|
+
this.timeoutIds = this.timeoutIds.filter(i => i !== id);
|
|
521
506
|
fn();
|
|
522
507
|
}, time);
|
|
523
|
-
|
|
508
|
+
this.timeoutIds.push(id);
|
|
524
509
|
};
|
|
525
|
-
|
|
526
|
-
|
|
510
|
+
this.setItemCount = count => {
|
|
511
|
+
this.itemCount = count;
|
|
527
512
|
};
|
|
528
|
-
|
|
529
|
-
|
|
513
|
+
this.unsetItemCount = () => {
|
|
514
|
+
this.itemCount = null;
|
|
530
515
|
};
|
|
531
|
-
|
|
516
|
+
this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
532
517
|
if (highlightedIndex === void 0) {
|
|
533
518
|
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
534
519
|
}
|
|
@@ -536,41 +521,43 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
536
521
|
otherStateToSet = {};
|
|
537
522
|
}
|
|
538
523
|
otherStateToSet = pickState(otherStateToSet);
|
|
539
|
-
_this.internalSetState(_extends__default["default"]({
|
|
540
|
-
highlightedIndex: highlightedIndex
|
|
541
|
-
}, otherStateToSet));
|
|
542
|
-
};
|
|
543
|
-
_this.clearSelection = function (cb) {
|
|
544
524
|
_this.internalSetState({
|
|
525
|
+
highlightedIndex,
|
|
526
|
+
...otherStateToSet
|
|
527
|
+
});
|
|
528
|
+
};
|
|
529
|
+
this.clearSelection = cb => {
|
|
530
|
+
this.internalSetState({
|
|
545
531
|
selectedItem: null,
|
|
546
532
|
inputValue: '',
|
|
547
|
-
highlightedIndex:
|
|
548
|
-
isOpen:
|
|
533
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
534
|
+
isOpen: this.props.defaultIsOpen
|
|
549
535
|
}, cb);
|
|
550
536
|
};
|
|
551
|
-
|
|
537
|
+
this.selectItem = (item, otherStateToSet, cb) => {
|
|
552
538
|
otherStateToSet = pickState(otherStateToSet);
|
|
553
|
-
|
|
554
|
-
isOpen:
|
|
555
|
-
highlightedIndex:
|
|
539
|
+
this.internalSetState({
|
|
540
|
+
isOpen: this.props.defaultIsOpen,
|
|
541
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
556
542
|
selectedItem: item,
|
|
557
|
-
inputValue:
|
|
558
|
-
|
|
543
|
+
inputValue: this.props.itemToString(item),
|
|
544
|
+
...otherStateToSet
|
|
545
|
+
}, cb);
|
|
559
546
|
};
|
|
560
|
-
|
|
561
|
-
|
|
547
|
+
this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
|
|
548
|
+
const item = this.items[itemIndex];
|
|
562
549
|
if (item == null) {
|
|
563
550
|
return;
|
|
564
551
|
}
|
|
565
|
-
|
|
552
|
+
this.selectItem(item, otherStateToSet, cb);
|
|
566
553
|
};
|
|
567
|
-
|
|
568
|
-
return
|
|
554
|
+
this.selectHighlightedItem = (otherStateToSet, cb) => {
|
|
555
|
+
return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
|
|
569
556
|
};
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
557
|
+
this.internalSetState = (stateToSet, cb) => {
|
|
558
|
+
let isItemSelected, onChangeArg;
|
|
559
|
+
const onStateChangeArg = {};
|
|
560
|
+
const isStateToSetFunction = typeof stateToSet === 'function';
|
|
574
561
|
|
|
575
562
|
// we want to call `onInputValueChange` before the `setState` call
|
|
576
563
|
// so someone controlling the `inputValue` state gets notified of
|
|
@@ -578,21 +565,24 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
578
565
|
// preserving the cursor position.
|
|
579
566
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
580
567
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
581
|
-
|
|
568
|
+
this.props.onInputValueChange(stateToSet.inputValue, {
|
|
569
|
+
...this.getStateAndHelpers(),
|
|
570
|
+
...stateToSet
|
|
571
|
+
});
|
|
582
572
|
}
|
|
583
|
-
return
|
|
584
|
-
state =
|
|
585
|
-
|
|
573
|
+
return this.setState(state => {
|
|
574
|
+
state = this.getState(state);
|
|
575
|
+
let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
|
|
586
576
|
|
|
587
577
|
// Your own function that could modify the state that will be set.
|
|
588
|
-
newStateToSet =
|
|
578
|
+
newStateToSet = this.props.stateReducer(state, newStateToSet);
|
|
589
579
|
|
|
590
580
|
// checks if an item is selected, regardless of if it's different from
|
|
591
581
|
// what was selected before
|
|
592
582
|
// used to determine if onSelect and onChange callbacks should be called
|
|
593
583
|
isItemSelected = newStateToSet.hasOwnProperty('selectedItem');
|
|
594
584
|
// this keeps track of the object we want to call with setState
|
|
595
|
-
|
|
585
|
+
const nextState = {};
|
|
596
586
|
// we need to call on change if the outside world is controlling any of our state
|
|
597
587
|
// and we're trying to update that state. OR if the selection has changed and we're
|
|
598
588
|
// trying to update the selection
|
|
@@ -600,7 +590,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
600
590
|
onChangeArg = newStateToSet.selectedItem;
|
|
601
591
|
}
|
|
602
592
|
newStateToSet.type = newStateToSet.type || unknown;
|
|
603
|
-
Object.keys(newStateToSet).forEach(
|
|
593
|
+
Object.keys(newStateToSet).forEach(key => {
|
|
604
594
|
// onStateChangeArg should only have the state that is
|
|
605
595
|
// actually changing
|
|
606
596
|
if (state[key] !== newStateToSet[key]) {
|
|
@@ -617,7 +607,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
617
607
|
}
|
|
618
608
|
newStateToSet[key];
|
|
619
609
|
// if it's coming from props, then we don't care to set it internally
|
|
620
|
-
if (!isControlledProp(
|
|
610
|
+
if (!isControlledProp(this.props, key)) {
|
|
621
611
|
nextState[key] = newStateToSet[key];
|
|
622
612
|
}
|
|
623
613
|
});
|
|
@@ -625,58 +615,66 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
625
615
|
// if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
626
616
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
627
617
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
628
|
-
|
|
618
|
+
this.props.onInputValueChange(newStateToSet.inputValue, {
|
|
619
|
+
...this.getStateAndHelpers(),
|
|
620
|
+
...newStateToSet
|
|
621
|
+
});
|
|
629
622
|
}
|
|
630
623
|
return nextState;
|
|
631
|
-
},
|
|
624
|
+
}, () => {
|
|
632
625
|
// call the provided callback if it's a function
|
|
633
626
|
cbToCb(cb)();
|
|
634
627
|
|
|
635
628
|
// only call the onStateChange and onChange callbacks if
|
|
636
629
|
// we have relevant information to pass them.
|
|
637
|
-
|
|
630
|
+
const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
638
631
|
if (hasMoreStateThanType) {
|
|
639
|
-
|
|
632
|
+
this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
|
|
640
633
|
}
|
|
641
634
|
if (isItemSelected) {
|
|
642
|
-
|
|
635
|
+
this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
|
|
643
636
|
}
|
|
644
637
|
if (onChangeArg !== undefined) {
|
|
645
|
-
|
|
638
|
+
this.props.onChange(onChangeArg, this.getStateAndHelpers());
|
|
646
639
|
}
|
|
647
640
|
// this is currently undocumented and therefore subject to change
|
|
648
641
|
// We'll try to not break it, but just be warned.
|
|
649
|
-
|
|
642
|
+
this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
|
|
650
643
|
});
|
|
651
644
|
};
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
663
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
664
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
645
|
+
this.rootRef = node => this._rootNode = node;
|
|
646
|
+
this.getRootProps = function (_temp, _temp2) {
|
|
647
|
+
let {
|
|
648
|
+
refKey = 'ref',
|
|
649
|
+
ref,
|
|
650
|
+
...rest
|
|
651
|
+
} = _temp === void 0 ? {} : _temp;
|
|
652
|
+
let {
|
|
653
|
+
suppressRefError = false
|
|
654
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
665
655
|
// this is used in the render to know whether the user has called getRootProps.
|
|
666
656
|
// It uses that to know whether to apply the props automatically
|
|
667
657
|
_this.getRootProps.called = true;
|
|
668
658
|
_this.getRootProps.refKey = refKey;
|
|
669
659
|
_this.getRootProps.suppressRefError = suppressRefError;
|
|
670
|
-
|
|
671
|
-
isOpen
|
|
672
|
-
|
|
660
|
+
const {
|
|
661
|
+
isOpen
|
|
662
|
+
} = _this.getState();
|
|
663
|
+
return {
|
|
664
|
+
[refKey]: handleRefs(ref, _this.rootRef),
|
|
665
|
+
role: 'combobox',
|
|
666
|
+
'aria-expanded': isOpen,
|
|
667
|
+
'aria-haspopup': 'listbox',
|
|
668
|
+
'aria-owns': isOpen ? _this.menuId : null,
|
|
669
|
+
'aria-labelledby': _this.labelId,
|
|
670
|
+
...rest
|
|
671
|
+
};
|
|
673
672
|
};
|
|
674
|
-
|
|
675
|
-
ArrowDown
|
|
676
|
-
var _this2 = this;
|
|
673
|
+
this.keyDownHandlers = {
|
|
674
|
+
ArrowDown(event) {
|
|
677
675
|
event.preventDefault();
|
|
678
676
|
if (this.getState().isOpen) {
|
|
679
|
-
|
|
677
|
+
const amount = event.shiftKey ? 5 : 1;
|
|
680
678
|
this.moveHighlightedIndex(amount, {
|
|
681
679
|
type: keyDownArrowDown
|
|
682
680
|
});
|
|
@@ -684,26 +682,24 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
684
682
|
this.internalSetState({
|
|
685
683
|
isOpen: true,
|
|
686
684
|
type: keyDownArrowDown
|
|
687
|
-
},
|
|
688
|
-
|
|
685
|
+
}, () => {
|
|
686
|
+
const itemCount = this.getItemCount();
|
|
689
687
|
if (itemCount > 0) {
|
|
690
|
-
|
|
691
|
-
highlightedIndex
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
_this2.setHighlightedIndex(nextHighlightedIndex, {
|
|
688
|
+
const {
|
|
689
|
+
highlightedIndex
|
|
690
|
+
} = this.getState();
|
|
691
|
+
const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
692
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
696
693
|
type: keyDownArrowDown
|
|
697
694
|
});
|
|
698
695
|
}
|
|
699
696
|
});
|
|
700
697
|
}
|
|
701
698
|
},
|
|
702
|
-
ArrowUp
|
|
703
|
-
var _this3 = this;
|
|
699
|
+
ArrowUp(event) {
|
|
704
700
|
event.preventDefault();
|
|
705
701
|
if (this.getState().isOpen) {
|
|
706
|
-
|
|
702
|
+
const amount = event.shiftKey ? -5 : -1;
|
|
707
703
|
this.moveHighlightedIndex(amount, {
|
|
708
704
|
type: keyDownArrowUp
|
|
709
705
|
});
|
|
@@ -711,32 +707,32 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
711
707
|
this.internalSetState({
|
|
712
708
|
isOpen: true,
|
|
713
709
|
type: keyDownArrowUp
|
|
714
|
-
},
|
|
715
|
-
|
|
710
|
+
}, () => {
|
|
711
|
+
const itemCount = this.getItemCount();
|
|
716
712
|
if (itemCount > 0) {
|
|
717
|
-
|
|
718
|
-
highlightedIndex
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
_this3.setHighlightedIndex(nextHighlightedIndex, {
|
|
713
|
+
const {
|
|
714
|
+
highlightedIndex
|
|
715
|
+
} = this.getState();
|
|
716
|
+
const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
717
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
723
718
|
type: keyDownArrowUp
|
|
724
719
|
});
|
|
725
720
|
}
|
|
726
721
|
});
|
|
727
722
|
}
|
|
728
723
|
},
|
|
729
|
-
Enter
|
|
724
|
+
Enter(event) {
|
|
730
725
|
if (event.which === 229) {
|
|
731
726
|
return;
|
|
732
727
|
}
|
|
733
|
-
|
|
734
|
-
isOpen
|
|
735
|
-
highlightedIndex
|
|
728
|
+
const {
|
|
729
|
+
isOpen,
|
|
730
|
+
highlightedIndex
|
|
731
|
+
} = this.getState();
|
|
736
732
|
if (isOpen && highlightedIndex != null) {
|
|
737
733
|
event.preventDefault();
|
|
738
|
-
|
|
739
|
-
|
|
734
|
+
const item = this.items[highlightedIndex];
|
|
735
|
+
const itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
740
736
|
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
741
737
|
return;
|
|
742
738
|
}
|
|
@@ -745,176 +741,181 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
745
741
|
});
|
|
746
742
|
}
|
|
747
743
|
},
|
|
748
|
-
Escape
|
|
744
|
+
Escape(event) {
|
|
749
745
|
event.preventDefault();
|
|
750
|
-
this.reset(
|
|
751
|
-
type: keyDownEscape
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
746
|
+
this.reset({
|
|
747
|
+
type: keyDownEscape,
|
|
748
|
+
...(!this.state.isOpen && {
|
|
749
|
+
selectedItem: null,
|
|
750
|
+
inputValue: ''
|
|
751
|
+
})
|
|
752
|
+
});
|
|
756
753
|
}
|
|
757
754
|
};
|
|
758
|
-
|
|
759
|
-
|
|
755
|
+
this.buttonKeyDownHandlers = {
|
|
756
|
+
...this.keyDownHandlers,
|
|
757
|
+
' '(event) {
|
|
760
758
|
event.preventDefault();
|
|
761
759
|
this.toggleMenu({
|
|
762
760
|
type: keyDownSpaceButton
|
|
763
761
|
});
|
|
764
762
|
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
isOpen
|
|
763
|
+
};
|
|
764
|
+
this.inputKeyDownHandlers = {
|
|
765
|
+
...this.keyDownHandlers,
|
|
766
|
+
Home(event) {
|
|
767
|
+
const {
|
|
768
|
+
isOpen
|
|
769
|
+
} = this.getState();
|
|
771
770
|
if (!isOpen) {
|
|
772
771
|
return;
|
|
773
772
|
}
|
|
774
773
|
event.preventDefault();
|
|
775
|
-
|
|
774
|
+
const itemCount = this.getItemCount();
|
|
776
775
|
if (itemCount <= 0 || !isOpen) {
|
|
777
776
|
return;
|
|
778
777
|
}
|
|
779
778
|
|
|
780
779
|
// get next non-disabled starting downwards from 0 if that's disabled.
|
|
781
|
-
|
|
782
|
-
return _this4.getItemNodeFromIndex(index);
|
|
783
|
-
}, false);
|
|
780
|
+
const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
784
781
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
785
782
|
type: keyDownHome
|
|
786
783
|
});
|
|
787
784
|
},
|
|
788
|
-
End
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
785
|
+
End(event) {
|
|
786
|
+
const {
|
|
787
|
+
isOpen
|
|
788
|
+
} = this.getState();
|
|
792
789
|
if (!isOpen) {
|
|
793
790
|
return;
|
|
794
791
|
}
|
|
795
792
|
event.preventDefault();
|
|
796
|
-
|
|
793
|
+
const itemCount = this.getItemCount();
|
|
797
794
|
if (itemCount <= 0 || !isOpen) {
|
|
798
795
|
return;
|
|
799
796
|
}
|
|
800
797
|
|
|
801
798
|
// get next non-disabled starting upwards from last index if that's disabled.
|
|
802
|
-
|
|
803
|
-
return _this5.getItemNodeFromIndex(index);
|
|
804
|
-
}, false);
|
|
799
|
+
const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
805
800
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
806
801
|
type: keyDownEnd
|
|
807
802
|
});
|
|
808
803
|
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
804
|
+
};
|
|
805
|
+
this.getToggleButtonProps = function (_temp3) {
|
|
806
|
+
let {
|
|
807
|
+
onClick,
|
|
808
|
+
onPress,
|
|
809
|
+
onKeyDown,
|
|
810
|
+
onKeyUp,
|
|
811
|
+
onBlur,
|
|
812
|
+
...rest
|
|
813
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
814
|
+
const {
|
|
815
|
+
isOpen
|
|
816
|
+
} = _this.getState();
|
|
817
|
+
const enabledEventHandlers = /* istanbul ignore next (react-native) */
|
|
821
818
|
{
|
|
822
819
|
onPress: callAllEventHandlers(onPress, _this.buttonHandleClick)
|
|
823
820
|
} ;
|
|
824
|
-
|
|
825
|
-
return
|
|
821
|
+
const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
822
|
+
return {
|
|
826
823
|
type: 'button',
|
|
827
824
|
role: 'button',
|
|
828
825
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
829
826
|
'aria-haspopup': true,
|
|
830
|
-
'data-toggle': true
|
|
831
|
-
|
|
827
|
+
'data-toggle': true,
|
|
828
|
+
...eventHandlers,
|
|
829
|
+
...rest
|
|
830
|
+
};
|
|
832
831
|
};
|
|
833
|
-
|
|
832
|
+
this.buttonHandleKeyUp = event => {
|
|
834
833
|
// Prevent click event from emitting in Firefox
|
|
835
834
|
event.preventDefault();
|
|
836
835
|
};
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
if (
|
|
840
|
-
|
|
836
|
+
this.buttonHandleKeyDown = event => {
|
|
837
|
+
const key = normalizeArrowKey(event);
|
|
838
|
+
if (this.buttonKeyDownHandlers[key]) {
|
|
839
|
+
this.buttonKeyDownHandlers[key].call(this, event);
|
|
841
840
|
}
|
|
842
841
|
};
|
|
843
|
-
|
|
842
|
+
this.buttonHandleClick = event => {
|
|
844
843
|
event.preventDefault();
|
|
845
844
|
// to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
846
845
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
847
846
|
// when building for production and should therefore have no impact on production code.
|
|
848
847
|
if (process.env.NODE_ENV === 'test') {
|
|
849
|
-
|
|
848
|
+
this.toggleMenu({
|
|
850
849
|
type: clickButton
|
|
851
850
|
});
|
|
852
851
|
} else {
|
|
853
852
|
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
});
|
|
858
|
-
});
|
|
853
|
+
this.internalSetTimeout(() => this.toggleMenu({
|
|
854
|
+
type: clickButton
|
|
855
|
+
}));
|
|
859
856
|
}
|
|
860
857
|
};
|
|
861
|
-
|
|
862
|
-
|
|
858
|
+
this.buttonHandleBlur = event => {
|
|
859
|
+
const blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
863
860
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
864
|
-
|
|
865
|
-
if (!
|
|
861
|
+
this.internalSetTimeout(() => {
|
|
862
|
+
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)
|
|
866
863
|
) {
|
|
867
|
-
|
|
864
|
+
this.reset({
|
|
868
865
|
type: blurButton
|
|
869
866
|
});
|
|
870
867
|
}
|
|
871
868
|
});
|
|
872
869
|
};
|
|
873
|
-
|
|
874
|
-
return
|
|
875
|
-
htmlFor:
|
|
876
|
-
id:
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
870
|
+
this.getLabelProps = props => {
|
|
871
|
+
return {
|
|
872
|
+
htmlFor: this.inputId,
|
|
873
|
+
id: this.labelId,
|
|
874
|
+
...props
|
|
875
|
+
};
|
|
876
|
+
};
|
|
877
|
+
this.getInputProps = function (_temp4) {
|
|
878
|
+
let {
|
|
879
|
+
onKeyDown,
|
|
880
|
+
onBlur,
|
|
881
|
+
onChange,
|
|
882
|
+
onInput,
|
|
883
|
+
onChangeText,
|
|
884
|
+
...rest
|
|
885
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
886
|
+
let onChangeKey;
|
|
887
|
+
let eventHandlers = {};
|
|
889
888
|
|
|
890
889
|
/* istanbul ignore next (preact) */
|
|
891
890
|
{
|
|
892
891
|
onChangeKey = 'onChange';
|
|
893
892
|
}
|
|
894
|
-
|
|
895
|
-
inputValue
|
|
896
|
-
isOpen
|
|
897
|
-
highlightedIndex
|
|
893
|
+
const {
|
|
894
|
+
inputValue,
|
|
895
|
+
isOpen,
|
|
896
|
+
highlightedIndex
|
|
897
|
+
} = _this.getState();
|
|
898
898
|
if (!rest.disabled) {
|
|
899
|
-
|
|
900
|
-
|
|
899
|
+
eventHandlers = {
|
|
900
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
|
|
901
|
+
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
|
|
902
|
+
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
903
|
+
};
|
|
901
904
|
}
|
|
902
905
|
|
|
903
906
|
/* istanbul ignore if (react-native) */
|
|
904
907
|
{
|
|
905
908
|
eventHandlers = {
|
|
906
909
|
onChange: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
|
|
907
|
-
onChangeText: callAllEventHandlers(onChangeText, onInput,
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
});
|
|
913
|
-
}),
|
|
910
|
+
onChangeText: callAllEventHandlers(onChangeText, onInput, text => _this.inputHandleChange({
|
|
911
|
+
nativeEvent: {
|
|
912
|
+
text
|
|
913
|
+
}
|
|
914
|
+
})),
|
|
914
915
|
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
915
916
|
};
|
|
916
917
|
}
|
|
917
|
-
return
|
|
918
|
+
return {
|
|
918
919
|
'aria-autocomplete': 'list',
|
|
919
920
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
920
921
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -923,76 +924,82 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
923
924
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
924
925
|
autoComplete: 'off',
|
|
925
926
|
value: inputValue,
|
|
926
|
-
id: _this.inputId
|
|
927
|
-
|
|
927
|
+
id: _this.inputId,
|
|
928
|
+
...eventHandlers,
|
|
929
|
+
...rest
|
|
930
|
+
};
|
|
928
931
|
};
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
if (key &&
|
|
932
|
-
|
|
932
|
+
this.inputHandleKeyDown = event => {
|
|
933
|
+
const key = normalizeArrowKey(event);
|
|
934
|
+
if (key && this.inputKeyDownHandlers[key]) {
|
|
935
|
+
this.inputKeyDownHandlers[key].call(this, event);
|
|
933
936
|
}
|
|
934
937
|
};
|
|
935
|
-
|
|
936
|
-
|
|
938
|
+
this.inputHandleChange = event => {
|
|
939
|
+
this.internalSetState({
|
|
937
940
|
type: changeInput,
|
|
938
941
|
isOpen: true,
|
|
939
942
|
inputValue: /* istanbul ignore next (react-native) */event.nativeEvent.text ,
|
|
940
|
-
highlightedIndex:
|
|
943
|
+
highlightedIndex: this.props.defaultHighlightedIndex
|
|
941
944
|
});
|
|
942
945
|
};
|
|
943
|
-
|
|
946
|
+
this.inputHandleBlur = () => {
|
|
944
947
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
if (!
|
|
948
|
-
|
|
948
|
+
this.internalSetTimeout(() => {
|
|
949
|
+
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);
|
|
950
|
+
if (!this.isMouseDown && !downshiftButtonIsActive) {
|
|
951
|
+
this.reset({
|
|
949
952
|
type: blurInput
|
|
950
953
|
});
|
|
951
954
|
}
|
|
952
955
|
});
|
|
953
956
|
};
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
957
|
+
this.menuRef = node => {
|
|
958
|
+
this._menuNode = node;
|
|
959
|
+
};
|
|
960
|
+
this.getMenuProps = function (_temp5, _temp6) {
|
|
961
|
+
let {
|
|
962
|
+
refKey = 'ref',
|
|
963
|
+
ref,
|
|
964
|
+
...props
|
|
965
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
966
|
+
let {
|
|
967
|
+
suppressRefError = false
|
|
968
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
967
969
|
_this.getMenuProps.called = true;
|
|
968
970
|
_this.getMenuProps.refKey = refKey;
|
|
969
971
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
970
|
-
return
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
972
|
+
return {
|
|
973
|
+
[refKey]: handleRefs(ref, _this.menuRef),
|
|
974
|
+
role: 'listbox',
|
|
975
|
+
'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
|
|
976
|
+
id: _this.menuId,
|
|
977
|
+
...props
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
this.getItemProps = function (_temp7) {
|
|
981
|
+
let {
|
|
982
|
+
onMouseMove,
|
|
983
|
+
onMouseDown,
|
|
984
|
+
onClick,
|
|
985
|
+
onPress,
|
|
986
|
+
index,
|
|
987
|
+
item = process.env.NODE_ENV === 'production' ? /* istanbul ignore next */undefined : requiredProp('getItemProps', 'item'),
|
|
988
|
+
...rest
|
|
989
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
983
990
|
if (index === undefined) {
|
|
984
991
|
_this.items.push(item);
|
|
985
992
|
index = _this.items.indexOf(item);
|
|
986
993
|
} else {
|
|
987
994
|
_this.items[index] = item;
|
|
988
995
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
996
|
+
const onSelectKey = /* istanbul ignore next (react-native) */'onPress' ;
|
|
997
|
+
const customClickHandler = /* istanbul ignore next (react-native) */onPress ;
|
|
998
|
+
const enabledEventHandlers = {
|
|
992
999
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
993
1000
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
994
1001
|
// can fire on DOM changes, interrupting keyboard navigation
|
|
995
|
-
onMouseMove: callAllEventHandlers(onMouseMove,
|
|
1002
|
+
onMouseMove: callAllEventHandlers(onMouseMove, () => {
|
|
996
1003
|
if (index === _this.getState().highlightedIndex) {
|
|
997
1004
|
return;
|
|
998
1005
|
}
|
|
@@ -1005,66 +1012,75 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1005
1012
|
// from under the user which is currently scrolling/moving the
|
|
1006
1013
|
// cursor
|
|
1007
1014
|
_this.avoidScrolling = true;
|
|
1008
|
-
_this.internalSetTimeout(
|
|
1009
|
-
return _this.avoidScrolling = false;
|
|
1010
|
-
}, 250);
|
|
1015
|
+
_this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
|
|
1011
1016
|
}),
|
|
1012
|
-
onMouseDown: callAllEventHandlers(onMouseDown,
|
|
1017
|
+
onMouseDown: callAllEventHandlers(onMouseDown, event => {
|
|
1013
1018
|
// This prevents the activeElement from being changed
|
|
1014
1019
|
// to the item so it can remain with the current activeElement
|
|
1015
1020
|
// which is a more common use case.
|
|
1016
1021
|
event.preventDefault();
|
|
1022
|
+
}),
|
|
1023
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, () => {
|
|
1024
|
+
_this.selectItemAtIndex(index, {
|
|
1025
|
+
type: clickItem
|
|
1026
|
+
});
|
|
1017
1027
|
})
|
|
1018
|
-
}
|
|
1019
|
-
_this.selectItemAtIndex(index, {
|
|
1020
|
-
type: clickItem
|
|
1021
|
-
});
|
|
1022
|
-
}), _enabledEventHandlers);
|
|
1028
|
+
};
|
|
1023
1029
|
|
|
1024
1030
|
// Passing down the onMouseDown handler to prevent redirect
|
|
1025
1031
|
// of the activeElement if clicking on disabled items
|
|
1026
|
-
|
|
1032
|
+
const eventHandlers = rest.disabled ? {
|
|
1027
1033
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
1028
1034
|
} : enabledEventHandlers;
|
|
1029
|
-
return
|
|
1035
|
+
return {
|
|
1030
1036
|
id: _this.getItemId(index),
|
|
1031
1037
|
role: 'option',
|
|
1032
|
-
'aria-selected': _this.getState().highlightedIndex === index
|
|
1033
|
-
|
|
1038
|
+
'aria-selected': _this.getState().highlightedIndex === index,
|
|
1039
|
+
...eventHandlers,
|
|
1040
|
+
...rest
|
|
1041
|
+
};
|
|
1034
1042
|
};
|
|
1035
|
-
|
|
1036
|
-
|
|
1043
|
+
this.clearItems = () => {
|
|
1044
|
+
this.items = [];
|
|
1037
1045
|
};
|
|
1038
|
-
|
|
1046
|
+
this.reset = function (otherStateToSet, cb) {
|
|
1039
1047
|
if (otherStateToSet === void 0) {
|
|
1040
1048
|
otherStateToSet = {};
|
|
1041
1049
|
}
|
|
1042
1050
|
otherStateToSet = pickState(otherStateToSet);
|
|
1043
|
-
_this.internalSetState(
|
|
1044
|
-
|
|
1045
|
-
|
|
1051
|
+
_this.internalSetState(_ref => {
|
|
1052
|
+
let {
|
|
1053
|
+
selectedItem
|
|
1054
|
+
} = _ref;
|
|
1055
|
+
return {
|
|
1046
1056
|
isOpen: _this.props.defaultIsOpen,
|
|
1047
1057
|
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1048
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
1049
|
-
|
|
1058
|
+
inputValue: _this.props.itemToString(selectedItem),
|
|
1059
|
+
...otherStateToSet
|
|
1060
|
+
};
|
|
1050
1061
|
}, cb);
|
|
1051
1062
|
};
|
|
1052
|
-
|
|
1063
|
+
this.toggleMenu = function (otherStateToSet, cb) {
|
|
1053
1064
|
if (otherStateToSet === void 0) {
|
|
1054
1065
|
otherStateToSet = {};
|
|
1055
1066
|
}
|
|
1056
1067
|
otherStateToSet = pickState(otherStateToSet);
|
|
1057
|
-
_this.internalSetState(
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
+
_this.internalSetState(_ref2 => {
|
|
1069
|
+
let {
|
|
1070
|
+
isOpen
|
|
1071
|
+
} = _ref2;
|
|
1072
|
+
return {
|
|
1073
|
+
isOpen: !isOpen,
|
|
1074
|
+
...(isOpen && {
|
|
1075
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
1076
|
+
}),
|
|
1077
|
+
...otherStateToSet
|
|
1078
|
+
};
|
|
1079
|
+
}, () => {
|
|
1080
|
+
const {
|
|
1081
|
+
isOpen,
|
|
1082
|
+
highlightedIndex
|
|
1083
|
+
} = _this.getState();
|
|
1068
1084
|
if (isOpen) {
|
|
1069
1085
|
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
1070
1086
|
_this.setHighlightedIndex(highlightedIndex, otherStateToSet);
|
|
@@ -1073,58 +1089,57 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1073
1089
|
cbToCb(cb)();
|
|
1074
1090
|
});
|
|
1075
1091
|
};
|
|
1076
|
-
|
|
1077
|
-
|
|
1092
|
+
this.openMenu = cb => {
|
|
1093
|
+
this.internalSetState({
|
|
1078
1094
|
isOpen: true
|
|
1079
1095
|
}, cb);
|
|
1080
1096
|
};
|
|
1081
|
-
|
|
1082
|
-
|
|
1097
|
+
this.closeMenu = cb => {
|
|
1098
|
+
this.internalSetState({
|
|
1083
1099
|
isOpen: false
|
|
1084
1100
|
}, cb);
|
|
1085
1101
|
};
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
itemToString:
|
|
1092
|
-
previousResultCount:
|
|
1093
|
-
resultCount
|
|
1094
|
-
highlightedItem: item
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1102
|
+
this.updateStatus = debounce(() => {
|
|
1103
|
+
const state = this.getState();
|
|
1104
|
+
const item = this.items[state.highlightedIndex];
|
|
1105
|
+
const resultCount = this.getItemCount();
|
|
1106
|
+
const status = this.props.getA11yStatusMessage({
|
|
1107
|
+
itemToString: this.props.itemToString,
|
|
1108
|
+
previousResultCount: this.previousResultCount,
|
|
1109
|
+
resultCount,
|
|
1110
|
+
highlightedItem: item,
|
|
1111
|
+
...state
|
|
1112
|
+
});
|
|
1113
|
+
this.previousResultCount = resultCount;
|
|
1114
|
+
setStatus(status, this.props.environment.document);
|
|
1098
1115
|
}, 200);
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
_inputValue =
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1116
|
+
// fancy destructuring + defaults + aliases
|
|
1117
|
+
// this basically says each value of state should either be set to
|
|
1118
|
+
// the initial value or the default value if the initial value is not provided
|
|
1119
|
+
const {
|
|
1120
|
+
defaultHighlightedIndex,
|
|
1121
|
+
initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
|
|
1122
|
+
defaultIsOpen,
|
|
1123
|
+
initialIsOpen: _isOpen = defaultIsOpen,
|
|
1124
|
+
initialInputValue: _inputValue = '',
|
|
1125
|
+
initialSelectedItem: _selectedItem = null
|
|
1126
|
+
} = this.props;
|
|
1127
|
+
const _state = this.getState({
|
|
1111
1128
|
highlightedIndex: _highlightedIndex,
|
|
1112
1129
|
isOpen: _isOpen,
|
|
1113
1130
|
inputValue: _inputValue,
|
|
1114
1131
|
selectedItem: _selectedItem
|
|
1115
1132
|
});
|
|
1116
|
-
if (_state.selectedItem != null &&
|
|
1117
|
-
_state.inputValue =
|
|
1133
|
+
if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
|
|
1134
|
+
_state.inputValue = this.props.itemToString(_state.selectedItem);
|
|
1118
1135
|
}
|
|
1119
|
-
|
|
1120
|
-
return _this;
|
|
1136
|
+
this.state = _state;
|
|
1121
1137
|
}
|
|
1122
|
-
var _proto = Downshift.prototype;
|
|
1123
1138
|
/**
|
|
1124
1139
|
* Clear all running timeouts
|
|
1125
1140
|
*/
|
|
1126
|
-
|
|
1127
|
-
this.timeoutIds.forEach(
|
|
1141
|
+
internalClearTimeouts() {
|
|
1142
|
+
this.timeoutIds.forEach(id => {
|
|
1128
1143
|
clearTimeout(id);
|
|
1129
1144
|
});
|
|
1130
1145
|
this.timeoutIds = [];
|
|
@@ -1138,108 +1153,112 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1138
1153
|
*
|
|
1139
1154
|
* @param {Object} stateToMerge defaults to this.state
|
|
1140
1155
|
* @return {Object} the state
|
|
1141
|
-
|
|
1142
|
-
|
|
1156
|
+
*/
|
|
1157
|
+
getState(stateToMerge) {
|
|
1143
1158
|
if (stateToMerge === void 0) {
|
|
1144
1159
|
stateToMerge = this.state;
|
|
1145
1160
|
}
|
|
1146
1161
|
return getState(stateToMerge, this.props);
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1162
|
+
}
|
|
1163
|
+
getItemCount() {
|
|
1149
1164
|
// things read better this way. They're in priority order:
|
|
1150
1165
|
// 1. `this.itemCount`
|
|
1151
1166
|
// 2. `this.props.itemCount`
|
|
1152
1167
|
// 3. `this.items.length`
|
|
1153
|
-
|
|
1168
|
+
let itemCount = this.items.length;
|
|
1154
1169
|
if (this.itemCount != null) {
|
|
1155
1170
|
itemCount = this.itemCount;
|
|
1156
1171
|
} else if (this.props.itemCount !== undefined) {
|
|
1157
1172
|
itemCount = this.props.itemCount;
|
|
1158
1173
|
}
|
|
1159
1174
|
return itemCount;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1175
|
+
}
|
|
1176
|
+
getItemNodeFromIndex(index) {
|
|
1162
1177
|
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1178
|
+
}
|
|
1179
|
+
scrollHighlightedItemIntoView() {
|
|
1180
|
+
}
|
|
1181
|
+
moveHighlightedIndex(amount, otherStateToSet) {
|
|
1182
|
+
const itemCount = this.getItemCount();
|
|
1183
|
+
const {
|
|
1184
|
+
highlightedIndex
|
|
1185
|
+
} = this.getState();
|
|
1171
1186
|
if (itemCount > 0) {
|
|
1172
|
-
|
|
1173
|
-
return _this6.getItemNodeFromIndex(index);
|
|
1174
|
-
});
|
|
1187
|
+
const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
1175
1188
|
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
1176
1189
|
}
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
highlightedIndex
|
|
1181
|
-
inputValue
|
|
1182
|
-
selectedItem
|
|
1183
|
-
isOpen
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1190
|
+
}
|
|
1191
|
+
getStateAndHelpers() {
|
|
1192
|
+
const {
|
|
1193
|
+
highlightedIndex,
|
|
1194
|
+
inputValue,
|
|
1195
|
+
selectedItem,
|
|
1196
|
+
isOpen
|
|
1197
|
+
} = this.getState();
|
|
1198
|
+
const {
|
|
1199
|
+
itemToString
|
|
1200
|
+
} = this.props;
|
|
1201
|
+
const {
|
|
1202
|
+
id
|
|
1203
|
+
} = this;
|
|
1204
|
+
const {
|
|
1205
|
+
getRootProps,
|
|
1206
|
+
getToggleButtonProps,
|
|
1207
|
+
getLabelProps,
|
|
1208
|
+
getMenuProps,
|
|
1209
|
+
getInputProps,
|
|
1210
|
+
getItemProps,
|
|
1211
|
+
openMenu,
|
|
1212
|
+
closeMenu,
|
|
1213
|
+
toggleMenu,
|
|
1214
|
+
selectItem,
|
|
1215
|
+
selectItemAtIndex,
|
|
1216
|
+
selectHighlightedItem,
|
|
1217
|
+
setHighlightedIndex,
|
|
1218
|
+
clearSelection,
|
|
1219
|
+
clearItems,
|
|
1220
|
+
reset,
|
|
1221
|
+
setItemCount,
|
|
1222
|
+
unsetItemCount,
|
|
1223
|
+
internalSetState: setState
|
|
1224
|
+
} = this;
|
|
1205
1225
|
return {
|
|
1206
1226
|
// prop getters
|
|
1207
|
-
getRootProps
|
|
1208
|
-
getToggleButtonProps
|
|
1209
|
-
getLabelProps
|
|
1210
|
-
getMenuProps
|
|
1211
|
-
getInputProps
|
|
1212
|
-
getItemProps
|
|
1227
|
+
getRootProps,
|
|
1228
|
+
getToggleButtonProps,
|
|
1229
|
+
getLabelProps,
|
|
1230
|
+
getMenuProps,
|
|
1231
|
+
getInputProps,
|
|
1232
|
+
getItemProps,
|
|
1213
1233
|
// actions
|
|
1214
|
-
reset
|
|
1215
|
-
openMenu
|
|
1216
|
-
closeMenu
|
|
1217
|
-
toggleMenu
|
|
1218
|
-
selectItem
|
|
1219
|
-
selectItemAtIndex
|
|
1220
|
-
selectHighlightedItem
|
|
1221
|
-
setHighlightedIndex
|
|
1222
|
-
clearSelection
|
|
1223
|
-
clearItems
|
|
1224
|
-
setItemCount
|
|
1225
|
-
unsetItemCount
|
|
1226
|
-
setState
|
|
1234
|
+
reset,
|
|
1235
|
+
openMenu,
|
|
1236
|
+
closeMenu,
|
|
1237
|
+
toggleMenu,
|
|
1238
|
+
selectItem,
|
|
1239
|
+
selectItemAtIndex,
|
|
1240
|
+
selectHighlightedItem,
|
|
1241
|
+
setHighlightedIndex,
|
|
1242
|
+
clearSelection,
|
|
1243
|
+
clearItems,
|
|
1244
|
+
setItemCount,
|
|
1245
|
+
unsetItemCount,
|
|
1246
|
+
setState,
|
|
1227
1247
|
// props
|
|
1228
|
-
itemToString
|
|
1248
|
+
itemToString,
|
|
1229
1249
|
// derived
|
|
1230
|
-
id
|
|
1250
|
+
id,
|
|
1231
1251
|
// state
|
|
1232
|
-
highlightedIndex
|
|
1233
|
-
inputValue
|
|
1234
|
-
isOpen
|
|
1235
|
-
selectedItem
|
|
1252
|
+
highlightedIndex,
|
|
1253
|
+
inputValue,
|
|
1254
|
+
isOpen,
|
|
1255
|
+
selectedItem
|
|
1236
1256
|
};
|
|
1237
1257
|
}
|
|
1238
1258
|
|
|
1239
1259
|
//////////////////////////// ROOT
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
var _this7 = this;
|
|
1260
|
+
|
|
1261
|
+
componentDidMount() {
|
|
1243
1262
|
/* istanbul ignore if (react-native) */
|
|
1244
1263
|
if (process.env.NODE_ENV !== 'production' && !true && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
1245
1264
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
@@ -1247,21 +1266,23 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1247
1266
|
|
|
1248
1267
|
/* istanbul ignore if (react-native) */
|
|
1249
1268
|
{
|
|
1250
|
-
this.cleanup =
|
|
1251
|
-
|
|
1269
|
+
this.cleanup = () => {
|
|
1270
|
+
this.internalClearTimeouts();
|
|
1252
1271
|
};
|
|
1253
1272
|
}
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
currentHighlightedIndex
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1273
|
+
}
|
|
1274
|
+
shouldScroll(prevState, prevProps) {
|
|
1275
|
+
const {
|
|
1276
|
+
highlightedIndex: currentHighlightedIndex
|
|
1277
|
+
} = this.props.highlightedIndex === undefined ? this.getState() : this.props;
|
|
1278
|
+
const {
|
|
1279
|
+
highlightedIndex: prevHighlightedIndex
|
|
1280
|
+
} = prevProps.highlightedIndex === undefined ? prevState : prevProps;
|
|
1281
|
+
const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
1282
|
+
const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
1262
1283
|
return scrollWhenOpen || scrollWhenNavigating;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1284
|
+
}
|
|
1285
|
+
componentDidUpdate(prevProps, prevState) {
|
|
1265
1286
|
if (process.env.NODE_ENV !== 'production') {
|
|
1266
1287
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
1267
1288
|
}
|
|
@@ -1274,12 +1295,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1274
1295
|
if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
|
|
1275
1296
|
this.scrollHighlightedItemIntoView();
|
|
1276
1297
|
}
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1298
|
+
}
|
|
1299
|
+
componentWillUnmount() {
|
|
1279
1300
|
this.cleanup(); // avoids memory leak
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
render() {
|
|
1304
|
+
const children = unwrapArray(this.props.children, noop);
|
|
1283
1305
|
// because the items are rerendered every time we call the children
|
|
1284
1306
|
// we clear this out each render and it will be populated again as
|
|
1285
1307
|
// getItemProps is called.
|
|
@@ -1299,7 +1321,7 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1299
1321
|
this.getLabelProps.called = false;
|
|
1300
1322
|
// and something similar for getInputProps
|
|
1301
1323
|
this.getInputProps.called = false;
|
|
1302
|
-
|
|
1324
|
+
const element = unwrapArray(children(this.getStateAndHelpers()));
|
|
1303
1325
|
if (!element) {
|
|
1304
1326
|
return null;
|
|
1305
1327
|
}
|
|
@@ -1324,14 +1346,13 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1324
1346
|
|
|
1325
1347
|
/* istanbul ignore next */
|
|
1326
1348
|
return undefined;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
}(react.Component);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1330
1351
|
Downshift.defaultProps = {
|
|
1331
1352
|
defaultHighlightedIndex: null,
|
|
1332
1353
|
defaultIsOpen: false,
|
|
1333
1354
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
1334
|
-
itemToString:
|
|
1355
|
+
itemToString: i => {
|
|
1335
1356
|
if (i == null) {
|
|
1336
1357
|
return '';
|
|
1337
1358
|
}
|
|
@@ -1347,20 +1368,16 @@ var Downshift = /*#__PURE__*/function () {
|
|
|
1347
1368
|
onChange: noop,
|
|
1348
1369
|
onSelect: noop,
|
|
1349
1370
|
onOuterClick: noop,
|
|
1350
|
-
selectedItemChanged:
|
|
1351
|
-
return prevItem !== item;
|
|
1352
|
-
},
|
|
1371
|
+
selectedItemChanged: (prevItem, item) => prevItem !== item,
|
|
1353
1372
|
environment: /* istanbul ignore next (ssr) */
|
|
1354
1373
|
typeof window === 'undefined' ? {} : window,
|
|
1355
|
-
stateReducer:
|
|
1356
|
-
return stateToSet;
|
|
1357
|
-
},
|
|
1374
|
+
stateReducer: (state, stateToSet) => stateToSet,
|
|
1358
1375
|
suppressRefError: false,
|
|
1359
|
-
scrollIntoView
|
|
1376
|
+
scrollIntoView
|
|
1360
1377
|
};
|
|
1361
1378
|
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
1362
1379
|
return Downshift;
|
|
1363
|
-
}();
|
|
1380
|
+
})();
|
|
1364
1381
|
process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
|
|
1365
1382
|
children: PropTypes__default["default"].func,
|
|
1366
1383
|
defaultHighlightedIndex: PropTypes__default["default"].number,
|
|
@@ -1406,61 +1423,70 @@ process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
|
|
|
1406
1423
|
/* eslint-enable react/no-unused-prop-types */
|
|
1407
1424
|
} : void 0;
|
|
1408
1425
|
var Downshift$1 = Downshift;
|
|
1409
|
-
function validateGetMenuPropsCalledCorrectly(node,
|
|
1410
|
-
|
|
1426
|
+
function validateGetMenuPropsCalledCorrectly(node, _ref3) {
|
|
1427
|
+
let {
|
|
1428
|
+
refKey
|
|
1429
|
+
} = _ref3;
|
|
1411
1430
|
if (!node) {
|
|
1412
1431
|
// eslint-disable-next-line no-console
|
|
1413
|
-
console.error(
|
|
1432
|
+
console.error(`downshift: The ref prop "${refKey}" from getMenuProps was not applied correctly on your menu element.`);
|
|
1414
1433
|
}
|
|
1415
1434
|
}
|
|
1416
|
-
function validateGetRootPropsCalledCorrectly(element,
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1435
|
+
function validateGetRootPropsCalledCorrectly(element, _ref4) {
|
|
1436
|
+
let {
|
|
1437
|
+
refKey
|
|
1438
|
+
} = _ref4;
|
|
1439
|
+
const refKeySpecified = refKey !== 'ref';
|
|
1440
|
+
const isComposite = !isDOMElement(element);
|
|
1420
1441
|
if (isComposite && !refKeySpecified && !reactIs.isForwardRef(element)) {
|
|
1421
1442
|
// eslint-disable-next-line no-console
|
|
1422
1443
|
console.error('downshift: You returned a non-DOM element. You must specify a refKey in getRootProps');
|
|
1423
1444
|
} else if (!isComposite && refKeySpecified) {
|
|
1424
1445
|
// eslint-disable-next-line no-console
|
|
1425
|
-
console.error(
|
|
1446
|
+
console.error(`downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified "${refKey}"`);
|
|
1426
1447
|
}
|
|
1427
1448
|
if (!reactIs.isForwardRef(element) && !getElementProps(element)[refKey]) {
|
|
1428
1449
|
// eslint-disable-next-line no-console
|
|
1429
|
-
console.error(
|
|
1450
|
+
console.error(`downshift: You must apply the ref prop "${refKey}" from getRootProps onto your root element.`);
|
|
1430
1451
|
}
|
|
1431
1452
|
}
|
|
1432
1453
|
|
|
1433
|
-
|
|
1434
|
-
var dropdownDefaultStateValues = {
|
|
1454
|
+
const dropdownDefaultStateValues = {
|
|
1435
1455
|
highlightedIndex: -1,
|
|
1436
1456
|
isOpen: false,
|
|
1437
1457
|
selectedItem: null,
|
|
1438
1458
|
inputValue: ''
|
|
1439
1459
|
};
|
|
1440
1460
|
function callOnChangeProps(action, state, newState) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1461
|
+
const {
|
|
1462
|
+
props,
|
|
1463
|
+
type
|
|
1464
|
+
} = action;
|
|
1465
|
+
const changes = {};
|
|
1466
|
+
Object.keys(state).forEach(key => {
|
|
1445
1467
|
invokeOnChangeHandler(key, action, state, newState);
|
|
1446
1468
|
if (newState[key] !== state[key]) {
|
|
1447
1469
|
changes[key] = newState[key];
|
|
1448
1470
|
}
|
|
1449
1471
|
});
|
|
1450
1472
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
1451
|
-
props.onStateChange(
|
|
1452
|
-
type
|
|
1453
|
-
|
|
1473
|
+
props.onStateChange({
|
|
1474
|
+
type,
|
|
1475
|
+
...changes
|
|
1476
|
+
});
|
|
1454
1477
|
}
|
|
1455
1478
|
}
|
|
1456
1479
|
function invokeOnChangeHandler(key, action, state, newState) {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1480
|
+
const {
|
|
1481
|
+
props,
|
|
1482
|
+
type
|
|
1483
|
+
} = action;
|
|
1484
|
+
const handler = `on${capitalizeString(key)}Change`;
|
|
1460
1485
|
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
1461
|
-
props[handler](
|
|
1462
|
-
type
|
|
1463
|
-
|
|
1486
|
+
props[handler]({
|
|
1487
|
+
type,
|
|
1488
|
+
...newState
|
|
1489
|
+
});
|
|
1464
1490
|
}
|
|
1465
1491
|
}
|
|
1466
1492
|
|
|
@@ -1482,36 +1508,37 @@ function stateReducer(s, a) {
|
|
|
1482
1508
|
* @returns {string} The a11y message.
|
|
1483
1509
|
*/
|
|
1484
1510
|
function getA11ySelectionMessage(selectionParameters) {
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1511
|
+
const {
|
|
1512
|
+
selectedItem,
|
|
1513
|
+
itemToString: itemToStringLocal
|
|
1514
|
+
} = selectionParameters;
|
|
1515
|
+
return selectedItem ? `${itemToStringLocal(selectedItem)} has been selected.` : '';
|
|
1488
1516
|
}
|
|
1489
1517
|
|
|
1490
1518
|
/**
|
|
1491
1519
|
* Debounced call for updating the a11y message.
|
|
1492
1520
|
*/
|
|
1493
|
-
|
|
1521
|
+
const updateA11yStatus = debounce((getA11yMessage, document) => {
|
|
1494
1522
|
setStatus(getA11yMessage(), document);
|
|
1495
1523
|
}, 200);
|
|
1496
1524
|
|
|
1497
1525
|
// istanbul ignore next
|
|
1498
|
-
|
|
1526
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
|
|
1499
1527
|
function useElementIds(_ref) {
|
|
1500
|
-
|
|
1501
|
-
id =
|
|
1502
|
-
labelId
|
|
1503
|
-
menuId
|
|
1504
|
-
getItemId
|
|
1505
|
-
toggleButtonId
|
|
1506
|
-
inputId
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
inputId: inputId || id + "-input"
|
|
1528
|
+
let {
|
|
1529
|
+
id = `downshift-${generateId()}`,
|
|
1530
|
+
labelId,
|
|
1531
|
+
menuId,
|
|
1532
|
+
getItemId,
|
|
1533
|
+
toggleButtonId,
|
|
1534
|
+
inputId
|
|
1535
|
+
} = _ref;
|
|
1536
|
+
const elementIdsRef = react.useRef({
|
|
1537
|
+
labelId: labelId || `${id}-label`,
|
|
1538
|
+
menuId: menuId || `${id}-menu`,
|
|
1539
|
+
getItemId: getItemId || (index => `${id}-item-${index}`),
|
|
1540
|
+
toggleButtonId: toggleButtonId || `${id}-toggle-button`,
|
|
1541
|
+
inputId: inputId || `${id}-input`
|
|
1515
1542
|
});
|
|
1516
1543
|
return elementIdsRef.current;
|
|
1517
1544
|
}
|
|
@@ -1531,10 +1558,10 @@ function isAcceptedCharacterKey(key) {
|
|
|
1531
1558
|
return /^\S{1}$/.test(key);
|
|
1532
1559
|
}
|
|
1533
1560
|
function capitalizeString(string) {
|
|
1534
|
-
return
|
|
1561
|
+
return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
|
|
1535
1562
|
}
|
|
1536
1563
|
function useLatestRef(val) {
|
|
1537
|
-
|
|
1564
|
+
const ref = react.useRef(val);
|
|
1538
1565
|
// technically this is not "concurrent mode safe" because we're manipulating
|
|
1539
1566
|
// the value during render (so it's not idempotent). However, the places this
|
|
1540
1567
|
// hook is used is to support memoizing callbacks which will be called
|
|
@@ -1555,28 +1582,26 @@ function useLatestRef(val) {
|
|
|
1555
1582
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
1556
1583
|
*/
|
|
1557
1584
|
function useEnhancedReducer(reducer, initialState, props) {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1585
|
+
const prevStateRef = react.useRef();
|
|
1586
|
+
const actionRef = react.useRef();
|
|
1587
|
+
const enhancedReducer = react.useCallback((state, action) => {
|
|
1561
1588
|
actionRef.current = action;
|
|
1562
1589
|
state = getState(state, action.props);
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1590
|
+
const changes = reducer(state, action);
|
|
1591
|
+
const newState = action.props.stateReducer(state, {
|
|
1592
|
+
...action,
|
|
1593
|
+
changes
|
|
1594
|
+
});
|
|
1567
1595
|
return newState;
|
|
1568
1596
|
}, [reducer]);
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
}, [propsRef]);
|
|
1578
|
-
var action = actionRef.current;
|
|
1579
|
-
react.useEffect(function () {
|
|
1597
|
+
const [state, dispatch] = react.useReducer(enhancedReducer, initialState);
|
|
1598
|
+
const propsRef = useLatestRef(props);
|
|
1599
|
+
const dispatchWithProps = react.useCallback(action => dispatch({
|
|
1600
|
+
props: propsRef.current,
|
|
1601
|
+
...action
|
|
1602
|
+
}), [propsRef]);
|
|
1603
|
+
const action = actionRef.current;
|
|
1604
|
+
react.useEffect(() => {
|
|
1580
1605
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
1581
1606
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
1582
1607
|
}
|
|
@@ -1595,16 +1620,14 @@ function useEnhancedReducer(reducer, initialState, props) {
|
|
|
1595
1620
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
1596
1621
|
*/
|
|
1597
1622
|
function useControlledReducer$1(reducer, initialState, props) {
|
|
1598
|
-
|
|
1599
|
-
state = _useEnhancedReducer[0],
|
|
1600
|
-
dispatch = _useEnhancedReducer[1];
|
|
1623
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
|
|
1601
1624
|
return [getState(state, props), dispatch];
|
|
1602
1625
|
}
|
|
1603
|
-
|
|
1604
|
-
itemToString
|
|
1605
|
-
stateReducer
|
|
1606
|
-
getA11ySelectionMessage
|
|
1607
|
-
scrollIntoView
|
|
1626
|
+
const defaultProps$3 = {
|
|
1627
|
+
itemToString,
|
|
1628
|
+
stateReducer,
|
|
1629
|
+
getA11ySelectionMessage,
|
|
1630
|
+
scrollIntoView,
|
|
1608
1631
|
environment: /* istanbul ignore next (ssr) */
|
|
1609
1632
|
typeof window === 'undefined' ? {} : window
|
|
1610
1633
|
};
|
|
@@ -1612,7 +1635,7 @@ function getDefaultValue$1(props, propKey, defaultStateValues) {
|
|
|
1612
1635
|
if (defaultStateValues === void 0) {
|
|
1613
1636
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1614
1637
|
}
|
|
1615
|
-
|
|
1638
|
+
const defaultValue = props[`default${capitalizeString(propKey)}`];
|
|
1616
1639
|
if (defaultValue !== undefined) {
|
|
1617
1640
|
return defaultValue;
|
|
1618
1641
|
}
|
|
@@ -1622,34 +1645,38 @@ function getInitialValue$1(props, propKey, defaultStateValues) {
|
|
|
1622
1645
|
if (defaultStateValues === void 0) {
|
|
1623
1646
|
defaultStateValues = dropdownDefaultStateValues;
|
|
1624
1647
|
}
|
|
1625
|
-
|
|
1648
|
+
const value = props[propKey];
|
|
1626
1649
|
if (value !== undefined) {
|
|
1627
1650
|
return value;
|
|
1628
1651
|
}
|
|
1629
|
-
|
|
1652
|
+
const initialValue = props[`initial${capitalizeString(propKey)}`];
|
|
1630
1653
|
if (initialValue !== undefined) {
|
|
1631
1654
|
return initialValue;
|
|
1632
1655
|
}
|
|
1633
1656
|
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
1634
1657
|
}
|
|
1635
1658
|
function getInitialState$2(props) {
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1659
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
1660
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
1661
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
1662
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
1640
1663
|
return {
|
|
1641
1664
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
1642
|
-
isOpen
|
|
1643
|
-
selectedItem
|
|
1644
|
-
inputValue
|
|
1665
|
+
isOpen,
|
|
1666
|
+
selectedItem,
|
|
1667
|
+
inputValue
|
|
1645
1668
|
};
|
|
1646
1669
|
}
|
|
1647
1670
|
function getHighlightedIndexOnOpen(props, state, offset) {
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1671
|
+
const {
|
|
1672
|
+
items,
|
|
1673
|
+
initialHighlightedIndex,
|
|
1674
|
+
defaultHighlightedIndex
|
|
1675
|
+
} = props;
|
|
1676
|
+
const {
|
|
1677
|
+
selectedItem,
|
|
1678
|
+
highlightedIndex
|
|
1679
|
+
} = state;
|
|
1653
1680
|
if (items.length === 0) {
|
|
1654
1681
|
return -1;
|
|
1655
1682
|
}
|
|
@@ -1680,34 +1707,30 @@ function getHighlightedIndexOnOpen(props, state, offset) {
|
|
|
1680
1707
|
* @returns {Object} Ref containing whether mouseDown or touchMove event is happening
|
|
1681
1708
|
*/
|
|
1682
1709
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
1683
|
-
|
|
1710
|
+
const mouseAndTouchTrackersRef = react.useRef({
|
|
1684
1711
|
isMouseDown: false,
|
|
1685
1712
|
isTouchMove: false
|
|
1686
1713
|
});
|
|
1687
|
-
react.useEffect(
|
|
1714
|
+
react.useEffect(() => {
|
|
1688
1715
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
1689
1716
|
// as in downshift.js.
|
|
1690
|
-
|
|
1717
|
+
const onMouseDown = () => {
|
|
1691
1718
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
1692
1719
|
};
|
|
1693
|
-
|
|
1720
|
+
const onMouseUp = event => {
|
|
1694
1721
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
1695
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
1696
|
-
return ref.current;
|
|
1697
|
-
}), environment)) {
|
|
1722
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
1698
1723
|
handleBlur();
|
|
1699
1724
|
}
|
|
1700
1725
|
};
|
|
1701
|
-
|
|
1726
|
+
const onTouchStart = () => {
|
|
1702
1727
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
1703
1728
|
};
|
|
1704
|
-
|
|
1729
|
+
const onTouchMove = () => {
|
|
1705
1730
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
1706
1731
|
};
|
|
1707
|
-
|
|
1708
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
1709
|
-
return ref.current;
|
|
1710
|
-
}), environment, false)) {
|
|
1732
|
+
const onTouchEnd = event => {
|
|
1733
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
1711
1734
|
handleBlur();
|
|
1712
1735
|
}
|
|
1713
1736
|
};
|
|
@@ -1730,9 +1753,7 @@ function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, hand
|
|
|
1730
1753
|
|
|
1731
1754
|
/* istanbul ignore next */
|
|
1732
1755
|
// eslint-disable-next-line import/no-mutable-exports
|
|
1733
|
-
|
|
1734
|
-
return noop;
|
|
1735
|
-
};
|
|
1756
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
1736
1757
|
/**
|
|
1737
1758
|
* Custom hook that checks if getter props are called correctly.
|
|
1738
1759
|
*
|
|
@@ -1741,77 +1762,82 @@ var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
|
1741
1762
|
*/
|
|
1742
1763
|
/* istanbul ignore next */
|
|
1743
1764
|
if (process.env.NODE_ENV !== 'production') {
|
|
1744
|
-
useGetterPropsCalledChecker = function
|
|
1745
|
-
|
|
1765
|
+
useGetterPropsCalledChecker = function () {
|
|
1766
|
+
const isInitialMountRef = react.useRef(true);
|
|
1746
1767
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1747
1768
|
propKeys[_key] = arguments[_key];
|
|
1748
1769
|
}
|
|
1749
|
-
|
|
1770
|
+
const getterPropsCalledRef = react.useRef(propKeys.reduce((acc, propKey) => {
|
|
1750
1771
|
acc[propKey] = {};
|
|
1751
1772
|
return acc;
|
|
1752
1773
|
}, {}));
|
|
1753
|
-
react.useEffect(
|
|
1754
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
1755
|
-
|
|
1774
|
+
react.useEffect(() => {
|
|
1775
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
1776
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
1756
1777
|
if (isInitialMountRef.current) {
|
|
1757
1778
|
if (!Object.keys(propCallInfo).length) {
|
|
1758
1779
|
// eslint-disable-next-line no-console
|
|
1759
|
-
console.error(
|
|
1780
|
+
console.error(`downshift: You forgot to call the ${propKey} getter function on your component / element.`);
|
|
1760
1781
|
return;
|
|
1761
1782
|
}
|
|
1762
1783
|
}
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1784
|
+
const {
|
|
1785
|
+
suppressRefError,
|
|
1786
|
+
refKey,
|
|
1787
|
+
elementRef
|
|
1788
|
+
} = propCallInfo;
|
|
1766
1789
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
1767
1790
|
// eslint-disable-next-line no-console
|
|
1768
|
-
console.error(
|
|
1791
|
+
console.error(`downshift: The ref prop "${refKey}" from ${propKey} was not applied correctly on your element.`);
|
|
1769
1792
|
}
|
|
1770
1793
|
});
|
|
1771
1794
|
isInitialMountRef.current = false;
|
|
1772
1795
|
});
|
|
1773
|
-
|
|
1796
|
+
const setGetterPropCallInfo = react.useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
1774
1797
|
getterPropsCalledRef.current[propKey] = {
|
|
1775
|
-
suppressRefError
|
|
1776
|
-
refKey
|
|
1777
|
-
elementRef
|
|
1798
|
+
suppressRefError,
|
|
1799
|
+
refKey,
|
|
1800
|
+
elementRef
|
|
1778
1801
|
};
|
|
1779
1802
|
}, []);
|
|
1780
1803
|
return setGetterPropCallInfo;
|
|
1781
1804
|
};
|
|
1782
1805
|
}
|
|
1783
1806
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1807
|
+
let {
|
|
1808
|
+
isInitialMount,
|
|
1809
|
+
highlightedIndex,
|
|
1810
|
+
items,
|
|
1811
|
+
environment,
|
|
1812
|
+
...rest
|
|
1813
|
+
} = _ref2;
|
|
1789
1814
|
// Sets a11y status message on changes in state.
|
|
1790
|
-
react.useEffect(
|
|
1815
|
+
react.useEffect(() => {
|
|
1791
1816
|
if (isInitialMount || true) {
|
|
1792
1817
|
return;
|
|
1793
1818
|
}
|
|
1794
|
-
updateA11yStatus(
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
}, environment.document);
|
|
1819
|
+
updateA11yStatus(() => getA11yMessage({
|
|
1820
|
+
highlightedIndex,
|
|
1821
|
+
highlightedItem: items[highlightedIndex],
|
|
1822
|
+
resultCount: items.length,
|
|
1823
|
+
...rest
|
|
1824
|
+
}), environment.document);
|
|
1801
1825
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1802
1826
|
}, dependencyArray);
|
|
1803
1827
|
}
|
|
1804
1828
|
function useScrollIntoView(_ref3) {
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1829
|
+
let {
|
|
1830
|
+
highlightedIndex,
|
|
1831
|
+
isOpen,
|
|
1832
|
+
itemRefs,
|
|
1833
|
+
getItemNodeFromIndex,
|
|
1834
|
+
menuElement,
|
|
1835
|
+
scrollIntoView: scrollIntoViewProp
|
|
1836
|
+
} = _ref3;
|
|
1811
1837
|
// used not to scroll on highlight by mouse.
|
|
1812
|
-
|
|
1838
|
+
const shouldScrollRef = react.useRef(true);
|
|
1813
1839
|
// Scroll on highlighted item if change comes from keyboard.
|
|
1814
|
-
useIsomorphicLayoutEffect(
|
|
1840
|
+
useIsomorphicLayoutEffect(() => {
|
|
1815
1841
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
1816
1842
|
return;
|
|
1817
1843
|
}
|
|
@@ -1826,16 +1852,18 @@ function useScrollIntoView(_ref3) {
|
|
|
1826
1852
|
}
|
|
1827
1853
|
|
|
1828
1854
|
// eslint-disable-next-line import/no-mutable-exports
|
|
1829
|
-
|
|
1855
|
+
let useControlPropsValidator = noop;
|
|
1830
1856
|
/* istanbul ignore next */
|
|
1831
1857
|
if (process.env.NODE_ENV !== 'production') {
|
|
1832
|
-
useControlPropsValidator =
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1858
|
+
useControlPropsValidator = _ref4 => {
|
|
1859
|
+
let {
|
|
1860
|
+
isInitialMount,
|
|
1861
|
+
props,
|
|
1862
|
+
state
|
|
1863
|
+
} = _ref4;
|
|
1836
1864
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
1837
|
-
|
|
1838
|
-
react.useEffect(
|
|
1865
|
+
const prevPropsRef = react.useRef(props);
|
|
1866
|
+
react.useEffect(() => {
|
|
1839
1867
|
if (isInitialMount) {
|
|
1840
1868
|
return;
|
|
1841
1869
|
}
|
|
@@ -1846,9 +1874,11 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1846
1874
|
}
|
|
1847
1875
|
|
|
1848
1876
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1877
|
+
const {
|
|
1878
|
+
type,
|
|
1879
|
+
props
|
|
1880
|
+
} = action;
|
|
1881
|
+
let changes;
|
|
1852
1882
|
switch (type) {
|
|
1853
1883
|
case stateChangeTypes.ItemMouseMove:
|
|
1854
1884
|
changes = {
|
|
@@ -1899,7 +1929,10 @@ function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
|
1899
1929
|
default:
|
|
1900
1930
|
throw new Error('Reducer called without proper action type.');
|
|
1901
1931
|
}
|
|
1902
|
-
return
|
|
1932
|
+
return {
|
|
1933
|
+
...state,
|
|
1934
|
+
...changes
|
|
1935
|
+
};
|
|
1903
1936
|
}
|
|
1904
1937
|
/* eslint-enable complexity */
|
|
1905
1938
|
|
|
@@ -1985,28 +2018,28 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
1985
2018
|
};
|
|
1986
2019
|
}
|
|
1987
2020
|
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2021
|
+
const ToggleButtonClick$1 = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 0;
|
|
2022
|
+
const ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 1;
|
|
2023
|
+
const ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 2;
|
|
2024
|
+
const ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 3;
|
|
2025
|
+
const ToggleButtonKeyDownEscape = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_escape__' : 4;
|
|
2026
|
+
const ToggleButtonKeyDownHome = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_home__' : 5;
|
|
2027
|
+
const ToggleButtonKeyDownEnd = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_end__' : 6;
|
|
2028
|
+
const ToggleButtonKeyDownEnter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_enter__' : 7;
|
|
2029
|
+
const ToggleButtonKeyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_space_button__' : 8;
|
|
2030
|
+
const ToggleButtonKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_up__' : 9;
|
|
2031
|
+
const ToggleButtonKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_page_down__' : 10;
|
|
2032
|
+
const ToggleButtonBlur = process.env.NODE_ENV !== "production" ? '__togglebutton_blur__' : 11;
|
|
2033
|
+
const MenuMouseLeave$1 = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 12;
|
|
2034
|
+
const ItemMouseMove$1 = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 13;
|
|
2035
|
+
const ItemClick$1 = process.env.NODE_ENV !== "production" ? '__item_click__' : 14;
|
|
2036
|
+
const FunctionToggleMenu$1 = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
|
|
2037
|
+
const FunctionOpenMenu$1 = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
|
|
2038
|
+
const FunctionCloseMenu$1 = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
|
|
2039
|
+
const FunctionSetHighlightedIndex$1 = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
|
|
2040
|
+
const FunctionSelectItem$1 = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
|
|
2041
|
+
const FunctionSetInputValue$1 = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
|
|
2042
|
+
const FunctionReset$2 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
|
|
2010
2043
|
|
|
2011
2044
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
2012
2045
|
__proto__: null,
|
|
@@ -2036,10 +2069,12 @@ var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
|
2036
2069
|
|
|
2037
2070
|
/* eslint-disable complexity */
|
|
2038
2071
|
function downshiftSelectReducer(state, action) {
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2072
|
+
const {
|
|
2073
|
+
type,
|
|
2074
|
+
props,
|
|
2075
|
+
altKey
|
|
2076
|
+
} = action;
|
|
2077
|
+
let changes;
|
|
2043
2078
|
switch (type) {
|
|
2044
2079
|
case ItemClick$1:
|
|
2045
2080
|
changes = {
|
|
@@ -2050,10 +2085,10 @@ function downshiftSelectReducer(state, action) {
|
|
|
2050
2085
|
break;
|
|
2051
2086
|
case ToggleButtonKeyDownCharacter:
|
|
2052
2087
|
{
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2088
|
+
const lowercasedKey = action.key;
|
|
2089
|
+
const inputValue = `${state.inputValue}${lowercasedKey}`;
|
|
2090
|
+
const prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
|
|
2091
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
2057
2092
|
keysSoFar: inputValue,
|
|
2058
2093
|
highlightedIndex: prevHighlightedIndex,
|
|
2059
2094
|
items: props.items,
|
|
@@ -2061,33 +2096,34 @@ function downshiftSelectReducer(state, action) {
|
|
|
2061
2096
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
2062
2097
|
});
|
|
2063
2098
|
changes = {
|
|
2064
|
-
inputValue
|
|
2065
|
-
highlightedIndex
|
|
2099
|
+
inputValue,
|
|
2100
|
+
highlightedIndex,
|
|
2066
2101
|
isOpen: true
|
|
2067
2102
|
};
|
|
2068
2103
|
}
|
|
2069
2104
|
break;
|
|
2070
2105
|
case ToggleButtonKeyDownArrowDown:
|
|
2071
2106
|
{
|
|
2072
|
-
|
|
2107
|
+
const highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
|
|
2073
2108
|
changes = {
|
|
2074
|
-
highlightedIndex
|
|
2109
|
+
highlightedIndex,
|
|
2075
2110
|
isOpen: true
|
|
2076
2111
|
};
|
|
2077
2112
|
}
|
|
2078
2113
|
break;
|
|
2079
2114
|
case ToggleButtonKeyDownArrowUp:
|
|
2080
2115
|
if (state.isOpen && altKey) {
|
|
2081
|
-
changes =
|
|
2116
|
+
changes = {
|
|
2082
2117
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2083
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2118
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2119
|
+
...(state.highlightedIndex >= 0 && {
|
|
2120
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2121
|
+
})
|
|
2122
|
+
};
|
|
2087
2123
|
} else {
|
|
2088
|
-
|
|
2124
|
+
const highlightedIndex = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
2089
2125
|
changes = {
|
|
2090
|
-
highlightedIndex
|
|
2126
|
+
highlightedIndex,
|
|
2091
2127
|
isOpen: true
|
|
2092
2128
|
};
|
|
2093
2129
|
}
|
|
@@ -2095,12 +2131,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2095
2131
|
// only triggered when menu is open.
|
|
2096
2132
|
case ToggleButtonKeyDownEnter:
|
|
2097
2133
|
case ToggleButtonKeyDownSpaceButton:
|
|
2098
|
-
changes =
|
|
2134
|
+
changes = {
|
|
2099
2135
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2100
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2136
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2137
|
+
...(state.highlightedIndex >= 0 && {
|
|
2138
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2139
|
+
})
|
|
2140
|
+
};
|
|
2104
2141
|
break;
|
|
2105
2142
|
case ToggleButtonKeyDownHome:
|
|
2106
2143
|
changes = {
|
|
@@ -2131,12 +2168,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2131
2168
|
};
|
|
2132
2169
|
break;
|
|
2133
2170
|
case ToggleButtonBlur:
|
|
2134
|
-
changes =
|
|
2171
|
+
changes = {
|
|
2135
2172
|
isOpen: false,
|
|
2136
|
-
highlightedIndex: -1
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2173
|
+
highlightedIndex: -1,
|
|
2174
|
+
...(state.highlightedIndex >= 0 && {
|
|
2175
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
2176
|
+
})
|
|
2177
|
+
};
|
|
2140
2178
|
break;
|
|
2141
2179
|
case FunctionSelectItem$1:
|
|
2142
2180
|
changes = {
|
|
@@ -2146,13 +2184,13 @@ function downshiftSelectReducer(state, action) {
|
|
|
2146
2184
|
default:
|
|
2147
2185
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
2148
2186
|
}
|
|
2149
|
-
return
|
|
2187
|
+
return {
|
|
2188
|
+
...state,
|
|
2189
|
+
...changes
|
|
2190
|
+
};
|
|
2150
2191
|
}
|
|
2151
2192
|
/* eslint-enable complexity */
|
|
2152
2193
|
|
|
2153
|
-
var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
|
|
2154
|
-
_excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
|
|
2155
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
|
|
2156
2194
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
2157
2195
|
function useSelect(userProps) {
|
|
2158
2196
|
if (userProps === void 0) {
|
|
@@ -2160,76 +2198,81 @@ function useSelect(userProps) {
|
|
|
2160
2198
|
}
|
|
2161
2199
|
validatePropTypes$2(userProps, useSelect);
|
|
2162
2200
|
// Props defaults and destructuring.
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2201
|
+
const props = {
|
|
2202
|
+
...defaultProps$2,
|
|
2203
|
+
...userProps
|
|
2204
|
+
};
|
|
2205
|
+
const {
|
|
2206
|
+
items,
|
|
2207
|
+
scrollIntoView,
|
|
2208
|
+
environment,
|
|
2209
|
+
itemToString,
|
|
2210
|
+
getA11ySelectionMessage,
|
|
2211
|
+
getA11yStatusMessage
|
|
2212
|
+
} = props;
|
|
2170
2213
|
// Initial state depending on controlled props.
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2214
|
+
const initialState = getInitialState$2(props);
|
|
2215
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
2216
|
+
const {
|
|
2217
|
+
isOpen,
|
|
2218
|
+
highlightedIndex,
|
|
2219
|
+
selectedItem,
|
|
2220
|
+
inputValue
|
|
2221
|
+
} = state;
|
|
2179
2222
|
|
|
2180
2223
|
// Element efs.
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2224
|
+
const toggleButtonRef = react.useRef(null);
|
|
2225
|
+
const menuRef = react.useRef(null);
|
|
2226
|
+
const itemRefs = react.useRef({});
|
|
2184
2227
|
// used to keep the inputValue clearTimeout object between renders.
|
|
2185
|
-
|
|
2228
|
+
const clearTimeoutRef = react.useRef(null);
|
|
2186
2229
|
// prevent id re-generation between renders.
|
|
2187
|
-
|
|
2230
|
+
const elementIds = useElementIds(props);
|
|
2188
2231
|
// used to keep track of how many items we had on previous cycle.
|
|
2189
|
-
|
|
2190
|
-
|
|
2232
|
+
const previousResultCountRef = react.useRef();
|
|
2233
|
+
const isInitialMountRef = react.useRef(true);
|
|
2191
2234
|
// utility callback to get item element.
|
|
2192
|
-
|
|
2193
|
-
state
|
|
2194
|
-
props
|
|
2235
|
+
const latest = useLatestRef({
|
|
2236
|
+
state,
|
|
2237
|
+
props
|
|
2195
2238
|
});
|
|
2196
2239
|
|
|
2197
2240
|
// Some utils.
|
|
2198
|
-
|
|
2199
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2200
|
-
}, [elementIds]);
|
|
2241
|
+
const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
|
|
2201
2242
|
|
|
2202
2243
|
// Effects.
|
|
2203
2244
|
// Sets a11y status message on changes in state.
|
|
2204
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2245
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2205
2246
|
isInitialMount: isInitialMountRef.current,
|
|
2206
2247
|
previousResultCount: previousResultCountRef.current,
|
|
2207
|
-
items
|
|
2208
|
-
environment
|
|
2209
|
-
itemToString
|
|
2210
|
-
|
|
2248
|
+
items,
|
|
2249
|
+
environment,
|
|
2250
|
+
itemToString,
|
|
2251
|
+
...state
|
|
2252
|
+
});
|
|
2211
2253
|
// Sets a11y status message on changes in selectedItem.
|
|
2212
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2254
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2213
2255
|
isInitialMount: isInitialMountRef.current,
|
|
2214
2256
|
previousResultCount: previousResultCountRef.current,
|
|
2215
|
-
items
|
|
2216
|
-
environment
|
|
2217
|
-
itemToString
|
|
2218
|
-
|
|
2257
|
+
items,
|
|
2258
|
+
environment,
|
|
2259
|
+
itemToString,
|
|
2260
|
+
...state
|
|
2261
|
+
});
|
|
2219
2262
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2220
|
-
|
|
2263
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2221
2264
|
menuElement: menuRef.current,
|
|
2222
|
-
highlightedIndex
|
|
2223
|
-
isOpen
|
|
2224
|
-
itemRefs
|
|
2225
|
-
scrollIntoView
|
|
2226
|
-
getItemNodeFromIndex
|
|
2265
|
+
highlightedIndex,
|
|
2266
|
+
isOpen,
|
|
2267
|
+
itemRefs,
|
|
2268
|
+
scrollIntoView,
|
|
2269
|
+
getItemNodeFromIndex
|
|
2227
2270
|
});
|
|
2228
2271
|
|
|
2229
2272
|
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
2230
|
-
react.useEffect(
|
|
2273
|
+
react.useEffect(() => {
|
|
2231
2274
|
// init the clean function here as we need access to dispatch.
|
|
2232
|
-
clearTimeoutRef.current = debounce(
|
|
2275
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
2233
2276
|
outerDispatch({
|
|
2234
2277
|
type: FunctionSetInputValue$1,
|
|
2235
2278
|
inputValue: ''
|
|
@@ -2237,13 +2280,13 @@ function useSelect(userProps) {
|
|
|
2237
2280
|
}, 500);
|
|
2238
2281
|
|
|
2239
2282
|
// Cancel any pending debounced calls on mount
|
|
2240
|
-
return
|
|
2283
|
+
return () => {
|
|
2241
2284
|
clearTimeoutRef.current.cancel();
|
|
2242
2285
|
};
|
|
2243
2286
|
}, []);
|
|
2244
2287
|
|
|
2245
2288
|
// Invokes the keysSoFar callback set up above.
|
|
2246
|
-
react.useEffect(
|
|
2289
|
+
react.useEffect(() => {
|
|
2247
2290
|
if (!inputValue) {
|
|
2248
2291
|
return;
|
|
2249
2292
|
}
|
|
@@ -2251,234 +2294,249 @@ function useSelect(userProps) {
|
|
|
2251
2294
|
}, [dispatch, inputValue]);
|
|
2252
2295
|
useControlPropsValidator({
|
|
2253
2296
|
isInitialMount: isInitialMountRef.current,
|
|
2254
|
-
props
|
|
2255
|
-
state
|
|
2297
|
+
props,
|
|
2298
|
+
state
|
|
2256
2299
|
});
|
|
2257
|
-
react.useEffect(
|
|
2300
|
+
react.useEffect(() => {
|
|
2258
2301
|
if (isInitialMountRef.current) {
|
|
2259
2302
|
return;
|
|
2260
2303
|
}
|
|
2261
2304
|
previousResultCountRef.current = items.length;
|
|
2262
2305
|
});
|
|
2263
2306
|
// Add mouse/touch events to document.
|
|
2264
|
-
|
|
2307
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
2265
2308
|
dispatch({
|
|
2266
2309
|
type: ToggleButtonBlur
|
|
2267
2310
|
});
|
|
2268
2311
|
});
|
|
2269
|
-
|
|
2312
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
|
|
2270
2313
|
// Make initial ref false.
|
|
2271
|
-
react.useEffect(
|
|
2314
|
+
react.useEffect(() => {
|
|
2272
2315
|
isInitialMountRef.current = false;
|
|
2273
|
-
return
|
|
2316
|
+
return () => {
|
|
2274
2317
|
isInitialMountRef.current = true;
|
|
2275
2318
|
};
|
|
2276
2319
|
}, []);
|
|
2277
2320
|
// Reset itemRefs on close.
|
|
2278
|
-
react.useEffect(
|
|
2321
|
+
react.useEffect(() => {
|
|
2279
2322
|
if (!isOpen) {
|
|
2280
2323
|
itemRefs.current = {};
|
|
2281
2324
|
}
|
|
2282
2325
|
}, [isOpen]);
|
|
2283
2326
|
|
|
2284
2327
|
// Event handler functions.
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2328
|
+
const toggleButtonKeyDownHandlers = react.useMemo(() => ({
|
|
2329
|
+
ArrowDown(event) {
|
|
2330
|
+
event.preventDefault();
|
|
2331
|
+
dispatch({
|
|
2332
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
2333
|
+
getItemNodeFromIndex,
|
|
2334
|
+
altKey: event.altKey
|
|
2335
|
+
});
|
|
2336
|
+
},
|
|
2337
|
+
ArrowUp(event) {
|
|
2338
|
+
event.preventDefault();
|
|
2339
|
+
dispatch({
|
|
2340
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
2341
|
+
getItemNodeFromIndex,
|
|
2342
|
+
altKey: event.altKey
|
|
2343
|
+
});
|
|
2344
|
+
},
|
|
2345
|
+
Home(event) {
|
|
2346
|
+
event.preventDefault();
|
|
2347
|
+
dispatch({
|
|
2348
|
+
type: ToggleButtonKeyDownHome,
|
|
2349
|
+
getItemNodeFromIndex
|
|
2350
|
+
});
|
|
2351
|
+
},
|
|
2352
|
+
End(event) {
|
|
2353
|
+
event.preventDefault();
|
|
2354
|
+
dispatch({
|
|
2355
|
+
type: ToggleButtonKeyDownEnd,
|
|
2356
|
+
getItemNodeFromIndex
|
|
2357
|
+
});
|
|
2358
|
+
},
|
|
2359
|
+
Escape() {
|
|
2360
|
+
if (latest.current.state.isOpen) {
|
|
2289
2361
|
dispatch({
|
|
2290
|
-
type:
|
|
2291
|
-
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
2292
|
-
altKey: event.altKey
|
|
2362
|
+
type: ToggleButtonKeyDownEscape
|
|
2293
2363
|
});
|
|
2294
|
-
}
|
|
2295
|
-
|
|
2364
|
+
}
|
|
2365
|
+
},
|
|
2366
|
+
Enter(event) {
|
|
2367
|
+
event.preventDefault();
|
|
2368
|
+
dispatch({
|
|
2369
|
+
type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
|
|
2370
|
+
});
|
|
2371
|
+
},
|
|
2372
|
+
PageUp(event) {
|
|
2373
|
+
if (latest.current.state.isOpen) {
|
|
2296
2374
|
event.preventDefault();
|
|
2297
2375
|
dispatch({
|
|
2298
|
-
type:
|
|
2299
|
-
getItemNodeFromIndex
|
|
2300
|
-
altKey: event.altKey
|
|
2376
|
+
type: ToggleButtonKeyDownPageUp,
|
|
2377
|
+
getItemNodeFromIndex
|
|
2301
2378
|
});
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2379
|
+
}
|
|
2380
|
+
},
|
|
2381
|
+
PageDown(event) {
|
|
2382
|
+
if (latest.current.state.isOpen) {
|
|
2304
2383
|
event.preventDefault();
|
|
2305
2384
|
dispatch({
|
|
2306
|
-
type:
|
|
2307
|
-
getItemNodeFromIndex
|
|
2385
|
+
type: ToggleButtonKeyDownPageDown,
|
|
2386
|
+
getItemNodeFromIndex
|
|
2308
2387
|
});
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2388
|
+
}
|
|
2389
|
+
},
|
|
2390
|
+
' '(event) {
|
|
2391
|
+
event.preventDefault();
|
|
2392
|
+
const currentState = latest.current.state;
|
|
2393
|
+
if (!currentState.isOpen) {
|
|
2312
2394
|
dispatch({
|
|
2313
|
-
type:
|
|
2314
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2395
|
+
type: ToggleButtonClick$1
|
|
2315
2396
|
});
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
dispatch({
|
|
2320
|
-
type: ToggleButtonKeyDownEscape
|
|
2321
|
-
});
|
|
2322
|
-
}
|
|
2323
|
-
},
|
|
2324
|
-
Enter: function Enter(event) {
|
|
2325
|
-
event.preventDefault();
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
if (currentState.inputValue) {
|
|
2326
2400
|
dispatch({
|
|
2327
|
-
type:
|
|
2401
|
+
type: ToggleButtonKeyDownCharacter,
|
|
2402
|
+
key: ' ',
|
|
2403
|
+
getItemNodeFromIndex
|
|
2404
|
+
});
|
|
2405
|
+
} else {
|
|
2406
|
+
dispatch({
|
|
2407
|
+
type: ToggleButtonKeyDownSpaceButton
|
|
2328
2408
|
});
|
|
2329
|
-
},
|
|
2330
|
-
PageUp: function PageUp(event) {
|
|
2331
|
-
if (latest.current.state.isOpen) {
|
|
2332
|
-
event.preventDefault();
|
|
2333
|
-
dispatch({
|
|
2334
|
-
type: ToggleButtonKeyDownPageUp,
|
|
2335
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2336
|
-
});
|
|
2337
|
-
}
|
|
2338
|
-
},
|
|
2339
|
-
PageDown: function PageDown(event) {
|
|
2340
|
-
if (latest.current.state.isOpen) {
|
|
2341
|
-
event.preventDefault();
|
|
2342
|
-
dispatch({
|
|
2343
|
-
type: ToggleButtonKeyDownPageDown,
|
|
2344
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2345
|
-
});
|
|
2346
|
-
}
|
|
2347
|
-
},
|
|
2348
|
-
' ': function _(event) {
|
|
2349
|
-
event.preventDefault();
|
|
2350
|
-
var currentState = latest.current.state;
|
|
2351
|
-
if (!currentState.isOpen) {
|
|
2352
|
-
dispatch({
|
|
2353
|
-
type: ToggleButtonClick$1
|
|
2354
|
-
});
|
|
2355
|
-
return;
|
|
2356
|
-
}
|
|
2357
|
-
if (currentState.inputValue) {
|
|
2358
|
-
dispatch({
|
|
2359
|
-
type: ToggleButtonKeyDownCharacter,
|
|
2360
|
-
key: ' ',
|
|
2361
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
2362
|
-
});
|
|
2363
|
-
} else {
|
|
2364
|
-
dispatch({
|
|
2365
|
-
type: ToggleButtonKeyDownSpaceButton
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2368
2409
|
}
|
|
2369
|
-
}
|
|
2370
|
-
}, [dispatch, getItemNodeFromIndex, latest]);
|
|
2410
|
+
}
|
|
2411
|
+
}), [dispatch, getItemNodeFromIndex, latest]);
|
|
2371
2412
|
|
|
2372
2413
|
// Action functions.
|
|
2373
|
-
|
|
2414
|
+
const toggleMenu = react.useCallback(() => {
|
|
2374
2415
|
dispatch({
|
|
2375
2416
|
type: FunctionToggleMenu$1
|
|
2376
2417
|
});
|
|
2377
2418
|
}, [dispatch]);
|
|
2378
|
-
|
|
2419
|
+
const closeMenu = react.useCallback(() => {
|
|
2379
2420
|
dispatch({
|
|
2380
2421
|
type: FunctionCloseMenu$1
|
|
2381
2422
|
});
|
|
2382
2423
|
}, [dispatch]);
|
|
2383
|
-
|
|
2424
|
+
const openMenu = react.useCallback(() => {
|
|
2384
2425
|
dispatch({
|
|
2385
2426
|
type: FunctionOpenMenu$1
|
|
2386
2427
|
});
|
|
2387
2428
|
}, [dispatch]);
|
|
2388
|
-
|
|
2429
|
+
const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
|
|
2389
2430
|
dispatch({
|
|
2390
2431
|
type: FunctionSetHighlightedIndex$1,
|
|
2391
2432
|
highlightedIndex: newHighlightedIndex
|
|
2392
2433
|
});
|
|
2393
2434
|
}, [dispatch]);
|
|
2394
|
-
|
|
2435
|
+
const selectItem = react.useCallback(newSelectedItem => {
|
|
2395
2436
|
dispatch({
|
|
2396
2437
|
type: FunctionSelectItem$1,
|
|
2397
2438
|
selectedItem: newSelectedItem
|
|
2398
2439
|
});
|
|
2399
2440
|
}, [dispatch]);
|
|
2400
|
-
|
|
2441
|
+
const reset = react.useCallback(() => {
|
|
2401
2442
|
dispatch({
|
|
2402
2443
|
type: FunctionReset$2
|
|
2403
2444
|
});
|
|
2404
2445
|
}, [dispatch]);
|
|
2405
|
-
|
|
2446
|
+
const setInputValue = react.useCallback(newInputValue => {
|
|
2406
2447
|
dispatch({
|
|
2407
2448
|
type: FunctionSetInputValue$1,
|
|
2408
2449
|
inputValue: newInputValue
|
|
2409
2450
|
});
|
|
2410
2451
|
}, [dispatch]);
|
|
2411
2452
|
// Getter functions.
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
2431
|
-
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
2453
|
+
const getLabelProps = react.useCallback(labelProps => ({
|
|
2454
|
+
id: elementIds.labelId,
|
|
2455
|
+
htmlFor: elementIds.toggleButtonId,
|
|
2456
|
+
...labelProps
|
|
2457
|
+
}), [elementIds]);
|
|
2458
|
+
const getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
2459
|
+
let {
|
|
2460
|
+
onMouseLeave,
|
|
2461
|
+
refKey = 'ref',
|
|
2462
|
+
onKeyDown,
|
|
2463
|
+
onBlur,
|
|
2464
|
+
ref,
|
|
2465
|
+
...rest
|
|
2466
|
+
} = _temp === void 0 ? {} : _temp;
|
|
2467
|
+
let {
|
|
2468
|
+
suppressRefError = false
|
|
2469
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2470
|
+
const menuHandleMouseLeave = () => {
|
|
2432
2471
|
dispatch({
|
|
2433
2472
|
type: MenuMouseLeave$1
|
|
2434
2473
|
});
|
|
2435
2474
|
};
|
|
2436
2475
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
2437
|
-
return
|
|
2438
|
-
|
|
2439
|
-
|
|
2476
|
+
return {
|
|
2477
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
2478
|
+
menuRef.current = menuNode;
|
|
2479
|
+
}),
|
|
2480
|
+
id: elementIds.menuId,
|
|
2481
|
+
role: 'listbox',
|
|
2482
|
+
'aria-labelledby': elementIds.labelId,
|
|
2483
|
+
tabIndex: -1,
|
|
2484
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
2485
|
+
...rest
|
|
2486
|
+
};
|
|
2440
2487
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
2488
|
+
const getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
|
|
2489
|
+
let {
|
|
2490
|
+
onBlur,
|
|
2491
|
+
onClick,
|
|
2492
|
+
onKeyDown,
|
|
2493
|
+
refKey = 'ref',
|
|
2494
|
+
ref,
|
|
2495
|
+
...rest
|
|
2496
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2497
|
+
let {
|
|
2498
|
+
suppressRefError = false
|
|
2499
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2500
|
+
const latestState = latest.current.state;
|
|
2501
|
+
const toggleButtonHandleClick = () => {
|
|
2456
2502
|
dispatch({
|
|
2457
2503
|
type: ToggleButtonClick$1
|
|
2458
2504
|
});
|
|
2459
2505
|
};
|
|
2460
|
-
|
|
2506
|
+
const toggleButtonHandleBlur = () => {
|
|
2461
2507
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
2462
2508
|
dispatch({
|
|
2463
2509
|
type: ToggleButtonBlur
|
|
2464
2510
|
});
|
|
2465
2511
|
}
|
|
2466
2512
|
};
|
|
2467
|
-
|
|
2468
|
-
|
|
2513
|
+
const toggleButtonHandleKeyDown = event => {
|
|
2514
|
+
const key = normalizeArrowKey(event);
|
|
2469
2515
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
2470
2516
|
toggleButtonKeyDownHandlers[key](event);
|
|
2471
2517
|
} else if (isAcceptedCharacterKey(key)) {
|
|
2472
2518
|
dispatch({
|
|
2473
2519
|
type: ToggleButtonKeyDownCharacter,
|
|
2474
|
-
key
|
|
2475
|
-
getItemNodeFromIndex
|
|
2520
|
+
key,
|
|
2521
|
+
getItemNodeFromIndex
|
|
2476
2522
|
});
|
|
2477
2523
|
}
|
|
2478
2524
|
};
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2525
|
+
const toggleProps = {
|
|
2526
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
2527
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
2528
|
+
}),
|
|
2529
|
+
'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
|
|
2530
|
+
'aria-controls': elementIds.menuId,
|
|
2531
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
2532
|
+
'aria-haspopup': 'listbox',
|
|
2533
|
+
'aria-labelledby': `${elementIds.labelId}`,
|
|
2534
|
+
id: elementIds.toggleButtonId,
|
|
2535
|
+
role: 'combobox',
|
|
2536
|
+
tabIndex: 0,
|
|
2537
|
+
onBlur: callAllEventHandlers(onBlur, toggleButtonHandleBlur),
|
|
2538
|
+
...rest
|
|
2539
|
+
};
|
|
2482
2540
|
if (!rest.disabled) {
|
|
2483
2541
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
2484
2542
|
toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
|
|
@@ -2486,54 +2544,56 @@ function useSelect(userProps) {
|
|
|
2486
2544
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
2487
2545
|
return toggleProps;
|
|
2488
2546
|
}, [latest, elementIds, setGetterPropCallInfo, dispatch, mouseAndTouchTrackersRef, toggleButtonKeyDownHandlers, getItemNodeFromIndex]);
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2547
|
+
const getItemProps = react.useCallback(function (_temp5) {
|
|
2548
|
+
let {
|
|
2549
|
+
item: itemProp,
|
|
2550
|
+
index: indexProp,
|
|
2551
|
+
onMouseMove,
|
|
2552
|
+
onClick,
|
|
2553
|
+
refKey = 'ref',
|
|
2554
|
+
ref,
|
|
2555
|
+
disabled,
|
|
2556
|
+
...rest
|
|
2557
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
2558
|
+
const {
|
|
2559
|
+
state: latestState,
|
|
2560
|
+
props: latestProps
|
|
2561
|
+
} = latest.current;
|
|
2562
|
+
const item = itemProp ?? items[indexProp];
|
|
2563
|
+
const index = getItemIndex(indexProp, item, latestProps.items);
|
|
2564
|
+
const itemHandleMouseMove = () => {
|
|
2507
2565
|
if (index === latestState.highlightedIndex) {
|
|
2508
2566
|
return;
|
|
2509
2567
|
}
|
|
2510
2568
|
shouldScrollRef.current = false;
|
|
2511
2569
|
dispatch({
|
|
2512
2570
|
type: ItemMouseMove$1,
|
|
2513
|
-
index
|
|
2514
|
-
disabled
|
|
2571
|
+
index,
|
|
2572
|
+
disabled
|
|
2515
2573
|
});
|
|
2516
2574
|
};
|
|
2517
|
-
|
|
2575
|
+
const itemHandleClick = () => {
|
|
2518
2576
|
dispatch({
|
|
2519
2577
|
type: ItemClick$1,
|
|
2520
|
-
index
|
|
2578
|
+
index
|
|
2521
2579
|
});
|
|
2522
2580
|
};
|
|
2523
|
-
|
|
2581
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
2524
2582
|
if (itemIndex < 0) {
|
|
2525
2583
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
2526
2584
|
}
|
|
2527
|
-
|
|
2528
|
-
disabled
|
|
2585
|
+
const itemProps = {
|
|
2586
|
+
disabled,
|
|
2529
2587
|
role: 'option',
|
|
2530
|
-
'aria-selected':
|
|
2531
|
-
id: elementIds.getItemId(itemIndex)
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2588
|
+
'aria-selected': `${item === selectedItem}`,
|
|
2589
|
+
id: elementIds.getItemId(itemIndex),
|
|
2590
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
2591
|
+
if (itemNode) {
|
|
2592
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
2593
|
+
}
|
|
2594
|
+
}),
|
|
2595
|
+
...rest
|
|
2596
|
+
};
|
|
2537
2597
|
if (!disabled) {
|
|
2538
2598
|
itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
|
|
2539
2599
|
}
|
|
@@ -2542,49 +2602,49 @@ function useSelect(userProps) {
|
|
|
2542
2602
|
}, [latest, items, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
2543
2603
|
return {
|
|
2544
2604
|
// prop getters.
|
|
2545
|
-
getToggleButtonProps
|
|
2546
|
-
getLabelProps
|
|
2547
|
-
getMenuProps
|
|
2548
|
-
getItemProps
|
|
2605
|
+
getToggleButtonProps,
|
|
2606
|
+
getLabelProps,
|
|
2607
|
+
getMenuProps,
|
|
2608
|
+
getItemProps,
|
|
2549
2609
|
// actions.
|
|
2550
|
-
toggleMenu
|
|
2551
|
-
openMenu
|
|
2552
|
-
closeMenu
|
|
2553
|
-
setHighlightedIndex
|
|
2554
|
-
selectItem
|
|
2555
|
-
reset
|
|
2556
|
-
setInputValue
|
|
2610
|
+
toggleMenu,
|
|
2611
|
+
openMenu,
|
|
2612
|
+
closeMenu,
|
|
2613
|
+
setHighlightedIndex,
|
|
2614
|
+
selectItem,
|
|
2615
|
+
reset,
|
|
2616
|
+
setInputValue,
|
|
2557
2617
|
// state.
|
|
2558
|
-
highlightedIndex
|
|
2559
|
-
isOpen
|
|
2560
|
-
selectedItem
|
|
2561
|
-
inputValue
|
|
2618
|
+
highlightedIndex,
|
|
2619
|
+
isOpen,
|
|
2620
|
+
selectedItem,
|
|
2621
|
+
inputValue
|
|
2562
2622
|
};
|
|
2563
2623
|
}
|
|
2564
2624
|
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2625
|
+
const InputKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_down__' : 0;
|
|
2626
|
+
const InputKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__input_keydown_arrow_up__' : 1;
|
|
2627
|
+
const InputKeyDownEscape = process.env.NODE_ENV !== "production" ? '__input_keydown_escape__' : 2;
|
|
2628
|
+
const InputKeyDownHome = process.env.NODE_ENV !== "production" ? '__input_keydown_home__' : 3;
|
|
2629
|
+
const InputKeyDownEnd = process.env.NODE_ENV !== "production" ? '__input_keydown_end__' : 4;
|
|
2630
|
+
const InputKeyDownPageUp = process.env.NODE_ENV !== "production" ? '__input_keydown_page_up__' : 5;
|
|
2631
|
+
const InputKeyDownPageDown = process.env.NODE_ENV !== "production" ? '__input_keydown_page_down__' : 6;
|
|
2632
|
+
const InputKeyDownEnter = process.env.NODE_ENV !== "production" ? '__input_keydown_enter__' : 7;
|
|
2633
|
+
const InputChange = process.env.NODE_ENV !== "production" ? '__input_change__' : 8;
|
|
2634
|
+
const InputBlur = process.env.NODE_ENV !== "production" ? '__input_blur__' : 9;
|
|
2635
|
+
const InputFocus = process.env.NODE_ENV !== "production" ? '__input_focus__' : 10;
|
|
2636
|
+
const MenuMouseLeave = process.env.NODE_ENV !== "production" ? '__menu_mouse_leave__' : 11;
|
|
2637
|
+
const ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 12;
|
|
2638
|
+
const ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 13;
|
|
2639
|
+
const ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 14;
|
|
2640
|
+
const FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 15;
|
|
2641
|
+
const FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 16;
|
|
2642
|
+
const FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 17;
|
|
2643
|
+
const FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 18;
|
|
2644
|
+
const FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 19;
|
|
2645
|
+
const FunctionSetInputValue = process.env.NODE_ENV !== "production" ? '__function_set_input_value__' : 20;
|
|
2646
|
+
const FunctionReset$1 = process.env.NODE_ENV !== "production" ? '__function_reset__' : 21;
|
|
2647
|
+
const ControlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__controlled_prop_updated_selected_item__' : 22;
|
|
2588
2648
|
|
|
2589
2649
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
2590
2650
|
__proto__: null,
|
|
@@ -2614,17 +2674,22 @@ var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
|
2614
2674
|
});
|
|
2615
2675
|
|
|
2616
2676
|
function getInitialState$1(props) {
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2677
|
+
const initialState = getInitialState$2(props);
|
|
2678
|
+
const {
|
|
2679
|
+
selectedItem
|
|
2680
|
+
} = initialState;
|
|
2681
|
+
let {
|
|
2682
|
+
inputValue
|
|
2683
|
+
} = initialState;
|
|
2620
2684
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
2621
2685
|
inputValue = props.itemToString(selectedItem);
|
|
2622
2686
|
}
|
|
2623
|
-
return
|
|
2624
|
-
|
|
2625
|
-
|
|
2687
|
+
return {
|
|
2688
|
+
...initialState,
|
|
2689
|
+
inputValue
|
|
2690
|
+
};
|
|
2626
2691
|
}
|
|
2627
|
-
|
|
2692
|
+
const propTypes$1 = {
|
|
2628
2693
|
items: PropTypes__default["default"].array.isRequired,
|
|
2629
2694
|
itemToString: PropTypes__default["default"].func,
|
|
2630
2695
|
getA11yStatusMessage: PropTypes__default["default"].func,
|
|
@@ -2677,13 +2742,11 @@ var propTypes$1 = {
|
|
|
2677
2742
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
2678
2743
|
*/
|
|
2679
2744
|
function useControlledReducer(reducer, initialState, props) {
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
state = _useEnhancedReducer[0],
|
|
2683
|
-
dispatch = _useEnhancedReducer[1];
|
|
2745
|
+
const previousSelectedItemRef = react.useRef();
|
|
2746
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
|
|
2684
2747
|
|
|
2685
2748
|
// ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
2686
|
-
react.useEffect(
|
|
2749
|
+
react.useEffect(() => {
|
|
2687
2750
|
if (isControlledProp(props, 'selectedItem')) {
|
|
2688
2751
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
2689
2752
|
dispatch({
|
|
@@ -2698,23 +2761,26 @@ function useControlledReducer(reducer, initialState, props) {
|
|
|
2698
2761
|
}
|
|
2699
2762
|
|
|
2700
2763
|
// eslint-disable-next-line import/no-mutable-exports
|
|
2701
|
-
|
|
2764
|
+
let validatePropTypes$1 = noop;
|
|
2702
2765
|
/* istanbul ignore next */
|
|
2703
2766
|
if (process.env.NODE_ENV !== 'production') {
|
|
2704
|
-
validatePropTypes$1 =
|
|
2767
|
+
validatePropTypes$1 = (options, caller) => {
|
|
2705
2768
|
PropTypes__default["default"].checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
2706
2769
|
};
|
|
2707
2770
|
}
|
|
2708
|
-
|
|
2771
|
+
const defaultProps$1 = {
|
|
2772
|
+
...defaultProps$3,
|
|
2709
2773
|
getA11yStatusMessage: getA11yStatusMessage$1
|
|
2710
|
-
}
|
|
2774
|
+
};
|
|
2711
2775
|
|
|
2712
2776
|
/* eslint-disable complexity */
|
|
2713
2777
|
function downshiftUseComboboxReducer(state, action) {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2778
|
+
const {
|
|
2779
|
+
type,
|
|
2780
|
+
props,
|
|
2781
|
+
altKey
|
|
2782
|
+
} = action;
|
|
2783
|
+
let changes;
|
|
2718
2784
|
switch (type) {
|
|
2719
2785
|
case ItemClick:
|
|
2720
2786
|
changes = {
|
|
@@ -2739,13 +2805,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2739
2805
|
case InputKeyDownArrowUp:
|
|
2740
2806
|
if (state.isOpen) {
|
|
2741
2807
|
if (altKey) {
|
|
2742
|
-
changes =
|
|
2808
|
+
changes = {
|
|
2743
2809
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2744
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2810
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2811
|
+
...(state.highlightedIndex >= 0 && {
|
|
2812
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
2813
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2814
|
+
})
|
|
2815
|
+
};
|
|
2749
2816
|
} else {
|
|
2750
2817
|
changes = {
|
|
2751
2818
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -2759,22 +2826,24 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2759
2826
|
}
|
|
2760
2827
|
break;
|
|
2761
2828
|
case InputKeyDownEnter:
|
|
2762
|
-
changes =
|
|
2829
|
+
changes = {
|
|
2763
2830
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
2764
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2831
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
2832
|
+
...(state.highlightedIndex >= 0 && {
|
|
2833
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
2834
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2835
|
+
})
|
|
2836
|
+
};
|
|
2769
2837
|
break;
|
|
2770
2838
|
case InputKeyDownEscape:
|
|
2771
|
-
changes =
|
|
2839
|
+
changes = {
|
|
2772
2840
|
isOpen: false,
|
|
2773
|
-
highlightedIndex: -1
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2841
|
+
highlightedIndex: -1,
|
|
2842
|
+
...(!state.isOpen && {
|
|
2843
|
+
selectedItem: null,
|
|
2844
|
+
inputValue: ''
|
|
2845
|
+
})
|
|
2846
|
+
};
|
|
2778
2847
|
break;
|
|
2779
2848
|
case InputKeyDownPageUp:
|
|
2780
2849
|
changes = {
|
|
@@ -2797,13 +2866,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2797
2866
|
};
|
|
2798
2867
|
break;
|
|
2799
2868
|
case InputBlur:
|
|
2800
|
-
changes =
|
|
2869
|
+
changes = {
|
|
2801
2870
|
isOpen: false,
|
|
2802
|
-
highlightedIndex: -1
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2871
|
+
highlightedIndex: -1,
|
|
2872
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
2873
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
2874
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
2875
|
+
})
|
|
2876
|
+
};
|
|
2807
2877
|
break;
|
|
2808
2878
|
case InputChange:
|
|
2809
2879
|
changes = {
|
|
@@ -2832,14 +2902,14 @@ function downshiftUseComboboxReducer(state, action) {
|
|
|
2832
2902
|
default:
|
|
2833
2903
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
2834
2904
|
}
|
|
2835
|
-
return
|
|
2905
|
+
return {
|
|
2906
|
+
...state,
|
|
2907
|
+
...changes
|
|
2908
|
+
};
|
|
2836
2909
|
}
|
|
2837
2910
|
/* eslint-enable complexity */
|
|
2838
2911
|
|
|
2839
|
-
|
|
2840
|
-
_excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
2841
|
-
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
2842
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onFocus", "onBlur", "onChangeText", "refKey", "ref"];
|
|
2912
|
+
/* eslint-disable max-statements */
|
|
2843
2913
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
2844
2914
|
function useCombobox(userProps) {
|
|
2845
2915
|
if (userProps === void 0) {
|
|
@@ -2847,327 +2917,349 @@ function useCombobox(userProps) {
|
|
|
2847
2917
|
}
|
|
2848
2918
|
validatePropTypes$1(userProps, useCombobox);
|
|
2849
2919
|
// Props defaults and destructuring.
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2920
|
+
const props = {
|
|
2921
|
+
...defaultProps$1,
|
|
2922
|
+
...userProps
|
|
2923
|
+
};
|
|
2924
|
+
const {
|
|
2925
|
+
initialIsOpen,
|
|
2926
|
+
defaultIsOpen,
|
|
2927
|
+
items,
|
|
2928
|
+
scrollIntoView,
|
|
2929
|
+
environment,
|
|
2930
|
+
getA11yStatusMessage,
|
|
2931
|
+
getA11ySelectionMessage,
|
|
2932
|
+
itemToString
|
|
2933
|
+
} = props;
|
|
2859
2934
|
// Initial state depending on controlled props.
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2935
|
+
const initialState = getInitialState$1(props);
|
|
2936
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
2937
|
+
const {
|
|
2938
|
+
isOpen,
|
|
2939
|
+
highlightedIndex,
|
|
2940
|
+
selectedItem,
|
|
2941
|
+
inputValue
|
|
2942
|
+
} = state;
|
|
2868
2943
|
|
|
2869
2944
|
// Element refs.
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2945
|
+
const menuRef = react.useRef(null);
|
|
2946
|
+
const itemRefs = react.useRef({});
|
|
2947
|
+
const inputRef = react.useRef(null);
|
|
2948
|
+
const toggleButtonRef = react.useRef(null);
|
|
2949
|
+
const isInitialMountRef = react.useRef(true);
|
|
2875
2950
|
// prevent id re-generation between renders.
|
|
2876
|
-
|
|
2951
|
+
const elementIds = useElementIds(props);
|
|
2877
2952
|
// used to keep track of how many items we had on previous cycle.
|
|
2878
|
-
|
|
2953
|
+
const previousResultCountRef = react.useRef();
|
|
2879
2954
|
// utility callback to get item element.
|
|
2880
|
-
|
|
2881
|
-
state
|
|
2882
|
-
props
|
|
2955
|
+
const latest = useLatestRef({
|
|
2956
|
+
state,
|
|
2957
|
+
props
|
|
2883
2958
|
});
|
|
2884
|
-
|
|
2885
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
2886
|
-
}, [elementIds]);
|
|
2959
|
+
const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]);
|
|
2887
2960
|
|
|
2888
2961
|
// Effects.
|
|
2889
2962
|
// Sets a11y status message on changes in state.
|
|
2890
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
2963
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
2891
2964
|
isInitialMount: isInitialMountRef.current,
|
|
2892
2965
|
previousResultCount: previousResultCountRef.current,
|
|
2893
|
-
items
|
|
2894
|
-
environment
|
|
2895
|
-
itemToString
|
|
2896
|
-
|
|
2966
|
+
items,
|
|
2967
|
+
environment,
|
|
2968
|
+
itemToString,
|
|
2969
|
+
...state
|
|
2970
|
+
});
|
|
2897
2971
|
// Sets a11y status message on changes in selectedItem.
|
|
2898
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
2972
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
2899
2973
|
isInitialMount: isInitialMountRef.current,
|
|
2900
2974
|
previousResultCount: previousResultCountRef.current,
|
|
2901
|
-
items
|
|
2902
|
-
environment
|
|
2903
|
-
itemToString
|
|
2904
|
-
|
|
2975
|
+
items,
|
|
2976
|
+
environment,
|
|
2977
|
+
itemToString,
|
|
2978
|
+
...state
|
|
2979
|
+
});
|
|
2905
2980
|
// Scroll on highlighted item if change comes from keyboard.
|
|
2906
|
-
|
|
2981
|
+
const shouldScrollRef = useScrollIntoView({
|
|
2907
2982
|
menuElement: menuRef.current,
|
|
2908
|
-
highlightedIndex
|
|
2909
|
-
isOpen
|
|
2910
|
-
itemRefs
|
|
2911
|
-
scrollIntoView
|
|
2912
|
-
getItemNodeFromIndex
|
|
2983
|
+
highlightedIndex,
|
|
2984
|
+
isOpen,
|
|
2985
|
+
itemRefs,
|
|
2986
|
+
scrollIntoView,
|
|
2987
|
+
getItemNodeFromIndex
|
|
2913
2988
|
});
|
|
2914
2989
|
useControlPropsValidator({
|
|
2915
2990
|
isInitialMount: isInitialMountRef.current,
|
|
2916
|
-
props
|
|
2917
|
-
state
|
|
2991
|
+
props,
|
|
2992
|
+
state
|
|
2918
2993
|
});
|
|
2919
2994
|
// Focus the input on first render if required.
|
|
2920
|
-
react.useEffect(
|
|
2921
|
-
|
|
2995
|
+
react.useEffect(() => {
|
|
2996
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
2922
2997
|
if (focusOnOpen && inputRef.current) {
|
|
2923
2998
|
inputRef.current.focus();
|
|
2924
2999
|
}
|
|
2925
3000
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2926
3001
|
}, []);
|
|
2927
|
-
react.useEffect(
|
|
3002
|
+
react.useEffect(() => {
|
|
2928
3003
|
if (isInitialMountRef.current) {
|
|
2929
3004
|
return;
|
|
2930
3005
|
}
|
|
2931
3006
|
previousResultCountRef.current = items.length;
|
|
2932
3007
|
});
|
|
2933
3008
|
// Add mouse/touch events to document.
|
|
2934
|
-
|
|
3009
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, () => {
|
|
2935
3010
|
dispatch({
|
|
2936
3011
|
type: InputBlur,
|
|
2937
3012
|
selectItem: false
|
|
2938
3013
|
});
|
|
2939
3014
|
});
|
|
2940
|
-
|
|
3015
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
|
|
2941
3016
|
// Make initial ref false.
|
|
2942
|
-
react.useEffect(
|
|
3017
|
+
react.useEffect(() => {
|
|
2943
3018
|
isInitialMountRef.current = false;
|
|
2944
|
-
return
|
|
3019
|
+
return () => {
|
|
2945
3020
|
isInitialMountRef.current = true;
|
|
2946
3021
|
};
|
|
2947
3022
|
}, []);
|
|
2948
3023
|
// Reset itemRefs on close.
|
|
2949
|
-
react.useEffect(
|
|
3024
|
+
react.useEffect(() => {
|
|
2950
3025
|
if (!isOpen) {
|
|
2951
3026
|
itemRefs.current = {};
|
|
2952
3027
|
} else if (document.activeElement !== inputRef.current) {
|
|
2953
|
-
|
|
2954
|
-
inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
3028
|
+
inputRef?.current?.focus();
|
|
2955
3029
|
}
|
|
2956
3030
|
}, [isOpen]);
|
|
2957
3031
|
|
|
2958
3032
|
/* Event handler functions */
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
3033
|
+
const inputKeyDownHandlers = react.useMemo(() => ({
|
|
3034
|
+
ArrowDown(event) {
|
|
3035
|
+
event.preventDefault();
|
|
3036
|
+
dispatch({
|
|
3037
|
+
type: InputKeyDownArrowDown,
|
|
3038
|
+
altKey: event.altKey,
|
|
3039
|
+
getItemNodeFromIndex
|
|
3040
|
+
});
|
|
3041
|
+
},
|
|
3042
|
+
ArrowUp(event) {
|
|
3043
|
+
event.preventDefault();
|
|
3044
|
+
dispatch({
|
|
3045
|
+
type: InputKeyDownArrowUp,
|
|
3046
|
+
altKey: event.altKey,
|
|
3047
|
+
getItemNodeFromIndex
|
|
3048
|
+
});
|
|
3049
|
+
},
|
|
3050
|
+
Home(event) {
|
|
3051
|
+
if (!latest.current.state.isOpen) {
|
|
3052
|
+
return;
|
|
3053
|
+
}
|
|
3054
|
+
event.preventDefault();
|
|
3055
|
+
dispatch({
|
|
3056
|
+
type: InputKeyDownHome,
|
|
3057
|
+
getItemNodeFromIndex
|
|
3058
|
+
});
|
|
3059
|
+
},
|
|
3060
|
+
End(event) {
|
|
3061
|
+
if (!latest.current.state.isOpen) {
|
|
3062
|
+
return;
|
|
3063
|
+
}
|
|
3064
|
+
event.preventDefault();
|
|
3065
|
+
dispatch({
|
|
3066
|
+
type: InputKeyDownEnd,
|
|
3067
|
+
getItemNodeFromIndex
|
|
3068
|
+
});
|
|
3069
|
+
},
|
|
3070
|
+
Escape(event) {
|
|
3071
|
+
const latestState = latest.current.state;
|
|
3072
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
2981
3073
|
event.preventDefault();
|
|
2982
3074
|
dispatch({
|
|
2983
|
-
type:
|
|
2984
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3075
|
+
type: InputKeyDownEscape
|
|
2985
3076
|
});
|
|
2986
|
-
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
3077
|
+
}
|
|
3078
|
+
},
|
|
3079
|
+
Enter(event) {
|
|
3080
|
+
const latestState = latest.current.state;
|
|
3081
|
+
// if closed or no highlighted index, do nothing.
|
|
3082
|
+
if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3083
|
+
) {
|
|
3084
|
+
return;
|
|
3085
|
+
}
|
|
3086
|
+
event.preventDefault();
|
|
3087
|
+
dispatch({
|
|
3088
|
+
type: InputKeyDownEnter,
|
|
3089
|
+
getItemNodeFromIndex
|
|
3090
|
+
});
|
|
3091
|
+
},
|
|
3092
|
+
PageUp(event) {
|
|
3093
|
+
if (latest.current.state.isOpen) {
|
|
2991
3094
|
event.preventDefault();
|
|
2992
3095
|
dispatch({
|
|
2993
|
-
type:
|
|
2994
|
-
getItemNodeFromIndex
|
|
3096
|
+
type: InputKeyDownPageUp,
|
|
3097
|
+
getItemNodeFromIndex
|
|
2995
3098
|
});
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
event.preventDefault();
|
|
3001
|
-
dispatch({
|
|
3002
|
-
type: InputKeyDownEscape
|
|
3003
|
-
});
|
|
3004
|
-
}
|
|
3005
|
-
},
|
|
3006
|
-
Enter: function Enter(event) {
|
|
3007
|
-
var latestState = latest.current.state;
|
|
3008
|
-
// if closed or no highlighted index, do nothing.
|
|
3009
|
-
if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
3010
|
-
) {
|
|
3011
|
-
return;
|
|
3012
|
-
}
|
|
3099
|
+
}
|
|
3100
|
+
},
|
|
3101
|
+
PageDown(event) {
|
|
3102
|
+
if (latest.current.state.isOpen) {
|
|
3013
3103
|
event.preventDefault();
|
|
3014
3104
|
dispatch({
|
|
3015
|
-
type:
|
|
3016
|
-
getItemNodeFromIndex
|
|
3105
|
+
type: InputKeyDownPageDown,
|
|
3106
|
+
getItemNodeFromIndex
|
|
3017
3107
|
});
|
|
3018
|
-
},
|
|
3019
|
-
PageUp: function PageUp(event) {
|
|
3020
|
-
if (latest.current.state.isOpen) {
|
|
3021
|
-
event.preventDefault();
|
|
3022
|
-
dispatch({
|
|
3023
|
-
type: InputKeyDownPageUp,
|
|
3024
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3025
|
-
});
|
|
3026
|
-
}
|
|
3027
|
-
},
|
|
3028
|
-
PageDown: function PageDown(event) {
|
|
3029
|
-
if (latest.current.state.isOpen) {
|
|
3030
|
-
event.preventDefault();
|
|
3031
|
-
dispatch({
|
|
3032
|
-
type: InputKeyDownPageDown,
|
|
3033
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3034
|
-
});
|
|
3035
|
-
}
|
|
3036
3108
|
}
|
|
3037
|
-
}
|
|
3038
|
-
}, [dispatch, latest, getItemNodeFromIndex]);
|
|
3109
|
+
}
|
|
3110
|
+
}), [dispatch, latest, getItemNodeFromIndex]);
|
|
3039
3111
|
|
|
3040
3112
|
// Getter props.
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3057
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3113
|
+
const getLabelProps = react.useCallback(labelProps => ({
|
|
3114
|
+
id: elementIds.labelId,
|
|
3115
|
+
htmlFor: elementIds.inputId,
|
|
3116
|
+
...labelProps
|
|
3117
|
+
}), [elementIds]);
|
|
3118
|
+
const getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
3119
|
+
let {
|
|
3120
|
+
onMouseLeave,
|
|
3121
|
+
refKey = 'ref',
|
|
3122
|
+
ref,
|
|
3123
|
+
...rest
|
|
3124
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3125
|
+
let {
|
|
3126
|
+
suppressRefError = false
|
|
3127
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3058
3128
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3059
|
-
return
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3129
|
+
return {
|
|
3130
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
3131
|
+
menuRef.current = menuNode;
|
|
3132
|
+
}),
|
|
3133
|
+
id: elementIds.menuId,
|
|
3134
|
+
role: 'listbox',
|
|
3135
|
+
'aria-labelledby': elementIds.labelId,
|
|
3136
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
3137
|
+
dispatch({
|
|
3138
|
+
type: MenuMouseLeave
|
|
3139
|
+
});
|
|
3140
|
+
}),
|
|
3141
|
+
...rest
|
|
3142
|
+
};
|
|
3066
3143
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3144
|
+
const getItemProps = react.useCallback(function (_temp3) {
|
|
3145
|
+
let {
|
|
3146
|
+
item,
|
|
3147
|
+
index,
|
|
3148
|
+
refKey = 'ref',
|
|
3149
|
+
ref,
|
|
3150
|
+
onMouseMove,
|
|
3151
|
+
onMouseDown,
|
|
3152
|
+
onClick,
|
|
3153
|
+
onPress,
|
|
3154
|
+
disabled,
|
|
3155
|
+
...rest
|
|
3156
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3157
|
+
const {
|
|
3158
|
+
props: latestProps,
|
|
3159
|
+
state: latestState
|
|
3160
|
+
} = latest.current;
|
|
3161
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3085
3162
|
if (itemIndex < 0) {
|
|
3086
3163
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3087
3164
|
}
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3165
|
+
const onSelectKey = /* istanbul ignore next (react-native) */'onPress' ;
|
|
3166
|
+
const customClickHandler = /* istanbul ignore next (react-native) */onPress ;
|
|
3167
|
+
const itemHandleMouseMove = () => {
|
|
3091
3168
|
if (index === latestState.highlightedIndex) {
|
|
3092
3169
|
return;
|
|
3093
3170
|
}
|
|
3094
3171
|
shouldScrollRef.current = false;
|
|
3095
3172
|
dispatch({
|
|
3096
3173
|
type: ItemMouseMove,
|
|
3097
|
-
index
|
|
3098
|
-
disabled
|
|
3174
|
+
index,
|
|
3175
|
+
disabled
|
|
3099
3176
|
});
|
|
3100
3177
|
};
|
|
3101
|
-
|
|
3178
|
+
const itemHandleClick = () => {
|
|
3102
3179
|
dispatch({
|
|
3103
3180
|
type: ItemClick,
|
|
3104
|
-
index
|
|
3181
|
+
index
|
|
3105
3182
|
});
|
|
3106
3183
|
};
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3184
|
+
const itemHandleMouseDown = e => e.preventDefault();
|
|
3185
|
+
return {
|
|
3186
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
3187
|
+
if (itemNode) {
|
|
3188
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3189
|
+
}
|
|
3190
|
+
}),
|
|
3191
|
+
disabled,
|
|
3192
|
+
role: 'option',
|
|
3193
|
+
'aria-selected': `${itemIndex === latestState.highlightedIndex}`,
|
|
3194
|
+
id: elementIds.getItemId(itemIndex),
|
|
3195
|
+
...(!disabled && {
|
|
3196
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
3197
|
+
}),
|
|
3115
3198
|
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
3116
|
-
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
3117
|
-
|
|
3199
|
+
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown),
|
|
3200
|
+
...rest
|
|
3201
|
+
};
|
|
3118
3202
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3203
|
+
const getToggleButtonProps = react.useCallback(function (_temp4) {
|
|
3204
|
+
let {
|
|
3205
|
+
onClick,
|
|
3206
|
+
onPress,
|
|
3207
|
+
refKey = 'ref',
|
|
3208
|
+
ref,
|
|
3209
|
+
...rest
|
|
3210
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
3211
|
+
const latestState = latest.current.state;
|
|
3212
|
+
const toggleButtonHandleClick = () => {
|
|
3130
3213
|
dispatch({
|
|
3131
3214
|
type: ToggleButtonClick
|
|
3132
3215
|
});
|
|
3133
3216
|
};
|
|
3134
|
-
return
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3217
|
+
return {
|
|
3218
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
3219
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3220
|
+
}),
|
|
3221
|
+
'aria-controls': elementIds.menuId,
|
|
3222
|
+
'aria-expanded': latestState.isOpen,
|
|
3223
|
+
id: elementIds.toggleButtonId,
|
|
3224
|
+
tabIndex: -1,
|
|
3225
|
+
...(!rest.disabled && {
|
|
3226
|
+
...(/* istanbul ignore next (react-native) */{
|
|
3227
|
+
onPress: callAllEventHandlers(onPress, toggleButtonHandleClick)
|
|
3228
|
+
} )
|
|
3229
|
+
}),
|
|
3230
|
+
...rest
|
|
3231
|
+
};
|
|
3139
3232
|
}, [dispatch, latest, elementIds]);
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
3233
|
+
const getInputProps = react.useCallback(function (_temp5, _temp6) {
|
|
3234
|
+
let {
|
|
3235
|
+
onKeyDown,
|
|
3236
|
+
onChange,
|
|
3237
|
+
onInput,
|
|
3238
|
+
onFocus,
|
|
3239
|
+
onBlur,
|
|
3240
|
+
onChangeText,
|
|
3241
|
+
refKey = 'ref',
|
|
3242
|
+
ref,
|
|
3243
|
+
...rest
|
|
3244
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
3245
|
+
let {
|
|
3246
|
+
suppressRefError = false
|
|
3247
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
3156
3248
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3249
|
+
const latestState = latest.current.state;
|
|
3250
|
+
const inputHandleKeyDown = event => {
|
|
3251
|
+
const key = normalizeArrowKey(event);
|
|
3160
3252
|
if (key && inputKeyDownHandlers[key]) {
|
|
3161
3253
|
inputKeyDownHandlers[key](event);
|
|
3162
3254
|
}
|
|
3163
3255
|
};
|
|
3164
|
-
|
|
3256
|
+
const inputHandleChange = event => {
|
|
3165
3257
|
dispatch({
|
|
3166
3258
|
type: InputChange,
|
|
3167
3259
|
inputValue: /* istanbul ignore next (react-native) */event.nativeEvent.text
|
|
3168
3260
|
});
|
|
3169
3261
|
};
|
|
3170
|
-
|
|
3262
|
+
const inputHandleBlur = () => {
|
|
3171
3263
|
/* istanbul ignore else */
|
|
3172
3264
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3173
3265
|
dispatch({
|
|
@@ -3176,7 +3268,7 @@ function useCombobox(userProps) {
|
|
|
3176
3268
|
});
|
|
3177
3269
|
}
|
|
3178
3270
|
};
|
|
3179
|
-
|
|
3271
|
+
const inputHandleFocus = () => {
|
|
3180
3272
|
if (!latestState.isOpen) {
|
|
3181
3273
|
dispatch({
|
|
3182
3274
|
type: InputFocus
|
|
@@ -3185,92 +3277,111 @@ function useCombobox(userProps) {
|
|
|
3185
3277
|
};
|
|
3186
3278
|
|
|
3187
3279
|
/* istanbul ignore next (preact) */
|
|
3188
|
-
|
|
3189
|
-
|
|
3280
|
+
const onChangeKey = 'onChange';
|
|
3281
|
+
let eventHandlers = {};
|
|
3190
3282
|
if (!rest.disabled) {
|
|
3191
|
-
|
|
3192
|
-
|
|
3283
|
+
eventHandlers = {
|
|
3284
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
3285
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
3286
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur),
|
|
3287
|
+
onFocus: callAllEventHandlers(onFocus, inputHandleFocus)
|
|
3288
|
+
};
|
|
3193
3289
|
}
|
|
3194
3290
|
|
|
3195
3291
|
/* istanbul ignore if (react-native) */
|
|
3196
3292
|
{
|
|
3197
3293
|
eventHandlers.onChange = callAllEventHandlers(onChange, onInput, inputHandleChange);
|
|
3198
|
-
eventHandlers.onChangeText = callAllEventHandlers(onChangeText, onInput,
|
|
3294
|
+
eventHandlers.onChangeText = callAllEventHandlers(onChangeText, onInput, text => {
|
|
3199
3295
|
inputHandleChange({
|
|
3200
3296
|
nativeEvent: {
|
|
3201
|
-
text
|
|
3297
|
+
text
|
|
3202
3298
|
}
|
|
3203
3299
|
});
|
|
3204
3300
|
});
|
|
3205
3301
|
}
|
|
3206
|
-
return
|
|
3207
|
-
|
|
3208
|
-
|
|
3302
|
+
return {
|
|
3303
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
3304
|
+
inputRef.current = inputNode;
|
|
3305
|
+
}),
|
|
3306
|
+
'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
|
|
3307
|
+
'aria-autocomplete': 'list',
|
|
3308
|
+
'aria-controls': elementIds.menuId,
|
|
3309
|
+
'aria-expanded': latestState.isOpen,
|
|
3310
|
+
'aria-labelledby': elementIds.labelId,
|
|
3311
|
+
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
3312
|
+
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
3313
|
+
autoComplete: 'off',
|
|
3314
|
+
id: elementIds.inputId,
|
|
3315
|
+
role: 'combobox',
|
|
3316
|
+
value: latestState.inputValue,
|
|
3317
|
+
...eventHandlers,
|
|
3318
|
+
...rest
|
|
3319
|
+
};
|
|
3209
3320
|
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
|
|
3210
3321
|
|
|
3211
3322
|
// returns
|
|
3212
|
-
|
|
3323
|
+
const toggleMenu = react.useCallback(() => {
|
|
3213
3324
|
dispatch({
|
|
3214
3325
|
type: FunctionToggleMenu
|
|
3215
3326
|
});
|
|
3216
3327
|
}, [dispatch]);
|
|
3217
|
-
|
|
3328
|
+
const closeMenu = react.useCallback(() => {
|
|
3218
3329
|
dispatch({
|
|
3219
3330
|
type: FunctionCloseMenu
|
|
3220
3331
|
});
|
|
3221
3332
|
}, [dispatch]);
|
|
3222
|
-
|
|
3333
|
+
const openMenu = react.useCallback(() => {
|
|
3223
3334
|
dispatch({
|
|
3224
3335
|
type: FunctionOpenMenu
|
|
3225
3336
|
});
|
|
3226
3337
|
}, [dispatch]);
|
|
3227
|
-
|
|
3338
|
+
const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
|
|
3228
3339
|
dispatch({
|
|
3229
3340
|
type: FunctionSetHighlightedIndex,
|
|
3230
3341
|
highlightedIndex: newHighlightedIndex
|
|
3231
3342
|
});
|
|
3232
3343
|
}, [dispatch]);
|
|
3233
|
-
|
|
3344
|
+
const selectItem = react.useCallback(newSelectedItem => {
|
|
3234
3345
|
dispatch({
|
|
3235
3346
|
type: FunctionSelectItem,
|
|
3236
3347
|
selectedItem: newSelectedItem
|
|
3237
3348
|
});
|
|
3238
3349
|
}, [dispatch]);
|
|
3239
|
-
|
|
3350
|
+
const setInputValue = react.useCallback(newInputValue => {
|
|
3240
3351
|
dispatch({
|
|
3241
3352
|
type: FunctionSetInputValue,
|
|
3242
3353
|
inputValue: newInputValue
|
|
3243
3354
|
});
|
|
3244
3355
|
}, [dispatch]);
|
|
3245
|
-
|
|
3356
|
+
const reset = react.useCallback(() => {
|
|
3246
3357
|
dispatch({
|
|
3247
3358
|
type: FunctionReset$1
|
|
3248
3359
|
});
|
|
3249
3360
|
}, [dispatch]);
|
|
3250
3361
|
return {
|
|
3251
3362
|
// prop getters.
|
|
3252
|
-
getItemProps
|
|
3253
|
-
getLabelProps
|
|
3254
|
-
getMenuProps
|
|
3255
|
-
getInputProps
|
|
3256
|
-
getToggleButtonProps
|
|
3363
|
+
getItemProps,
|
|
3364
|
+
getLabelProps,
|
|
3365
|
+
getMenuProps,
|
|
3366
|
+
getInputProps,
|
|
3367
|
+
getToggleButtonProps,
|
|
3257
3368
|
// actions.
|
|
3258
|
-
toggleMenu
|
|
3259
|
-
openMenu
|
|
3260
|
-
closeMenu
|
|
3261
|
-
setHighlightedIndex
|
|
3262
|
-
setInputValue
|
|
3263
|
-
selectItem
|
|
3264
|
-
reset
|
|
3369
|
+
toggleMenu,
|
|
3370
|
+
openMenu,
|
|
3371
|
+
closeMenu,
|
|
3372
|
+
setHighlightedIndex,
|
|
3373
|
+
setInputValue,
|
|
3374
|
+
selectItem,
|
|
3375
|
+
reset,
|
|
3265
3376
|
// state.
|
|
3266
|
-
highlightedIndex
|
|
3267
|
-
isOpen
|
|
3268
|
-
selectedItem
|
|
3269
|
-
inputValue
|
|
3377
|
+
highlightedIndex,
|
|
3378
|
+
isOpen,
|
|
3379
|
+
selectedItem,
|
|
3380
|
+
inputValue
|
|
3270
3381
|
};
|
|
3271
3382
|
}
|
|
3272
3383
|
|
|
3273
|
-
|
|
3384
|
+
const defaultStateValues = {
|
|
3274
3385
|
activeIndex: -1,
|
|
3275
3386
|
selectedItems: []
|
|
3276
3387
|
};
|
|
@@ -3308,11 +3419,11 @@ function getDefaultValue(props, propKey) {
|
|
|
3308
3419
|
* @returns {Object} The initial state.
|
|
3309
3420
|
*/
|
|
3310
3421
|
function getInitialState(props) {
|
|
3311
|
-
|
|
3312
|
-
|
|
3422
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
3423
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
3313
3424
|
return {
|
|
3314
|
-
activeIndex
|
|
3315
|
-
selectedItems
|
|
3425
|
+
activeIndex,
|
|
3426
|
+
selectedItems
|
|
3316
3427
|
};
|
|
3317
3428
|
}
|
|
3318
3429
|
|
|
@@ -3329,7 +3440,7 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3329
3440
|
if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) {
|
|
3330
3441
|
return false;
|
|
3331
3442
|
}
|
|
3332
|
-
|
|
3443
|
+
const element = event.target;
|
|
3333
3444
|
if (element instanceof HTMLInputElement &&
|
|
3334
3445
|
// if element is a text input
|
|
3335
3446
|
element.value !== '' && (
|
|
@@ -3348,11 +3459,13 @@ function isKeyDownOperationPermitted(event) {
|
|
|
3348
3459
|
* @returns {string} The a11y message.
|
|
3349
3460
|
*/
|
|
3350
3461
|
function getA11yRemovalMessage(selectionParameters) {
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3462
|
+
const {
|
|
3463
|
+
removedSelectedItem,
|
|
3464
|
+
itemToString: itemToStringLocal
|
|
3465
|
+
} = selectionParameters;
|
|
3466
|
+
return `${itemToStringLocal(removedSelectedItem)} has been removed.`;
|
|
3354
3467
|
}
|
|
3355
|
-
|
|
3468
|
+
const propTypes = {
|
|
3356
3469
|
selectedItems: PropTypes__default["default"].array,
|
|
3357
3470
|
initialSelectedItems: PropTypes__default["default"].array,
|
|
3358
3471
|
defaultSelectedItems: PropTypes__default["default"].array,
|
|
@@ -3376,37 +3489,37 @@ var propTypes = {
|
|
|
3376
3489
|
})
|
|
3377
3490
|
})
|
|
3378
3491
|
};
|
|
3379
|
-
|
|
3492
|
+
const defaultProps = {
|
|
3380
3493
|
itemToString: defaultProps$3.itemToString,
|
|
3381
3494
|
stateReducer: defaultProps$3.stateReducer,
|
|
3382
3495
|
environment: defaultProps$3.environment,
|
|
3383
|
-
getA11yRemovalMessage
|
|
3496
|
+
getA11yRemovalMessage,
|
|
3384
3497
|
keyNavigationNext: 'ArrowRight',
|
|
3385
3498
|
keyNavigationPrevious: 'ArrowLeft'
|
|
3386
3499
|
};
|
|
3387
3500
|
|
|
3388
3501
|
// eslint-disable-next-line import/no-mutable-exports
|
|
3389
|
-
|
|
3502
|
+
let validatePropTypes = noop;
|
|
3390
3503
|
/* istanbul ignore next */
|
|
3391
3504
|
if (process.env.NODE_ENV !== 'production') {
|
|
3392
|
-
validatePropTypes =
|
|
3505
|
+
validatePropTypes = (options, caller) => {
|
|
3393
3506
|
PropTypes__default["default"].checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
3394
3507
|
};
|
|
3395
3508
|
}
|
|
3396
3509
|
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3510
|
+
const SelectedItemClick = process.env.NODE_ENV !== "production" ? '__selected_item_click__' : 0;
|
|
3511
|
+
const SelectedItemKeyDownDelete = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_delete__' : 1;
|
|
3512
|
+
const SelectedItemKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_backspace__' : 2;
|
|
3513
|
+
const SelectedItemKeyDownNavigationNext = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_next__' : 3;
|
|
3514
|
+
const SelectedItemKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__selected_item_keydown_navigation_previous__' : 4;
|
|
3515
|
+
const DropdownKeyDownNavigationPrevious = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_navigation_previous__' : 5;
|
|
3516
|
+
const DropdownKeyDownBackspace = process.env.NODE_ENV !== "production" ? '__dropdown_keydown_backspace__' : 6;
|
|
3517
|
+
const DropdownClick = process.env.NODE_ENV !== "production" ? '__dropdown_click__' : 7;
|
|
3518
|
+
const FunctionAddSelectedItem = process.env.NODE_ENV !== "production" ? '__function_add_selected_item__' : 8;
|
|
3519
|
+
const FunctionRemoveSelectedItem = process.env.NODE_ENV !== "production" ? '__function_remove_selected_item__' : 9;
|
|
3520
|
+
const FunctionSetSelectedItems = process.env.NODE_ENV !== "production" ? '__function_set_selected_items__' : 10;
|
|
3521
|
+
const FunctionSetActiveIndex = process.env.NODE_ENV !== "production" ? '__function_set_active_index__' : 11;
|
|
3522
|
+
const FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 12;
|
|
3410
3523
|
|
|
3411
3524
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
3412
3525
|
__proto__: null,
|
|
@@ -3427,13 +3540,17 @@ var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
|
3427
3540
|
|
|
3428
3541
|
/* eslint-disable complexity */
|
|
3429
3542
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3543
|
+
const {
|
|
3544
|
+
type,
|
|
3545
|
+
index,
|
|
3546
|
+
props,
|
|
3547
|
+
selectedItem
|
|
3548
|
+
} = action;
|
|
3549
|
+
const {
|
|
3550
|
+
activeIndex,
|
|
3551
|
+
selectedItems
|
|
3552
|
+
} = state;
|
|
3553
|
+
let changes;
|
|
3437
3554
|
switch (type) {
|
|
3438
3555
|
case SelectedItemClick:
|
|
3439
3556
|
changes = {
|
|
@@ -3456,17 +3573,18 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3456
3573
|
if (activeIndex < 0) {
|
|
3457
3574
|
break;
|
|
3458
3575
|
}
|
|
3459
|
-
|
|
3576
|
+
let newActiveIndex = activeIndex;
|
|
3460
3577
|
if (selectedItems.length === 1) {
|
|
3461
3578
|
newActiveIndex = -1;
|
|
3462
3579
|
} else if (activeIndex === selectedItems.length - 1) {
|
|
3463
3580
|
newActiveIndex = selectedItems.length - 2;
|
|
3464
3581
|
}
|
|
3465
|
-
changes =
|
|
3466
|
-
selectedItems: [
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3582
|
+
changes = {
|
|
3583
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
3584
|
+
...{
|
|
3585
|
+
activeIndex: newActiveIndex
|
|
3586
|
+
}
|
|
3587
|
+
};
|
|
3470
3588
|
break;
|
|
3471
3589
|
}
|
|
3472
3590
|
case DropdownKeyDownNavigationPrevious:
|
|
@@ -3481,7 +3599,7 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3481
3599
|
break;
|
|
3482
3600
|
case FunctionAddSelectedItem:
|
|
3483
3601
|
changes = {
|
|
3484
|
-
selectedItems: [
|
|
3602
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
3485
3603
|
};
|
|
3486
3604
|
break;
|
|
3487
3605
|
case DropdownClick:
|
|
@@ -3491,25 +3609,27 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3491
3609
|
break;
|
|
3492
3610
|
case FunctionRemoveSelectedItem:
|
|
3493
3611
|
{
|
|
3494
|
-
|
|
3495
|
-
|
|
3612
|
+
let newActiveIndex = activeIndex;
|
|
3613
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
3496
3614
|
if (selectedItemIndex < 0) {
|
|
3497
3615
|
break;
|
|
3498
3616
|
}
|
|
3499
3617
|
if (selectedItems.length === 1) {
|
|
3500
|
-
|
|
3618
|
+
newActiveIndex = -1;
|
|
3501
3619
|
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
3502
|
-
|
|
3620
|
+
newActiveIndex = selectedItems.length - 2;
|
|
3503
3621
|
}
|
|
3504
3622
|
changes = {
|
|
3505
|
-
selectedItems: [
|
|
3506
|
-
activeIndex:
|
|
3623
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
3624
|
+
activeIndex: newActiveIndex
|
|
3507
3625
|
};
|
|
3508
3626
|
break;
|
|
3509
3627
|
}
|
|
3510
3628
|
case FunctionSetSelectedItems:
|
|
3511
3629
|
{
|
|
3512
|
-
|
|
3630
|
+
const {
|
|
3631
|
+
selectedItems: newSelectedItems
|
|
3632
|
+
} = action;
|
|
3513
3633
|
changes = {
|
|
3514
3634
|
selectedItems: newSelectedItems
|
|
3515
3635
|
};
|
|
@@ -3517,9 +3637,11 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3517
3637
|
}
|
|
3518
3638
|
case FunctionSetActiveIndex:
|
|
3519
3639
|
{
|
|
3520
|
-
|
|
3640
|
+
const {
|
|
3641
|
+
activeIndex: newActiveIndex
|
|
3642
|
+
} = action;
|
|
3521
3643
|
changes = {
|
|
3522
|
-
activeIndex:
|
|
3644
|
+
activeIndex: newActiveIndex
|
|
3523
3645
|
};
|
|
3524
3646
|
break;
|
|
3525
3647
|
}
|
|
@@ -3532,11 +3654,12 @@ function downshiftMultipleSelectionReducer(state, action) {
|
|
|
3532
3654
|
default:
|
|
3533
3655
|
throw new Error('Reducer called without proper action type.');
|
|
3534
3656
|
}
|
|
3535
|
-
return
|
|
3657
|
+
return {
|
|
3658
|
+
...state,
|
|
3659
|
+
...changes
|
|
3660
|
+
};
|
|
3536
3661
|
}
|
|
3537
3662
|
|
|
3538
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
3539
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
3540
3663
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
3541
3664
|
function useMultipleSelection(userProps) {
|
|
3542
3665
|
if (userProps === void 0) {
|
|
@@ -3544,46 +3667,49 @@ function useMultipleSelection(userProps) {
|
|
|
3544
3667
|
}
|
|
3545
3668
|
validatePropTypes(userProps, useMultipleSelection);
|
|
3546
3669
|
// Props defaults and destructuring.
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3670
|
+
const props = {
|
|
3671
|
+
...defaultProps,
|
|
3672
|
+
...userProps
|
|
3673
|
+
};
|
|
3674
|
+
const {
|
|
3675
|
+
getA11yRemovalMessage,
|
|
3676
|
+
itemToString,
|
|
3677
|
+
environment,
|
|
3678
|
+
keyNavigationNext,
|
|
3679
|
+
keyNavigationPrevious
|
|
3680
|
+
} = props;
|
|
3553
3681
|
|
|
3554
3682
|
// Reducer init.
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3683
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
3684
|
+
const {
|
|
3685
|
+
activeIndex,
|
|
3686
|
+
selectedItems
|
|
3687
|
+
} = state;
|
|
3560
3688
|
|
|
3561
3689
|
// Refs.
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3690
|
+
const isInitialMountRef = react.useRef(true);
|
|
3691
|
+
const dropdownRef = react.useRef(null);
|
|
3692
|
+
const previousSelectedItemsRef = react.useRef(selectedItems);
|
|
3693
|
+
const selectedItemRefs = react.useRef();
|
|
3566
3694
|
selectedItemRefs.current = [];
|
|
3567
|
-
|
|
3568
|
-
state
|
|
3569
|
-
props
|
|
3695
|
+
const latest = useLatestRef({
|
|
3696
|
+
state,
|
|
3697
|
+
props
|
|
3570
3698
|
});
|
|
3571
3699
|
|
|
3572
3700
|
// Effects.
|
|
3573
3701
|
/* Sets a11y status message on changes in selectedItem. */
|
|
3574
|
-
react.useEffect(
|
|
3702
|
+
react.useEffect(() => {
|
|
3575
3703
|
if (isInitialMountRef.current) {
|
|
3576
3704
|
return;
|
|
3577
3705
|
}
|
|
3578
3706
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
3579
|
-
|
|
3580
|
-
return selectedItems.indexOf(item) < 0;
|
|
3581
|
-
});
|
|
3707
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
3582
3708
|
setStatus(getA11yRemovalMessage({
|
|
3583
|
-
itemToString
|
|
3709
|
+
itemToString,
|
|
3584
3710
|
resultCount: selectedItems.length,
|
|
3585
|
-
removedSelectedItem
|
|
3586
|
-
activeIndex
|
|
3711
|
+
removedSelectedItem,
|
|
3712
|
+
activeIndex,
|
|
3587
3713
|
activeSelectedItem: selectedItems[activeIndex]
|
|
3588
3714
|
}), environment.document);
|
|
3589
3715
|
}
|
|
@@ -3592,7 +3718,7 @@ function useMultipleSelection(userProps) {
|
|
|
3592
3718
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3593
3719
|
}, [selectedItems.length]);
|
|
3594
3720
|
// Sets focus on active item.
|
|
3595
|
-
react.useEffect(
|
|
3721
|
+
react.useEffect(() => {
|
|
3596
3722
|
if (isInitialMountRef.current) {
|
|
3597
3723
|
return;
|
|
3598
3724
|
}
|
|
@@ -3604,167 +3730,178 @@ function useMultipleSelection(userProps) {
|
|
|
3604
3730
|
}, [activeIndex]);
|
|
3605
3731
|
useControlPropsValidator({
|
|
3606
3732
|
isInitialMount: isInitialMountRef.current,
|
|
3607
|
-
props
|
|
3608
|
-
state
|
|
3733
|
+
props,
|
|
3734
|
+
state
|
|
3609
3735
|
});
|
|
3610
|
-
|
|
3736
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
|
|
3611
3737
|
// Make initial ref false.
|
|
3612
|
-
react.useEffect(
|
|
3738
|
+
react.useEffect(() => {
|
|
3613
3739
|
isInitialMountRef.current = false;
|
|
3614
|
-
return
|
|
3740
|
+
return () => {
|
|
3615
3741
|
isInitialMountRef.current = true;
|
|
3616
3742
|
};
|
|
3617
3743
|
}, []);
|
|
3618
3744
|
|
|
3619
3745
|
// Event handler functions.
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
3746
|
+
const selectedItemKeyDownHandlers = react.useMemo(() => ({
|
|
3747
|
+
[keyNavigationPrevious]() {
|
|
3623
3748
|
dispatch({
|
|
3624
3749
|
type: SelectedItemKeyDownNavigationPrevious
|
|
3625
3750
|
});
|
|
3626
|
-
},
|
|
3751
|
+
},
|
|
3752
|
+
[keyNavigationNext]() {
|
|
3627
3753
|
dispatch({
|
|
3628
3754
|
type: SelectedItemKeyDownNavigationNext
|
|
3629
3755
|
});
|
|
3630
|
-
},
|
|
3756
|
+
},
|
|
3757
|
+
Delete() {
|
|
3631
3758
|
dispatch({
|
|
3632
3759
|
type: SelectedItemKeyDownDelete
|
|
3633
3760
|
});
|
|
3634
|
-
},
|
|
3761
|
+
},
|
|
3762
|
+
Backspace() {
|
|
3635
3763
|
dispatch({
|
|
3636
3764
|
type: SelectedItemKeyDownBackspace
|
|
3637
3765
|
});
|
|
3638
|
-
}
|
|
3639
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
|
|
3766
|
+
}
|
|
3767
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
3768
|
+
const dropdownKeyDownHandlers = react.useMemo(() => ({
|
|
3769
|
+
[keyNavigationPrevious](event) {
|
|
3643
3770
|
if (isKeyDownOperationPermitted(event)) {
|
|
3644
3771
|
dispatch({
|
|
3645
3772
|
type: DropdownKeyDownNavigationPrevious
|
|
3646
3773
|
});
|
|
3647
3774
|
}
|
|
3648
|
-
},
|
|
3775
|
+
},
|
|
3776
|
+
Backspace(event) {
|
|
3649
3777
|
if (isKeyDownOperationPermitted(event)) {
|
|
3650
3778
|
dispatch({
|
|
3651
3779
|
type: DropdownKeyDownBackspace
|
|
3652
3780
|
});
|
|
3653
3781
|
}
|
|
3654
|
-
}
|
|
3655
|
-
}, [dispatch, keyNavigationPrevious]);
|
|
3782
|
+
}
|
|
3783
|
+
}), [dispatch, keyNavigationPrevious]);
|
|
3656
3784
|
|
|
3657
3785
|
// Getter props.
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3786
|
+
const getSelectedItemProps = react.useCallback(function (_temp) {
|
|
3787
|
+
let {
|
|
3788
|
+
refKey = 'ref',
|
|
3789
|
+
ref,
|
|
3790
|
+
onClick,
|
|
3791
|
+
onKeyDown,
|
|
3792
|
+
selectedItem,
|
|
3793
|
+
index,
|
|
3794
|
+
...rest
|
|
3795
|
+
} = _temp === void 0 ? {} : _temp;
|
|
3796
|
+
const {
|
|
3797
|
+
state: latestState
|
|
3798
|
+
} = latest.current;
|
|
3799
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
3671
3800
|
if (itemIndex < 0) {
|
|
3672
3801
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
3673
3802
|
}
|
|
3674
|
-
|
|
3803
|
+
const selectedItemHandleClick = () => {
|
|
3675
3804
|
dispatch({
|
|
3676
3805
|
type: SelectedItemClick,
|
|
3677
|
-
index
|
|
3806
|
+
index
|
|
3678
3807
|
});
|
|
3679
3808
|
};
|
|
3680
|
-
|
|
3681
|
-
|
|
3809
|
+
const selectedItemHandleKeyDown = event => {
|
|
3810
|
+
const key = normalizeArrowKey(event);
|
|
3682
3811
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
3683
3812
|
selectedItemKeyDownHandlers[key](event);
|
|
3684
3813
|
}
|
|
3685
3814
|
};
|
|
3686
|
-
return
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3815
|
+
return {
|
|
3816
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
3817
|
+
if (selectedItemNode) {
|
|
3818
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
3819
|
+
}
|
|
3820
|
+
}),
|
|
3821
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
3822
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
3823
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
3824
|
+
...rest
|
|
3825
|
+
};
|
|
3691
3826
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
3705
|
-
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
3827
|
+
const getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
3828
|
+
let {
|
|
3829
|
+
refKey = 'ref',
|
|
3830
|
+
ref,
|
|
3831
|
+
onKeyDown,
|
|
3832
|
+
onClick,
|
|
3833
|
+
preventKeyAction = false,
|
|
3834
|
+
...rest
|
|
3835
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
3836
|
+
let {
|
|
3837
|
+
suppressRefError = false
|
|
3838
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
3706
3839
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
3707
|
-
|
|
3708
|
-
|
|
3840
|
+
const dropdownHandleKeyDown = event => {
|
|
3841
|
+
const key = normalizeArrowKey(event);
|
|
3709
3842
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
3710
3843
|
dropdownKeyDownHandlers[key](event);
|
|
3711
3844
|
}
|
|
3712
3845
|
};
|
|
3713
|
-
|
|
3846
|
+
const dropdownHandleClick = () => {
|
|
3714
3847
|
dispatch({
|
|
3715
3848
|
type: DropdownClick
|
|
3716
3849
|
});
|
|
3717
3850
|
};
|
|
3718
|
-
return
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3851
|
+
return {
|
|
3852
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
3853
|
+
if (dropdownNode) {
|
|
3854
|
+
dropdownRef.current = dropdownNode;
|
|
3855
|
+
}
|
|
3856
|
+
}),
|
|
3857
|
+
...(!preventKeyAction && {
|
|
3858
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
3859
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
3860
|
+
}),
|
|
3861
|
+
...rest
|
|
3862
|
+
};
|
|
3726
3863
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]);
|
|
3727
3864
|
|
|
3728
3865
|
// returns
|
|
3729
|
-
|
|
3866
|
+
const addSelectedItem = react.useCallback(selectedItem => {
|
|
3730
3867
|
dispatch({
|
|
3731
3868
|
type: FunctionAddSelectedItem,
|
|
3732
|
-
selectedItem
|
|
3869
|
+
selectedItem
|
|
3733
3870
|
});
|
|
3734
3871
|
}, [dispatch]);
|
|
3735
|
-
|
|
3872
|
+
const removeSelectedItem = react.useCallback(selectedItem => {
|
|
3736
3873
|
dispatch({
|
|
3737
3874
|
type: FunctionRemoveSelectedItem,
|
|
3738
|
-
selectedItem
|
|
3875
|
+
selectedItem
|
|
3739
3876
|
});
|
|
3740
3877
|
}, [dispatch]);
|
|
3741
|
-
|
|
3878
|
+
const setSelectedItems = react.useCallback(newSelectedItems => {
|
|
3742
3879
|
dispatch({
|
|
3743
3880
|
type: FunctionSetSelectedItems,
|
|
3744
3881
|
selectedItems: newSelectedItems
|
|
3745
3882
|
});
|
|
3746
3883
|
}, [dispatch]);
|
|
3747
|
-
|
|
3884
|
+
const setActiveIndex = react.useCallback(newActiveIndex => {
|
|
3748
3885
|
dispatch({
|
|
3749
3886
|
type: FunctionSetActiveIndex,
|
|
3750
3887
|
activeIndex: newActiveIndex
|
|
3751
3888
|
});
|
|
3752
3889
|
}, [dispatch]);
|
|
3753
|
-
|
|
3890
|
+
const reset = react.useCallback(() => {
|
|
3754
3891
|
dispatch({
|
|
3755
3892
|
type: FunctionReset
|
|
3756
3893
|
});
|
|
3757
3894
|
}, [dispatch]);
|
|
3758
3895
|
return {
|
|
3759
|
-
getSelectedItemProps
|
|
3760
|
-
getDropdownProps
|
|
3761
|
-
addSelectedItem
|
|
3762
|
-
removeSelectedItem
|
|
3763
|
-
setSelectedItems
|
|
3764
|
-
setActiveIndex
|
|
3765
|
-
reset
|
|
3766
|
-
selectedItems
|
|
3767
|
-
activeIndex
|
|
3896
|
+
getSelectedItemProps,
|
|
3897
|
+
getDropdownProps,
|
|
3898
|
+
addSelectedItem,
|
|
3899
|
+
removeSelectedItem,
|
|
3900
|
+
setSelectedItems,
|
|
3901
|
+
setActiveIndex,
|
|
3902
|
+
reset,
|
|
3903
|
+
selectedItems,
|
|
3904
|
+
activeIndex
|
|
3768
3905
|
};
|
|
3769
3906
|
}
|
|
3770
3907
|
|