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