1 | import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
|
2 | import _extends from '@babel/runtime/helpers/esm/extends';
|
3 | import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized';
|
4 | import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
|
5 | import PropTypes from 'prop-types';
|
6 | import React, { Component, useReducer, useRef, useEffect } from 'react';
|
7 | import { isForwardRef } from 'react-is';
|
8 | import computeScrollIntoView from 'compute-scroll-into-view';
|
9 | import keyboardKey from 'keyboard-key';
|
10 | import { useId } from '@reach/auto-id';
|
11 |
|
12 | var idCounter = 0;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function cbToCb(cb) {
|
23 | return typeof cb === 'function' ? cb : noop;
|
24 | }
|
25 |
|
26 | function noop() {}
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | function scrollIntoView(node, menuNode) {
|
35 | if (node === null) {
|
36 | return;
|
37 | }
|
38 |
|
39 | var actions = computeScrollIntoView(node, {
|
40 | boundary: menuNode,
|
41 | block: 'nearest',
|
42 | scrollMode: 'if-needed'
|
43 | });
|
44 | actions.forEach(function (_ref) {
|
45 | var el = _ref.el,
|
46 | top = _ref.top,
|
47 | left = _ref.left;
|
48 | el.scrollTop = top;
|
49 | el.scrollLeft = left;
|
50 | });
|
51 | }
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function isOrContainsNode(parent, child) {
|
60 | return parent === child || parent.contains && parent.contains(child);
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function debounce(fn, time) {
|
73 | var timeoutId;
|
74 |
|
75 | function cancel() {
|
76 | if (timeoutId) {
|
77 | clearTimeout(timeoutId);
|
78 | }
|
79 | }
|
80 |
|
81 | function wrapper() {
|
82 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
83 | args[_key] = arguments[_key];
|
84 | }
|
85 |
|
86 | cancel();
|
87 | timeoutId = setTimeout(function () {
|
88 | timeoutId = null;
|
89 | fn.apply(void 0, args);
|
90 | }, time);
|
91 | }
|
92 |
|
93 | wrapper.cancel = cancel;
|
94 | return wrapper;
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | function callAllEventHandlers() {
|
106 | for (var _len2 = arguments.length, fns = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
107 | fns[_key2] = arguments[_key2];
|
108 | }
|
109 |
|
110 | return function (event) {
|
111 | for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
112 | args[_key3 - 1] = arguments[_key3];
|
113 | }
|
114 |
|
115 | return fns.some(function (fn) {
|
116 | if (fn) {
|
117 | fn.apply(void 0, [event].concat(args));
|
118 | }
|
119 |
|
120 | return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
121 | });
|
122 | };
|
123 | }
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | function callAll() {
|
134 | for (var _len4 = arguments.length, fns = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
135 | fns[_key4] = arguments[_key4];
|
136 | }
|
137 |
|
138 | return function () {
|
139 | for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
140 | args[_key5] = arguments[_key5];
|
141 | }
|
142 |
|
143 | fns.forEach(function (fn) {
|
144 | if (fn) {
|
145 | fn.apply(void 0, args);
|
146 | }
|
147 | });
|
148 | };
|
149 | }
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | function generateId() {
|
157 | return String(idCounter++);
|
158 | }
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | function resetIdCounter() {
|
165 | idCounter = 0;
|
166 | }
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | function getA11yStatusMessage(_ref2) {
|
174 | var isOpen = _ref2.isOpen,
|
175 | selectedItem = _ref2.selectedItem,
|
176 | resultCount = _ref2.resultCount,
|
177 | previousResultCount = _ref2.previousResultCount,
|
178 | itemToString = _ref2.itemToString;
|
179 |
|
180 | if (!isOpen) {
|
181 | return selectedItem ? itemToString(selectedItem) : '';
|
182 | }
|
183 |
|
184 | if (!resultCount) {
|
185 | return 'No results are available.';
|
186 | }
|
187 |
|
188 | if (resultCount !== previousResultCount) {
|
189 | return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
|
190 | }
|
191 |
|
192 | return '';
|
193 | }
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | function unwrapArray(arg, defaultValue) {
|
204 | arg = Array.isArray(arg) ?
|
205 |
|
206 | arg[0] : arg;
|
207 |
|
208 | if (!arg && defaultValue) {
|
209 | return defaultValue;
|
210 | } else {
|
211 | return arg;
|
212 | }
|
213 | }
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | function isDOMElement(element) {
|
221 |
|
222 | return typeof element.type === 'string';
|
223 | }
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | function getElementProps(element) {
|
231 | return element.props;
|
232 | }
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 | function requiredProp(fnName, propName) {
|
242 |
|
243 | console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
|
244 | }
|
245 |
|
246 | var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | function pickState(state) {
|
253 | if (state === void 0) {
|
254 | state = {};
|
255 | }
|
256 |
|
257 | var result = {};
|
258 | stateKeys.forEach(function (k) {
|
259 | if (state.hasOwnProperty(k)) {
|
260 | result[k] = state[k];
|
261 | }
|
262 | });
|
263 | return result;
|
264 | }
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 | function normalizeArrowKey(event) {
|
273 | var key = event.key,
|
274 | keyCode = event.keyCode;
|
275 |
|
276 |
|
277 | if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
278 | return "Arrow" + key;
|
279 | }
|
280 |
|
281 | return key;
|
282 | }
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 | function isPlainObject(obj) {
|
291 | return Object.prototype.toString.call(obj) === '[object Object]';
|
292 | }
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | function getNextWrappingIndex(moveAmount, baseIndex, itemCount) {
|
305 | var itemsLastIndex = itemCount - 1;
|
306 |
|
307 | if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
308 | baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
309 | }
|
310 |
|
311 | var newIndex = baseIndex + moveAmount;
|
312 |
|
313 | if (newIndex < 0) {
|
314 | newIndex = itemsLastIndex;
|
315 | } else if (newIndex > itemsLastIndex) {
|
316 | newIndex = 0;
|
317 | }
|
318 |
|
319 | return newIndex;
|
320 | }
|
321 |
|
322 | var statusDiv;
|
323 | var cleanupStatus = debounce(function () {
|
324 | getStatusDiv().textContent = '';
|
325 | }, 500);
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 | function setStatus(status, documentProp) {
|
332 | var div = getStatusDiv(documentProp);
|
333 |
|
334 | if (!status) {
|
335 | return;
|
336 | }
|
337 |
|
338 | div.textContent = status;
|
339 | cleanupStatus();
|
340 | }
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 | function getStatusDiv(documentProp) {
|
349 | if (documentProp === void 0) {
|
350 | documentProp = document;
|
351 | }
|
352 |
|
353 | if (statusDiv) {
|
354 | return statusDiv;
|
355 | }
|
356 |
|
357 | statusDiv = documentProp.createElement('div');
|
358 | statusDiv.setAttribute('id', 'a11y-status-message');
|
359 | statusDiv.setAttribute('role', 'status');
|
360 | statusDiv.setAttribute('aria-live', 'polite');
|
361 | statusDiv.setAttribute('aria-relevant', 'additions text');
|
362 | Object.assign(statusDiv.style, {
|
363 | border: '0',
|
364 | clip: 'rect(0 0 0 0)',
|
365 | height: '1px',
|
366 | margin: '-1px',
|
367 | overflow: 'hidden',
|
368 | padding: '0',
|
369 | position: 'absolute',
|
370 | width: '1px'
|
371 | });
|
372 | documentProp.body.appendChild(statusDiv);
|
373 | return statusDiv;
|
374 | }
|
375 |
|
376 | var unknown = process.env.NODE_ENV !== "production" ? '__autocomplete_unknown__' : 0;
|
377 | var mouseUp = process.env.NODE_ENV !== "production" ? '__autocomplete_mouseup__' : 1;
|
378 | var itemMouseEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_item_mouseenter__' : 2;
|
379 | var keyDownArrowUp = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_up__' : 3;
|
380 | var keyDownArrowDown = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_arrow_down__' : 4;
|
381 | var keyDownEscape = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_escape__' : 5;
|
382 | var keyDownEnter = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_enter__' : 6;
|
383 | var keyDownHome = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_home__' : 7;
|
384 | var keyDownEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_end__' : 8;
|
385 | var clickItem = process.env.NODE_ENV !== "production" ? '__autocomplete_click_item__' : 9;
|
386 | var blurInput = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_input__' : 10;
|
387 | var changeInput = process.env.NODE_ENV !== "production" ? '__autocomplete_change_input__' : 11;
|
388 | var keyDownSpaceButton = process.env.NODE_ENV !== "production" ? '__autocomplete_keydown_space_button__' : 12;
|
389 | var clickButton = process.env.NODE_ENV !== "production" ? '__autocomplete_click_button__' : 13;
|
390 | var blurButton = process.env.NODE_ENV !== "production" ? '__autocomplete_blur_button__' : 14;
|
391 | var controlledPropUpdatedSelectedItem = process.env.NODE_ENV !== "production" ? '__autocomplete_controlled_prop_updated_selected_item__' : 15;
|
392 | var touchEnd = process.env.NODE_ENV !== "production" ? '__autocomplete_touchend__' : 16;
|
393 |
|
394 | var stateChangeTypes = Object.freeze({
|
395 | unknown: unknown,
|
396 | mouseUp: mouseUp,
|
397 | itemMouseEnter: itemMouseEnter,
|
398 | keyDownArrowUp: keyDownArrowUp,
|
399 | keyDownArrowDown: keyDownArrowDown,
|
400 | keyDownEscape: keyDownEscape,
|
401 | keyDownEnter: keyDownEnter,
|
402 | keyDownHome: keyDownHome,
|
403 | keyDownEnd: keyDownEnd,
|
404 | clickItem: clickItem,
|
405 | blurInput: blurInput,
|
406 | changeInput: changeInput,
|
407 | keyDownSpaceButton: keyDownSpaceButton,
|
408 | clickButton: clickButton,
|
409 | blurButton: blurButton,
|
410 | controlledPropUpdatedSelectedItem: controlledPropUpdatedSelectedItem,
|
411 | touchEnd: touchEnd
|
412 | });
|
413 |
|
414 | var Downshift =
|
415 |
|
416 | function (_Component) {
|
417 | _inheritsLoose(Downshift, _Component);
|
418 |
|
419 | function Downshift(_props) {
|
420 | var _this = _Component.call(this, _props) || this;
|
421 |
|
422 | _this.id = _this.props.id || "downshift-" + generateId();
|
423 | _this.menuId = _this.props.menuId || _this.id + "-menu";
|
424 | _this.labelId = _this.props.labelId || _this.id + "-label";
|
425 | _this.inputId = _this.props.inputId || _this.id + "-input";
|
426 |
|
427 | _this.getItemId = _this.props.getItemId || function (index) {
|
428 | return _this.id + "-item-" + index;
|
429 | };
|
430 |
|
431 | _this.input = null;
|
432 | _this.items = [];
|
433 | _this.itemCount = null;
|
434 | _this.previousResultCount = 0;
|
435 | _this.timeoutIds = [];
|
436 |
|
437 | _this.internalSetTimeout = function (fn, time) {
|
438 | var id = setTimeout(function () {
|
439 | _this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
440 | return i !== id;
|
441 | });
|
442 | fn();
|
443 | }, time);
|
444 |
|
445 | _this.timeoutIds.push(id);
|
446 | };
|
447 |
|
448 | _this.setItemCount = function (count) {
|
449 | _this.itemCount = count;
|
450 | };
|
451 |
|
452 | _this.unsetItemCount = function () {
|
453 | _this.itemCount = null;
|
454 | };
|
455 |
|
456 | _this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
457 | if (highlightedIndex === void 0) {
|
458 | highlightedIndex = _this.props.defaultHighlightedIndex;
|
459 | }
|
460 |
|
461 | if (otherStateToSet === void 0) {
|
462 | otherStateToSet = {};
|
463 | }
|
464 |
|
465 | otherStateToSet = pickState(otherStateToSet);
|
466 |
|
467 | _this.internalSetState(_extends({
|
468 | highlightedIndex: highlightedIndex
|
469 | }, otherStateToSet));
|
470 | };
|
471 |
|
472 | _this.clearSelection = function (cb) {
|
473 | _this.internalSetState({
|
474 | selectedItem: null,
|
475 | inputValue: '',
|
476 | highlightedIndex: _this.props.defaultHighlightedIndex,
|
477 | isOpen: _this.props.defaultIsOpen
|
478 | }, cb);
|
479 | };
|
480 |
|
481 | _this.selectItem = function (item, otherStateToSet, cb) {
|
482 | otherStateToSet = pickState(otherStateToSet);
|
483 |
|
484 | _this.internalSetState(_extends({
|
485 | isOpen: _this.props.defaultIsOpen,
|
486 | highlightedIndex: _this.props.defaultHighlightedIndex,
|
487 | selectedItem: item,
|
488 | inputValue: _this.props.itemToString(item)
|
489 | }, otherStateToSet), cb);
|
490 | };
|
491 |
|
492 | _this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
|
493 | var item = _this.items[itemIndex];
|
494 |
|
495 | if (item == null) {
|
496 | return;
|
497 | }
|
498 |
|
499 | _this.selectItem(item, otherStateToSet, cb);
|
500 | };
|
501 |
|
502 | _this.selectHighlightedItem = function (otherStateToSet, cb) {
|
503 | return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
504 | };
|
505 |
|
506 | _this.internalSetState = function (stateToSet, cb) {
|
507 | var isItemSelected, onChangeArg;
|
508 | var onStateChangeArg = {};
|
509 | var isStateToSetFunction = typeof stateToSet === 'function';
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 | if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
516 | _this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
|
517 | }
|
518 |
|
519 | return _this.setState(function (state) {
|
520 | state = _this.getState(state);
|
521 | var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
|
522 |
|
523 | newStateToSet = _this.props.stateReducer(state, newStateToSet);
|
524 |
|
525 |
|
526 |
|
527 | isItemSelected = newStateToSet.hasOwnProperty('selectedItem');
|
528 |
|
529 | var nextState = {};
|
530 |
|
531 | var nextFullState = {};
|
532 |
|
533 |
|
534 |
|
535 | if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
|
536 | onChangeArg = newStateToSet.selectedItem;
|
537 | }
|
538 |
|
539 | newStateToSet.type = newStateToSet.type || unknown;
|
540 | Object.keys(newStateToSet).forEach(function (key) {
|
541 |
|
542 |
|
543 | if (state[key] !== newStateToSet[key]) {
|
544 | onStateChangeArg[key] = newStateToSet[key];
|
545 | }
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 |
|
553 | if (key === 'type') {
|
554 | return;
|
555 | }
|
556 |
|
557 | nextFullState[key] = newStateToSet[key];
|
558 |
|
559 | if (!_this.isControlledProp(key)) {
|
560 | nextState[key] = newStateToSet[key];
|
561 | }
|
562 | });
|
563 |
|
564 |
|
565 | if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
566 | _this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
|
567 | }
|
568 |
|
569 | return nextState;
|
570 | }, function () {
|
571 |
|
572 | cbToCb(cb)();
|
573 |
|
574 |
|
575 | var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
576 |
|
577 | if (hasMoreStateThanType) {
|
578 | _this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
|
579 | }
|
580 |
|
581 | if (isItemSelected) {
|
582 | _this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
|
583 | }
|
584 |
|
585 | if (onChangeArg !== undefined) {
|
586 | _this.props.onChange(onChangeArg, _this.getStateAndHelpers());
|
587 | }
|
588 |
|
589 |
|
590 |
|
591 | _this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
592 | });
|
593 | };
|
594 |
|
595 | _this.rootRef = function (node) {
|
596 | return _this._rootNode = node;
|
597 | };
|
598 |
|
599 | _this.getRootProps = function (_temp, _temp2) {
|
600 | var _extends2;
|
601 |
|
602 | var _ref = _temp === void 0 ? {} : _temp,
|
603 | _ref$refKey = _ref.refKey,
|
604 | refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
605 | ref = _ref.ref,
|
606 | rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
|
607 |
|
608 | var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
609 | _ref2$suppressRefErro = _ref2.suppressRefError,
|
610 | suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
611 |
|
612 |
|
613 |
|
614 | _this.getRootProps.called = true;
|
615 | _this.getRootProps.refKey = refKey;
|
616 | _this.getRootProps.suppressRefError = suppressRefError;
|
617 |
|
618 | var _this$getState = _this.getState(),
|
619 | isOpen = _this$getState.isOpen;
|
620 |
|
621 | return _extends((_extends2 = {}, _extends2[refKey] = callAll(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);
|
622 | };
|
623 |
|
624 | _this.keyDownHandlers = {
|
625 | ArrowDown: function ArrowDown(event) {
|
626 | var _this2 = this;
|
627 |
|
628 | event.preventDefault();
|
629 |
|
630 | if (this.getState().isOpen) {
|
631 | var amount = event.shiftKey ? 5 : 1;
|
632 | this.moveHighlightedIndex(amount, {
|
633 | type: keyDownArrowDown
|
634 | });
|
635 | } else {
|
636 | this.internalSetState({
|
637 | isOpen: true,
|
638 | type: keyDownArrowDown
|
639 | }, function () {
|
640 | var itemCount = _this2.getItemCount();
|
641 |
|
642 | if (itemCount > 0) {
|
643 | _this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
|
644 | type: keyDownArrowDown
|
645 | });
|
646 | }
|
647 | });
|
648 | }
|
649 | },
|
650 | ArrowUp: function ArrowUp(event) {
|
651 | var _this3 = this;
|
652 |
|
653 | event.preventDefault();
|
654 |
|
655 | if (this.getState().isOpen) {
|
656 | var amount = event.shiftKey ? -5 : -1;
|
657 | this.moveHighlightedIndex(amount, {
|
658 | type: keyDownArrowUp
|
659 | });
|
660 | } else {
|
661 | this.internalSetState({
|
662 | isOpen: true,
|
663 | type: keyDownArrowUp
|
664 | }, function () {
|
665 | var itemCount = _this3.getItemCount();
|
666 |
|
667 | if (itemCount > 0) {
|
668 | _this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
|
669 | type: keyDownArrowDown
|
670 | });
|
671 | }
|
672 | });
|
673 | }
|
674 | },
|
675 | Enter: function Enter(event) {
|
676 | var _this$getState2 = this.getState(),
|
677 | isOpen = _this$getState2.isOpen,
|
678 | highlightedIndex = _this$getState2.highlightedIndex;
|
679 |
|
680 | if (isOpen && highlightedIndex != null) {
|
681 | event.preventDefault();
|
682 | var item = this.items[highlightedIndex];
|
683 | var itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
684 |
|
685 | if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
686 | return;
|
687 | }
|
688 |
|
689 | this.selectHighlightedItem({
|
690 | type: keyDownEnter
|
691 | });
|
692 | }
|
693 | },
|
694 | Escape: function Escape(event) {
|
695 | event.preventDefault();
|
696 | this.reset({
|
697 | type: keyDownEscape,
|
698 | selectedItem: null,
|
699 | inputValue: ''
|
700 | });
|
701 | }
|
702 | };
|
703 | _this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
704 | ' ': function _(event) {
|
705 | event.preventDefault();
|
706 | this.toggleMenu({
|
707 | type: keyDownSpaceButton
|
708 | });
|
709 | }
|
710 | });
|
711 | _this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
712 | Home: function Home(event) {
|
713 | this.highlightFirstOrLastIndex(event, true, {
|
714 | type: keyDownHome
|
715 | });
|
716 | },
|
717 | End: function End(event) {
|
718 | this.highlightFirstOrLastIndex(event, false, {
|
719 | type: keyDownEnd
|
720 | });
|
721 | }
|
722 | });
|
723 |
|
724 | _this.getToggleButtonProps = function (_temp3) {
|
725 | var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
726 | onClick = _ref3.onClick,
|
727 | onPress = _ref3.onPress,
|
728 | onKeyDown = _ref3.onKeyDown,
|
729 | onKeyUp = _ref3.onKeyUp,
|
730 | onBlur = _ref3.onBlur,
|
731 | rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
|
732 |
|
733 | var _this$getState3 = _this.getState(),
|
734 | isOpen = _this$getState3.isOpen;
|
735 |
|
736 | var enabledEventHandlers = {
|
737 | onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
738 | onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
739 | onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
740 | onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
741 | };
|
742 | var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
743 | return _extends({
|
744 | type: 'button',
|
745 | role: 'button',
|
746 | 'aria-label': isOpen ? 'close menu' : 'open menu',
|
747 | 'aria-haspopup': true,
|
748 | 'data-toggle': true
|
749 | }, eventHandlers, {}, rest);
|
750 | };
|
751 |
|
752 | _this.buttonHandleKeyUp = function (event) {
|
753 |
|
754 | event.preventDefault();
|
755 | };
|
756 |
|
757 | _this.buttonHandleKeyDown = function (event) {
|
758 | var key = normalizeArrowKey(event);
|
759 |
|
760 | if (_this.buttonKeyDownHandlers[key]) {
|
761 | _this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
762 | }
|
763 | };
|
764 |
|
765 | _this.buttonHandleClick = function (event) {
|
766 | event.preventDefault();
|
767 |
|
768 |
|
769 |
|
770 |
|
771 | if ( _this.props.environment.document.activeElement === _this.props.environment.document.body) {
|
772 | event.target.focus();
|
773 | }
|
774 |
|
775 |
|
776 |
|
777 |
|
778 | if (process.env.NODE_ENV === 'test') {
|
779 | _this.toggleMenu({
|
780 | type: clickButton
|
781 | });
|
782 | } else {
|
783 |
|
784 | _this.internalSetTimeout(function () {
|
785 | return _this.toggleMenu({
|
786 | type: clickButton
|
787 | });
|
788 | });
|
789 | }
|
790 | };
|
791 |
|
792 | _this.buttonHandleBlur = function (event) {
|
793 | var blurTarget = event.target;
|
794 |
|
795 |
|
796 | _this.internalSetTimeout(function () {
|
797 | if (!_this.isMouseDown && (_this.props.environment.document.activeElement == null || _this.props.environment.document.activeElement.id !== _this.inputId) && _this.props.environment.document.activeElement !== blurTarget
|
798 | ) {
|
799 | _this.reset({
|
800 | type: blurButton
|
801 | });
|
802 | }
|
803 | });
|
804 | };
|
805 |
|
806 | _this.getLabelProps = function (props) {
|
807 | return _extends({
|
808 | htmlFor: _this.inputId,
|
809 | id: _this.labelId
|
810 | }, props);
|
811 | };
|
812 |
|
813 | _this.getInputProps = function (_temp4) {
|
814 | var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
815 | onKeyDown = _ref4.onKeyDown,
|
816 | onBlur = _ref4.onBlur,
|
817 | onChange = _ref4.onChange,
|
818 | onInput = _ref4.onInput,
|
819 | onChangeText = _ref4.onChangeText,
|
820 | rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
|
821 |
|
822 | var onChangeKey;
|
823 | var eventHandlers = {};
|
824 |
|
825 |
|
826 | onChangeKey = 'onChange';
|
827 |
|
828 | var _this$getState4 = _this.getState(),
|
829 | inputValue = _this$getState4.inputValue,
|
830 | isOpen = _this$getState4.isOpen,
|
831 | highlightedIndex = _this$getState4.highlightedIndex;
|
832 |
|
833 | if (!rest.disabled) {
|
834 | var _eventHandlers;
|
835 |
|
836 | eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
|
837 | }
|
838 |
|
839 |
|
840 |
|
841 | return _extends({
|
842 | 'aria-autocomplete': 'list',
|
843 | 'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
844 | 'aria-controls': isOpen ? _this.menuId : null,
|
845 | 'aria-labelledby': _this.labelId,
|
846 |
|
847 |
|
848 | autoComplete: 'off',
|
849 | value: inputValue,
|
850 | id: _this.inputId
|
851 | }, eventHandlers, {}, rest);
|
852 | };
|
853 |
|
854 | _this.inputHandleKeyDown = function (event) {
|
855 | var key = normalizeArrowKey(event);
|
856 |
|
857 | if (key && _this.inputKeyDownHandlers[key]) {
|
858 | _this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
859 | }
|
860 | };
|
861 |
|
862 | _this.inputHandleChange = function (event) {
|
863 | _this.internalSetState({
|
864 | type: changeInput,
|
865 | isOpen: true,
|
866 | inputValue: event.target.value,
|
867 | highlightedIndex: _this.props.defaultHighlightedIndex
|
868 | });
|
869 | };
|
870 |
|
871 | _this.inputHandleBlur = function () {
|
872 |
|
873 | _this.internalSetTimeout(function () {
|
874 | 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);
|
875 |
|
876 | if (!_this.isMouseDown && !downshiftButtonIsActive) {
|
877 | _this.reset({
|
878 | type: blurInput
|
879 | });
|
880 | }
|
881 | });
|
882 | };
|
883 |
|
884 | _this.menuRef = function (node) {
|
885 | _this._menuNode = node;
|
886 | };
|
887 |
|
888 | _this.getMenuProps = function (_temp5, _temp6) {
|
889 | var _extends3;
|
890 |
|
891 | var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
892 | _ref5$refKey = _ref5.refKey,
|
893 | refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
894 | ref = _ref5.ref,
|
895 | props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
|
896 |
|
897 | var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
898 | _ref6$suppressRefErro = _ref6.suppressRefError,
|
899 | suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
900 |
|
901 | _this.getMenuProps.called = true;
|
902 | _this.getMenuProps.refKey = refKey;
|
903 | _this.getMenuProps.suppressRefError = suppressRefError;
|
904 | return _extends((_extends3 = {}, _extends3[refKey] = callAll(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
905 | };
|
906 |
|
907 | _this.getItemProps = function (_temp7) {
|
908 | var _enabledEventHandlers;
|
909 |
|
910 | var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
911 | onMouseMove = _ref7.onMouseMove,
|
912 | onMouseDown = _ref7.onMouseDown,
|
913 | onClick = _ref7.onClick,
|
914 | onPress = _ref7.onPress,
|
915 | index = _ref7.index,
|
916 | _ref7$item = _ref7.item,
|
917 | item = _ref7$item === void 0 ? process.env.NODE_ENV === 'production' ?
|
918 |
|
919 | undefined : requiredProp('getItemProps', 'item') : _ref7$item,
|
920 | rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
|
921 |
|
922 | if (index === undefined) {
|
923 | _this.items.push(item);
|
924 |
|
925 | index = _this.items.indexOf(item);
|
926 | } else {
|
927 | _this.items[index] = item;
|
928 | }
|
929 |
|
930 | var onSelectKey = 'onClick';
|
931 | var customClickHandler = onClick;
|
932 | var enabledEventHandlers = (_enabledEventHandlers = {
|
933 |
|
934 |
|
935 |
|
936 | onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
937 | if (index === _this.getState().highlightedIndex) {
|
938 | return;
|
939 | }
|
940 |
|
941 | _this.setHighlightedIndex(index, {
|
942 | type: itemMouseEnter
|
943 | });
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 | _this.avoidScrolling = true;
|
950 |
|
951 | _this.internalSetTimeout(function () {
|
952 | return _this.avoidScrolling = false;
|
953 | }, 250);
|
954 | }),
|
955 | onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
|
956 |
|
957 |
|
958 |
|
959 | event.preventDefault();
|
960 | })
|
961 | }, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
|
962 | _this.selectItemAtIndex(index, {
|
963 | type: clickItem
|
964 | });
|
965 | }), _enabledEventHandlers);
|
966 |
|
967 |
|
968 | var eventHandlers = rest.disabled ? {
|
969 | onMouseDown: enabledEventHandlers.onMouseDown
|
970 | } : enabledEventHandlers;
|
971 | return _extends({
|
972 | id: _this.getItemId(index),
|
973 | role: 'option',
|
974 | 'aria-selected': _this.getState().highlightedIndex === index
|
975 | }, eventHandlers, {}, rest);
|
976 | };
|
977 |
|
978 | _this.clearItems = function () {
|
979 | _this.items = [];
|
980 | };
|
981 |
|
982 | _this.reset = function (otherStateToSet, cb) {
|
983 | if (otherStateToSet === void 0) {
|
984 | otherStateToSet = {};
|
985 | }
|
986 |
|
987 | otherStateToSet = pickState(otherStateToSet);
|
988 |
|
989 | _this.internalSetState(function (_ref8) {
|
990 | var selectedItem = _ref8.selectedItem;
|
991 | return _extends({
|
992 | isOpen: _this.props.defaultIsOpen,
|
993 | highlightedIndex: _this.props.defaultHighlightedIndex,
|
994 | inputValue: _this.props.itemToString(selectedItem)
|
995 | }, otherStateToSet);
|
996 | }, cb);
|
997 | };
|
998 |
|
999 | _this.toggleMenu = function (otherStateToSet, cb) {
|
1000 | if (otherStateToSet === void 0) {
|
1001 | otherStateToSet = {};
|
1002 | }
|
1003 |
|
1004 | otherStateToSet = pickState(otherStateToSet);
|
1005 |
|
1006 | _this.internalSetState(function (_ref9) {
|
1007 | var isOpen = _ref9.isOpen;
|
1008 | return _extends({
|
1009 | isOpen: !isOpen
|
1010 | }, isOpen && {
|
1011 | highlightedIndex: _this.props.defaultHighlightedIndex
|
1012 | }, {}, otherStateToSet);
|
1013 | }, function () {
|
1014 | var _this$getState5 = _this.getState(),
|
1015 | isOpen = _this$getState5.isOpen,
|
1016 | highlightedIndex = _this$getState5.highlightedIndex;
|
1017 |
|
1018 | if (isOpen) {
|
1019 | if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
1020 | _this.setHighlightedIndex(highlightedIndex, otherStateToSet);
|
1021 | }
|
1022 | }
|
1023 |
|
1024 | cbToCb(cb)();
|
1025 | });
|
1026 | };
|
1027 |
|
1028 | _this.openMenu = function (cb) {
|
1029 | _this.internalSetState({
|
1030 | isOpen: true
|
1031 | }, cb);
|
1032 | };
|
1033 |
|
1034 | _this.closeMenu = function (cb) {
|
1035 | _this.internalSetState({
|
1036 | isOpen: false
|
1037 | }, cb);
|
1038 | };
|
1039 |
|
1040 | _this.updateStatus = debounce(function () {
|
1041 | var state = _this.getState();
|
1042 |
|
1043 | var item = _this.items[state.highlightedIndex];
|
1044 |
|
1045 | var resultCount = _this.getItemCount();
|
1046 |
|
1047 | var status = _this.props.getA11yStatusMessage(_extends({
|
1048 | itemToString: _this.props.itemToString,
|
1049 | previousResultCount: _this.previousResultCount,
|
1050 | resultCount: resultCount,
|
1051 | highlightedItem: item
|
1052 | }, state));
|
1053 |
|
1054 | _this.previousResultCount = resultCount;
|
1055 | setStatus(status, _this.props.environment.document);
|
1056 | }, 200);
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 | var _this$props = _this.props,
|
1062 | defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
|
1063 | _this$props$initialHi = _this$props.initialHighlightedIndex,
|
1064 | _highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
|
1065 | defaultIsOpen = _this$props.defaultIsOpen,
|
1066 | _this$props$initialIs = _this$props.initialIsOpen,
|
1067 | _isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
|
1068 | _this$props$initialIn = _this$props.initialInputValue,
|
1069 | _inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
|
1070 | _this$props$initialSe = _this$props.initialSelectedItem,
|
1071 | _selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
|
1072 |
|
1073 | var _state = _this.getState({
|
1074 | highlightedIndex: _highlightedIndex,
|
1075 | isOpen: _isOpen,
|
1076 | inputValue: _inputValue,
|
1077 | selectedItem: _selectedItem
|
1078 | });
|
1079 |
|
1080 | if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
|
1081 | _state.inputValue = _this.props.itemToString(_state.selectedItem);
|
1082 | }
|
1083 |
|
1084 | _this.state = _state;
|
1085 | return _this;
|
1086 | }
|
1087 |
|
1088 | var _proto = Downshift.prototype;
|
1089 |
|
1090 | |
1091 |
|
1092 |
|
1093 | _proto.internalClearTimeouts = function internalClearTimeouts() {
|
1094 | this.timeoutIds.forEach(function (id) {
|
1095 | clearTimeout(id);
|
1096 | });
|
1097 | this.timeoutIds = [];
|
1098 | }
|
1099 | |
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 | ;
|
1115 |
|
1116 | _proto.getState = function getState(stateToMerge) {
|
1117 | var _this4 = this;
|
1118 |
|
1119 | if (stateToMerge === void 0) {
|
1120 | stateToMerge = this.state;
|
1121 | }
|
1122 |
|
1123 | return Object.keys(stateToMerge).reduce(function (state, key) {
|
1124 | state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
|
1125 | return state;
|
1126 | }, {});
|
1127 | }
|
1128 | |
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 | ;
|
1136 |
|
1137 | _proto.isControlledProp = function isControlledProp(key) {
|
1138 | return this.props[key] !== undefined;
|
1139 | };
|
1140 |
|
1141 | _proto.getItemCount = function getItemCount() {
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 | var itemCount = this.items.length;
|
1147 |
|
1148 | if (this.itemCount != null) {
|
1149 | itemCount = this.itemCount;
|
1150 | } else if (this.props.itemCount !== undefined) {
|
1151 | itemCount = this.props.itemCount;
|
1152 | }
|
1153 |
|
1154 | return itemCount;
|
1155 | };
|
1156 |
|
1157 | _proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
|
1158 | return this.props.environment.document.getElementById(this.getItemId(index));
|
1159 | };
|
1160 |
|
1161 | _proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
|
1162 |
|
1163 | {
|
1164 | var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
1165 | this.props.scrollIntoView(node, this._menuNode);
|
1166 | }
|
1167 | };
|
1168 |
|
1169 | _proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
1170 | var itemCount = this.getItemCount();
|
1171 |
|
1172 | if (itemCount > 0) {
|
1173 | var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
|
1174 | this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
1175 | }
|
1176 | };
|
1177 |
|
1178 | _proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
|
1179 | var itemsLastIndex = this.getItemCount() - 1;
|
1180 |
|
1181 | if (itemsLastIndex < 0 || !this.getState().isOpen) {
|
1182 | return;
|
1183 | }
|
1184 |
|
1185 | event.preventDefault();
|
1186 | this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
|
1187 | };
|
1188 |
|
1189 | _proto.getStateAndHelpers = function getStateAndHelpers() {
|
1190 | var _this$getState6 = this.getState(),
|
1191 | highlightedIndex = _this$getState6.highlightedIndex,
|
1192 | inputValue = _this$getState6.inputValue,
|
1193 | selectedItem = _this$getState6.selectedItem,
|
1194 | isOpen = _this$getState6.isOpen;
|
1195 |
|
1196 | var itemToString = this.props.itemToString;
|
1197 | var id = this.id;
|
1198 | var getRootProps = this.getRootProps,
|
1199 | getToggleButtonProps = this.getToggleButtonProps,
|
1200 | getLabelProps = this.getLabelProps,
|
1201 | getMenuProps = this.getMenuProps,
|
1202 | getInputProps = this.getInputProps,
|
1203 | getItemProps = this.getItemProps,
|
1204 | openMenu = this.openMenu,
|
1205 | closeMenu = this.closeMenu,
|
1206 | toggleMenu = this.toggleMenu,
|
1207 | selectItem = this.selectItem,
|
1208 | selectItemAtIndex = this.selectItemAtIndex,
|
1209 | selectHighlightedItem = this.selectHighlightedItem,
|
1210 | setHighlightedIndex = this.setHighlightedIndex,
|
1211 | clearSelection = this.clearSelection,
|
1212 | clearItems = this.clearItems,
|
1213 | reset = this.reset,
|
1214 | setItemCount = this.setItemCount,
|
1215 | unsetItemCount = this.unsetItemCount,
|
1216 | setState = this.internalSetState;
|
1217 | return {
|
1218 |
|
1219 | getRootProps: getRootProps,
|
1220 | getToggleButtonProps: getToggleButtonProps,
|
1221 | getLabelProps: getLabelProps,
|
1222 | getMenuProps: getMenuProps,
|
1223 | getInputProps: getInputProps,
|
1224 | getItemProps: getItemProps,
|
1225 |
|
1226 | reset: reset,
|
1227 | openMenu: openMenu,
|
1228 | closeMenu: closeMenu,
|
1229 | toggleMenu: toggleMenu,
|
1230 | selectItem: selectItem,
|
1231 | selectItemAtIndex: selectItemAtIndex,
|
1232 | selectHighlightedItem: selectHighlightedItem,
|
1233 | setHighlightedIndex: setHighlightedIndex,
|
1234 | clearSelection: clearSelection,
|
1235 | clearItems: clearItems,
|
1236 | setItemCount: setItemCount,
|
1237 | unsetItemCount: unsetItemCount,
|
1238 | setState: setState,
|
1239 |
|
1240 | itemToString: itemToString,
|
1241 |
|
1242 | id: id,
|
1243 |
|
1244 | highlightedIndex: highlightedIndex,
|
1245 | inputValue: inputValue,
|
1246 | isOpen: isOpen,
|
1247 | selectedItem: selectedItem
|
1248 | };
|
1249 | }
|
1250 | ;
|
1251 |
|
1252 | _proto.componentDidMount = function componentDidMount() {
|
1253 | var _this5 = this;
|
1254 |
|
1255 |
|
1256 | if (process.env.NODE_ENV !== 'production' && !false && this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
1257 | validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
1258 | }
|
1259 |
|
1260 |
|
1261 |
|
1262 | {
|
1263 | var targetWithinDownshift = function (target, checkActiveElement) {
|
1264 | if (checkActiveElement === void 0) {
|
1265 | checkActiveElement = true;
|
1266 | }
|
1267 |
|
1268 | var document = _this5.props.environment.document;
|
1269 | return [_this5._rootNode, _this5._menuNode].some(function (contextNode) {
|
1270 | return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
|
1271 | });
|
1272 | };
|
1273 |
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 |
|
1279 | var onMouseDown = function () {
|
1280 | _this5.isMouseDown = true;
|
1281 | };
|
1282 |
|
1283 | var onMouseUp = function (event) {
|
1284 | _this5.isMouseDown = false;
|
1285 |
|
1286 |
|
1287 | var contextWithinDownshift = targetWithinDownshift(event.target);
|
1288 |
|
1289 | if (!contextWithinDownshift && _this5.getState().isOpen) {
|
1290 | _this5.reset({
|
1291 | type: mouseUp
|
1292 | }, function () {
|
1293 | return _this5.props.onOuterClick(_this5.getStateAndHelpers());
|
1294 | });
|
1295 | }
|
1296 | };
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 | var onTouchStart = function () {
|
1305 | _this5.isTouchMove = false;
|
1306 | };
|
1307 |
|
1308 | var onTouchMove = function () {
|
1309 | _this5.isTouchMove = true;
|
1310 | };
|
1311 |
|
1312 | var onTouchEnd = function (event) {
|
1313 | var contextWithinDownshift = targetWithinDownshift(event.target, false);
|
1314 |
|
1315 | if (!_this5.isTouchMove && !contextWithinDownshift && _this5.getState().isOpen) {
|
1316 | _this5.reset({
|
1317 | type: touchEnd
|
1318 | }, function () {
|
1319 | return _this5.props.onOuterClick(_this5.getStateAndHelpers());
|
1320 | });
|
1321 | }
|
1322 | };
|
1323 |
|
1324 | var environment = this.props.environment;
|
1325 | environment.addEventListener('mousedown', onMouseDown);
|
1326 | environment.addEventListener('mouseup', onMouseUp);
|
1327 | environment.addEventListener('touchstart', onTouchStart);
|
1328 | environment.addEventListener('touchmove', onTouchMove);
|
1329 | environment.addEventListener('touchend', onTouchEnd);
|
1330 |
|
1331 | this.cleanup = function () {
|
1332 | _this5.internalClearTimeouts();
|
1333 |
|
1334 | _this5.updateStatus.cancel();
|
1335 |
|
1336 | environment.removeEventListener('mousedown', onMouseDown);
|
1337 | environment.removeEventListener('mouseup', onMouseUp);
|
1338 | environment.removeEventListener('touchstart', onTouchStart);
|
1339 | environment.removeEventListener('touchmove', onTouchMove);
|
1340 | environment.removeEventListener('touchend', onTouchEnd);
|
1341 | };
|
1342 | }
|
1343 | };
|
1344 |
|
1345 | _proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
1346 | var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
1347 | currentHighlightedIndex = _ref10.highlightedIndex;
|
1348 |
|
1349 | var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
1350 | prevHighlightedIndex = _ref11.highlightedIndex;
|
1351 |
|
1352 | var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
1353 | return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
|
1354 | };
|
1355 |
|
1356 | _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
1357 | if (process.env.NODE_ENV !== 'production') {
|
1358 | validateControlledUnchanged(prevProps, this.props);
|
1359 |
|
1360 |
|
1361 | if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
1362 | validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
1363 | }
|
1364 | }
|
1365 |
|
1366 | if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
|
1367 | this.internalSetState({
|
1368 | type: controlledPropUpdatedSelectedItem,
|
1369 | inputValue: this.props.itemToString(this.props.selectedItem)
|
1370 | });
|
1371 | }
|
1372 |
|
1373 | if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
|
1374 | this.scrollHighlightedItemIntoView();
|
1375 | }
|
1376 |
|
1377 |
|
1378 |
|
1379 | this.updateStatus();
|
1380 | };
|
1381 |
|
1382 | _proto.componentWillUnmount = function componentWillUnmount() {
|
1383 | this.cleanup();
|
1384 | };
|
1385 |
|
1386 | _proto.render = function render() {
|
1387 | var children = unwrapArray(this.props.children, noop);
|
1388 |
|
1389 |
|
1390 |
|
1391 | this.clearItems();
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 | this.getRootProps.called = false;
|
1397 | this.getRootProps.refKey = undefined;
|
1398 | this.getRootProps.suppressRefError = undefined;
|
1399 |
|
1400 | this.getMenuProps.called = false;
|
1401 | this.getMenuProps.refKey = undefined;
|
1402 | this.getMenuProps.suppressRefError = undefined;
|
1403 |
|
1404 | this.getLabelProps.called = false;
|
1405 |
|
1406 | this.getInputProps.called = false;
|
1407 | var element = unwrapArray(children(this.getStateAndHelpers()));
|
1408 |
|
1409 | if (!element) {
|
1410 | return null;
|
1411 | }
|
1412 |
|
1413 | if (this.getRootProps.called || this.props.suppressRefError) {
|
1414 | if (process.env.NODE_ENV !== 'production' && !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
|
1415 | validateGetRootPropsCalledCorrectly(element, this.getRootProps);
|
1416 | }
|
1417 |
|
1418 | return element;
|
1419 | } else if (isDOMElement(element)) {
|
1420 |
|
1421 |
|
1422 | return React.cloneElement(element, this.getRootProps(getElementProps(element)));
|
1423 | }
|
1424 |
|
1425 |
|
1426 |
|
1427 | if (process.env.NODE_ENV !== 'production') {
|
1428 |
|
1429 |
|
1430 | throw new Error('downshift: If you return a non-DOM element, you must use apply the getRootProps function');
|
1431 | }
|
1432 |
|
1433 |
|
1434 |
|
1435 | return undefined;
|
1436 | };
|
1437 |
|
1438 | return Downshift;
|
1439 | }(Component);
|
1440 |
|
1441 | Downshift.defaultProps = {
|
1442 | defaultHighlightedIndex: null,
|
1443 | defaultIsOpen: false,
|
1444 | getA11yStatusMessage: getA11yStatusMessage,
|
1445 | itemToString: function itemToString(i) {
|
1446 | if (i == null) {
|
1447 | return '';
|
1448 | }
|
1449 |
|
1450 | if (process.env.NODE_ENV !== 'production' && isPlainObject(i) && !i.hasOwnProperty('toString')) {
|
1451 |
|
1452 | console.warn('downshift: An object was passed to the default implementation of `itemToString`. You should probably provide your own `itemToString` implementation. Please refer to the `itemToString` API documentation.', 'The object that was passed:', i);
|
1453 | }
|
1454 |
|
1455 | return String(i);
|
1456 | },
|
1457 | onStateChange: noop,
|
1458 | onInputValueChange: noop,
|
1459 | onUserAction: noop,
|
1460 | onChange: noop,
|
1461 | onSelect: noop,
|
1462 | onOuterClick: noop,
|
1463 | selectedItemChanged: function selectedItemChanged(prevItem, item) {
|
1464 | return prevItem !== item;
|
1465 | },
|
1466 | environment: typeof window === 'undefined'
|
1467 |
|
1468 | ? {} : window,
|
1469 | stateReducer: function stateReducer(state, stateToSet) {
|
1470 | return stateToSet;
|
1471 | },
|
1472 | suppressRefError: false,
|
1473 | scrollIntoView: scrollIntoView
|
1474 | };
|
1475 | Downshift.stateChangeTypes = stateChangeTypes;
|
1476 | process.env.NODE_ENV !== "production" ? Downshift.propTypes = {
|
1477 | children: PropTypes.func,
|
1478 | defaultHighlightedIndex: PropTypes.number,
|
1479 | defaultIsOpen: PropTypes.bool,
|
1480 | initialHighlightedIndex: PropTypes.number,
|
1481 | initialSelectedItem: PropTypes.any,
|
1482 | initialInputValue: PropTypes.string,
|
1483 | initialIsOpen: PropTypes.bool,
|
1484 | getA11yStatusMessage: PropTypes.func,
|
1485 | itemToString: PropTypes.func,
|
1486 | onChange: PropTypes.func,
|
1487 | onSelect: PropTypes.func,
|
1488 | onStateChange: PropTypes.func,
|
1489 | onInputValueChange: PropTypes.func,
|
1490 | onUserAction: PropTypes.func,
|
1491 | onOuterClick: PropTypes.func,
|
1492 | selectedItemChanged: PropTypes.func,
|
1493 | stateReducer: PropTypes.func,
|
1494 | itemCount: PropTypes.number,
|
1495 | id: PropTypes.string,
|
1496 | environment: PropTypes.shape({
|
1497 | addEventListener: PropTypes.func,
|
1498 | removeEventListener: PropTypes.func,
|
1499 | document: PropTypes.shape({
|
1500 | getElementById: PropTypes.func,
|
1501 | activeElement: PropTypes.any,
|
1502 | body: PropTypes.any
|
1503 | })
|
1504 | }),
|
1505 | suppressRefError: PropTypes.bool,
|
1506 | scrollIntoView: PropTypes.func,
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 | selectedItem: PropTypes.any,
|
1512 | isOpen: PropTypes.bool,
|
1513 | inputValue: PropTypes.string,
|
1514 | highlightedIndex: PropTypes.number,
|
1515 | labelId: PropTypes.string,
|
1516 | inputId: PropTypes.string,
|
1517 | menuId: PropTypes.string,
|
1518 | getItemId: PropTypes.func
|
1519 |
|
1520 |
|
1521 | } : void 0;
|
1522 |
|
1523 | function validateGetMenuPropsCalledCorrectly(node, _ref12) {
|
1524 | var refKey = _ref12.refKey;
|
1525 |
|
1526 | if (!node) {
|
1527 |
|
1528 | console.error("downshift: The ref prop \"" + refKey + "\" from getMenuProps was not applied correctly on your menu element.");
|
1529 | }
|
1530 | }
|
1531 |
|
1532 | function validateGetRootPropsCalledCorrectly(element, _ref13) {
|
1533 | var refKey = _ref13.refKey;
|
1534 | var refKeySpecified = refKey !== 'ref';
|
1535 | var isComposite = !isDOMElement(element);
|
1536 |
|
1537 | if (isComposite && !refKeySpecified && !isForwardRef(element)) {
|
1538 |
|
1539 | console.error('downshift: You returned a non-DOM element. You must specify a refKey in getRootProps');
|
1540 | } else if (!isComposite && refKeySpecified) {
|
1541 |
|
1542 | console.error("downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified \"" + refKey + "\"");
|
1543 | }
|
1544 |
|
1545 | if (!isForwardRef(element) && !getElementProps(element)[refKey]) {
|
1546 |
|
1547 | console.error("downshift: You must apply the ref prop \"" + refKey + "\" from getRootProps onto your root element.");
|
1548 | }
|
1549 | }
|
1550 |
|
1551 | function validateControlledUnchanged(prevProps, nextProps) {
|
1552 | 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";
|
1553 | ['selectedItem', 'isOpen', 'inputValue', 'highlightedIndex'].forEach(function (propKey) {
|
1554 | if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
1555 |
|
1556 | console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
1557 | } else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
1558 |
|
1559 | console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
1560 | }
|
1561 | });
|
1562 | }
|
1563 |
|
1564 | function getElementIds(generateDefaultId, _temp) {
|
1565 | var _ref = _temp === void 0 ? {} : _temp,
|
1566 | id = _ref.id,
|
1567 | labelId = _ref.labelId,
|
1568 | menuId = _ref.menuId,
|
1569 | getItemId = _ref.getItemId,
|
1570 | toggleButtonId = _ref.toggleButtonId;
|
1571 |
|
1572 | var uniqueId = id === undefined ? "downshift-" + generateDefaultId() : id;
|
1573 | return {
|
1574 | labelId: labelId || uniqueId + "-label",
|
1575 | menuId: menuId || uniqueId + "-menu",
|
1576 | getItemId: getItemId || function (index) {
|
1577 | return uniqueId + "-item-" + index;
|
1578 | },
|
1579 | toggleButtonId: toggleButtonId || uniqueId + "-toggle-button"
|
1580 | };
|
1581 | }
|
1582 |
|
1583 | function getNextWrappingIndex$1(moveAmount, baseIndex, itemsLength, circular) {
|
1584 | if (baseIndex === -1) {
|
1585 | return moveAmount > 0 ? 0 : itemsLength - 1;
|
1586 | }
|
1587 |
|
1588 | var nextIndex = baseIndex + moveAmount;
|
1589 |
|
1590 | if (nextIndex < 0) {
|
1591 | return circular ? itemsLength - 1 : 0;
|
1592 | }
|
1593 |
|
1594 | if (nextIndex >= itemsLength) {
|
1595 | return circular ? 0 : itemsLength - 1;
|
1596 | }
|
1597 |
|
1598 | return nextIndex;
|
1599 | }
|
1600 |
|
1601 | function getItemIndexByCharacterKey(keysSoFar, highlightedIndex, items, itemToStringParam) {
|
1602 | var newHighlightedIndex = -1;
|
1603 | var itemStrings = items.map(function (item) {
|
1604 | return itemToStringParam(item).toLowerCase();
|
1605 | });
|
1606 | var startPosition = highlightedIndex + 1;
|
1607 | newHighlightedIndex = itemStrings.slice(startPosition).findIndex(function (itemString) {
|
1608 | return itemString.startsWith(keysSoFar);
|
1609 | });
|
1610 |
|
1611 | if (newHighlightedIndex > -1) {
|
1612 | return newHighlightedIndex + startPosition;
|
1613 | } else {
|
1614 | return itemStrings.slice(0, startPosition).findIndex(function (itemString) {
|
1615 | return itemString.startsWith(keysSoFar);
|
1616 | });
|
1617 | }
|
1618 | }
|
1619 |
|
1620 | function getState(state, props) {
|
1621 | return Object.keys(state).reduce(function (prevState, key) {
|
1622 |
|
1623 | prevState[key] = props[key] === undefined ? state[key] : props[key];
|
1624 | return prevState;
|
1625 | }, {});
|
1626 | }
|
1627 |
|
1628 | function getItemIndex(index, item, items) {
|
1629 | if (index !== undefined) {
|
1630 | return index;
|
1631 | }
|
1632 |
|
1633 | if (items.length === 0) {
|
1634 | return -1;
|
1635 | }
|
1636 |
|
1637 | return items.indexOf(item);
|
1638 | }
|
1639 |
|
1640 | function itemToString(item) {
|
1641 | return item ? String(item) : '';
|
1642 | }
|
1643 |
|
1644 | function getPropTypesValidator(caller, propTypes) {
|
1645 |
|
1646 | return function (options) {
|
1647 | if (options === void 0) {
|
1648 | options = {};
|
1649 | }
|
1650 |
|
1651 | Object.entries(propTypes).forEach(function (_ref2) {
|
1652 | var key = _ref2[0];
|
1653 | PropTypes.checkPropTypes(propTypes, options, key, caller.name);
|
1654 | });
|
1655 | };
|
1656 | }
|
1657 |
|
1658 | function isAcceptedCharacterKey(key) {
|
1659 | return /^\S{1}$/.test(key);
|
1660 | }
|
1661 |
|
1662 | var defaultStateValues = {
|
1663 | highlightedIndex: -1,
|
1664 | isOpen: false,
|
1665 | selectedItem: null
|
1666 | };
|
1667 |
|
1668 | function getA11yStatusMessage$1(_ref) {
|
1669 | var isOpen = _ref.isOpen,
|
1670 | items = _ref.items;
|
1671 |
|
1672 | if (!items) {
|
1673 | return '';
|
1674 | }
|
1675 |
|
1676 | var resultCount = items.length;
|
1677 |
|
1678 | if (isOpen) {
|
1679 | if (resultCount === 0) {
|
1680 | return 'No results are available';
|
1681 | }
|
1682 |
|
1683 | return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
|
1684 | }
|
1685 |
|
1686 | return '';
|
1687 | }
|
1688 |
|
1689 | function getA11ySelectionMessage(_ref2) {
|
1690 | var selectedItem = _ref2.selectedItem,
|
1691 | itemToString = _ref2.itemToString;
|
1692 | return itemToString(selectedItem) + " has been selected.";
|
1693 | }
|
1694 |
|
1695 | function getHighlightedIndexOnOpen(props, state, offset) {
|
1696 | var items = props.items,
|
1697 | initialHighlightedIndex = props.initialHighlightedIndex,
|
1698 | defaultHighlightedIndex = props.defaultHighlightedIndex;
|
1699 | var selectedItem = state.selectedItem,
|
1700 | highlightedIndex = state.highlightedIndex;
|
1701 |
|
1702 | if (initialHighlightedIndex !== undefined && highlightedIndex > -1) {
|
1703 | return initialHighlightedIndex;
|
1704 | }
|
1705 |
|
1706 | if (defaultHighlightedIndex !== undefined) {
|
1707 | return defaultHighlightedIndex;
|
1708 | }
|
1709 |
|
1710 | if (selectedItem) {
|
1711 | if (offset === 0) {
|
1712 | return items.indexOf(selectedItem);
|
1713 | }
|
1714 |
|
1715 | return getNextWrappingIndex$1(offset, items.indexOf(selectedItem), items.length, false);
|
1716 | }
|
1717 |
|
1718 | if (offset === 0) {
|
1719 | return -1;
|
1720 | }
|
1721 |
|
1722 | return offset < 0 ? items.length - 1 : 0;
|
1723 | }
|
1724 |
|
1725 | function capitalizeString(string) {
|
1726 | return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
|
1727 | }
|
1728 |
|
1729 | function getDefaultValue(props, propKey) {
|
1730 | var defaultPropKey = "default" + capitalizeString(propKey);
|
1731 |
|
1732 | if (props[defaultPropKey] !== undefined) {
|
1733 | return props[defaultPropKey];
|
1734 | }
|
1735 |
|
1736 | return defaultStateValues[propKey];
|
1737 | }
|
1738 |
|
1739 | function getInitialValue(props, propKey) {
|
1740 | if (props[propKey] !== undefined) {
|
1741 | return props[propKey];
|
1742 | }
|
1743 |
|
1744 | var initialPropKey = "initial" + capitalizeString(propKey);
|
1745 |
|
1746 | if (props[initialPropKey] !== undefined) {
|
1747 | return props[initialPropKey];
|
1748 | }
|
1749 |
|
1750 | return getDefaultValue(props, propKey);
|
1751 | }
|
1752 |
|
1753 | function getInitialState(props) {
|
1754 | return {
|
1755 | highlightedIndex: getInitialValue(props, 'highlightedIndex'),
|
1756 | isOpen: getInitialValue(props, 'isOpen'),
|
1757 | selectedItem: getInitialValue(props, 'selectedItem'),
|
1758 | keysSoFar: ''
|
1759 | };
|
1760 | }
|
1761 |
|
1762 | function invokeOnChangeHandler(propKey, props, state, changes) {
|
1763 | var handler = "on" + capitalizeString(propKey) + "Change";
|
1764 |
|
1765 | if (props[handler] && changes[propKey] !== undefined && changes[propKey] !== state[propKey]) {
|
1766 | props[handler](changes);
|
1767 | }
|
1768 | }
|
1769 |
|
1770 | function callOnChangeProps(props, state, changes) {
|
1771 | ['isOpen', 'highlightedIndex', 'selectedItem'].forEach(function (propKey) {
|
1772 | invokeOnChangeHandler(propKey, props, state, changes);
|
1773 | });
|
1774 |
|
1775 | if (props.onStateChange && changes !== undefined) {
|
1776 | props.onStateChange(changes);
|
1777 | }
|
1778 | }
|
1779 |
|
1780 | var propTypes = {
|
1781 | items: PropTypes.array.isRequired,
|
1782 | itemToString: PropTypes.func,
|
1783 | getA11yStatusMessage: PropTypes.func,
|
1784 | getA11ySelectionMessage: PropTypes.func,
|
1785 | circularNavigation: PropTypes.bool,
|
1786 | highlightedIndex: PropTypes.number,
|
1787 | defaultHighlightedIndex: PropTypes.number,
|
1788 | initialHighlightedIndex: PropTypes.number,
|
1789 | isOpen: PropTypes.bool,
|
1790 | defaultIsOpen: PropTypes.bool,
|
1791 | initialIsOpen: PropTypes.bool,
|
1792 | selectedItem: PropTypes.any,
|
1793 | initialSelectedItem: PropTypes.any,
|
1794 | defaultSelectedItem: PropTypes.any,
|
1795 | id: PropTypes.string,
|
1796 | labelId: PropTypes.string,
|
1797 | menuId: PropTypes.string,
|
1798 | getItemId: PropTypes.func,
|
1799 | toggleButtonId: PropTypes.string,
|
1800 | stateReducer: PropTypes.func,
|
1801 | onSelectedItemChange: PropTypes.func,
|
1802 | onHighlightedIndexChange: PropTypes.func,
|
1803 | onStateChange: PropTypes.func,
|
1804 | onIsOpenChange: PropTypes.func,
|
1805 | environment: PropTypes.shape({
|
1806 | addEventListener: PropTypes.func,
|
1807 | removeEventListener: PropTypes.func,
|
1808 | document: PropTypes.shape({
|
1809 | getElementById: PropTypes.func,
|
1810 | activeElement: PropTypes.any,
|
1811 | body: PropTypes.any
|
1812 | })
|
1813 | })
|
1814 | };
|
1815 |
|
1816 | var MenuKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_down__' : 0;
|
1817 | var MenuKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__menu_keydown_arrow_up__' : 1;
|
1818 | var MenuKeyDownEscape = process.env.NODE_ENV !== "production" ? '__menu_keydown_escape__' : 2;
|
1819 | var MenuKeyDownHome = process.env.NODE_ENV !== "production" ? '__menu_keydown_home__' : 3;
|
1820 | var MenuKeyDownEnd = process.env.NODE_ENV !== "production" ? '__menu_keydown_end__' : 4;
|
1821 | var MenuKeyDownEnter = process.env.NODE_ENV !== "production" ? '__menu_keydown_enter__' : 5;
|
1822 | var MenuKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__menu_keydown_character__' : 6;
|
1823 | var MenuBlur = process.env.NODE_ENV !== "production" ? '__menu_blur__' : 7;
|
1824 | var ItemMouseMove = process.env.NODE_ENV !== "production" ? '__item_mouse_move__' : 8;
|
1825 | var ItemClick = process.env.NODE_ENV !== "production" ? '__item_click__' : 9;
|
1826 | var ToggleButtonKeyDownCharacter = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_character__' : 10;
|
1827 | var ToggleButtonKeyDownArrowDown = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_down__' : 11;
|
1828 | var ToggleButtonKeyDownArrowUp = process.env.NODE_ENV !== "production" ? '__togglebutton_keydown_arrow_up__' : 12;
|
1829 | var ToggleButtonClick = process.env.NODE_ENV !== "production" ? '__togglebutton_click__' : 13;
|
1830 | var FunctionToggleMenu = process.env.NODE_ENV !== "production" ? '__function_toggle_menu__' : 14;
|
1831 | var FunctionOpenMenu = process.env.NODE_ENV !== "production" ? '__function_open_menu__' : 15;
|
1832 | var FunctionCloseMenu = process.env.NODE_ENV !== "production" ? '__function_close_menu__' : 16;
|
1833 | var FunctionSetHighlightedIndex = process.env.NODE_ENV !== "production" ? '__function_set_highlighted_index__' : 17;
|
1834 | var FunctionSelectItem = process.env.NODE_ENV !== "production" ? '__function_select_item__' : 18;
|
1835 | var FunctionClearKeysSoFar = process.env.NODE_ENV !== "production" ? '__function_clear_keys_so_far__' : 19;
|
1836 | var FunctionReset = process.env.NODE_ENV !== "production" ? '__function_reset__' : 20;
|
1837 |
|
1838 | var stateChangeTypes$1 = Object.freeze({
|
1839 | MenuKeyDownArrowDown: MenuKeyDownArrowDown,
|
1840 | MenuKeyDownArrowUp: MenuKeyDownArrowUp,
|
1841 | MenuKeyDownEscape: MenuKeyDownEscape,
|
1842 | MenuKeyDownHome: MenuKeyDownHome,
|
1843 | MenuKeyDownEnd: MenuKeyDownEnd,
|
1844 | MenuKeyDownEnter: MenuKeyDownEnter,
|
1845 | MenuKeyDownCharacter: MenuKeyDownCharacter,
|
1846 | MenuBlur: MenuBlur,
|
1847 | ItemMouseMove: ItemMouseMove,
|
1848 | ItemClick: ItemClick,
|
1849 | ToggleButtonKeyDownCharacter: ToggleButtonKeyDownCharacter,
|
1850 | ToggleButtonKeyDownArrowDown: ToggleButtonKeyDownArrowDown,
|
1851 | ToggleButtonKeyDownArrowUp: ToggleButtonKeyDownArrowUp,
|
1852 | ToggleButtonClick: ToggleButtonClick,
|
1853 | FunctionToggleMenu: FunctionToggleMenu,
|
1854 | FunctionOpenMenu: FunctionOpenMenu,
|
1855 | FunctionCloseMenu: FunctionCloseMenu,
|
1856 | FunctionSetHighlightedIndex: FunctionSetHighlightedIndex,
|
1857 | FunctionSelectItem: FunctionSelectItem,
|
1858 | FunctionClearKeysSoFar: FunctionClearKeysSoFar,
|
1859 | FunctionReset: FunctionReset
|
1860 | });
|
1861 |
|
1862 |
|
1863 |
|
1864 | function downshiftSelectReducer(state, action) {
|
1865 | var type = action.type,
|
1866 | props = action.props,
|
1867 | shiftKey = action.shiftKey;
|
1868 | var changes;
|
1869 |
|
1870 | switch (type) {
|
1871 | case ItemMouseMove:
|
1872 | changes = {
|
1873 | highlightedIndex: action.index
|
1874 | };
|
1875 | break;
|
1876 |
|
1877 | case ItemClick:
|
1878 | changes = {
|
1879 | isOpen: getDefaultValue(props, 'isOpen'),
|
1880 | highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
1881 | selectedItem: props.items[action.index]
|
1882 | };
|
1883 | break;
|
1884 |
|
1885 | case MenuBlur:
|
1886 | changes = _extends({
|
1887 | isOpen: false,
|
1888 | highlightedIndex: -1
|
1889 | }, state.highlightedIndex >= 0 && {
|
1890 | selectedItem: props.items[state.highlightedIndex]
|
1891 | });
|
1892 | break;
|
1893 |
|
1894 | case MenuKeyDownArrowDown:
|
1895 | changes = {
|
1896 | highlightedIndex: getNextWrappingIndex$1(shiftKey ? 5 : 1, state.highlightedIndex, props.items.length, props.circularNavigation)
|
1897 | };
|
1898 | break;
|
1899 |
|
1900 | case MenuKeyDownArrowUp:
|
1901 | changes = {
|
1902 | highlightedIndex: getNextWrappingIndex$1(shiftKey ? -5 : -1, state.highlightedIndex, props.items.length, props.circularNavigation)
|
1903 | };
|
1904 | break;
|
1905 |
|
1906 | case MenuKeyDownHome:
|
1907 | changes = {
|
1908 | highlightedIndex: 0
|
1909 | };
|
1910 | break;
|
1911 |
|
1912 | case MenuKeyDownEnd:
|
1913 | changes = {
|
1914 | highlightedIndex: props.items.length - 1
|
1915 | };
|
1916 | break;
|
1917 |
|
1918 | case MenuKeyDownEscape:
|
1919 | changes = {
|
1920 | isOpen: false,
|
1921 | highlightedIndex: -1
|
1922 | };
|
1923 | break;
|
1924 |
|
1925 | case MenuKeyDownEnter:
|
1926 | changes = _extends({
|
1927 | isOpen: getDefaultValue(props, 'isOpen'),
|
1928 | highlightedIndex: getDefaultValue(props, 'highlightedIndex')
|
1929 | }, state.highlightedIndex >= 0 && {
|
1930 | selectedItem: props.items[state.highlightedIndex]
|
1931 | });
|
1932 | break;
|
1933 |
|
1934 | case MenuKeyDownCharacter:
|
1935 | {
|
1936 | var lowercasedKey = action.key;
|
1937 | var keysSoFar = "" + state.keysSoFar + lowercasedKey;
|
1938 | var highlightedIndex = getItemIndexByCharacterKey(keysSoFar, state.highlightedIndex, props.items, props.itemToString);
|
1939 | changes = _extends({
|
1940 | keysSoFar: keysSoFar
|
1941 | }, highlightedIndex >= 0 && {
|
1942 | highlightedIndex: highlightedIndex
|
1943 | });
|
1944 | }
|
1945 | break;
|
1946 |
|
1947 | case ToggleButtonKeyDownCharacter:
|
1948 | {
|
1949 | var _lowercasedKey = action.key;
|
1950 |
|
1951 | var _keysSoFar = "" + state.keysSoFar + _lowercasedKey;
|
1952 |
|
1953 | var itemIndex = getItemIndexByCharacterKey(_keysSoFar, state.selectedItem ? props.items.indexOf(state.selectedItem) : -1, props.items, props.itemToString);
|
1954 | changes = _extends({
|
1955 | keysSoFar: _keysSoFar
|
1956 | }, itemIndex >= 0 && {
|
1957 | selectedItem: props.items[itemIndex]
|
1958 | });
|
1959 | }
|
1960 | break;
|
1961 |
|
1962 | case ToggleButtonKeyDownArrowDown:
|
1963 | {
|
1964 | changes = {
|
1965 | isOpen: true,
|
1966 | highlightedIndex: getHighlightedIndexOnOpen(props, state, 1)
|
1967 | };
|
1968 | break;
|
1969 | }
|
1970 |
|
1971 | case ToggleButtonKeyDownArrowUp:
|
1972 | changes = {
|
1973 | isOpen: true,
|
1974 | highlightedIndex: getHighlightedIndexOnOpen(props, state, -1)
|
1975 | };
|
1976 | break;
|
1977 |
|
1978 | case ToggleButtonClick:
|
1979 | case FunctionToggleMenu:
|
1980 | changes = {
|
1981 | isOpen: !state.isOpen,
|
1982 | highlightedIndex: state.isOpen ? -1 : getHighlightedIndexOnOpen(props, state, 0)
|
1983 | };
|
1984 | break;
|
1985 |
|
1986 | case FunctionOpenMenu:
|
1987 | changes = {
|
1988 | isOpen: true,
|
1989 | highlightedIndex: getHighlightedIndexOnOpen(props, state, 0)
|
1990 | };
|
1991 | break;
|
1992 |
|
1993 | case FunctionCloseMenu:
|
1994 | changes = {
|
1995 | isOpen: false
|
1996 | };
|
1997 | break;
|
1998 |
|
1999 | case FunctionSetHighlightedIndex:
|
2000 | changes = {
|
2001 | highlightedIndex: action.highlightedIndex
|
2002 | };
|
2003 | break;
|
2004 |
|
2005 | case FunctionSelectItem:
|
2006 | changes = {
|
2007 | selectedItem: action.selectedItem
|
2008 | };
|
2009 | break;
|
2010 |
|
2011 | case FunctionClearKeysSoFar:
|
2012 | changes = {
|
2013 | keysSoFar: ''
|
2014 | };
|
2015 | break;
|
2016 |
|
2017 | case FunctionReset:
|
2018 | changes = {
|
2019 | highlightedIndex: getDefaultValue(props, 'highlightedIndex'),
|
2020 | isOpen: getDefaultValue(props, 'isOpen'),
|
2021 | selectedItem: getDefaultValue(props, 'selectedItem')
|
2022 | };
|
2023 | break;
|
2024 |
|
2025 | default:
|
2026 | throw new Error('Reducer called without proper action type.');
|
2027 | }
|
2028 |
|
2029 | return _extends({}, state, {}, changes);
|
2030 | }
|
2031 |
|
2032 |
|
2033 | var validatePropTypes = getPropTypesValidator(useSelect, propTypes);
|
2034 | var defaultProps = {
|
2035 | itemToString: itemToString,
|
2036 | stateReducer: function stateReducer(s, a) {
|
2037 | return a.changes;
|
2038 | },
|
2039 | getA11yStatusMessage: getA11yStatusMessage$1,
|
2040 | getA11ySelectionMessage: getA11ySelectionMessage,
|
2041 | scrollIntoView: scrollIntoView,
|
2042 | environment: typeof window === 'undefined'
|
2043 |
|
2044 | ? {} : window
|
2045 | };
|
2046 | var clearTimeout$1;
|
2047 | useSelect.stateChangeTypes = stateChangeTypes$1;
|
2048 |
|
2049 | function useSelect(userProps) {
|
2050 | if (userProps === void 0) {
|
2051 | userProps = {};
|
2052 | }
|
2053 |
|
2054 | validatePropTypes(userProps);
|
2055 |
|
2056 | var props = _extends({}, defaultProps, {}, userProps);
|
2057 |
|
2058 | var items = props.items,
|
2059 | itemToString = props.itemToString,
|
2060 | getA11yStatusMessage = props.getA11yStatusMessage,
|
2061 | getA11ySelectionMessage = props.getA11ySelectionMessage,
|
2062 | initialIsOpen = props.initialIsOpen,
|
2063 | defaultIsOpen = props.defaultIsOpen,
|
2064 | stateReducer = props.stateReducer,
|
2065 | scrollIntoView = props.scrollIntoView,
|
2066 | environment = props.environment;
|
2067 |
|
2068 | var initialState = getInitialState(props);
|
2069 |
|
2070 | var _useReducer = useReducer(function (state, action) {
|
2071 | var changes = downshiftSelectReducer(state, action);
|
2072 |
|
2073 | var reducedState = stateReducer(state, _extends({}, action, {
|
2074 | changes: changes
|
2075 | }));
|
2076 |
|
2077 | callOnChangeProps(props, state, reducedState);
|
2078 |
|
2079 | return getState(reducedState, props);
|
2080 | }, initialState),
|
2081 | _useReducer$ = _useReducer[0],
|
2082 | isOpen = _useReducer$.isOpen,
|
2083 | highlightedIndex = _useReducer$.highlightedIndex,
|
2084 | selectedItem = _useReducer$.selectedItem,
|
2085 | keysSoFar = _useReducer$.keysSoFar,
|
2086 | dispatch = _useReducer[1];
|
2087 |
|
2088 |
|
2089 | var _getElementIds = getElementIds(useId, props),
|
2090 | labelId = _getElementIds.labelId,
|
2091 | getItemId = _getElementIds.getItemId,
|
2092 | menuId = _getElementIds.menuId,
|
2093 | toggleButtonId = _getElementIds.toggleButtonId;
|
2094 |
|
2095 |
|
2096 |
|
2097 | var toggleButtonRef = useRef(null);
|
2098 | var menuRef = useRef(null);
|
2099 | var itemRefs = useRef();
|
2100 | itemRefs.current = [];
|
2101 | var isInitialMount = useRef(true);
|
2102 | var shouldScroll = useRef(true);
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 | useEffect(function () {
|
2108 | if (isInitialMount.current) {
|
2109 | return;
|
2110 | }
|
2111 |
|
2112 | setStatus(getA11yStatusMessage({
|
2113 | isOpen: isOpen,
|
2114 | items: items,
|
2115 | selectedItem: selectedItem,
|
2116 | itemToString: itemToString
|
2117 | }));
|
2118 | }, [isOpen]);
|
2119 |
|
2120 |
|
2121 | useEffect(function () {
|
2122 | if (isInitialMount.current) {
|
2123 | return;
|
2124 | }
|
2125 |
|
2126 | setStatus(getA11ySelectionMessage({
|
2127 | isOpen: isOpen,
|
2128 | items: items,
|
2129 | selectedItem: selectedItem,
|
2130 | itemToString: itemToString
|
2131 | }));
|
2132 | }, [selectedItem]);
|
2133 |
|
2134 |
|
2135 | useEffect(function () {
|
2136 |
|
2137 | if (isInitialMount.current) {
|
2138 | clearTimeout$1 = debounce(function () {
|
2139 | dispatch({
|
2140 | type: FunctionClearKeysSoFar,
|
2141 | props: props
|
2142 | });
|
2143 | }, 500);
|
2144 | }
|
2145 |
|
2146 | if (!keysSoFar) {
|
2147 | return;
|
2148 | }
|
2149 |
|
2150 | clearTimeout$1();
|
2151 | }, [keysSoFar]);
|
2152 |
|
2153 |
|
2154 | useEffect(function () {
|
2155 |
|
2156 | if (isInitialMount.current) {
|
2157 |
|
2158 | if (initialIsOpen || defaultIsOpen || isOpen) {
|
2159 | menuRef.current.focus();
|
2160 | }
|
2161 |
|
2162 | return;
|
2163 | }
|
2164 |
|
2165 |
|
2166 |
|
2167 | if (isOpen) {
|
2168 | menuRef.current.focus();
|
2169 | } else if (environment.document.activeElement === menuRef.current) {
|
2170 | toggleButtonRef.current.focus();
|
2171 | }
|
2172 |
|
2173 | }, [isOpen]);
|
2174 |
|
2175 |
|
2176 | useEffect(function () {
|
2177 | if (highlightedIndex < 0 || !isOpen || !itemRefs.current.length) {
|
2178 | return;
|
2179 | }
|
2180 |
|
2181 | if (shouldScroll.current === false) {
|
2182 | shouldScroll.current = true;
|
2183 | } else {
|
2184 | scrollIntoView(itemRefs.current[highlightedIndex], menuRef.current);
|
2185 | }
|
2186 |
|
2187 | }, [highlightedIndex]);
|
2188 |
|
2189 |
|
2190 | useEffect(function () {
|
2191 | isInitialMount.current = false;
|
2192 | }, []);
|
2193 |
|
2194 |
|
2195 | var menuKeyDownHandlers = {
|
2196 | ArrowDown: function ArrowDown(event) {
|
2197 | event.preventDefault();
|
2198 | dispatch({
|
2199 | type: MenuKeyDownArrowDown,
|
2200 | props: props,
|
2201 | shiftKey: event.shiftKey
|
2202 | });
|
2203 | },
|
2204 | ArrowUp: function ArrowUp(event) {
|
2205 | event.preventDefault();
|
2206 | dispatch({
|
2207 | type: MenuKeyDownArrowUp,
|
2208 | props: props,
|
2209 | shiftKey: event.shiftKey
|
2210 | });
|
2211 | },
|
2212 | Home: function Home(event) {
|
2213 | event.preventDefault();
|
2214 | dispatch({
|
2215 | type: MenuKeyDownHome,
|
2216 | props: props
|
2217 | });
|
2218 | },
|
2219 | End: function End(event) {
|
2220 | event.preventDefault();
|
2221 | dispatch({
|
2222 | type: MenuKeyDownEnd,
|
2223 | props: props
|
2224 | });
|
2225 | },
|
2226 | Escape: function Escape() {
|
2227 | dispatch({
|
2228 | type: MenuKeyDownEscape,
|
2229 | props: props
|
2230 | });
|
2231 | },
|
2232 | Enter: function Enter() {
|
2233 | dispatch({
|
2234 | type: MenuKeyDownEnter,
|
2235 | props: props
|
2236 | });
|
2237 | },
|
2238 | Tab: function Tab(event) {
|
2239 |
|
2240 |
|
2241 | if (event.shiftKey) {
|
2242 | dispatch({
|
2243 | type: MenuBlur,
|
2244 | props: props
|
2245 | });
|
2246 | }
|
2247 | }
|
2248 | };
|
2249 | var toggleButtonKeyDownHandlers = {
|
2250 | ArrowDown: function ArrowDown(event) {
|
2251 | event.preventDefault();
|
2252 | dispatch({
|
2253 | type: ToggleButtonKeyDownArrowDown,
|
2254 | props: props
|
2255 | });
|
2256 | },
|
2257 | ArrowUp: function ArrowUp(event) {
|
2258 | event.preventDefault();
|
2259 | dispatch({
|
2260 | type: ToggleButtonKeyDownArrowUp,
|
2261 | props: props
|
2262 | });
|
2263 | }
|
2264 | };
|
2265 |
|
2266 | var menuHandleKeyDown = function (event) {
|
2267 | var key = keyboardKey.getKey(event);
|
2268 |
|
2269 | if (key && menuKeyDownHandlers[key]) {
|
2270 | menuKeyDownHandlers[key](event);
|
2271 | } else if (isAcceptedCharacterKey(key)) {
|
2272 | dispatch({
|
2273 | type: MenuKeyDownCharacter,
|
2274 | key: key,
|
2275 | props: props
|
2276 | });
|
2277 | }
|
2278 | };
|
2279 |
|
2280 |
|
2281 |
|
2282 |
|
2283 | var menuHandleBlur = function (event) {
|
2284 | if (event.relatedTarget !== toggleButtonRef.current) {
|
2285 | dispatch({
|
2286 | type: MenuBlur,
|
2287 | props: props
|
2288 | });
|
2289 | }
|
2290 | };
|
2291 |
|
2292 | var toggleButtonHandleClick = function () {
|
2293 | dispatch({
|
2294 | type: ToggleButtonClick,
|
2295 | props: props
|
2296 | });
|
2297 | };
|
2298 |
|
2299 | var toggleButtonHandleKeyDown = function (event) {
|
2300 | var key = keyboardKey.getKey(event);
|
2301 |
|
2302 | if (key && toggleButtonKeyDownHandlers[key]) {
|
2303 | toggleButtonKeyDownHandlers[key](event);
|
2304 | } else if (isAcceptedCharacterKey(key)) {
|
2305 | dispatch({
|
2306 | type: ToggleButtonKeyDownCharacter,
|
2307 | key: key,
|
2308 | props: props
|
2309 | });
|
2310 | }
|
2311 | };
|
2312 |
|
2313 | var itemHandleMouseMove = function (index) {
|
2314 | if (index === highlightedIndex) {
|
2315 | return;
|
2316 | }
|
2317 |
|
2318 | shouldScroll.current = false;
|
2319 | dispatch({
|
2320 | type: ItemMouseMove,
|
2321 | props: props,
|
2322 | index: index
|
2323 | });
|
2324 | };
|
2325 |
|
2326 | var itemHandleClick = function (index) {
|
2327 | dispatch({
|
2328 | type: ItemClick,
|
2329 | props: props,
|
2330 | index: index
|
2331 | });
|
2332 | };
|
2333 |
|
2334 |
|
2335 | return {
|
2336 |
|
2337 | getToggleButtonProps: function getToggleButtonProps(_temp2) {
|
2338 | var _extends3;
|
2339 |
|
2340 | var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
2341 | onClick = _ref2.onClick,
|
2342 | onKeyDown = _ref2.onKeyDown,
|
2343 | _ref2$refKey = _ref2.refKey,
|
2344 | refKey = _ref2$refKey === void 0 ? 'ref' : _ref2$refKey,
|
2345 | ref = _ref2.ref,
|
2346 | rest = _objectWithoutPropertiesLoose(_ref2, ["onClick", "onKeyDown", "refKey", "ref"]);
|
2347 |
|
2348 | return _extends((_extends3 = {}, _extends3[refKey] = callAll(ref, function (toggleButtonNode) {
|
2349 | toggleButtonRef.current = toggleButtonNode;
|
2350 | }), _extends3.id = toggleButtonId, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-expanded'] = isOpen, _extends3['aria-labelledby'] = labelId + " " + toggleButtonId, _extends3.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick), _extends3.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown), _extends3), rest);
|
2351 | },
|
2352 | getLabelProps: function getLabelProps(labelProps) {
|
2353 | return _extends({
|
2354 | id: labelId
|
2355 | }, labelProps);
|
2356 | },
|
2357 | getMenuProps: function getMenuProps(_temp) {
|
2358 | var _extends2;
|
2359 |
|
2360 | var _ref = _temp === void 0 ? {} : _temp,
|
2361 | onKeyDown = _ref.onKeyDown,
|
2362 | onBlur = _ref.onBlur,
|
2363 | _ref$refKey = _ref.refKey,
|
2364 | refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
2365 | ref = _ref.ref,
|
2366 | rest = _objectWithoutPropertiesLoose(_ref, ["onKeyDown", "onBlur", "refKey", "ref"]);
|
2367 |
|
2368 | return _extends((_extends2 = {}, _extends2[refKey] = callAll(ref, function (menuNode) {
|
2369 | menuRef.current = menuNode;
|
2370 | }), _extends2.id = menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = labelId, _extends2.tabIndex = -1, _extends2), highlightedIndex > -1 && {
|
2371 | 'aria-activedescendant': getItemId(highlightedIndex)
|
2372 | }, {
|
2373 | onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
2374 | onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
2375 | }, rest);
|
2376 | },
|
2377 | getItemProps: function getItemProps(_temp3) {
|
2378 | var _extends4;
|
2379 |
|
2380 | var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
2381 | item = _ref3.item,
|
2382 | index = _ref3.index,
|
2383 | _ref3$refKey = _ref3.refKey,
|
2384 | refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
2385 | ref = _ref3.ref,
|
2386 | onMouseMove = _ref3.onMouseMove,
|
2387 | onClick = _ref3.onClick,
|
2388 | rest = _objectWithoutPropertiesLoose(_ref3, ["item", "index", "refKey", "ref", "onMouseMove", "onClick"]);
|
2389 |
|
2390 | var itemIndex = getItemIndex(index, item, items);
|
2391 |
|
2392 | if (itemIndex < 0) {
|
2393 | throw new Error('Pass either item or item index in getItemProps!');
|
2394 | }
|
2395 |
|
2396 | return _extends((_extends4 = {}, _extends4[refKey] = callAll(ref, function (itemNode) {
|
2397 | if (itemNode) {
|
2398 | itemRefs.current.push(itemNode);
|
2399 | }
|
2400 | }), _extends4.role = 'option', _extends4), itemIndex === highlightedIndex && {
|
2401 | 'aria-selected': true
|
2402 | }, {
|
2403 | id: getItemId(itemIndex),
|
2404 | onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
2405 | return itemHandleMouseMove(itemIndex);
|
2406 | }),
|
2407 | onClick: callAllEventHandlers(onClick, function () {
|
2408 | return itemHandleClick(itemIndex);
|
2409 | })
|
2410 | }, rest);
|
2411 | },
|
2412 |
|
2413 | toggleMenu: function toggleMenu() {
|
2414 | dispatch({
|
2415 | type: FunctionToggleMenu,
|
2416 | props: props
|
2417 | });
|
2418 | },
|
2419 | openMenu: function openMenu() {
|
2420 | dispatch({
|
2421 | type: FunctionOpenMenu,
|
2422 | props: props
|
2423 | });
|
2424 | },
|
2425 | closeMenu: function closeMenu() {
|
2426 | dispatch({
|
2427 | type: FunctionCloseMenu
|
2428 | });
|
2429 | },
|
2430 | setHighlightedIndex: function setHighlightedIndex(newHighlightedIndex) {
|
2431 | dispatch({
|
2432 | type: FunctionSetHighlightedIndex,
|
2433 | highlightedIndex: newHighlightedIndex
|
2434 | });
|
2435 | },
|
2436 | selectItem: function selectItem(newSelectedItem) {
|
2437 | dispatch({
|
2438 | type: FunctionSelectItem,
|
2439 | selectedItem: newSelectedItem
|
2440 | });
|
2441 | },
|
2442 | reset: function reset() {
|
2443 | dispatch({
|
2444 | type: FunctionReset,
|
2445 | props: props
|
2446 | });
|
2447 | },
|
2448 |
|
2449 | highlightedIndex: highlightedIndex,
|
2450 | isOpen: isOpen,
|
2451 | selectedItem: selectedItem
|
2452 | };
|
2453 | }
|
2454 |
|
2455 | export default Downshift;
|
2456 | export { resetIdCounter, useSelect };
|