downshift 6.1.7 → 6.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -9
- package/dist/downshift.cjs.js +1695 -1631
- package/dist/downshift.esm.js +1569 -1501
- package/dist/downshift.native.cjs.js +1680 -1614
- package/dist/downshift.umd.js +1606 -1568
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -21
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +23 -10
- package/preact/dist/downshift.cjs.js +1659 -1595
- package/preact/dist/downshift.esm.js +1569 -1501
- package/preact/dist/downshift.umd.js +1659 -1643
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -23
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.umd.js
CHANGED
|
@@ -2,63 +2,7 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Downshift = {}, global.React));
|
|
5
|
-
}(this, (function (exports, react) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
8
|
-
if (source == null) return {};
|
|
9
|
-
var target = {};
|
|
10
|
-
var sourceKeys = Object.keys(source);
|
|
11
|
-
var key, i;
|
|
12
|
-
|
|
13
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
14
|
-
key = sourceKeys[i];
|
|
15
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
16
|
-
target[key] = source[key];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return target;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _extends() {
|
|
23
|
-
_extends = Object.assign || function (target) {
|
|
24
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
25
|
-
var source = arguments[i];
|
|
26
|
-
|
|
27
|
-
for (var key in source) {
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
29
|
-
target[key] = source[key];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return _extends.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _assertThisInitialized(self) {
|
|
41
|
-
if (self === void 0) {
|
|
42
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return self;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _setPrototypeOf(o, p) {
|
|
49
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
50
|
-
o.__proto__ = p;
|
|
51
|
-
return o;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return _setPrototypeOf(o, p);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function _inheritsLoose(subClass, superClass) {
|
|
58
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
59
|
-
subClass.prototype.constructor = subClass;
|
|
60
|
-
_setPrototypeOf(subClass, superClass);
|
|
61
|
-
}
|
|
5
|
+
})(this, (function (exports, react) { 'use strict';
|
|
62
6
|
|
|
63
7
|
var propTypes$3 = {exports: {}};
|
|
64
8
|
|
|
@@ -349,6 +293,8 @@
|
|
|
349
293
|
|
|
350
294
|
var ReactPropTypesSecret_1 = ReactPropTypesSecret$2;
|
|
351
295
|
|
|
296
|
+
var has$2 = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
297
|
+
|
|
352
298
|
/**
|
|
353
299
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
354
300
|
*
|
|
@@ -361,7 +307,7 @@
|
|
|
361
307
|
{
|
|
362
308
|
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
|
363
309
|
var loggedTypeFailures = {};
|
|
364
|
-
var has$1 =
|
|
310
|
+
var has$1 = has$2;
|
|
365
311
|
|
|
366
312
|
printWarning$1 = function(text) {
|
|
367
313
|
var message = 'Warning: ' + text;
|
|
@@ -373,7 +319,7 @@
|
|
|
373
319
|
// This error was thrown as a convenience so that you can use this stack
|
|
374
320
|
// to find the callsite that caused this warning to fire.
|
|
375
321
|
throw new Error(message);
|
|
376
|
-
} catch (x) {}
|
|
322
|
+
} catch (x) { /**/ }
|
|
377
323
|
};
|
|
378
324
|
}
|
|
379
325
|
|
|
@@ -402,7 +348,8 @@
|
|
|
402
348
|
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
403
349
|
var err = Error(
|
|
404
350
|
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
|
|
405
|
-
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
|
|
351
|
+
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' +
|
|
352
|
+
'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'
|
|
406
353
|
);
|
|
407
354
|
err.name = 'Invariant Violation';
|
|
408
355
|
throw err;
|
|
@@ -461,9 +408,9 @@
|
|
|
461
408
|
var assign = objectAssign;
|
|
462
409
|
|
|
463
410
|
var ReactPropTypesSecret = ReactPropTypesSecret_1;
|
|
411
|
+
var has = has$2;
|
|
464
412
|
var checkPropTypes = checkPropTypes_1;
|
|
465
413
|
|
|
466
|
-
var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
467
414
|
var printWarning = function() {};
|
|
468
415
|
|
|
469
416
|
{
|
|
@@ -564,6 +511,7 @@
|
|
|
564
511
|
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
|
|
565
512
|
var ReactPropTypes = {
|
|
566
513
|
array: createPrimitiveTypeChecker('array'),
|
|
514
|
+
bigint: createPrimitiveTypeChecker('bigint'),
|
|
567
515
|
bool: createPrimitiveTypeChecker('boolean'),
|
|
568
516
|
func: createPrimitiveTypeChecker('function'),
|
|
569
517
|
number: createPrimitiveTypeChecker('number'),
|
|
@@ -609,8 +557,9 @@
|
|
|
609
557
|
* is prohibitively expensive if they are created too often, such as what
|
|
610
558
|
* happens in oneOfType() for any type before the one that matched.
|
|
611
559
|
*/
|
|
612
|
-
function PropTypeError(message) {
|
|
560
|
+
function PropTypeError(message, data) {
|
|
613
561
|
this.message = message;
|
|
562
|
+
this.data = data && typeof data === 'object' ? data: {};
|
|
614
563
|
this.stack = '';
|
|
615
564
|
}
|
|
616
565
|
// Make `instanceof Error` still work for returned errors.
|
|
@@ -645,7 +594,7 @@
|
|
|
645
594
|
) {
|
|
646
595
|
printWarning(
|
|
647
596
|
'You are manually calling a React.PropTypes validation ' +
|
|
648
|
-
'function for the `' + propFullName + '` prop on `' + componentName
|
|
597
|
+
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
|
|
649
598
|
'and will throw in the standalone `prop-types` package. ' +
|
|
650
599
|
'You may be seeing this warning due to a third-party PropTypes ' +
|
|
651
600
|
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
|
|
@@ -684,7 +633,10 @@
|
|
|
684
633
|
// 'of type `object`'.
|
|
685
634
|
var preciseType = getPreciseType(propValue);
|
|
686
635
|
|
|
687
|
-
return new PropTypeError(
|
|
636
|
+
return new PropTypeError(
|
|
637
|
+
'Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'),
|
|
638
|
+
{expectedType: expectedType}
|
|
639
|
+
);
|
|
688
640
|
}
|
|
689
641
|
return null;
|
|
690
642
|
}
|
|
@@ -828,14 +780,19 @@
|
|
|
828
780
|
}
|
|
829
781
|
|
|
830
782
|
function validate(props, propName, componentName, location, propFullName) {
|
|
783
|
+
var expectedTypes = [];
|
|
831
784
|
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
832
785
|
var checker = arrayOfTypeCheckers[i];
|
|
833
|
-
|
|
786
|
+
var checkerResult = checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret);
|
|
787
|
+
if (checkerResult == null) {
|
|
834
788
|
return null;
|
|
835
789
|
}
|
|
790
|
+
if (checkerResult.data && has(checkerResult.data, 'expectedType')) {
|
|
791
|
+
expectedTypes.push(checkerResult.data.expectedType);
|
|
792
|
+
}
|
|
836
793
|
}
|
|
837
|
-
|
|
838
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '
|
|
794
|
+
var expectedTypesMessage = (expectedTypes.length > 0) ? ', expected one of type [' + expectedTypes.join(', ') + ']': '';
|
|
795
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`' + expectedTypesMessage + '.'));
|
|
839
796
|
}
|
|
840
797
|
return createChainableTypeChecker(validate);
|
|
841
798
|
}
|
|
@@ -850,6 +807,13 @@
|
|
|
850
807
|
return createChainableTypeChecker(validate);
|
|
851
808
|
}
|
|
852
809
|
|
|
810
|
+
function invalidValidatorError(componentName, location, propFullName, key, type) {
|
|
811
|
+
return new PropTypeError(
|
|
812
|
+
(componentName || 'React class') + ': ' + location + ' type `' + propFullName + '.' + key + '` is invalid; ' +
|
|
813
|
+
'it must be a function, usually from the `prop-types` package, but received `' + type + '`.'
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
|
|
853
817
|
function createShapeTypeChecker(shapeTypes) {
|
|
854
818
|
function validate(props, propName, componentName, location, propFullName) {
|
|
855
819
|
var propValue = props[propName];
|
|
@@ -859,8 +823,8 @@
|
|
|
859
823
|
}
|
|
860
824
|
for (var key in shapeTypes) {
|
|
861
825
|
var checker = shapeTypes[key];
|
|
862
|
-
if (
|
|
863
|
-
|
|
826
|
+
if (typeof checker !== 'function') {
|
|
827
|
+
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
864
828
|
}
|
|
865
829
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
866
830
|
if (error) {
|
|
@@ -879,16 +843,18 @@
|
|
|
879
843
|
if (propType !== 'object') {
|
|
880
844
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
881
845
|
}
|
|
882
|
-
// We need to check all keys in case some are required but missing from
|
|
883
|
-
// props.
|
|
846
|
+
// We need to check all keys in case some are required but missing from props.
|
|
884
847
|
var allKeys = assign({}, props[propName], shapeTypes);
|
|
885
848
|
for (var key in allKeys) {
|
|
886
849
|
var checker = shapeTypes[key];
|
|
850
|
+
if (has(shapeTypes, key) && typeof checker !== 'function') {
|
|
851
|
+
return invalidValidatorError(componentName, location, propFullName, key, getPreciseType(checker));
|
|
852
|
+
}
|
|
887
853
|
if (!checker) {
|
|
888
854
|
return new PropTypeError(
|
|
889
855
|
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' +
|
|
890
856
|
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') +
|
|
891
|
-
'\nValid keys: ' +
|
|
857
|
+
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ')
|
|
892
858
|
);
|
|
893
859
|
}
|
|
894
860
|
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
@@ -1299,7 +1265,7 @@
|
|
|
1299
1265
|
|
|
1300
1266
|
function t(t){return "object"==typeof t&&null!=t&&1===t.nodeType}function e(t,e){return (!e||"hidden"!==t)&&"visible"!==t&&"clip"!==t}function n(t,n){if(t.clientHeight<t.scrollHeight||t.clientWidth<t.scrollWidth){var r=getComputedStyle(t,null);return e(r.overflowY,n)||e(r.overflowX,n)||function(t){var e=function(t){if(!t.ownerDocument||!t.ownerDocument.defaultView)return null;try{return t.ownerDocument.defaultView.frameElement}catch(t){return null}}(t);return !!e&&(e.clientHeight<t.scrollHeight||e.clientWidth<t.scrollWidth)}(t)}return !1}function r(t,e,n,r,i,o,l,d){return o<t&&l>e||o>t&&l<e?0:o<=t&&d<=n||l>=e&&d>=n?o-t-r:l>e&&d<n||o<t&&d>n?l-e+i:0}function computeScrollIntoView(e,i){var o=window,l=i.scrollMode,d=i.block,u=i.inline,h=i.boundary,a=i.skipOverflowHiddenElements,c="function"==typeof h?h:function(t){return t!==h};if(!t(e))throw new TypeError("Invalid target");for(var f=document.scrollingElement||document.documentElement,s=[],p=e;t(p)&&c(p);){if((p=p.parentElement)===f){s.push(p);break}null!=p&&p===document.body&&n(p)&&!n(document.documentElement)||null!=p&&n(p,a)&&s.push(p);}for(var m=o.visualViewport?o.visualViewport.width:innerWidth,g=o.visualViewport?o.visualViewport.height:innerHeight,w=window.scrollX||pageXOffset,v=window.scrollY||pageYOffset,W=e.getBoundingClientRect(),b=W.height,H=W.width,y=W.top,E=W.right,M=W.bottom,V=W.left,x="start"===d||"nearest"===d?y:"end"===d?M:y+b/2,I="center"===u?V+H/2:"end"===u?E:V,C=[],T=0;T<s.length;T++){var k=s[T],B=k.getBoundingClientRect(),D=B.height,O=B.width,R=B.top,X=B.right,Y=B.bottom,L=B.left;if("if-needed"===l&&y>=0&&V>=0&&M<=g&&E<=m&&y>=R&&M<=Y&&V>=L&&E<=X)return C;var S=getComputedStyle(k),j=parseInt(S.borderLeftWidth,10),q=parseInt(S.borderTopWidth,10),z=parseInt(S.borderRightWidth,10),A=parseInt(S.borderBottomWidth,10),F=0,G=0,J="offsetWidth"in k?k.offsetWidth-k.clientWidth-j-z:0,K="offsetHeight"in k?k.offsetHeight-k.clientHeight-q-A:0;if(f===k)F="start"===d?x:"end"===d?x-g:"nearest"===d?r(v,v+g,g,q,A,v+x,v+x+b,b):x-g/2,G="start"===u?I:"center"===u?I-m/2:"end"===u?I-m:r(w,w+m,m,j,z,w+I,w+I+H,H),F=Math.max(0,F+v),G=Math.max(0,G+w);else {F="start"===d?x-R-q:"end"===d?x-Y+A+K:"nearest"===d?r(R,Y,D,q,A+K,x,x+b,b):x-(R+D/2)+K/2,G="start"===u?I-L-j:"center"===u?I-(L+O/2)+J/2:"end"===u?I-X+z+J:r(L,X,O,j,z+J,I,I+H,H);var N=k.scrollLeft,P=k.scrollTop;x+=P-(F=Math.max(0,Math.min(P+F,k.scrollHeight-D+K))),I+=N-(G=Math.max(0,Math.min(N+G,k.scrollWidth-O+J)));}C.push({el:k,top:F,left:G});}return C}
|
|
1301
1267
|
|
|
1302
|
-
|
|
1268
|
+
let idCounter = 0;
|
|
1303
1269
|
/**
|
|
1304
1270
|
* Accepts a parameter and returns it if it's a function
|
|
1305
1271
|
* or a noop function if it's not. This allows us to
|
|
@@ -1326,15 +1292,17 @@
|
|
|
1326
1292
|
return;
|
|
1327
1293
|
}
|
|
1328
1294
|
|
|
1329
|
-
|
|
1295
|
+
const actions = computeScrollIntoView(node, {
|
|
1330
1296
|
boundary: menuNode,
|
|
1331
1297
|
block: 'nearest',
|
|
1332
1298
|
scrollMode: 'if-needed'
|
|
1333
1299
|
});
|
|
1334
|
-
actions.forEach(
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1300
|
+
actions.forEach(_ref => {
|
|
1301
|
+
let {
|
|
1302
|
+
el,
|
|
1303
|
+
top,
|
|
1304
|
+
left
|
|
1305
|
+
} = _ref;
|
|
1338
1306
|
el.scrollTop = top;
|
|
1339
1307
|
el.scrollLeft = left;
|
|
1340
1308
|
});
|
|
@@ -1348,7 +1316,7 @@
|
|
|
1348
1316
|
|
|
1349
1317
|
|
|
1350
1318
|
function isOrContainsNode(parent, child, environment) {
|
|
1351
|
-
|
|
1319
|
+
const result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
1352
1320
|
return result;
|
|
1353
1321
|
}
|
|
1354
1322
|
/**
|
|
@@ -1362,7 +1330,7 @@
|
|
|
1362
1330
|
|
|
1363
1331
|
|
|
1364
1332
|
function debounce(fn, time) {
|
|
1365
|
-
|
|
1333
|
+
let timeoutId;
|
|
1366
1334
|
|
|
1367
1335
|
function cancel() {
|
|
1368
1336
|
if (timeoutId) {
|
|
@@ -1376,9 +1344,9 @@
|
|
|
1376
1344
|
}
|
|
1377
1345
|
|
|
1378
1346
|
cancel();
|
|
1379
|
-
timeoutId = setTimeout(
|
|
1347
|
+
timeoutId = setTimeout(() => {
|
|
1380
1348
|
timeoutId = null;
|
|
1381
|
-
fn
|
|
1349
|
+
fn(...args);
|
|
1382
1350
|
}, time);
|
|
1383
1351
|
}
|
|
1384
1352
|
|
|
@@ -1404,9 +1372,9 @@
|
|
|
1404
1372
|
args[_key3 - 1] = arguments[_key3];
|
|
1405
1373
|
}
|
|
1406
1374
|
|
|
1407
|
-
return fns.some(
|
|
1375
|
+
return fns.some(fn => {
|
|
1408
1376
|
if (fn) {
|
|
1409
|
-
fn
|
|
1377
|
+
fn(event, ...args);
|
|
1410
1378
|
}
|
|
1411
1379
|
|
|
1412
1380
|
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
@@ -1419,8 +1387,8 @@
|
|
|
1419
1387
|
refs[_key4] = arguments[_key4];
|
|
1420
1388
|
}
|
|
1421
1389
|
|
|
1422
|
-
return
|
|
1423
|
-
refs.forEach(
|
|
1390
|
+
return node => {
|
|
1391
|
+
refs.forEach(ref => {
|
|
1424
1392
|
if (typeof ref === 'function') {
|
|
1425
1393
|
ref(node);
|
|
1426
1394
|
} else if (ref) {
|
|
@@ -1457,9 +1425,11 @@
|
|
|
1457
1425
|
|
|
1458
1426
|
|
|
1459
1427
|
function getA11yStatusMessage$1(_ref2) {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1428
|
+
let {
|
|
1429
|
+
isOpen,
|
|
1430
|
+
resultCount,
|
|
1431
|
+
previousResultCount
|
|
1432
|
+
} = _ref2;
|
|
1463
1433
|
|
|
1464
1434
|
if (!isOpen) {
|
|
1465
1435
|
return '';
|
|
@@ -1529,7 +1499,7 @@
|
|
|
1529
1499
|
console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
|
|
1530
1500
|
}
|
|
1531
1501
|
|
|
1532
|
-
|
|
1502
|
+
const stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
|
1533
1503
|
/**
|
|
1534
1504
|
* @param {Object} state the state object
|
|
1535
1505
|
* @return {Object} state that is relevant to downshift
|
|
@@ -1540,8 +1510,8 @@
|
|
|
1540
1510
|
state = {};
|
|
1541
1511
|
}
|
|
1542
1512
|
|
|
1543
|
-
|
|
1544
|
-
stateKeys.forEach(
|
|
1513
|
+
const result = {};
|
|
1514
|
+
stateKeys.forEach(k => {
|
|
1545
1515
|
if (state.hasOwnProperty(k)) {
|
|
1546
1516
|
result[k] = state[k];
|
|
1547
1517
|
}
|
|
@@ -1562,7 +1532,7 @@
|
|
|
1562
1532
|
|
|
1563
1533
|
|
|
1564
1534
|
function getState(state, props) {
|
|
1565
|
-
return Object.keys(state).reduce(
|
|
1535
|
+
return Object.keys(state).reduce((prevState, key) => {
|
|
1566
1536
|
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
1567
1537
|
return prevState;
|
|
1568
1538
|
}, {});
|
|
@@ -1589,8 +1559,10 @@
|
|
|
1589
1559
|
|
|
1590
1560
|
|
|
1591
1561
|
function normalizeArrowKey(event) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1562
|
+
const {
|
|
1563
|
+
key,
|
|
1564
|
+
keyCode
|
|
1565
|
+
} = event;
|
|
1594
1566
|
/* istanbul ignore next (ie) */
|
|
1595
1567
|
|
|
1596
1568
|
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
@@ -1631,13 +1603,13 @@
|
|
|
1631
1603
|
return -1;
|
|
1632
1604
|
}
|
|
1633
1605
|
|
|
1634
|
-
|
|
1606
|
+
const itemsLastIndex = itemCount - 1;
|
|
1635
1607
|
|
|
1636
1608
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
1637
1609
|
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
|
1638
1610
|
}
|
|
1639
1611
|
|
|
1640
|
-
|
|
1612
|
+
let newIndex = baseIndex + moveAmount;
|
|
1641
1613
|
|
|
1642
1614
|
if (newIndex < 0) {
|
|
1643
1615
|
newIndex = circular ? itemsLastIndex : 0;
|
|
@@ -1645,7 +1617,7 @@
|
|
|
1645
1617
|
newIndex = circular ? 0 : itemsLastIndex;
|
|
1646
1618
|
}
|
|
1647
1619
|
|
|
1648
|
-
|
|
1620
|
+
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
|
|
1649
1621
|
|
|
1650
1622
|
if (nonDisabledNewIndex === -1) {
|
|
1651
1623
|
return baseIndex >= itemCount ? -1 : baseIndex;
|
|
@@ -1666,22 +1638,22 @@
|
|
|
1666
1638
|
|
|
1667
1639
|
|
|
1668
1640
|
function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
|
|
1669
|
-
|
|
1641
|
+
const currentElementNode = getItemNodeFromIndex(baseIndex);
|
|
1670
1642
|
|
|
1671
1643
|
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
|
|
1672
1644
|
return baseIndex;
|
|
1673
1645
|
}
|
|
1674
1646
|
|
|
1675
1647
|
if (moveAmount > 0) {
|
|
1676
|
-
for (
|
|
1648
|
+
for (let index = baseIndex + 1; index < itemCount; index++) {
|
|
1677
1649
|
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
1678
1650
|
return index;
|
|
1679
1651
|
}
|
|
1680
1652
|
}
|
|
1681
1653
|
} else {
|
|
1682
|
-
for (
|
|
1683
|
-
if (!getItemNodeFromIndex(
|
|
1684
|
-
return
|
|
1654
|
+
for (let index = baseIndex - 1; index >= 0; index--) {
|
|
1655
|
+
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
1656
|
+
return index;
|
|
1685
1657
|
}
|
|
1686
1658
|
}
|
|
1687
1659
|
}
|
|
@@ -1709,19 +1681,17 @@
|
|
|
1709
1681
|
checkActiveElement = true;
|
|
1710
1682
|
}
|
|
1711
1683
|
|
|
1712
|
-
return downshiftElements.some(
|
|
1713
|
-
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
1714
|
-
});
|
|
1684
|
+
return downshiftElements.some(contextNode => contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment)));
|
|
1715
1685
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
1716
1686
|
|
|
1717
1687
|
|
|
1718
|
-
|
|
1688
|
+
let validateControlledUnchanged = noop;
|
|
1719
1689
|
/* istanbul ignore next */
|
|
1720
1690
|
|
|
1721
1691
|
{
|
|
1722
|
-
validateControlledUnchanged =
|
|
1723
|
-
|
|
1724
|
-
Object.keys(state).forEach(
|
|
1692
|
+
validateControlledUnchanged = (state, prevProps, nextProps) => {
|
|
1693
|
+
const warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
|
|
1694
|
+
Object.keys(state).forEach(propKey => {
|
|
1725
1695
|
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
1726
1696
|
// eslint-disable-next-line no-console
|
|
1727
1697
|
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
@@ -1733,7 +1703,7 @@
|
|
|
1733
1703
|
};
|
|
1734
1704
|
}
|
|
1735
1705
|
|
|
1736
|
-
|
|
1706
|
+
const cleanupStatus = debounce(documentProp => {
|
|
1737
1707
|
getStatusDiv(documentProp).textContent = '';
|
|
1738
1708
|
}, 500);
|
|
1739
1709
|
/**
|
|
@@ -1742,7 +1712,7 @@
|
|
|
1742
1712
|
*/
|
|
1743
1713
|
|
|
1744
1714
|
function setStatus(status, documentProp) {
|
|
1745
|
-
|
|
1715
|
+
const div = getStatusDiv(documentProp);
|
|
1746
1716
|
|
|
1747
1717
|
if (!status) {
|
|
1748
1718
|
return;
|
|
@@ -1763,7 +1733,7 @@
|
|
|
1763
1733
|
documentProp = document;
|
|
1764
1734
|
}
|
|
1765
1735
|
|
|
1766
|
-
|
|
1736
|
+
let statusDiv = documentProp.getElementById('a11y-status-message');
|
|
1767
1737
|
|
|
1768
1738
|
if (statusDiv) {
|
|
1769
1739
|
return statusDiv;
|
|
@@ -1788,23 +1758,23 @@
|
|
|
1788
1758
|
return statusDiv;
|
|
1789
1759
|
}
|
|
1790
1760
|
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1761
|
+
const unknown = '__autocomplete_unknown__' ;
|
|
1762
|
+
const mouseUp = '__autocomplete_mouseup__' ;
|
|
1763
|
+
const itemMouseEnter = '__autocomplete_item_mouseenter__' ;
|
|
1764
|
+
const keyDownArrowUp = '__autocomplete_keydown_arrow_up__' ;
|
|
1765
|
+
const keyDownArrowDown = '__autocomplete_keydown_arrow_down__' ;
|
|
1766
|
+
const keyDownEscape = '__autocomplete_keydown_escape__' ;
|
|
1767
|
+
const keyDownEnter = '__autocomplete_keydown_enter__' ;
|
|
1768
|
+
const keyDownHome = '__autocomplete_keydown_home__' ;
|
|
1769
|
+
const keyDownEnd = '__autocomplete_keydown_end__' ;
|
|
1770
|
+
const clickItem = '__autocomplete_click_item__' ;
|
|
1771
|
+
const blurInput = '__autocomplete_blur_input__' ;
|
|
1772
|
+
const changeInput = '__autocomplete_change_input__' ;
|
|
1773
|
+
const keyDownSpaceButton = '__autocomplete_keydown_space_button__' ;
|
|
1774
|
+
const clickButton = '__autocomplete_click_button__' ;
|
|
1775
|
+
const blurButton = '__autocomplete_blur_button__' ;
|
|
1776
|
+
const controlledPropUpdatedSelectedItem = '__autocomplete_controlled_prop_updated_selected_item__' ;
|
|
1777
|
+
const touchEnd = '__autocomplete_touchend__' ;
|
|
1808
1778
|
|
|
1809
1779
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
1810
1780
|
__proto__: null,
|
|
@@ -1827,58 +1797,45 @@
|
|
|
1827
1797
|
touchEnd: touchEnd
|
|
1828
1798
|
});
|
|
1829
1799
|
|
|
1830
|
-
|
|
1831
|
-
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
1832
|
-
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
1833
|
-
_excluded4$1 = ["refKey", "ref"],
|
|
1834
|
-
_excluded5$1 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
1835
|
-
|
|
1836
|
-
var Downshift = /*#__PURE__*/function () {
|
|
1837
|
-
var Downshift = /*#__PURE__*/function (_Component) {
|
|
1838
|
-
_inheritsLoose(Downshift, _Component);
|
|
1800
|
+
/* eslint camelcase:0 */
|
|
1839
1801
|
|
|
1840
|
-
|
|
1802
|
+
const Downshift = /*#__PURE__*/(() => {
|
|
1803
|
+
class Downshift extends react.Component {
|
|
1804
|
+
constructor(_props) {
|
|
1841
1805
|
var _this;
|
|
1842
1806
|
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
_this.labelId = _this.props.labelId || _this.id + "-label";
|
|
1850
|
-
_this.inputId = _this.props.inputId || _this.id + "-input";
|
|
1807
|
+
super(_props);
|
|
1808
|
+
_this = this;
|
|
1809
|
+
this.id = this.props.id || "downshift-" + generateId();
|
|
1810
|
+
this.menuId = this.props.menuId || this.id + "-menu";
|
|
1811
|
+
this.labelId = this.props.labelId || this.id + "-label";
|
|
1812
|
+
this.inputId = this.props.inputId || this.id + "-input";
|
|
1851
1813
|
|
|
1852
|
-
|
|
1853
|
-
return _this.id + "-item-" + index;
|
|
1854
|
-
};
|
|
1814
|
+
this.getItemId = this.props.getItemId || (index => this.id + "-item-" + index);
|
|
1855
1815
|
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1816
|
+
this.input = null;
|
|
1817
|
+
this.items = [];
|
|
1818
|
+
this.itemCount = null;
|
|
1819
|
+
this.previousResultCount = 0;
|
|
1820
|
+
this.timeoutIds = [];
|
|
1861
1821
|
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
return i !== id;
|
|
1866
|
-
});
|
|
1822
|
+
this.internalSetTimeout = (fn, time) => {
|
|
1823
|
+
const id = setTimeout(() => {
|
|
1824
|
+
this.timeoutIds = this.timeoutIds.filter(i => i !== id);
|
|
1867
1825
|
fn();
|
|
1868
1826
|
}, time);
|
|
1869
|
-
|
|
1870
|
-
_this.timeoutIds.push(id);
|
|
1827
|
+
this.timeoutIds.push(id);
|
|
1871
1828
|
};
|
|
1872
1829
|
|
|
1873
|
-
|
|
1874
|
-
|
|
1830
|
+
this.setItemCount = count => {
|
|
1831
|
+
this.itemCount = count;
|
|
1875
1832
|
};
|
|
1876
1833
|
|
|
1877
|
-
|
|
1878
|
-
|
|
1834
|
+
this.unsetItemCount = () => {
|
|
1835
|
+
this.itemCount = null;
|
|
1879
1836
|
};
|
|
1880
1837
|
|
|
1881
|
-
|
|
1838
|
+
this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
1882
1839
|
if (highlightedIndex === void 0) {
|
|
1883
1840
|
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
1884
1841
|
}
|
|
@@ -1889,71 +1846,72 @@
|
|
|
1889
1846
|
|
|
1890
1847
|
otherStateToSet = pickState(otherStateToSet);
|
|
1891
1848
|
|
|
1892
|
-
_this.internalSetState(
|
|
1893
|
-
highlightedIndex
|
|
1894
|
-
|
|
1849
|
+
_this.internalSetState({
|
|
1850
|
+
highlightedIndex,
|
|
1851
|
+
...otherStateToSet
|
|
1852
|
+
});
|
|
1895
1853
|
};
|
|
1896
1854
|
|
|
1897
|
-
|
|
1898
|
-
|
|
1855
|
+
this.clearSelection = cb => {
|
|
1856
|
+
this.internalSetState({
|
|
1899
1857
|
selectedItem: null,
|
|
1900
1858
|
inputValue: '',
|
|
1901
|
-
highlightedIndex:
|
|
1902
|
-
isOpen:
|
|
1859
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
1860
|
+
isOpen: this.props.defaultIsOpen
|
|
1903
1861
|
}, cb);
|
|
1904
1862
|
};
|
|
1905
1863
|
|
|
1906
|
-
|
|
1864
|
+
this.selectItem = (item, otherStateToSet, cb) => {
|
|
1907
1865
|
otherStateToSet = pickState(otherStateToSet);
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1866
|
+
this.internalSetState({
|
|
1867
|
+
isOpen: this.props.defaultIsOpen,
|
|
1868
|
+
highlightedIndex: this.props.defaultHighlightedIndex,
|
|
1912
1869
|
selectedItem: item,
|
|
1913
|
-
inputValue:
|
|
1914
|
-
|
|
1870
|
+
inputValue: this.props.itemToString(item),
|
|
1871
|
+
...otherStateToSet
|
|
1872
|
+
}, cb);
|
|
1915
1873
|
};
|
|
1916
1874
|
|
|
1917
|
-
|
|
1918
|
-
|
|
1875
|
+
this.selectItemAtIndex = (itemIndex, otherStateToSet, cb) => {
|
|
1876
|
+
const item = this.items[itemIndex];
|
|
1919
1877
|
|
|
1920
1878
|
if (item == null) {
|
|
1921
1879
|
return;
|
|
1922
1880
|
}
|
|
1923
1881
|
|
|
1924
|
-
|
|
1882
|
+
this.selectItem(item, otherStateToSet, cb);
|
|
1925
1883
|
};
|
|
1926
1884
|
|
|
1927
|
-
|
|
1928
|
-
return
|
|
1885
|
+
this.selectHighlightedItem = (otherStateToSet, cb) => {
|
|
1886
|
+
return this.selectItemAtIndex(this.getState().highlightedIndex, otherStateToSet, cb);
|
|
1929
1887
|
};
|
|
1930
1888
|
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1889
|
+
this.internalSetState = (stateToSet, cb) => {
|
|
1890
|
+
let isItemSelected, onChangeArg;
|
|
1891
|
+
const onStateChangeArg = {};
|
|
1892
|
+
const isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
|
|
1935
1893
|
// so someone controlling the `inputValue` state gets notified of
|
|
1936
1894
|
// the input change as soon as possible. This avoids issues with
|
|
1937
1895
|
// preserving the cursor position.
|
|
1938
1896
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
1939
1897
|
|
|
1940
1898
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
1941
|
-
|
|
1899
|
+
this.props.onInputValueChange(stateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
1900
|
+
...stateToSet
|
|
1901
|
+
});
|
|
1942
1902
|
}
|
|
1943
1903
|
|
|
1944
|
-
return
|
|
1945
|
-
state =
|
|
1946
|
-
|
|
1904
|
+
return this.setState(state => {
|
|
1905
|
+
state = this.getState(state);
|
|
1906
|
+
let newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
|
|
1947
1907
|
|
|
1948
|
-
newStateToSet =
|
|
1908
|
+
newStateToSet = this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
|
|
1949
1909
|
// what was selected before
|
|
1950
1910
|
// used to determine if onSelect and onChange callbacks should be called
|
|
1951
1911
|
|
|
1952
1912
|
isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
|
|
1953
1913
|
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
|
|
1914
|
+
const nextState = {}; // this is just used to tell whether the state changed
|
|
1957
1915
|
// and we're trying to update that state. OR if the selection has changed and we're
|
|
1958
1916
|
// trying to update the selection
|
|
1959
1917
|
|
|
@@ -1962,7 +1920,7 @@
|
|
|
1962
1920
|
}
|
|
1963
1921
|
|
|
1964
1922
|
newStateToSet.type = newStateToSet.type || unknown;
|
|
1965
|
-
Object.keys(newStateToSet).forEach(
|
|
1923
|
+
Object.keys(newStateToSet).forEach(key => {
|
|
1966
1924
|
// onStateChangeArg should only have the state that is
|
|
1967
1925
|
// actually changing
|
|
1968
1926
|
if (state[key] !== newStateToSet[key]) {
|
|
@@ -1979,81 +1937,84 @@
|
|
|
1979
1937
|
return;
|
|
1980
1938
|
}
|
|
1981
1939
|
|
|
1982
|
-
|
|
1940
|
+
newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
|
|
1983
1941
|
|
|
1984
|
-
if (!isControlledProp(
|
|
1942
|
+
if (!isControlledProp(this.props, key)) {
|
|
1985
1943
|
nextState[key] = newStateToSet[key];
|
|
1986
1944
|
}
|
|
1987
1945
|
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
1988
1946
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
1989
1947
|
|
|
1990
1948
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
1991
|
-
|
|
1949
|
+
this.props.onInputValueChange(newStateToSet.inputValue, { ...this.getStateAndHelpers(),
|
|
1950
|
+
...newStateToSet
|
|
1951
|
+
});
|
|
1992
1952
|
}
|
|
1993
1953
|
|
|
1994
1954
|
return nextState;
|
|
1995
|
-
},
|
|
1955
|
+
}, () => {
|
|
1996
1956
|
// call the provided callback if it's a function
|
|
1997
1957
|
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
|
|
1998
1958
|
// we have relevant information to pass them.
|
|
1999
1959
|
|
|
2000
|
-
|
|
1960
|
+
const hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
2001
1961
|
|
|
2002
1962
|
if (hasMoreStateThanType) {
|
|
2003
|
-
|
|
1963
|
+
this.props.onStateChange(onStateChangeArg, this.getStateAndHelpers());
|
|
2004
1964
|
}
|
|
2005
1965
|
|
|
2006
1966
|
if (isItemSelected) {
|
|
2007
|
-
|
|
1967
|
+
this.props.onSelect(stateToSet.selectedItem, this.getStateAndHelpers());
|
|
2008
1968
|
}
|
|
2009
1969
|
|
|
2010
1970
|
if (onChangeArg !== undefined) {
|
|
2011
|
-
|
|
1971
|
+
this.props.onChange(onChangeArg, this.getStateAndHelpers());
|
|
2012
1972
|
} // this is currently undocumented and therefore subject to change
|
|
2013
1973
|
// We'll try to not break it, but just be warned.
|
|
2014
1974
|
|
|
2015
1975
|
|
|
2016
|
-
|
|
1976
|
+
this.props.onUserAction(onStateChangeArg, this.getStateAndHelpers());
|
|
2017
1977
|
});
|
|
2018
1978
|
};
|
|
2019
1979
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
2032
|
-
|
|
2033
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
2034
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
2035
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
2036
|
-
|
|
1980
|
+
this.rootRef = node => this._rootNode = node;
|
|
1981
|
+
|
|
1982
|
+
this.getRootProps = function (_temp, _temp2) {
|
|
1983
|
+
let {
|
|
1984
|
+
refKey = 'ref',
|
|
1985
|
+
ref,
|
|
1986
|
+
...rest
|
|
1987
|
+
} = _temp === void 0 ? {} : _temp;
|
|
1988
|
+
let {
|
|
1989
|
+
suppressRefError = false
|
|
1990
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
2037
1991
|
// this is used in the render to know whether the user has called getRootProps.
|
|
2038
1992
|
// It uses that to know whether to apply the props automatically
|
|
2039
1993
|
_this.getRootProps.called = true;
|
|
2040
1994
|
_this.getRootProps.refKey = refKey;
|
|
2041
1995
|
_this.getRootProps.suppressRefError = suppressRefError;
|
|
2042
1996
|
|
|
2043
|
-
|
|
2044
|
-
|
|
1997
|
+
const {
|
|
1998
|
+
isOpen
|
|
1999
|
+
} = _this.getState();
|
|
2045
2000
|
|
|
2046
|
-
return
|
|
2001
|
+
return {
|
|
2002
|
+
[refKey]: handleRefs(ref, _this.rootRef),
|
|
2003
|
+
role: 'combobox',
|
|
2004
|
+
'aria-expanded': isOpen,
|
|
2005
|
+
'aria-haspopup': 'listbox',
|
|
2006
|
+
'aria-owns': isOpen ? _this.menuId : null,
|
|
2007
|
+
'aria-labelledby': _this.labelId,
|
|
2008
|
+
...rest
|
|
2009
|
+
};
|
|
2047
2010
|
};
|
|
2048
2011
|
|
|
2049
|
-
|
|
2050
|
-
ArrowDown
|
|
2051
|
-
var _this2 = this;
|
|
2052
|
-
|
|
2012
|
+
this.keyDownHandlers = {
|
|
2013
|
+
ArrowDown(event) {
|
|
2053
2014
|
event.preventDefault();
|
|
2054
2015
|
|
|
2055
2016
|
if (this.getState().isOpen) {
|
|
2056
|
-
|
|
2017
|
+
const amount = event.shiftKey ? 5 : 1;
|
|
2057
2018
|
this.moveHighlightedIndex(amount, {
|
|
2058
2019
|
type: keyDownArrowDown
|
|
2059
2020
|
});
|
|
@@ -2061,31 +2022,27 @@
|
|
|
2061
2022
|
this.internalSetState({
|
|
2062
2023
|
isOpen: true,
|
|
2063
2024
|
type: keyDownArrowDown
|
|
2064
|
-
},
|
|
2065
|
-
|
|
2025
|
+
}, () => {
|
|
2026
|
+
const itemCount = this.getItemCount();
|
|
2066
2027
|
|
|
2067
2028
|
if (itemCount > 0) {
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
});
|
|
2074
|
-
|
|
2075
|
-
_this2.setHighlightedIndex(nextHighlightedIndex, {
|
|
2029
|
+
const {
|
|
2030
|
+
highlightedIndex
|
|
2031
|
+
} = this.getState();
|
|
2032
|
+
const nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
2033
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
2076
2034
|
type: keyDownArrowDown
|
|
2077
2035
|
});
|
|
2078
2036
|
}
|
|
2079
2037
|
});
|
|
2080
2038
|
}
|
|
2081
2039
|
},
|
|
2082
|
-
ArrowUp: function ArrowUp(event) {
|
|
2083
|
-
var _this3 = this;
|
|
2084
2040
|
|
|
2041
|
+
ArrowUp(event) {
|
|
2085
2042
|
event.preventDefault();
|
|
2086
2043
|
|
|
2087
2044
|
if (this.getState().isOpen) {
|
|
2088
|
-
|
|
2045
|
+
const amount = event.shiftKey ? -5 : -1;
|
|
2089
2046
|
this.moveHighlightedIndex(amount, {
|
|
2090
2047
|
type: keyDownArrowUp
|
|
2091
2048
|
});
|
|
@@ -2093,37 +2050,36 @@
|
|
|
2093
2050
|
this.internalSetState({
|
|
2094
2051
|
isOpen: true,
|
|
2095
2052
|
type: keyDownArrowUp
|
|
2096
|
-
},
|
|
2097
|
-
|
|
2053
|
+
}, () => {
|
|
2054
|
+
const itemCount = this.getItemCount();
|
|
2098
2055
|
|
|
2099
2056
|
if (itemCount > 0) {
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
});
|
|
2106
|
-
|
|
2107
|
-
_this3.setHighlightedIndex(nextHighlightedIndex, {
|
|
2057
|
+
const {
|
|
2058
|
+
highlightedIndex
|
|
2059
|
+
} = this.getState();
|
|
2060
|
+
const nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
2061
|
+
this.setHighlightedIndex(nextHighlightedIndex, {
|
|
2108
2062
|
type: keyDownArrowUp
|
|
2109
2063
|
});
|
|
2110
2064
|
}
|
|
2111
2065
|
});
|
|
2112
2066
|
}
|
|
2113
2067
|
},
|
|
2114
|
-
|
|
2068
|
+
|
|
2069
|
+
Enter(event) {
|
|
2115
2070
|
if (event.which === 229) {
|
|
2116
2071
|
return;
|
|
2117
2072
|
}
|
|
2118
2073
|
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2074
|
+
const {
|
|
2075
|
+
isOpen,
|
|
2076
|
+
highlightedIndex
|
|
2077
|
+
} = this.getState();
|
|
2122
2078
|
|
|
2123
2079
|
if (isOpen && highlightedIndex != null) {
|
|
2124
2080
|
event.preventDefault();
|
|
2125
|
-
|
|
2126
|
-
|
|
2081
|
+
const item = this.items[highlightedIndex];
|
|
2082
|
+
const itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
2127
2083
|
|
|
2128
2084
|
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
2129
2085
|
return;
|
|
@@ -2134,125 +2090,131 @@
|
|
|
2134
2090
|
});
|
|
2135
2091
|
}
|
|
2136
2092
|
},
|
|
2137
|
-
|
|
2093
|
+
|
|
2094
|
+
Escape(event) {
|
|
2138
2095
|
event.preventDefault();
|
|
2139
|
-
this.reset(
|
|
2140
|
-
type: keyDownEscape
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2096
|
+
this.reset({
|
|
2097
|
+
type: keyDownEscape,
|
|
2098
|
+
...(!this.state.isOpen && {
|
|
2099
|
+
selectedItem: null,
|
|
2100
|
+
inputValue: ''
|
|
2101
|
+
})
|
|
2102
|
+
});
|
|
2145
2103
|
}
|
|
2104
|
+
|
|
2146
2105
|
};
|
|
2147
|
-
|
|
2148
|
-
|
|
2106
|
+
this.buttonKeyDownHandlers = { ...this.keyDownHandlers,
|
|
2107
|
+
|
|
2108
|
+
' '(event) {
|
|
2149
2109
|
event.preventDefault();
|
|
2150
2110
|
this.toggleMenu({
|
|
2151
2111
|
type: keyDownSpaceButton
|
|
2152
2112
|
});
|
|
2153
2113
|
}
|
|
2154
|
-
});
|
|
2155
|
-
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2156
|
-
Home: function Home(event) {
|
|
2157
|
-
var _this4 = this;
|
|
2158
2114
|
|
|
2159
|
-
|
|
2160
|
-
|
|
2115
|
+
};
|
|
2116
|
+
this.inputKeyDownHandlers = { ...this.keyDownHandlers,
|
|
2117
|
+
|
|
2118
|
+
Home(event) {
|
|
2119
|
+
const {
|
|
2120
|
+
isOpen
|
|
2121
|
+
} = this.getState();
|
|
2161
2122
|
|
|
2162
2123
|
if (!isOpen) {
|
|
2163
2124
|
return;
|
|
2164
2125
|
}
|
|
2165
2126
|
|
|
2166
2127
|
event.preventDefault();
|
|
2167
|
-
|
|
2128
|
+
const itemCount = this.getItemCount();
|
|
2168
2129
|
|
|
2169
2130
|
if (itemCount <= 0 || !isOpen) {
|
|
2170
2131
|
return;
|
|
2171
2132
|
} // get next non-disabled starting downwards from 0 if that's disabled.
|
|
2172
2133
|
|
|
2173
2134
|
|
|
2174
|
-
|
|
2175
|
-
return _this4.getItemNodeFromIndex(index);
|
|
2176
|
-
}, false);
|
|
2135
|
+
const newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
2177
2136
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
2178
2137
|
type: keyDownHome
|
|
2179
2138
|
});
|
|
2180
2139
|
},
|
|
2181
|
-
End: function End(event) {
|
|
2182
|
-
var _this5 = this;
|
|
2183
2140
|
|
|
2184
|
-
|
|
2185
|
-
|
|
2141
|
+
End(event) {
|
|
2142
|
+
const {
|
|
2143
|
+
isOpen
|
|
2144
|
+
} = this.getState();
|
|
2186
2145
|
|
|
2187
2146
|
if (!isOpen) {
|
|
2188
2147
|
return;
|
|
2189
2148
|
}
|
|
2190
2149
|
|
|
2191
2150
|
event.preventDefault();
|
|
2192
|
-
|
|
2151
|
+
const itemCount = this.getItemCount();
|
|
2193
2152
|
|
|
2194
2153
|
if (itemCount <= 0 || !isOpen) {
|
|
2195
2154
|
return;
|
|
2196
2155
|
} // get next non-disabled starting upwards from last index if that's disabled.
|
|
2197
2156
|
|
|
2198
2157
|
|
|
2199
|
-
|
|
2200
|
-
return _this5.getItemNodeFromIndex(index);
|
|
2201
|
-
}, false);
|
|
2158
|
+
const newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, index => this.getItemNodeFromIndex(index), false);
|
|
2202
2159
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
2203
2160
|
type: keyDownEnd
|
|
2204
2161
|
});
|
|
2205
2162
|
}
|
|
2206
|
-
});
|
|
2207
2163
|
|
|
2208
|
-
|
|
2209
|
-
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
2210
|
-
onClick = _ref3.onClick;
|
|
2211
|
-
_ref3.onPress;
|
|
2212
|
-
var onKeyDown = _ref3.onKeyDown,
|
|
2213
|
-
onKeyUp = _ref3.onKeyUp,
|
|
2214
|
-
onBlur = _ref3.onBlur,
|
|
2215
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$3);
|
|
2216
|
-
|
|
2217
|
-
var _this$getState5 = _this.getState(),
|
|
2218
|
-
isOpen = _this$getState5.isOpen;
|
|
2164
|
+
};
|
|
2219
2165
|
|
|
2220
|
-
|
|
2166
|
+
this.getToggleButtonProps = function (_temp3) {
|
|
2167
|
+
let {
|
|
2168
|
+
onClick,
|
|
2169
|
+
onPress,
|
|
2170
|
+
onKeyDown,
|
|
2171
|
+
onKeyUp,
|
|
2172
|
+
onBlur,
|
|
2173
|
+
...rest
|
|
2174
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
2175
|
+
|
|
2176
|
+
const {
|
|
2177
|
+
isOpen
|
|
2178
|
+
} = _this.getState();
|
|
2179
|
+
|
|
2180
|
+
const enabledEventHandlers = {
|
|
2221
2181
|
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
2222
2182
|
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
2223
2183
|
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
2224
2184
|
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
2225
2185
|
};
|
|
2226
|
-
|
|
2227
|
-
return
|
|
2186
|
+
const eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
2187
|
+
return {
|
|
2228
2188
|
type: 'button',
|
|
2229
2189
|
role: 'button',
|
|
2230
2190
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
2231
2191
|
'aria-haspopup': true,
|
|
2232
|
-
'data-toggle': true
|
|
2233
|
-
|
|
2192
|
+
'data-toggle': true,
|
|
2193
|
+
...eventHandlers,
|
|
2194
|
+
...rest
|
|
2195
|
+
};
|
|
2234
2196
|
};
|
|
2235
2197
|
|
|
2236
|
-
|
|
2198
|
+
this.buttonHandleKeyUp = event => {
|
|
2237
2199
|
// Prevent click event from emitting in Firefox
|
|
2238
2200
|
event.preventDefault();
|
|
2239
2201
|
};
|
|
2240
2202
|
|
|
2241
|
-
|
|
2242
|
-
|
|
2203
|
+
this.buttonHandleKeyDown = event => {
|
|
2204
|
+
const key = normalizeArrowKey(event);
|
|
2243
2205
|
|
|
2244
|
-
if (
|
|
2245
|
-
|
|
2206
|
+
if (this.buttonKeyDownHandlers[key]) {
|
|
2207
|
+
this.buttonKeyDownHandlers[key].call(this, event);
|
|
2246
2208
|
}
|
|
2247
2209
|
};
|
|
2248
2210
|
|
|
2249
|
-
|
|
2211
|
+
this.buttonHandleClick = event => {
|
|
2250
2212
|
event.preventDefault(); // handle odd case for Safari and Firefox which
|
|
2251
2213
|
// don't give the button the focus properly.
|
|
2252
2214
|
|
|
2253
2215
|
/* istanbul ignore if (can't reasonably test this) */
|
|
2254
2216
|
|
|
2255
|
-
if (
|
|
2217
|
+
if (this.props.environment.document.activeElement === this.props.environment.document.body) {
|
|
2256
2218
|
event.target.focus();
|
|
2257
2219
|
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
2258
2220
|
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
@@ -2261,64 +2223,66 @@
|
|
|
2261
2223
|
|
|
2262
2224
|
{
|
|
2263
2225
|
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
});
|
|
2268
|
-
});
|
|
2226
|
+
this.internalSetTimeout(() => this.toggleMenu({
|
|
2227
|
+
type: clickButton
|
|
2228
|
+
}));
|
|
2269
2229
|
}
|
|
2270
2230
|
};
|
|
2271
2231
|
|
|
2272
|
-
|
|
2273
|
-
|
|
2232
|
+
this.buttonHandleBlur = event => {
|
|
2233
|
+
const blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
2274
2234
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
2275
2235
|
|
|
2276
|
-
|
|
2277
|
-
if (!
|
|
2236
|
+
this.internalSetTimeout(() => {
|
|
2237
|
+
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)
|
|
2278
2238
|
) {
|
|
2279
|
-
|
|
2239
|
+
this.reset({
|
|
2280
2240
|
type: blurButton
|
|
2281
2241
|
});
|
|
2282
2242
|
}
|
|
2283
2243
|
});
|
|
2284
2244
|
};
|
|
2285
2245
|
|
|
2286
|
-
|
|
2287
|
-
return
|
|
2288
|
-
htmlFor:
|
|
2289
|
-
id:
|
|
2290
|
-
|
|
2246
|
+
this.getLabelProps = props => {
|
|
2247
|
+
return {
|
|
2248
|
+
htmlFor: this.inputId,
|
|
2249
|
+
id: this.labelId,
|
|
2250
|
+
...props
|
|
2251
|
+
};
|
|
2291
2252
|
};
|
|
2292
2253
|
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2254
|
+
this.getInputProps = function (_temp4) {
|
|
2255
|
+
let {
|
|
2256
|
+
onKeyDown,
|
|
2257
|
+
onBlur,
|
|
2258
|
+
onChange,
|
|
2259
|
+
onInput,
|
|
2260
|
+
onChangeText,
|
|
2261
|
+
...rest
|
|
2262
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
2263
|
+
let onChangeKey;
|
|
2264
|
+
let eventHandlers = {};
|
|
2304
2265
|
/* istanbul ignore next (preact) */
|
|
2305
2266
|
|
|
2306
2267
|
{
|
|
2307
2268
|
onChangeKey = 'onChange';
|
|
2308
2269
|
}
|
|
2309
2270
|
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2271
|
+
const {
|
|
2272
|
+
inputValue,
|
|
2273
|
+
isOpen,
|
|
2274
|
+
highlightedIndex
|
|
2275
|
+
} = _this.getState();
|
|
2314
2276
|
|
|
2315
2277
|
if (!rest.disabled) {
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2278
|
+
eventHandlers = {
|
|
2279
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, _this.inputHandleChange),
|
|
2280
|
+
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
|
|
2281
|
+
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
2282
|
+
};
|
|
2319
2283
|
}
|
|
2320
2284
|
|
|
2321
|
-
return
|
|
2285
|
+
return {
|
|
2322
2286
|
'aria-autocomplete': 'list',
|
|
2323
2287
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
2324
2288
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -2327,75 +2291,77 @@
|
|
|
2327
2291
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
2328
2292
|
autoComplete: 'off',
|
|
2329
2293
|
value: inputValue,
|
|
2330
|
-
id: _this.inputId
|
|
2331
|
-
|
|
2294
|
+
id: _this.inputId,
|
|
2295
|
+
...eventHandlers,
|
|
2296
|
+
...rest
|
|
2297
|
+
};
|
|
2332
2298
|
};
|
|
2333
2299
|
|
|
2334
|
-
|
|
2335
|
-
|
|
2300
|
+
this.inputHandleKeyDown = event => {
|
|
2301
|
+
const key = normalizeArrowKey(event);
|
|
2336
2302
|
|
|
2337
|
-
if (key &&
|
|
2338
|
-
|
|
2303
|
+
if (key && this.inputKeyDownHandlers[key]) {
|
|
2304
|
+
this.inputKeyDownHandlers[key].call(this, event);
|
|
2339
2305
|
}
|
|
2340
2306
|
};
|
|
2341
2307
|
|
|
2342
|
-
|
|
2343
|
-
|
|
2308
|
+
this.inputHandleChange = event => {
|
|
2309
|
+
this.internalSetState({
|
|
2344
2310
|
type: changeInput,
|
|
2345
2311
|
isOpen: true,
|
|
2346
2312
|
inputValue: event.target.value,
|
|
2347
|
-
highlightedIndex:
|
|
2313
|
+
highlightedIndex: this.props.defaultHighlightedIndex
|
|
2348
2314
|
});
|
|
2349
2315
|
};
|
|
2350
2316
|
|
|
2351
|
-
|
|
2317
|
+
this.inputHandleBlur = () => {
|
|
2352
2318
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
2353
|
-
|
|
2354
|
-
|
|
2319
|
+
this.internalSetTimeout(() => {
|
|
2320
|
+
const downshiftButtonIsActive = this.props.environment.document && !!this.props.environment.document.activeElement && !!this.props.environment.document.activeElement.dataset && this.props.environment.document.activeElement.dataset.toggle && this._rootNode && this._rootNode.contains(this.props.environment.document.activeElement);
|
|
2355
2321
|
|
|
2356
|
-
if (!
|
|
2357
|
-
|
|
2322
|
+
if (!this.isMouseDown && !downshiftButtonIsActive) {
|
|
2323
|
+
this.reset({
|
|
2358
2324
|
type: blurInput
|
|
2359
2325
|
});
|
|
2360
2326
|
}
|
|
2361
2327
|
});
|
|
2362
2328
|
};
|
|
2363
2329
|
|
|
2364
|
-
|
|
2365
|
-
|
|
2330
|
+
this.menuRef = node => {
|
|
2331
|
+
this._menuNode = node;
|
|
2366
2332
|
};
|
|
2367
2333
|
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
2378
|
-
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
2379
|
-
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
2380
|
-
|
|
2334
|
+
this.getMenuProps = function (_temp5, _temp6) {
|
|
2335
|
+
let {
|
|
2336
|
+
refKey = 'ref',
|
|
2337
|
+
ref,
|
|
2338
|
+
...props
|
|
2339
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
2340
|
+
let {
|
|
2341
|
+
suppressRefError = false
|
|
2342
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
2381
2343
|
_this.getMenuProps.called = true;
|
|
2382
2344
|
_this.getMenuProps.refKey = refKey;
|
|
2383
2345
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
2384
|
-
return
|
|
2346
|
+
return {
|
|
2347
|
+
[refKey]: handleRefs(ref, _this.menuRef),
|
|
2348
|
+
role: 'listbox',
|
|
2349
|
+
'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
|
|
2350
|
+
id: _this.menuId,
|
|
2351
|
+
...props
|
|
2352
|
+
};
|
|
2385
2353
|
};
|
|
2386
2354
|
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
item = _ref7$item === void 0 ? requiredProp('getItemProps', 'item') : _ref7$item,
|
|
2398
|
-
rest = _objectWithoutPropertiesLoose(_ref7, _excluded5$1);
|
|
2355
|
+
this.getItemProps = function (_temp7) {
|
|
2356
|
+
let {
|
|
2357
|
+
onMouseMove,
|
|
2358
|
+
onMouseDown,
|
|
2359
|
+
onClick,
|
|
2360
|
+
onPress,
|
|
2361
|
+
index,
|
|
2362
|
+
item = requiredProp('getItemProps', 'item'),
|
|
2363
|
+
...rest
|
|
2364
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
2399
2365
|
|
|
2400
2366
|
if (index === undefined) {
|
|
2401
2367
|
_this.items.push(item);
|
|
@@ -2405,13 +2371,13 @@
|
|
|
2405
2371
|
_this.items[index] = item;
|
|
2406
2372
|
}
|
|
2407
2373
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2374
|
+
const onSelectKey = 'onClick';
|
|
2375
|
+
const customClickHandler = onClick;
|
|
2376
|
+
const enabledEventHandlers = {
|
|
2411
2377
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
2412
2378
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
2413
2379
|
// can fire on DOM changes, interrupting keyboard navigation
|
|
2414
|
-
onMouseMove: callAllEventHandlers(onMouseMove,
|
|
2380
|
+
onMouseMove: callAllEventHandlers(onMouseMove, () => {
|
|
2415
2381
|
if (index === _this.getState().highlightedIndex) {
|
|
2416
2382
|
return;
|
|
2417
2383
|
}
|
|
@@ -2426,72 +2392,81 @@
|
|
|
2426
2392
|
|
|
2427
2393
|
_this.avoidScrolling = true;
|
|
2428
2394
|
|
|
2429
|
-
_this.internalSetTimeout(
|
|
2430
|
-
return _this.avoidScrolling = false;
|
|
2431
|
-
}, 250);
|
|
2395
|
+
_this.internalSetTimeout(() => _this.avoidScrolling = false, 250);
|
|
2432
2396
|
}),
|
|
2433
|
-
onMouseDown: callAllEventHandlers(onMouseDown,
|
|
2397
|
+
onMouseDown: callAllEventHandlers(onMouseDown, event => {
|
|
2434
2398
|
// This prevents the activeElement from being changed
|
|
2435
2399
|
// to the item so it can remain with the current activeElement
|
|
2436
2400
|
// which is a more common use case.
|
|
2437
2401
|
event.preventDefault();
|
|
2402
|
+
}),
|
|
2403
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, () => {
|
|
2404
|
+
_this.selectItemAtIndex(index, {
|
|
2405
|
+
type: clickItem
|
|
2406
|
+
});
|
|
2438
2407
|
})
|
|
2439
|
-
}
|
|
2440
|
-
_this.selectItemAtIndex(index, {
|
|
2441
|
-
type: clickItem
|
|
2442
|
-
});
|
|
2443
|
-
}), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
|
|
2408
|
+
}; // Passing down the onMouseDown handler to prevent redirect
|
|
2444
2409
|
// of the activeElement if clicking on disabled items
|
|
2445
2410
|
|
|
2446
|
-
|
|
2411
|
+
const eventHandlers = rest.disabled ? {
|
|
2447
2412
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
2448
2413
|
} : enabledEventHandlers;
|
|
2449
|
-
return
|
|
2414
|
+
return {
|
|
2450
2415
|
id: _this.getItemId(index),
|
|
2451
2416
|
role: 'option',
|
|
2452
|
-
'aria-selected': _this.getState().highlightedIndex === index
|
|
2453
|
-
|
|
2417
|
+
'aria-selected': _this.getState().highlightedIndex === index,
|
|
2418
|
+
...eventHandlers,
|
|
2419
|
+
...rest
|
|
2420
|
+
};
|
|
2454
2421
|
};
|
|
2455
2422
|
|
|
2456
|
-
|
|
2457
|
-
|
|
2423
|
+
this.clearItems = () => {
|
|
2424
|
+
this.items = [];
|
|
2458
2425
|
};
|
|
2459
2426
|
|
|
2460
|
-
|
|
2427
|
+
this.reset = function (otherStateToSet, cb) {
|
|
2461
2428
|
if (otherStateToSet === void 0) {
|
|
2462
2429
|
otherStateToSet = {};
|
|
2463
2430
|
}
|
|
2464
2431
|
|
|
2465
2432
|
otherStateToSet = pickState(otherStateToSet);
|
|
2466
2433
|
|
|
2467
|
-
_this.internalSetState(
|
|
2468
|
-
|
|
2469
|
-
|
|
2434
|
+
_this.internalSetState(_ref => {
|
|
2435
|
+
let {
|
|
2436
|
+
selectedItem
|
|
2437
|
+
} = _ref;
|
|
2438
|
+
return {
|
|
2470
2439
|
isOpen: _this.props.defaultIsOpen,
|
|
2471
2440
|
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
2472
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
2473
|
-
|
|
2441
|
+
inputValue: _this.props.itemToString(selectedItem),
|
|
2442
|
+
...otherStateToSet
|
|
2443
|
+
};
|
|
2474
2444
|
}, cb);
|
|
2475
2445
|
};
|
|
2476
2446
|
|
|
2477
|
-
|
|
2447
|
+
this.toggleMenu = function (otherStateToSet, cb) {
|
|
2478
2448
|
if (otherStateToSet === void 0) {
|
|
2479
2449
|
otherStateToSet = {};
|
|
2480
2450
|
}
|
|
2481
2451
|
|
|
2482
2452
|
otherStateToSet = pickState(otherStateToSet);
|
|
2483
2453
|
|
|
2484
|
-
_this.internalSetState(
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2454
|
+
_this.internalSetState(_ref2 => {
|
|
2455
|
+
let {
|
|
2456
|
+
isOpen
|
|
2457
|
+
} = _ref2;
|
|
2458
|
+
return {
|
|
2459
|
+
isOpen: !isOpen,
|
|
2460
|
+
...(isOpen && {
|
|
2461
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2462
|
+
}),
|
|
2463
|
+
...otherStateToSet
|
|
2464
|
+
};
|
|
2465
|
+
}, () => {
|
|
2466
|
+
const {
|
|
2467
|
+
isOpen,
|
|
2468
|
+
highlightedIndex
|
|
2469
|
+
} = _this.getState();
|
|
2495
2470
|
|
|
2496
2471
|
if (isOpen) {
|
|
2497
2472
|
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
@@ -2503,70 +2478,63 @@
|
|
|
2503
2478
|
});
|
|
2504
2479
|
};
|
|
2505
2480
|
|
|
2506
|
-
|
|
2507
|
-
|
|
2481
|
+
this.openMenu = cb => {
|
|
2482
|
+
this.internalSetState({
|
|
2508
2483
|
isOpen: true
|
|
2509
2484
|
}, cb);
|
|
2510
2485
|
};
|
|
2511
2486
|
|
|
2512
|
-
|
|
2513
|
-
|
|
2487
|
+
this.closeMenu = cb => {
|
|
2488
|
+
this.internalSetState({
|
|
2514
2489
|
isOpen: false
|
|
2515
2490
|
}, cb);
|
|
2516
2491
|
};
|
|
2517
2492
|
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
_this.previousResultCount = resultCount;
|
|
2533
|
-
setStatus(status, _this.props.environment.document);
|
|
2493
|
+
this.updateStatus = debounce(() => {
|
|
2494
|
+
const state = this.getState();
|
|
2495
|
+
const item = this.items[state.highlightedIndex];
|
|
2496
|
+
const resultCount = this.getItemCount();
|
|
2497
|
+
const status = this.props.getA11yStatusMessage({
|
|
2498
|
+
itemToString: this.props.itemToString,
|
|
2499
|
+
previousResultCount: this.previousResultCount,
|
|
2500
|
+
resultCount,
|
|
2501
|
+
highlightedItem: item,
|
|
2502
|
+
...state
|
|
2503
|
+
});
|
|
2504
|
+
this.previousResultCount = resultCount;
|
|
2505
|
+
setStatus(status, this.props.environment.document);
|
|
2534
2506
|
}, 200);
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
var _state = _this.getState({
|
|
2507
|
+
// fancy destructuring + defaults + aliases
|
|
2508
|
+
// this basically says each value of state should either be set to
|
|
2509
|
+
// the initial value or the default value if the initial value is not provided
|
|
2510
|
+
const {
|
|
2511
|
+
defaultHighlightedIndex,
|
|
2512
|
+
initialHighlightedIndex: _highlightedIndex = defaultHighlightedIndex,
|
|
2513
|
+
defaultIsOpen,
|
|
2514
|
+
initialIsOpen: _isOpen = defaultIsOpen,
|
|
2515
|
+
initialInputValue: _inputValue = '',
|
|
2516
|
+
initialSelectedItem: _selectedItem = null
|
|
2517
|
+
} = this.props;
|
|
2518
|
+
|
|
2519
|
+
const _state = this.getState({
|
|
2549
2520
|
highlightedIndex: _highlightedIndex,
|
|
2550
2521
|
isOpen: _isOpen,
|
|
2551
2522
|
inputValue: _inputValue,
|
|
2552
2523
|
selectedItem: _selectedItem
|
|
2553
2524
|
});
|
|
2554
2525
|
|
|
2555
|
-
if (_state.selectedItem != null &&
|
|
2556
|
-
_state.inputValue =
|
|
2526
|
+
if (_state.selectedItem != null && this.props.initialInputValue === undefined) {
|
|
2527
|
+
_state.inputValue = this.props.itemToString(_state.selectedItem);
|
|
2557
2528
|
}
|
|
2558
2529
|
|
|
2559
|
-
|
|
2560
|
-
return _this;
|
|
2530
|
+
this.state = _state;
|
|
2561
2531
|
}
|
|
2562
2532
|
|
|
2563
|
-
var _proto = Downshift.prototype;
|
|
2564
|
-
|
|
2565
2533
|
/**
|
|
2566
2534
|
* Clear all running timeouts
|
|
2567
2535
|
*/
|
|
2568
|
-
|
|
2569
|
-
this.timeoutIds.forEach(
|
|
2536
|
+
internalClearTimeouts() {
|
|
2537
|
+
this.timeoutIds.forEach(id => {
|
|
2570
2538
|
clearTimeout(id);
|
|
2571
2539
|
});
|
|
2572
2540
|
this.timeoutIds = [];
|
|
@@ -2580,22 +2548,22 @@
|
|
|
2580
2548
|
* @param {Object} stateToMerge defaults to this.state
|
|
2581
2549
|
* @return {Object} the state
|
|
2582
2550
|
*/
|
|
2583
|
-
;
|
|
2584
2551
|
|
|
2585
|
-
|
|
2552
|
+
|
|
2553
|
+
getState(stateToMerge) {
|
|
2586
2554
|
if (stateToMerge === void 0) {
|
|
2587
2555
|
stateToMerge = this.state;
|
|
2588
2556
|
}
|
|
2589
2557
|
|
|
2590
2558
|
return getState(stateToMerge, this.props);
|
|
2591
|
-
}
|
|
2559
|
+
}
|
|
2592
2560
|
|
|
2593
|
-
|
|
2561
|
+
getItemCount() {
|
|
2594
2562
|
// things read better this way. They're in priority order:
|
|
2595
2563
|
// 1. `this.itemCount`
|
|
2596
2564
|
// 2. `this.props.itemCount`
|
|
2597
2565
|
// 3. `this.items.length`
|
|
2598
|
-
|
|
2566
|
+
let itemCount = this.items.length;
|
|
2599
2567
|
|
|
2600
2568
|
if (this.itemCount != null) {
|
|
2601
2569
|
itemCount = this.itemCount;
|
|
@@ -2604,102 +2572,102 @@
|
|
|
2604
2572
|
}
|
|
2605
2573
|
|
|
2606
2574
|
return itemCount;
|
|
2607
|
-
}
|
|
2575
|
+
}
|
|
2608
2576
|
|
|
2609
|
-
|
|
2577
|
+
getItemNodeFromIndex(index) {
|
|
2610
2578
|
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
2611
|
-
}
|
|
2579
|
+
}
|
|
2612
2580
|
|
|
2613
|
-
|
|
2581
|
+
scrollHighlightedItemIntoView() {
|
|
2614
2582
|
/* istanbul ignore else (react-native) */
|
|
2615
2583
|
{
|
|
2616
|
-
|
|
2584
|
+
const node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
2617
2585
|
this.props.scrollIntoView(node, this._menuNode);
|
|
2618
2586
|
}
|
|
2619
|
-
}
|
|
2620
|
-
|
|
2621
|
-
_proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
|
2622
|
-
var _this6 = this;
|
|
2623
|
-
|
|
2624
|
-
var itemCount = this.getItemCount();
|
|
2587
|
+
}
|
|
2625
2588
|
|
|
2626
|
-
|
|
2627
|
-
|
|
2589
|
+
moveHighlightedIndex(amount, otherStateToSet) {
|
|
2590
|
+
const itemCount = this.getItemCount();
|
|
2591
|
+
const {
|
|
2592
|
+
highlightedIndex
|
|
2593
|
+
} = this.getState();
|
|
2628
2594
|
|
|
2629
2595
|
if (itemCount > 0) {
|
|
2630
|
-
|
|
2631
|
-
return _this6.getItemNodeFromIndex(index);
|
|
2632
|
-
});
|
|
2596
|
+
const nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, index => this.getItemNodeFromIndex(index));
|
|
2633
2597
|
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
2634
2598
|
}
|
|
2635
|
-
}
|
|
2599
|
+
}
|
|
2636
2600
|
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2601
|
+
getStateAndHelpers() {
|
|
2602
|
+
const {
|
|
2603
|
+
highlightedIndex,
|
|
2604
|
+
inputValue,
|
|
2605
|
+
selectedItem,
|
|
2606
|
+
isOpen
|
|
2607
|
+
} = this.getState();
|
|
2608
|
+
const {
|
|
2609
|
+
itemToString
|
|
2610
|
+
} = this.props;
|
|
2611
|
+
const {
|
|
2612
|
+
id
|
|
2613
|
+
} = this;
|
|
2614
|
+
const {
|
|
2615
|
+
getRootProps,
|
|
2616
|
+
getToggleButtonProps,
|
|
2617
|
+
getLabelProps,
|
|
2618
|
+
getMenuProps,
|
|
2619
|
+
getInputProps,
|
|
2620
|
+
getItemProps,
|
|
2621
|
+
openMenu,
|
|
2622
|
+
closeMenu,
|
|
2623
|
+
toggleMenu,
|
|
2624
|
+
selectItem,
|
|
2625
|
+
selectItemAtIndex,
|
|
2626
|
+
selectHighlightedItem,
|
|
2627
|
+
setHighlightedIndex,
|
|
2628
|
+
clearSelection,
|
|
2629
|
+
clearItems,
|
|
2630
|
+
reset,
|
|
2631
|
+
setItemCount,
|
|
2632
|
+
unsetItemCount,
|
|
2633
|
+
internalSetState: setState
|
|
2634
|
+
} = this;
|
|
2665
2635
|
return {
|
|
2666
2636
|
// prop getters
|
|
2667
|
-
getRootProps
|
|
2668
|
-
getToggleButtonProps
|
|
2669
|
-
getLabelProps
|
|
2670
|
-
getMenuProps
|
|
2671
|
-
getInputProps
|
|
2672
|
-
getItemProps
|
|
2637
|
+
getRootProps,
|
|
2638
|
+
getToggleButtonProps,
|
|
2639
|
+
getLabelProps,
|
|
2640
|
+
getMenuProps,
|
|
2641
|
+
getInputProps,
|
|
2642
|
+
getItemProps,
|
|
2673
2643
|
// actions
|
|
2674
|
-
reset
|
|
2675
|
-
openMenu
|
|
2676
|
-
closeMenu
|
|
2677
|
-
toggleMenu
|
|
2678
|
-
selectItem
|
|
2679
|
-
selectItemAtIndex
|
|
2680
|
-
selectHighlightedItem
|
|
2681
|
-
setHighlightedIndex
|
|
2682
|
-
clearSelection
|
|
2683
|
-
clearItems
|
|
2684
|
-
setItemCount
|
|
2685
|
-
unsetItemCount
|
|
2686
|
-
setState
|
|
2644
|
+
reset,
|
|
2645
|
+
openMenu,
|
|
2646
|
+
closeMenu,
|
|
2647
|
+
toggleMenu,
|
|
2648
|
+
selectItem,
|
|
2649
|
+
selectItemAtIndex,
|
|
2650
|
+
selectHighlightedItem,
|
|
2651
|
+
setHighlightedIndex,
|
|
2652
|
+
clearSelection,
|
|
2653
|
+
clearItems,
|
|
2654
|
+
setItemCount,
|
|
2655
|
+
unsetItemCount,
|
|
2656
|
+
setState,
|
|
2687
2657
|
// props
|
|
2688
|
-
itemToString
|
|
2658
|
+
itemToString,
|
|
2689
2659
|
// derived
|
|
2690
|
-
id
|
|
2660
|
+
id,
|
|
2691
2661
|
// state
|
|
2692
|
-
highlightedIndex
|
|
2693
|
-
inputValue
|
|
2694
|
-
isOpen
|
|
2695
|
-
selectedItem
|
|
2662
|
+
highlightedIndex,
|
|
2663
|
+
inputValue,
|
|
2664
|
+
isOpen,
|
|
2665
|
+
selectedItem
|
|
2696
2666
|
};
|
|
2697
2667
|
} //////////////////////////// ROOT
|
|
2698
|
-
;
|
|
2699
2668
|
|
|
2700
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
2701
|
-
var _this7 = this;
|
|
2702
2669
|
|
|
2670
|
+
componentDidMount() {
|
|
2703
2671
|
/* istanbul ignore if (react-native) */
|
|
2704
2672
|
if (this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
2705
2673
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
@@ -2713,22 +2681,20 @@
|
|
|
2713
2681
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
2714
2682
|
// this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
|
|
2715
2683
|
// trigger hiding the menu.
|
|
2716
|
-
|
|
2717
|
-
|
|
2684
|
+
const onMouseDown = () => {
|
|
2685
|
+
this.isMouseDown = true;
|
|
2718
2686
|
};
|
|
2719
2687
|
|
|
2720
|
-
|
|
2721
|
-
|
|
2688
|
+
const onMouseUp = event => {
|
|
2689
|
+
this.isMouseDown = false; // if the target element or the activeElement is within a downshift node
|
|
2722
2690
|
// then we don't want to reset downshift
|
|
2723
2691
|
|
|
2724
|
-
|
|
2692
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment);
|
|
2725
2693
|
|
|
2726
|
-
if (!contextWithinDownshift &&
|
|
2727
|
-
|
|
2694
|
+
if (!contextWithinDownshift && this.getState().isOpen) {
|
|
2695
|
+
this.reset({
|
|
2728
2696
|
type: mouseUp
|
|
2729
|
-
},
|
|
2730
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
2731
|
-
});
|
|
2697
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
2732
2698
|
}
|
|
2733
2699
|
}; // Touching an element in iOS gives focus and hover states, but touching out of
|
|
2734
2700
|
// the element will remove hover, and persist the focus state, resulting in the
|
|
@@ -2738,38 +2704,36 @@
|
|
|
2738
2704
|
// but not if the user is swiping
|
|
2739
2705
|
|
|
2740
2706
|
|
|
2741
|
-
|
|
2742
|
-
|
|
2707
|
+
const onTouchStart = () => {
|
|
2708
|
+
this.isTouchMove = false;
|
|
2743
2709
|
};
|
|
2744
2710
|
|
|
2745
|
-
|
|
2746
|
-
|
|
2711
|
+
const onTouchMove = () => {
|
|
2712
|
+
this.isTouchMove = true;
|
|
2747
2713
|
};
|
|
2748
2714
|
|
|
2749
|
-
|
|
2750
|
-
|
|
2715
|
+
const onTouchEnd = event => {
|
|
2716
|
+
const contextWithinDownshift = targetWithinDownshift(event.target, [this._rootNode, this._menuNode], this.props.environment, false);
|
|
2751
2717
|
|
|
2752
|
-
if (!
|
|
2753
|
-
|
|
2718
|
+
if (!this.isTouchMove && !contextWithinDownshift && this.getState().isOpen) {
|
|
2719
|
+
this.reset({
|
|
2754
2720
|
type: touchEnd
|
|
2755
|
-
},
|
|
2756
|
-
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
2757
|
-
});
|
|
2721
|
+
}, () => this.props.onOuterClick(this.getStateAndHelpers()));
|
|
2758
2722
|
}
|
|
2759
2723
|
};
|
|
2760
2724
|
|
|
2761
|
-
|
|
2725
|
+
const {
|
|
2726
|
+
environment
|
|
2727
|
+
} = this.props;
|
|
2762
2728
|
environment.addEventListener('mousedown', onMouseDown);
|
|
2763
2729
|
environment.addEventListener('mouseup', onMouseUp);
|
|
2764
2730
|
environment.addEventListener('touchstart', onTouchStart);
|
|
2765
2731
|
environment.addEventListener('touchmove', onTouchMove);
|
|
2766
2732
|
environment.addEventListener('touchend', onTouchEnd);
|
|
2767
2733
|
|
|
2768
|
-
this.cleanup =
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
_this7.updateStatus.cancel();
|
|
2772
|
-
|
|
2734
|
+
this.cleanup = () => {
|
|
2735
|
+
this.internalClearTimeouts();
|
|
2736
|
+
this.updateStatus.cancel();
|
|
2773
2737
|
environment.removeEventListener('mousedown', onMouseDown);
|
|
2774
2738
|
environment.removeEventListener('mouseup', onMouseUp);
|
|
2775
2739
|
environment.removeEventListener('touchstart', onTouchStart);
|
|
@@ -2777,21 +2741,21 @@
|
|
|
2777
2741
|
environment.removeEventListener('touchend', onTouchEnd);
|
|
2778
2742
|
};
|
|
2779
2743
|
}
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
_proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
|
2783
|
-
var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
|
2784
|
-
currentHighlightedIndex = _ref10.highlightedIndex;
|
|
2785
|
-
|
|
2786
|
-
var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
|
2787
|
-
prevHighlightedIndex = _ref11.highlightedIndex;
|
|
2744
|
+
}
|
|
2788
2745
|
|
|
2789
|
-
|
|
2790
|
-
|
|
2746
|
+
shouldScroll(prevState, prevProps) {
|
|
2747
|
+
const {
|
|
2748
|
+
highlightedIndex: currentHighlightedIndex
|
|
2749
|
+
} = this.props.highlightedIndex === undefined ? this.getState() : this.props;
|
|
2750
|
+
const {
|
|
2751
|
+
highlightedIndex: prevHighlightedIndex
|
|
2752
|
+
} = prevProps.highlightedIndex === undefined ? prevState : prevProps;
|
|
2753
|
+
const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
2754
|
+
const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
2791
2755
|
return scrollWhenOpen || scrollWhenNavigating;
|
|
2792
|
-
}
|
|
2756
|
+
}
|
|
2793
2757
|
|
|
2794
|
-
|
|
2758
|
+
componentDidUpdate(prevProps, prevState) {
|
|
2795
2759
|
{
|
|
2796
2760
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
2797
2761
|
/* istanbul ignore if (react-native) */
|
|
@@ -2817,14 +2781,14 @@
|
|
|
2817
2781
|
{
|
|
2818
2782
|
this.updateStatus();
|
|
2819
2783
|
}
|
|
2820
|
-
}
|
|
2784
|
+
}
|
|
2821
2785
|
|
|
2822
|
-
|
|
2786
|
+
componentWillUnmount() {
|
|
2823
2787
|
this.cleanup(); // avoids memory leak
|
|
2824
|
-
}
|
|
2788
|
+
}
|
|
2825
2789
|
|
|
2826
|
-
|
|
2827
|
-
|
|
2790
|
+
render() {
|
|
2791
|
+
const children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
|
|
2828
2792
|
// we clear this out each render and it will be populated again as
|
|
2829
2793
|
// getItemProps is called.
|
|
2830
2794
|
|
|
@@ -2844,7 +2808,7 @@
|
|
|
2844
2808
|
this.getLabelProps.called = false; // and something similar for getInputProps
|
|
2845
2809
|
|
|
2846
2810
|
this.getInputProps.called = false;
|
|
2847
|
-
|
|
2811
|
+
const element = unwrapArray(children(this.getStateAndHelpers()));
|
|
2848
2812
|
|
|
2849
2813
|
if (!element) {
|
|
2850
2814
|
return null;
|
|
@@ -2869,16 +2833,15 @@
|
|
|
2869
2833
|
// otherwise we can't query around the autocomplete
|
|
2870
2834
|
throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
|
|
2871
2835
|
}
|
|
2872
|
-
}
|
|
2836
|
+
}
|
|
2873
2837
|
|
|
2874
|
-
|
|
2875
|
-
}(react.Component);
|
|
2838
|
+
}
|
|
2876
2839
|
|
|
2877
2840
|
Downshift.defaultProps = {
|
|
2878
2841
|
defaultHighlightedIndex: null,
|
|
2879
2842
|
defaultIsOpen: false,
|
|
2880
2843
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
2881
|
-
itemToString:
|
|
2844
|
+
itemToString: i => {
|
|
2882
2845
|
if (i == null) {
|
|
2883
2846
|
return '';
|
|
2884
2847
|
}
|
|
@@ -2896,21 +2859,17 @@
|
|
|
2896
2859
|
onChange: noop,
|
|
2897
2860
|
onSelect: noop,
|
|
2898
2861
|
onOuterClick: noop,
|
|
2899
|
-
selectedItemChanged:
|
|
2900
|
-
return prevItem !== item;
|
|
2901
|
-
},
|
|
2862
|
+
selectedItemChanged: (prevItem, item) => prevItem !== item,
|
|
2902
2863
|
environment:
|
|
2903
2864
|
/* istanbul ignore next (ssr) */
|
|
2904
2865
|
typeof window === 'undefined' ? {} : window,
|
|
2905
|
-
stateReducer:
|
|
2906
|
-
return stateToSet;
|
|
2907
|
-
},
|
|
2866
|
+
stateReducer: (state, stateToSet) => stateToSet,
|
|
2908
2867
|
suppressRefError: false,
|
|
2909
|
-
scrollIntoView
|
|
2868
|
+
scrollIntoView
|
|
2910
2869
|
};
|
|
2911
2870
|
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
2912
2871
|
return Downshift;
|
|
2913
|
-
}();
|
|
2872
|
+
})();
|
|
2914
2873
|
|
|
2915
2874
|
Downshift.propTypes = {
|
|
2916
2875
|
children: PropTypes.func,
|
|
@@ -2960,8 +2919,10 @@
|
|
|
2960
2919
|
} ;
|
|
2961
2920
|
var Downshift$1 = Downshift;
|
|
2962
2921
|
|
|
2963
|
-
function validateGetMenuPropsCalledCorrectly(node,
|
|
2964
|
-
|
|
2922
|
+
function validateGetMenuPropsCalledCorrectly(node, _ref3) {
|
|
2923
|
+
let {
|
|
2924
|
+
refKey
|
|
2925
|
+
} = _ref3;
|
|
2965
2926
|
|
|
2966
2927
|
if (!node) {
|
|
2967
2928
|
// eslint-disable-next-line no-console
|
|
@@ -2969,10 +2930,12 @@
|
|
|
2969
2930
|
}
|
|
2970
2931
|
}
|
|
2971
2932
|
|
|
2972
|
-
function validateGetRootPropsCalledCorrectly(element,
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2933
|
+
function validateGetRootPropsCalledCorrectly(element, _ref4) {
|
|
2934
|
+
let {
|
|
2935
|
+
refKey
|
|
2936
|
+
} = _ref4;
|
|
2937
|
+
const refKeySpecified = refKey !== 'ref';
|
|
2938
|
+
const isComposite = !isDOMElement(element);
|
|
2976
2939
|
|
|
2977
2940
|
if (isComposite && !refKeySpecified && !reactIs.exports.isForwardRef(element)) {
|
|
2978
2941
|
// eslint-disable-next-line no-console
|
|
@@ -2988,8 +2951,7 @@
|
|
|
2988
2951
|
}
|
|
2989
2952
|
}
|
|
2990
2953
|
|
|
2991
|
-
|
|
2992
|
-
var dropdownDefaultStateValues = {
|
|
2954
|
+
const dropdownDefaultStateValues = {
|
|
2993
2955
|
highlightedIndex: -1,
|
|
2994
2956
|
isOpen: false,
|
|
2995
2957
|
selectedItem: null,
|
|
@@ -2997,10 +2959,12 @@
|
|
|
2997
2959
|
};
|
|
2998
2960
|
|
|
2999
2961
|
function callOnChangeProps(action, state, newState) {
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
2962
|
+
const {
|
|
2963
|
+
props,
|
|
2964
|
+
type
|
|
2965
|
+
} = action;
|
|
2966
|
+
const changes = {};
|
|
2967
|
+
Object.keys(state).forEach(key => {
|
|
3004
2968
|
invokeOnChangeHandler(key, action, state, newState);
|
|
3005
2969
|
|
|
3006
2970
|
if (newState[key] !== state[key]) {
|
|
@@ -3009,21 +2973,25 @@
|
|
|
3009
2973
|
});
|
|
3010
2974
|
|
|
3011
2975
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
3012
|
-
props.onStateChange(
|
|
3013
|
-
type
|
|
3014
|
-
|
|
2976
|
+
props.onStateChange({
|
|
2977
|
+
type,
|
|
2978
|
+
...changes
|
|
2979
|
+
});
|
|
3015
2980
|
}
|
|
3016
2981
|
}
|
|
3017
2982
|
|
|
3018
2983
|
function invokeOnChangeHandler(key, action, state, newState) {
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
2984
|
+
const {
|
|
2985
|
+
props,
|
|
2986
|
+
type
|
|
2987
|
+
} = action;
|
|
2988
|
+
const handler = "on" + capitalizeString(key) + "Change";
|
|
3022
2989
|
|
|
3023
2990
|
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
3024
|
-
props[handler](
|
|
3025
|
-
type
|
|
3026
|
-
|
|
2991
|
+
props[handler]({
|
|
2992
|
+
type,
|
|
2993
|
+
...newState
|
|
2994
|
+
});
|
|
3027
2995
|
}
|
|
3028
2996
|
}
|
|
3029
2997
|
/**
|
|
@@ -3047,8 +3015,10 @@
|
|
|
3047
3015
|
|
|
3048
3016
|
|
|
3049
3017
|
function getA11ySelectionMessage(selectionParameters) {
|
|
3050
|
-
|
|
3051
|
-
|
|
3018
|
+
const {
|
|
3019
|
+
selectedItem,
|
|
3020
|
+
itemToString: itemToStringLocal
|
|
3021
|
+
} = selectionParameters;
|
|
3052
3022
|
return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
|
|
3053
3023
|
}
|
|
3054
3024
|
/**
|
|
@@ -3056,26 +3026,25 @@
|
|
|
3056
3026
|
*/
|
|
3057
3027
|
|
|
3058
3028
|
|
|
3059
|
-
|
|
3029
|
+
const updateA11yStatus = debounce((getA11yMessage, document) => {
|
|
3060
3030
|
setStatus(getA11yMessage(), document);
|
|
3061
3031
|
}, 200); // istanbul ignore next
|
|
3062
3032
|
|
|
3063
|
-
|
|
3033
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
|
|
3064
3034
|
|
|
3065
3035
|
function useElementIds(_ref) {
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3036
|
+
let {
|
|
3037
|
+
id = "downshift-" + generateId(),
|
|
3038
|
+
labelId,
|
|
3039
|
+
menuId,
|
|
3040
|
+
getItemId,
|
|
3041
|
+
toggleButtonId,
|
|
3042
|
+
inputId
|
|
3043
|
+
} = _ref;
|
|
3044
|
+
const elementIdsRef = react.useRef({
|
|
3074
3045
|
labelId: labelId || id + "-label",
|
|
3075
3046
|
menuId: menuId || id + "-menu",
|
|
3076
|
-
getItemId: getItemId ||
|
|
3077
|
-
return id + "-item-" + index;
|
|
3078
|
-
},
|
|
3047
|
+
getItemId: getItemId || (index => id + "-item-" + index),
|
|
3079
3048
|
toggleButtonId: toggleButtonId || id + "-toggle-button",
|
|
3080
3049
|
inputId: inputId || id + "-input"
|
|
3081
3050
|
});
|
|
@@ -3107,7 +3076,7 @@
|
|
|
3107
3076
|
}
|
|
3108
3077
|
|
|
3109
3078
|
function useLatestRef(val) {
|
|
3110
|
-
|
|
3079
|
+
const ref = react.useRef(val); // technically this is not "concurrent mode safe" because we're manipulating
|
|
3111
3080
|
// the value during render (so it's not idempotent). However, the places this
|
|
3112
3081
|
// hook is used is to support memoizing callbacks which will be called
|
|
3113
3082
|
// *during* render, so we need the latest values *during* render.
|
|
@@ -3129,30 +3098,25 @@
|
|
|
3129
3098
|
|
|
3130
3099
|
|
|
3131
3100
|
function useEnhancedReducer(reducer, initialState, props) {
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3101
|
+
const prevStateRef = react.useRef();
|
|
3102
|
+
const actionRef = react.useRef();
|
|
3103
|
+
const enhancedReducer = react.useCallback((state, action) => {
|
|
3135
3104
|
actionRef.current = action;
|
|
3136
3105
|
state = getState(state, action.props);
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
changes
|
|
3140
|
-
})
|
|
3106
|
+
const changes = reducer(state, action);
|
|
3107
|
+
const newState = action.props.stateReducer(state, { ...action,
|
|
3108
|
+
changes
|
|
3109
|
+
});
|
|
3141
3110
|
return newState;
|
|
3142
3111
|
}, [reducer]);
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
props: propsRef.current
|
|
3152
|
-
}, action));
|
|
3153
|
-
}, [propsRef]);
|
|
3154
|
-
var action = actionRef.current;
|
|
3155
|
-
react.useEffect(function () {
|
|
3112
|
+
const [state, dispatch] = react.useReducer(enhancedReducer, initialState);
|
|
3113
|
+
const propsRef = useLatestRef(props);
|
|
3114
|
+
const dispatchWithProps = react.useCallback(action => dispatch({
|
|
3115
|
+
props: propsRef.current,
|
|
3116
|
+
...action
|
|
3117
|
+
}), [propsRef]);
|
|
3118
|
+
const action = actionRef.current;
|
|
3119
|
+
react.useEffect(() => {
|
|
3156
3120
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
3157
3121
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
3158
3122
|
}
|
|
@@ -3173,18 +3137,15 @@
|
|
|
3173
3137
|
|
|
3174
3138
|
|
|
3175
3139
|
function useControlledReducer$1(reducer, initialState, props) {
|
|
3176
|
-
|
|
3177
|
-
state = _useEnhancedReducer[0],
|
|
3178
|
-
dispatch = _useEnhancedReducer[1];
|
|
3179
|
-
|
|
3140
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props);
|
|
3180
3141
|
return [getState(state, props), dispatch];
|
|
3181
3142
|
}
|
|
3182
3143
|
|
|
3183
|
-
|
|
3184
|
-
itemToString
|
|
3185
|
-
stateReducer
|
|
3186
|
-
getA11ySelectionMessage
|
|
3187
|
-
scrollIntoView
|
|
3144
|
+
const defaultProps$3 = {
|
|
3145
|
+
itemToString,
|
|
3146
|
+
stateReducer,
|
|
3147
|
+
getA11ySelectionMessage,
|
|
3148
|
+
scrollIntoView,
|
|
3188
3149
|
circularNavigation: false,
|
|
3189
3150
|
environment:
|
|
3190
3151
|
/* istanbul ignore next (ssr) */
|
|
@@ -3196,7 +3157,7 @@
|
|
|
3196
3157
|
defaultStateValues = dropdownDefaultStateValues;
|
|
3197
3158
|
}
|
|
3198
3159
|
|
|
3199
|
-
|
|
3160
|
+
const defaultPropKey = "default" + capitalizeString(propKey);
|
|
3200
3161
|
|
|
3201
3162
|
if (defaultPropKey in props) {
|
|
3202
3163
|
return props[defaultPropKey];
|
|
@@ -3214,7 +3175,7 @@
|
|
|
3214
3175
|
return props[propKey];
|
|
3215
3176
|
}
|
|
3216
3177
|
|
|
3217
|
-
|
|
3178
|
+
const initialPropKey = "initial" + capitalizeString(propKey);
|
|
3218
3179
|
|
|
3219
3180
|
if (initialPropKey in props) {
|
|
3220
3181
|
return props[initialPropKey];
|
|
@@ -3224,24 +3185,28 @@
|
|
|
3224
3185
|
}
|
|
3225
3186
|
|
|
3226
3187
|
function getInitialState$2(props) {
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3188
|
+
const selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
3189
|
+
const isOpen = getInitialValue$1(props, 'isOpen');
|
|
3190
|
+
const highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
3191
|
+
const inputValue = getInitialValue$1(props, 'inputValue');
|
|
3231
3192
|
return {
|
|
3232
3193
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
3233
|
-
isOpen
|
|
3234
|
-
selectedItem
|
|
3235
|
-
inputValue
|
|
3194
|
+
isOpen,
|
|
3195
|
+
selectedItem,
|
|
3196
|
+
inputValue
|
|
3236
3197
|
};
|
|
3237
3198
|
}
|
|
3238
3199
|
|
|
3239
3200
|
function getHighlightedIndexOnOpen(props, state, offset, getItemNodeFromIndex) {
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3201
|
+
const {
|
|
3202
|
+
items,
|
|
3203
|
+
initialHighlightedIndex,
|
|
3204
|
+
defaultHighlightedIndex
|
|
3205
|
+
} = props;
|
|
3206
|
+
const {
|
|
3207
|
+
selectedItem,
|
|
3208
|
+
highlightedIndex
|
|
3209
|
+
} = state;
|
|
3245
3210
|
|
|
3246
3211
|
if (items.length === 0) {
|
|
3247
3212
|
return -1;
|
|
@@ -3282,39 +3247,35 @@
|
|
|
3282
3247
|
|
|
3283
3248
|
|
|
3284
3249
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
3285
|
-
|
|
3250
|
+
const mouseAndTouchTrackersRef = react.useRef({
|
|
3286
3251
|
isMouseDown: false,
|
|
3287
3252
|
isTouchMove: false
|
|
3288
3253
|
});
|
|
3289
|
-
react.useEffect(
|
|
3254
|
+
react.useEffect(() => {
|
|
3290
3255
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
3291
3256
|
// as in downshift.js.
|
|
3292
|
-
|
|
3257
|
+
const onMouseDown = () => {
|
|
3293
3258
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
3294
3259
|
};
|
|
3295
3260
|
|
|
3296
|
-
|
|
3261
|
+
const onMouseUp = event => {
|
|
3297
3262
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
3298
3263
|
|
|
3299
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
3300
|
-
return ref.current;
|
|
3301
|
-
}), environment)) {
|
|
3264
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment)) {
|
|
3302
3265
|
handleBlur();
|
|
3303
3266
|
}
|
|
3304
3267
|
};
|
|
3305
3268
|
|
|
3306
|
-
|
|
3269
|
+
const onTouchStart = () => {
|
|
3307
3270
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
3308
3271
|
};
|
|
3309
3272
|
|
|
3310
|
-
|
|
3273
|
+
const onTouchMove = () => {
|
|
3311
3274
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
3312
3275
|
};
|
|
3313
3276
|
|
|
3314
|
-
|
|
3315
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
3316
|
-
return ref.current;
|
|
3317
|
-
}), environment, false)) {
|
|
3277
|
+
const onTouchEnd = event => {
|
|
3278
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(ref => ref.current), environment, false)) {
|
|
3318
3279
|
handleBlur();
|
|
3319
3280
|
}
|
|
3320
3281
|
};
|
|
@@ -3338,9 +3299,7 @@
|
|
|
3338
3299
|
// eslint-disable-next-line import/no-mutable-exports
|
|
3339
3300
|
|
|
3340
3301
|
|
|
3341
|
-
|
|
3342
|
-
return noop;
|
|
3343
|
-
};
|
|
3302
|
+
let useGetterPropsCalledChecker = () => noop;
|
|
3344
3303
|
/**
|
|
3345
3304
|
* Custom hook that checks if getter props are called correctly.
|
|
3346
3305
|
*
|
|
@@ -3352,20 +3311,20 @@
|
|
|
3352
3311
|
|
|
3353
3312
|
|
|
3354
3313
|
{
|
|
3355
|
-
useGetterPropsCalledChecker = function
|
|
3356
|
-
|
|
3314
|
+
useGetterPropsCalledChecker = function () {
|
|
3315
|
+
const isInitialMountRef = react.useRef(true);
|
|
3357
3316
|
|
|
3358
3317
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3359
3318
|
propKeys[_key] = arguments[_key];
|
|
3360
3319
|
}
|
|
3361
3320
|
|
|
3362
|
-
|
|
3321
|
+
const getterPropsCalledRef = react.useRef(propKeys.reduce((acc, propKey) => {
|
|
3363
3322
|
acc[propKey] = {};
|
|
3364
3323
|
return acc;
|
|
3365
3324
|
}, {}));
|
|
3366
|
-
react.useEffect(
|
|
3367
|
-
Object.keys(getterPropsCalledRef.current).forEach(
|
|
3368
|
-
|
|
3325
|
+
react.useEffect(() => {
|
|
3326
|
+
Object.keys(getterPropsCalledRef.current).forEach(propKey => {
|
|
3327
|
+
const propCallInfo = getterPropsCalledRef.current[propKey];
|
|
3369
3328
|
|
|
3370
3329
|
if (isInitialMountRef.current) {
|
|
3371
3330
|
if (!Object.keys(propCallInfo).length) {
|
|
@@ -3375,9 +3334,11 @@
|
|
|
3375
3334
|
}
|
|
3376
3335
|
}
|
|
3377
3336
|
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3337
|
+
const {
|
|
3338
|
+
suppressRefError,
|
|
3339
|
+
refKey,
|
|
3340
|
+
elementRef
|
|
3341
|
+
} = propCallInfo;
|
|
3381
3342
|
|
|
3382
3343
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
3383
3344
|
// eslint-disable-next-line no-console
|
|
@@ -3386,11 +3347,11 @@
|
|
|
3386
3347
|
});
|
|
3387
3348
|
isInitialMountRef.current = false;
|
|
3388
3349
|
});
|
|
3389
|
-
|
|
3350
|
+
const setGetterPropCallInfo = react.useCallback((propKey, suppressRefError, refKey, elementRef) => {
|
|
3390
3351
|
getterPropsCalledRef.current[propKey] = {
|
|
3391
|
-
suppressRefError
|
|
3392
|
-
refKey
|
|
3393
|
-
elementRef
|
|
3352
|
+
suppressRefError,
|
|
3353
|
+
refKey,
|
|
3354
|
+
elementRef
|
|
3394
3355
|
};
|
|
3395
3356
|
}, []);
|
|
3396
3357
|
return setGetterPropCallInfo;
|
|
@@ -3398,39 +3359,41 @@
|
|
|
3398
3359
|
}
|
|
3399
3360
|
|
|
3400
3361
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3362
|
+
let {
|
|
3363
|
+
isInitialMount,
|
|
3364
|
+
highlightedIndex,
|
|
3365
|
+
items,
|
|
3366
|
+
environment,
|
|
3367
|
+
...rest
|
|
3368
|
+
} = _ref2;
|
|
3407
3369
|
// Sets a11y status message on changes in state.
|
|
3408
|
-
react.useEffect(
|
|
3370
|
+
react.useEffect(() => {
|
|
3409
3371
|
if (isInitialMount || false) {
|
|
3410
3372
|
return;
|
|
3411
3373
|
}
|
|
3412
3374
|
|
|
3413
|
-
updateA11yStatus(
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
}, environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3375
|
+
updateA11yStatus(() => getA11yMessage({
|
|
3376
|
+
highlightedIndex,
|
|
3377
|
+
highlightedItem: items[highlightedIndex],
|
|
3378
|
+
resultCount: items.length,
|
|
3379
|
+
...rest
|
|
3380
|
+
}), environment.document); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3420
3381
|
}, dependencyArray);
|
|
3421
3382
|
}
|
|
3422
3383
|
|
|
3423
3384
|
function useScrollIntoView(_ref3) {
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3385
|
+
let {
|
|
3386
|
+
highlightedIndex,
|
|
3387
|
+
isOpen,
|
|
3388
|
+
itemRefs,
|
|
3389
|
+
getItemNodeFromIndex,
|
|
3390
|
+
menuElement,
|
|
3391
|
+
scrollIntoView: scrollIntoViewProp
|
|
3392
|
+
} = _ref3;
|
|
3430
3393
|
// used not to scroll on highlight by mouse.
|
|
3431
|
-
|
|
3394
|
+
const shouldScrollRef = react.useRef(true); // Scroll on highlighted item if change comes from keyboard.
|
|
3432
3395
|
|
|
3433
|
-
useIsomorphicLayoutEffect(
|
|
3396
|
+
useIsomorphicLayoutEffect(() => {
|
|
3434
3397
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
3435
3398
|
return;
|
|
3436
3399
|
}
|
|
@@ -3446,17 +3409,19 @@
|
|
|
3446
3409
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
3447
3410
|
|
|
3448
3411
|
|
|
3449
|
-
|
|
3412
|
+
let useControlPropsValidator = noop;
|
|
3450
3413
|
/* istanbul ignore next */
|
|
3451
3414
|
|
|
3452
3415
|
{
|
|
3453
|
-
useControlPropsValidator =
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3416
|
+
useControlPropsValidator = _ref4 => {
|
|
3417
|
+
let {
|
|
3418
|
+
isInitialMount,
|
|
3419
|
+
props,
|
|
3420
|
+
state
|
|
3421
|
+
} = _ref4;
|
|
3457
3422
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
3458
|
-
|
|
3459
|
-
react.useEffect(
|
|
3423
|
+
const prevPropsRef = react.useRef(props);
|
|
3424
|
+
react.useEffect(() => {
|
|
3460
3425
|
if (isInitialMount) {
|
|
3461
3426
|
return;
|
|
3462
3427
|
}
|
|
@@ -3470,9 +3435,11 @@
|
|
|
3470
3435
|
/* eslint-disable complexity */
|
|
3471
3436
|
|
|
3472
3437
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3438
|
+
const {
|
|
3439
|
+
type,
|
|
3440
|
+
props
|
|
3441
|
+
} = action;
|
|
3442
|
+
let changes;
|
|
3476
3443
|
|
|
3477
3444
|
switch (type) {
|
|
3478
3445
|
case stateChangeTypes.ItemMouseMove:
|
|
@@ -3533,11 +3500,13 @@
|
|
|
3533
3500
|
throw new Error('Reducer called without proper action type.');
|
|
3534
3501
|
}
|
|
3535
3502
|
|
|
3536
|
-
return
|
|
3503
|
+
return { ...state,
|
|
3504
|
+
...changes
|
|
3505
|
+
};
|
|
3537
3506
|
}
|
|
3538
3507
|
/* eslint-enable complexity */
|
|
3539
3508
|
|
|
3540
|
-
|
|
3509
|
+
/******************************************************************************
|
|
3541
3510
|
Copyright (c) Microsoft Corporation.
|
|
3542
3511
|
|
|
3543
3512
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -3633,7 +3602,7 @@
|
|
|
3633
3602
|
return 'No results are available.';
|
|
3634
3603
|
}
|
|
3635
3604
|
if (resultCount !== previousResultCount) {
|
|
3636
|
-
return resultCount
|
|
3605
|
+
return "".concat(resultCount, " result").concat(resultCount === 1 ? ' is' : 's are', " available, use up and down arrow keys to navigate. Press Enter or Space Bar keys to select.");
|
|
3637
3606
|
}
|
|
3638
3607
|
return '';
|
|
3639
3608
|
}
|
|
@@ -3647,29 +3616,29 @@
|
|
|
3647
3616
|
};
|
|
3648
3617
|
}
|
|
3649
3618
|
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3619
|
+
const MenuKeyDownArrowDown = '__menu_keydown_arrow_down__' ;
|
|
3620
|
+
const MenuKeyDownArrowUp = '__menu_keydown_arrow_up__' ;
|
|
3621
|
+
const MenuKeyDownEscape = '__menu_keydown_escape__' ;
|
|
3622
|
+
const MenuKeyDownHome = '__menu_keydown_home__' ;
|
|
3623
|
+
const MenuKeyDownEnd = '__menu_keydown_end__' ;
|
|
3624
|
+
const MenuKeyDownEnter = '__menu_keydown_enter__' ;
|
|
3625
|
+
const MenuKeyDownSpaceButton = '__menu_keydown_space_button__' ;
|
|
3626
|
+
const MenuKeyDownCharacter = '__menu_keydown_character__' ;
|
|
3627
|
+
const MenuBlur = '__menu_blur__' ;
|
|
3628
|
+
const MenuMouseLeave$1 = '__menu_mouse_leave__' ;
|
|
3629
|
+
const ItemMouseMove$1 = '__item_mouse_move__' ;
|
|
3630
|
+
const ItemClick$1 = '__item_click__' ;
|
|
3631
|
+
const ToggleButtonClick$1 = '__togglebutton_click__' ;
|
|
3632
|
+
const ToggleButtonKeyDownArrowDown = '__togglebutton_keydown_arrow_down__' ;
|
|
3633
|
+
const ToggleButtonKeyDownArrowUp = '__togglebutton_keydown_arrow_up__' ;
|
|
3634
|
+
const ToggleButtonKeyDownCharacter = '__togglebutton_keydown_character__' ;
|
|
3635
|
+
const FunctionToggleMenu$1 = '__function_toggle_menu__' ;
|
|
3636
|
+
const FunctionOpenMenu$1 = '__function_open_menu__' ;
|
|
3637
|
+
const FunctionCloseMenu$1 = '__function_close_menu__' ;
|
|
3638
|
+
const FunctionSetHighlightedIndex$1 = '__function_set_highlighted_index__' ;
|
|
3639
|
+
const FunctionSelectItem$1 = '__function_select_item__' ;
|
|
3640
|
+
const FunctionSetInputValue$1 = '__function_set_input_value__' ;
|
|
3641
|
+
const FunctionReset$2 = '__function_reset__' ;
|
|
3673
3642
|
|
|
3674
3643
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
3675
3644
|
__proto__: null,
|
|
@@ -3701,10 +3670,12 @@
|
|
|
3701
3670
|
/* eslint-disable complexity */
|
|
3702
3671
|
|
|
3703
3672
|
function downshiftSelectReducer(state, action) {
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3673
|
+
const {
|
|
3674
|
+
type,
|
|
3675
|
+
props,
|
|
3676
|
+
shiftKey
|
|
3677
|
+
} = action;
|
|
3678
|
+
let changes;
|
|
3708
3679
|
|
|
3709
3680
|
switch (type) {
|
|
3710
3681
|
case ItemClick$1:
|
|
@@ -3717,20 +3688,21 @@
|
|
|
3717
3688
|
|
|
3718
3689
|
case ToggleButtonKeyDownCharacter:
|
|
3719
3690
|
{
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3691
|
+
const lowercasedKey = action.key;
|
|
3692
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
3693
|
+
const itemIndex = getItemIndexByCharacterKey({
|
|
3723
3694
|
keysSoFar: inputValue,
|
|
3724
3695
|
highlightedIndex: state.selectedItem ? props.items.indexOf(state.selectedItem) : -1,
|
|
3725
3696
|
items: props.items,
|
|
3726
3697
|
itemToString: props.itemToString,
|
|
3727
3698
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
3728
3699
|
});
|
|
3729
|
-
changes =
|
|
3730
|
-
inputValue
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3700
|
+
changes = {
|
|
3701
|
+
inputValue,
|
|
3702
|
+
...(itemIndex >= 0 && {
|
|
3703
|
+
selectedItem: props.items[itemIndex]
|
|
3704
|
+
})
|
|
3705
|
+
};
|
|
3734
3706
|
}
|
|
3735
3707
|
break;
|
|
3736
3708
|
|
|
@@ -3750,12 +3722,13 @@
|
|
|
3750
3722
|
|
|
3751
3723
|
case MenuKeyDownEnter:
|
|
3752
3724
|
case MenuKeyDownSpaceButton:
|
|
3753
|
-
changes =
|
|
3725
|
+
changes = {
|
|
3754
3726
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3755
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3727
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
3728
|
+
...(state.highlightedIndex >= 0 && {
|
|
3729
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
3730
|
+
})
|
|
3731
|
+
};
|
|
3759
3732
|
break;
|
|
3760
3733
|
|
|
3761
3734
|
case MenuKeyDownHome:
|
|
@@ -3786,22 +3759,21 @@
|
|
|
3786
3759
|
|
|
3787
3760
|
case MenuKeyDownCharacter:
|
|
3788
3761
|
{
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
var highlightedIndex = getItemIndexByCharacterKey({
|
|
3794
|
-
keysSoFar: _inputValue,
|
|
3762
|
+
const lowercasedKey = action.key;
|
|
3763
|
+
const inputValue = "" + state.inputValue + lowercasedKey;
|
|
3764
|
+
const highlightedIndex = getItemIndexByCharacterKey({
|
|
3765
|
+
keysSoFar: inputValue,
|
|
3795
3766
|
highlightedIndex: state.highlightedIndex,
|
|
3796
3767
|
items: props.items,
|
|
3797
3768
|
itemToString: props.itemToString,
|
|
3798
3769
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
3799
3770
|
});
|
|
3800
|
-
changes =
|
|
3801
|
-
inputValue
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3771
|
+
changes = {
|
|
3772
|
+
inputValue,
|
|
3773
|
+
...(highlightedIndex >= 0 && {
|
|
3774
|
+
highlightedIndex
|
|
3775
|
+
})
|
|
3776
|
+
};
|
|
3805
3777
|
}
|
|
3806
3778
|
break;
|
|
3807
3779
|
|
|
@@ -3827,13 +3799,13 @@
|
|
|
3827
3799
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
3828
3800
|
}
|
|
3829
3801
|
|
|
3830
|
-
return
|
|
3802
|
+
return { ...state,
|
|
3803
|
+
...changes
|
|
3804
|
+
};
|
|
3831
3805
|
}
|
|
3832
3806
|
/* eslint-enable complexity */
|
|
3833
3807
|
|
|
3834
|
-
|
|
3835
|
-
_excluded2$2 = ["onClick", "onKeyDown", "refKey", "ref"],
|
|
3836
|
-
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref"];
|
|
3808
|
+
/* eslint-disable max-statements */
|
|
3837
3809
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
3838
3810
|
|
|
3839
3811
|
function useSelect(userProps) {
|
|
@@ -3843,91 +3815,92 @@
|
|
|
3843
3815
|
|
|
3844
3816
|
validatePropTypes$2(userProps, useSelect); // Props defaults and destructuring.
|
|
3845
3817
|
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3818
|
+
const props = { ...defaultProps$2,
|
|
3819
|
+
...userProps
|
|
3820
|
+
};
|
|
3821
|
+
const {
|
|
3822
|
+
items,
|
|
3823
|
+
scrollIntoView,
|
|
3824
|
+
environment,
|
|
3825
|
+
initialIsOpen,
|
|
3826
|
+
defaultIsOpen,
|
|
3827
|
+
itemToString,
|
|
3828
|
+
getA11ySelectionMessage,
|
|
3829
|
+
getA11yStatusMessage
|
|
3830
|
+
} = props; // Initial state depending on controlled props.
|
|
3831
|
+
|
|
3832
|
+
const initialState = getInitialState$2(props);
|
|
3833
|
+
const [state, dispatch] = useControlledReducer$1(downshiftSelectReducer, initialState, props);
|
|
3834
|
+
const {
|
|
3835
|
+
isOpen,
|
|
3836
|
+
highlightedIndex,
|
|
3837
|
+
selectedItem,
|
|
3838
|
+
inputValue
|
|
3839
|
+
} = state; // Element efs.
|
|
3840
|
+
|
|
3841
|
+
const toggleButtonRef = react.useRef(null);
|
|
3842
|
+
const menuRef = react.useRef(null);
|
|
3843
|
+
const itemRefs = react.useRef({}); // used not to trigger menu blur action in some scenarios.
|
|
3844
|
+
|
|
3845
|
+
const shouldBlurRef = react.useRef(true); // used to keep the inputValue clearTimeout object between renders.
|
|
3846
|
+
|
|
3847
|
+
const clearTimeoutRef = react.useRef(null); // prevent id re-generation between renders.
|
|
3848
|
+
|
|
3849
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
3850
|
+
|
|
3851
|
+
const previousResultCountRef = react.useRef();
|
|
3852
|
+
const isInitialMountRef = react.useRef(true); // utility callback to get item element.
|
|
3853
|
+
|
|
3854
|
+
const latest = useLatestRef({
|
|
3855
|
+
state,
|
|
3856
|
+
props
|
|
3884
3857
|
}); // Some utils.
|
|
3885
3858
|
|
|
3886
|
-
|
|
3887
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
3888
|
-
}, [elementIds]); // Effects.
|
|
3859
|
+
const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
3889
3860
|
// Sets a11y status message on changes in state.
|
|
3890
3861
|
|
|
3891
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
3862
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3892
3863
|
isInitialMount: isInitialMountRef.current,
|
|
3893
3864
|
previousResultCount: previousResultCountRef.current,
|
|
3894
|
-
items
|
|
3895
|
-
environment
|
|
3896
|
-
itemToString
|
|
3897
|
-
|
|
3865
|
+
items,
|
|
3866
|
+
environment,
|
|
3867
|
+
itemToString,
|
|
3868
|
+
...state
|
|
3869
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
3898
3870
|
|
|
3899
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
3871
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3900
3872
|
isInitialMount: isInitialMountRef.current,
|
|
3901
3873
|
previousResultCount: previousResultCountRef.current,
|
|
3902
|
-
items
|
|
3903
|
-
environment
|
|
3904
|
-
itemToString
|
|
3905
|
-
|
|
3874
|
+
items,
|
|
3875
|
+
environment,
|
|
3876
|
+
itemToString,
|
|
3877
|
+
...state
|
|
3878
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
3906
3879
|
|
|
3907
|
-
|
|
3880
|
+
const shouldScrollRef = useScrollIntoView({
|
|
3908
3881
|
menuElement: menuRef.current,
|
|
3909
|
-
highlightedIndex
|
|
3910
|
-
isOpen
|
|
3911
|
-
itemRefs
|
|
3912
|
-
scrollIntoView
|
|
3913
|
-
getItemNodeFromIndex
|
|
3882
|
+
highlightedIndex,
|
|
3883
|
+
isOpen,
|
|
3884
|
+
itemRefs,
|
|
3885
|
+
scrollIntoView,
|
|
3886
|
+
getItemNodeFromIndex
|
|
3914
3887
|
}); // Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
3915
3888
|
|
|
3916
|
-
react.useEffect(
|
|
3889
|
+
react.useEffect(() => {
|
|
3917
3890
|
// init the clean function here as we need access to dispatch.
|
|
3918
|
-
clearTimeoutRef.current = debounce(
|
|
3891
|
+
clearTimeoutRef.current = debounce(outerDispatch => {
|
|
3919
3892
|
outerDispatch({
|
|
3920
3893
|
type: FunctionSetInputValue$1,
|
|
3921
3894
|
inputValue: ''
|
|
3922
3895
|
});
|
|
3923
3896
|
}, 500); // Cancel any pending debounced calls on mount
|
|
3924
3897
|
|
|
3925
|
-
return
|
|
3898
|
+
return () => {
|
|
3926
3899
|
clearTimeoutRef.current.cancel();
|
|
3927
3900
|
};
|
|
3928
3901
|
}, []); // Invokes the keysSoFar callback set up above.
|
|
3929
3902
|
|
|
3930
|
-
react.useEffect(
|
|
3903
|
+
react.useEffect(() => {
|
|
3931
3904
|
if (!inputValue) {
|
|
3932
3905
|
return;
|
|
3933
3906
|
}
|
|
@@ -3936,12 +3909,12 @@
|
|
|
3936
3909
|
}, [dispatch, inputValue]);
|
|
3937
3910
|
useControlPropsValidator({
|
|
3938
3911
|
isInitialMount: isInitialMountRef.current,
|
|
3939
|
-
props
|
|
3940
|
-
state
|
|
3912
|
+
props,
|
|
3913
|
+
state
|
|
3941
3914
|
});
|
|
3942
3915
|
/* Controls the focus on the menu or the toggle button. */
|
|
3943
3916
|
|
|
3944
|
-
react.useEffect(
|
|
3917
|
+
react.useEffect(() => {
|
|
3945
3918
|
// Don't focus menu on first render.
|
|
3946
3919
|
if (isInitialMountRef.current) {
|
|
3947
3920
|
// Unless it was initialised as open.
|
|
@@ -3972,7 +3945,7 @@
|
|
|
3972
3945
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3973
3946
|
|
|
3974
3947
|
}, [isOpen]);
|
|
3975
|
-
react.useEffect(
|
|
3948
|
+
react.useEffect(() => {
|
|
3976
3949
|
if (isInitialMountRef.current) {
|
|
3977
3950
|
return;
|
|
3978
3951
|
}
|
|
@@ -3980,180 +3953,180 @@
|
|
|
3980
3953
|
previousResultCountRef.current = items.length;
|
|
3981
3954
|
}); // Add mouse/touch events to document.
|
|
3982
3955
|
|
|
3983
|
-
|
|
3956
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, () => {
|
|
3984
3957
|
dispatch({
|
|
3985
3958
|
type: MenuBlur
|
|
3986
3959
|
});
|
|
3987
3960
|
});
|
|
3988
|
-
|
|
3961
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps'); // Make initial ref false.
|
|
3989
3962
|
|
|
3990
|
-
react.useEffect(
|
|
3963
|
+
react.useEffect(() => {
|
|
3991
3964
|
isInitialMountRef.current = false;
|
|
3992
3965
|
}, []); // Reset itemRefs on close.
|
|
3993
3966
|
|
|
3994
|
-
react.useEffect(
|
|
3967
|
+
react.useEffect(() => {
|
|
3995
3968
|
if (!isOpen) {
|
|
3996
3969
|
itemRefs.current = {};
|
|
3997
3970
|
}
|
|
3998
3971
|
}, [isOpen]); // Event handler functions.
|
|
3999
3972
|
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
}, [dispatch, getItemNodeFromIndex]);
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
Home: function Home(event) {
|
|
4039
|
-
event.preventDefault();
|
|
4040
|
-
dispatch({
|
|
4041
|
-
type: MenuKeyDownHome,
|
|
4042
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4043
|
-
});
|
|
4044
|
-
},
|
|
4045
|
-
End: function End(event) {
|
|
4046
|
-
event.preventDefault();
|
|
4047
|
-
dispatch({
|
|
4048
|
-
type: MenuKeyDownEnd,
|
|
4049
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4050
|
-
});
|
|
4051
|
-
},
|
|
4052
|
-
Escape: function Escape() {
|
|
4053
|
-
dispatch({
|
|
4054
|
-
type: MenuKeyDownEscape
|
|
4055
|
-
});
|
|
4056
|
-
},
|
|
4057
|
-
Enter: function Enter(event) {
|
|
4058
|
-
event.preventDefault();
|
|
4059
|
-
dispatch({
|
|
4060
|
-
type: MenuKeyDownEnter
|
|
4061
|
-
});
|
|
4062
|
-
},
|
|
4063
|
-
' ': function _(event) {
|
|
4064
|
-
event.preventDefault();
|
|
4065
|
-
dispatch({
|
|
4066
|
-
type: MenuKeyDownSpaceButton
|
|
4067
|
-
});
|
|
4068
|
-
}
|
|
4069
|
-
};
|
|
4070
|
-
}, [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
3973
|
+
const toggleButtonKeyDownHandlers = react.useMemo(() => ({
|
|
3974
|
+
ArrowDown(event) {
|
|
3975
|
+
event.preventDefault();
|
|
3976
|
+
dispatch({
|
|
3977
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
3978
|
+
getItemNodeFromIndex,
|
|
3979
|
+
shiftKey: event.shiftKey
|
|
3980
|
+
});
|
|
3981
|
+
},
|
|
3982
|
+
|
|
3983
|
+
ArrowUp(event) {
|
|
3984
|
+
event.preventDefault();
|
|
3985
|
+
dispatch({
|
|
3986
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
3987
|
+
getItemNodeFromIndex,
|
|
3988
|
+
shiftKey: event.shiftKey
|
|
3989
|
+
});
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
}), [dispatch, getItemNodeFromIndex]);
|
|
3993
|
+
const menuKeyDownHandlers = react.useMemo(() => ({
|
|
3994
|
+
ArrowDown(event) {
|
|
3995
|
+
event.preventDefault();
|
|
3996
|
+
dispatch({
|
|
3997
|
+
type: MenuKeyDownArrowDown,
|
|
3998
|
+
getItemNodeFromIndex,
|
|
3999
|
+
shiftKey: event.shiftKey
|
|
4000
|
+
});
|
|
4001
|
+
},
|
|
4002
|
+
|
|
4003
|
+
ArrowUp(event) {
|
|
4004
|
+
event.preventDefault();
|
|
4005
|
+
dispatch({
|
|
4006
|
+
type: MenuKeyDownArrowUp,
|
|
4007
|
+
getItemNodeFromIndex,
|
|
4008
|
+
shiftKey: event.shiftKey
|
|
4009
|
+
});
|
|
4010
|
+
},
|
|
4071
4011
|
|
|
4072
|
-
|
|
4012
|
+
Home(event) {
|
|
4013
|
+
event.preventDefault();
|
|
4014
|
+
dispatch({
|
|
4015
|
+
type: MenuKeyDownHome,
|
|
4016
|
+
getItemNodeFromIndex
|
|
4017
|
+
});
|
|
4018
|
+
},
|
|
4019
|
+
|
|
4020
|
+
End(event) {
|
|
4021
|
+
event.preventDefault();
|
|
4022
|
+
dispatch({
|
|
4023
|
+
type: MenuKeyDownEnd,
|
|
4024
|
+
getItemNodeFromIndex
|
|
4025
|
+
});
|
|
4026
|
+
},
|
|
4027
|
+
|
|
4028
|
+
Escape() {
|
|
4029
|
+
dispatch({
|
|
4030
|
+
type: MenuKeyDownEscape
|
|
4031
|
+
});
|
|
4032
|
+
},
|
|
4033
|
+
|
|
4034
|
+
Enter(event) {
|
|
4035
|
+
event.preventDefault();
|
|
4036
|
+
dispatch({
|
|
4037
|
+
type: MenuKeyDownEnter
|
|
4038
|
+
});
|
|
4039
|
+
},
|
|
4040
|
+
|
|
4041
|
+
' '(event) {
|
|
4042
|
+
event.preventDefault();
|
|
4043
|
+
dispatch({
|
|
4044
|
+
type: MenuKeyDownSpaceButton
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
|
|
4048
|
+
}), [dispatch, getItemNodeFromIndex]); // Action functions.
|
|
4049
|
+
|
|
4050
|
+
const toggleMenu = react.useCallback(() => {
|
|
4073
4051
|
dispatch({
|
|
4074
4052
|
type: FunctionToggleMenu$1
|
|
4075
4053
|
});
|
|
4076
4054
|
}, [dispatch]);
|
|
4077
|
-
|
|
4055
|
+
const closeMenu = react.useCallback(() => {
|
|
4078
4056
|
dispatch({
|
|
4079
4057
|
type: FunctionCloseMenu$1
|
|
4080
4058
|
});
|
|
4081
4059
|
}, [dispatch]);
|
|
4082
|
-
|
|
4060
|
+
const openMenu = react.useCallback(() => {
|
|
4083
4061
|
dispatch({
|
|
4084
4062
|
type: FunctionOpenMenu$1
|
|
4085
4063
|
});
|
|
4086
4064
|
}, [dispatch]);
|
|
4087
|
-
|
|
4065
|
+
const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
|
|
4088
4066
|
dispatch({
|
|
4089
4067
|
type: FunctionSetHighlightedIndex$1,
|
|
4090
4068
|
highlightedIndex: newHighlightedIndex
|
|
4091
4069
|
});
|
|
4092
4070
|
}, [dispatch]);
|
|
4093
|
-
|
|
4071
|
+
const selectItem = react.useCallback(newSelectedItem => {
|
|
4094
4072
|
dispatch({
|
|
4095
4073
|
type: FunctionSelectItem$1,
|
|
4096
4074
|
selectedItem: newSelectedItem
|
|
4097
4075
|
});
|
|
4098
4076
|
}, [dispatch]);
|
|
4099
|
-
|
|
4077
|
+
const reset = react.useCallback(() => {
|
|
4100
4078
|
dispatch({
|
|
4101
4079
|
type: FunctionReset$2
|
|
4102
4080
|
});
|
|
4103
4081
|
}, [dispatch]);
|
|
4104
|
-
|
|
4082
|
+
const setInputValue = react.useCallback(newInputValue => {
|
|
4105
4083
|
dispatch({
|
|
4106
4084
|
type: FunctionSetInputValue$1,
|
|
4107
4085
|
inputValue: newInputValue
|
|
4108
4086
|
});
|
|
4109
4087
|
}, [dispatch]); // Getter functions.
|
|
4110
4088
|
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
var latestState = latest.current.state;
|
|
4134
|
-
|
|
4135
|
-
var menuHandleKeyDown = function menuHandleKeyDown(event) {
|
|
4136
|
-
var key = normalizeArrowKey(event);
|
|
4089
|
+
const getLabelProps = react.useCallback(labelProps => ({
|
|
4090
|
+
id: elementIds.labelId,
|
|
4091
|
+
htmlFor: elementIds.toggleButtonId,
|
|
4092
|
+
...labelProps
|
|
4093
|
+
}), [elementIds]);
|
|
4094
|
+
const getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
4095
|
+
let {
|
|
4096
|
+
onMouseLeave,
|
|
4097
|
+
refKey = 'ref',
|
|
4098
|
+
onKeyDown,
|
|
4099
|
+
onBlur,
|
|
4100
|
+
ref,
|
|
4101
|
+
...rest
|
|
4102
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4103
|
+
let {
|
|
4104
|
+
suppressRefError = false
|
|
4105
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4106
|
+
const latestState = latest.current.state;
|
|
4107
|
+
|
|
4108
|
+
const menuHandleKeyDown = event => {
|
|
4109
|
+
const key = normalizeArrowKey(event);
|
|
4137
4110
|
|
|
4138
4111
|
if (key && menuKeyDownHandlers[key]) {
|
|
4139
4112
|
menuKeyDownHandlers[key](event);
|
|
4140
4113
|
} else if (isAcceptedCharacterKey(key)) {
|
|
4141
4114
|
dispatch({
|
|
4142
4115
|
type: MenuKeyDownCharacter,
|
|
4143
|
-
key
|
|
4144
|
-
getItemNodeFromIndex
|
|
4116
|
+
key,
|
|
4117
|
+
getItemNodeFromIndex
|
|
4145
4118
|
});
|
|
4146
4119
|
}
|
|
4147
4120
|
};
|
|
4148
4121
|
|
|
4149
|
-
|
|
4122
|
+
const menuHandleBlur = () => {
|
|
4150
4123
|
// if the blur was a result of selection, we don't trigger this action.
|
|
4151
4124
|
if (shouldBlurRef.current === false) {
|
|
4152
4125
|
shouldBlurRef.current = true;
|
|
4153
4126
|
return;
|
|
4154
4127
|
}
|
|
4155
4128
|
|
|
4156
|
-
|
|
4129
|
+
const shouldBlur = !mouseAndTouchTrackersRef.current.isMouseDown;
|
|
4157
4130
|
/* istanbul ignore else */
|
|
4158
4131
|
|
|
4159
4132
|
if (shouldBlur) {
|
|
@@ -4163,61 +4136,72 @@
|
|
|
4163
4136
|
}
|
|
4164
4137
|
};
|
|
4165
4138
|
|
|
4166
|
-
|
|
4139
|
+
const menuHandleMouseLeave = () => {
|
|
4167
4140
|
dispatch({
|
|
4168
4141
|
type: MenuMouseLeave$1
|
|
4169
4142
|
});
|
|
4170
4143
|
};
|
|
4171
4144
|
|
|
4172
4145
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
4173
|
-
return
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4146
|
+
return {
|
|
4147
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
4148
|
+
menuRef.current = menuNode;
|
|
4149
|
+
}),
|
|
4150
|
+
id: elementIds.menuId,
|
|
4151
|
+
role: 'listbox',
|
|
4152
|
+
'aria-labelledby': elementIds.labelId,
|
|
4153
|
+
tabIndex: -1,
|
|
4154
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
4155
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
4156
|
+
}),
|
|
4178
4157
|
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
4179
4158
|
onKeyDown: callAllEventHandlers(onKeyDown, menuHandleKeyDown),
|
|
4180
|
-
onBlur: callAllEventHandlers(onBlur, menuHandleBlur)
|
|
4181
|
-
|
|
4159
|
+
onBlur: callAllEventHandlers(onBlur, menuHandleBlur),
|
|
4160
|
+
...rest
|
|
4161
|
+
};
|
|
4182
4162
|
}, [dispatch, latest, menuKeyDownHandlers, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
|
|
4197
|
-
|
|
4198
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
4163
|
+
const getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
|
|
4164
|
+
let {
|
|
4165
|
+
onClick,
|
|
4166
|
+
onKeyDown,
|
|
4167
|
+
refKey = 'ref',
|
|
4168
|
+
ref,
|
|
4169
|
+
...rest
|
|
4170
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4171
|
+
let {
|
|
4172
|
+
suppressRefError = false
|
|
4173
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
4174
|
+
|
|
4175
|
+
const toggleButtonHandleClick = () => {
|
|
4199
4176
|
dispatch({
|
|
4200
4177
|
type: ToggleButtonClick$1
|
|
4201
4178
|
});
|
|
4202
4179
|
};
|
|
4203
4180
|
|
|
4204
|
-
|
|
4205
|
-
|
|
4181
|
+
const toggleButtonHandleKeyDown = event => {
|
|
4182
|
+
const key = normalizeArrowKey(event);
|
|
4206
4183
|
|
|
4207
4184
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
4208
4185
|
toggleButtonKeyDownHandlers[key](event);
|
|
4209
4186
|
} else if (isAcceptedCharacterKey(key)) {
|
|
4210
4187
|
dispatch({
|
|
4211
4188
|
type: ToggleButtonKeyDownCharacter,
|
|
4212
|
-
key
|
|
4213
|
-
getItemNodeFromIndex
|
|
4189
|
+
key,
|
|
4190
|
+
getItemNodeFromIndex
|
|
4214
4191
|
});
|
|
4215
4192
|
}
|
|
4216
4193
|
};
|
|
4217
4194
|
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4195
|
+
const toggleProps = {
|
|
4196
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
4197
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
4198
|
+
}),
|
|
4199
|
+
id: elementIds.toggleButtonId,
|
|
4200
|
+
'aria-haspopup': 'listbox',
|
|
4201
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
4202
|
+
'aria-labelledby': elementIds.labelId + " " + elementIds.toggleButtonId,
|
|
4203
|
+
...rest
|
|
4204
|
+
};
|
|
4221
4205
|
|
|
4222
4206
|
if (!rest.disabled) {
|
|
4223
4207
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
@@ -4227,24 +4211,22 @@
|
|
|
4227
4211
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
4228
4212
|
return toggleProps;
|
|
4229
4213
|
}, [dispatch, latest, toggleButtonKeyDownHandlers, setGetterPropCallInfo, elementIds, getItemNodeFromIndex]);
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
4214
|
+
const getItemProps = react.useCallback(function (_temp5) {
|
|
4215
|
+
let {
|
|
4216
|
+
item,
|
|
4217
|
+
index,
|
|
4218
|
+
onMouseMove,
|
|
4219
|
+
onClick,
|
|
4220
|
+
refKey = 'ref',
|
|
4221
|
+
ref,
|
|
4222
|
+
...rest
|
|
4223
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
4224
|
+
const {
|
|
4225
|
+
state: latestState,
|
|
4226
|
+
props: latestProps
|
|
4227
|
+
} = latest.current;
|
|
4228
|
+
|
|
4229
|
+
const itemHandleMouseMove = () => {
|
|
4248
4230
|
if (index === latestState.highlightedIndex) {
|
|
4249
4231
|
return;
|
|
4250
4232
|
}
|
|
@@ -4252,32 +4234,34 @@
|
|
|
4252
4234
|
shouldScrollRef.current = false;
|
|
4253
4235
|
dispatch({
|
|
4254
4236
|
type: ItemMouseMove$1,
|
|
4255
|
-
index
|
|
4237
|
+
index
|
|
4256
4238
|
});
|
|
4257
4239
|
};
|
|
4258
4240
|
|
|
4259
|
-
|
|
4241
|
+
const itemHandleClick = () => {
|
|
4260
4242
|
dispatch({
|
|
4261
4243
|
type: ItemClick$1,
|
|
4262
|
-
index
|
|
4244
|
+
index
|
|
4263
4245
|
});
|
|
4264
4246
|
};
|
|
4265
4247
|
|
|
4266
|
-
|
|
4248
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4267
4249
|
|
|
4268
4250
|
if (itemIndex < 0) {
|
|
4269
4251
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
4270
4252
|
}
|
|
4271
4253
|
|
|
4272
|
-
|
|
4254
|
+
const itemProps = {
|
|
4273
4255
|
role: 'option',
|
|
4274
4256
|
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
4275
|
-
id: elementIds.getItemId(itemIndex)
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4257
|
+
id: elementIds.getItemId(itemIndex),
|
|
4258
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
4259
|
+
if (itemNode) {
|
|
4260
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
4261
|
+
}
|
|
4262
|
+
}),
|
|
4263
|
+
...rest
|
|
4264
|
+
};
|
|
4281
4265
|
|
|
4282
4266
|
if (!rest.disabled) {
|
|
4283
4267
|
itemProps.onMouseMove = callAllEventHandlers(onMouseMove, itemHandleMouseMove);
|
|
@@ -4288,46 +4272,46 @@
|
|
|
4288
4272
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
4289
4273
|
return {
|
|
4290
4274
|
// prop getters.
|
|
4291
|
-
getToggleButtonProps
|
|
4292
|
-
getLabelProps
|
|
4293
|
-
getMenuProps
|
|
4294
|
-
getItemProps
|
|
4275
|
+
getToggleButtonProps,
|
|
4276
|
+
getLabelProps,
|
|
4277
|
+
getMenuProps,
|
|
4278
|
+
getItemProps,
|
|
4295
4279
|
// actions.
|
|
4296
|
-
toggleMenu
|
|
4297
|
-
openMenu
|
|
4298
|
-
closeMenu
|
|
4299
|
-
setHighlightedIndex
|
|
4300
|
-
selectItem
|
|
4301
|
-
reset
|
|
4302
|
-
setInputValue
|
|
4280
|
+
toggleMenu,
|
|
4281
|
+
openMenu,
|
|
4282
|
+
closeMenu,
|
|
4283
|
+
setHighlightedIndex,
|
|
4284
|
+
selectItem,
|
|
4285
|
+
reset,
|
|
4286
|
+
setInputValue,
|
|
4303
4287
|
// state.
|
|
4304
|
-
highlightedIndex
|
|
4305
|
-
isOpen
|
|
4306
|
-
selectedItem
|
|
4307
|
-
inputValue
|
|
4288
|
+
highlightedIndex,
|
|
4289
|
+
isOpen,
|
|
4290
|
+
selectedItem,
|
|
4291
|
+
inputValue
|
|
4308
4292
|
};
|
|
4309
4293
|
}
|
|
4310
4294
|
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4295
|
+
const InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
|
|
4296
|
+
const InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
|
|
4297
|
+
const InputKeyDownEscape = '__input_keydown_escape__' ;
|
|
4298
|
+
const InputKeyDownHome = '__input_keydown_home__' ;
|
|
4299
|
+
const InputKeyDownEnd = '__input_keydown_end__' ;
|
|
4300
|
+
const InputKeyDownEnter = '__input_keydown_enter__' ;
|
|
4301
|
+
const InputChange = '__input_change__' ;
|
|
4302
|
+
const InputBlur = '__input_blur__' ;
|
|
4303
|
+
const MenuMouseLeave = '__menu_mouse_leave__' ;
|
|
4304
|
+
const ItemMouseMove = '__item_mouse_move__' ;
|
|
4305
|
+
const ItemClick = '__item_click__' ;
|
|
4306
|
+
const ToggleButtonClick = '__togglebutton_click__' ;
|
|
4307
|
+
const FunctionToggleMenu = '__function_toggle_menu__' ;
|
|
4308
|
+
const FunctionOpenMenu = '__function_open_menu__' ;
|
|
4309
|
+
const FunctionCloseMenu = '__function_close_menu__' ;
|
|
4310
|
+
const FunctionSetHighlightedIndex = '__function_set_highlighted_index__' ;
|
|
4311
|
+
const FunctionSelectItem = '__function_select_item__' ;
|
|
4312
|
+
const FunctionSetInputValue = '__function_set_input_value__' ;
|
|
4313
|
+
const FunctionReset$1 = '__function_reset__' ;
|
|
4314
|
+
const ControlledPropUpdatedSelectedItem = '__controlled_prop_updated_selected_item__' ;
|
|
4331
4315
|
|
|
4332
4316
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
4333
4317
|
__proto__: null,
|
|
@@ -4354,20 +4338,24 @@
|
|
|
4354
4338
|
});
|
|
4355
4339
|
|
|
4356
4340
|
function getInitialState$1(props) {
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4341
|
+
const initialState = getInitialState$2(props);
|
|
4342
|
+
const {
|
|
4343
|
+
selectedItem
|
|
4344
|
+
} = initialState;
|
|
4345
|
+
let {
|
|
4346
|
+
inputValue
|
|
4347
|
+
} = initialState;
|
|
4360
4348
|
|
|
4361
4349
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
4362
4350
|
inputValue = props.itemToString(selectedItem);
|
|
4363
4351
|
}
|
|
4364
4352
|
|
|
4365
|
-
return
|
|
4366
|
-
inputValue
|
|
4367
|
-
}
|
|
4353
|
+
return { ...initialState,
|
|
4354
|
+
inputValue
|
|
4355
|
+
};
|
|
4368
4356
|
}
|
|
4369
4357
|
|
|
4370
|
-
|
|
4358
|
+
const propTypes$1 = {
|
|
4371
4359
|
items: PropTypes.array.isRequired,
|
|
4372
4360
|
itemToString: PropTypes.func,
|
|
4373
4361
|
getA11yStatusMessage: PropTypes.func,
|
|
@@ -4421,14 +4409,10 @@
|
|
|
4421
4409
|
*/
|
|
4422
4410
|
|
|
4423
4411
|
function useControlledReducer(reducer, initialState, props) {
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
4427
|
-
state = _useEnhancedReducer[0],
|
|
4428
|
-
dispatch = _useEnhancedReducer[1]; // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
4429
|
-
|
|
4412
|
+
const previousSelectedItemRef = react.useRef();
|
|
4413
|
+
const [state, dispatch] = useEnhancedReducer(reducer, initialState, props); // ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
4430
4414
|
|
|
4431
|
-
react.useEffect(
|
|
4415
|
+
react.useEffect(() => {
|
|
4432
4416
|
if (isControlledProp(props, 'selectedItem')) {
|
|
4433
4417
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
4434
4418
|
dispatch({
|
|
@@ -4444,27 +4428,29 @@
|
|
|
4444
4428
|
} // eslint-disable-next-line import/no-mutable-exports
|
|
4445
4429
|
|
|
4446
4430
|
|
|
4447
|
-
|
|
4431
|
+
let validatePropTypes$1 = noop;
|
|
4448
4432
|
/* istanbul ignore next */
|
|
4449
4433
|
|
|
4450
4434
|
{
|
|
4451
|
-
validatePropTypes$1 =
|
|
4435
|
+
validatePropTypes$1 = (options, caller) => {
|
|
4452
4436
|
PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
4453
4437
|
};
|
|
4454
4438
|
}
|
|
4455
4439
|
|
|
4456
|
-
|
|
4440
|
+
const defaultProps$1 = { ...defaultProps$3,
|
|
4457
4441
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
4458
4442
|
circularNavigation: true
|
|
4459
|
-
}
|
|
4443
|
+
};
|
|
4460
4444
|
|
|
4461
4445
|
/* eslint-disable complexity */
|
|
4462
4446
|
|
|
4463
4447
|
function downshiftUseComboboxReducer(state, action) {
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4448
|
+
const {
|
|
4449
|
+
type,
|
|
4450
|
+
props,
|
|
4451
|
+
shiftKey
|
|
4452
|
+
} = action;
|
|
4453
|
+
let changes;
|
|
4468
4454
|
|
|
4469
4455
|
switch (type) {
|
|
4470
4456
|
case ItemClick:
|
|
@@ -4505,22 +4491,24 @@
|
|
|
4505
4491
|
break;
|
|
4506
4492
|
|
|
4507
4493
|
case InputKeyDownEnter:
|
|
4508
|
-
changes =
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4494
|
+
changes = { ...(state.isOpen && state.highlightedIndex >= 0 && {
|
|
4495
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
4496
|
+
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4497
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex'),
|
|
4498
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4499
|
+
})
|
|
4500
|
+
};
|
|
4514
4501
|
break;
|
|
4515
4502
|
|
|
4516
4503
|
case InputKeyDownEscape:
|
|
4517
|
-
changes =
|
|
4504
|
+
changes = {
|
|
4518
4505
|
isOpen: false,
|
|
4519
|
-
highlightedIndex: -1
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4506
|
+
highlightedIndex: -1,
|
|
4507
|
+
...(!state.isOpen && {
|
|
4508
|
+
selectedItem: null,
|
|
4509
|
+
inputValue: ''
|
|
4510
|
+
})
|
|
4511
|
+
};
|
|
4524
4512
|
break;
|
|
4525
4513
|
|
|
4526
4514
|
case InputKeyDownHome:
|
|
@@ -4536,13 +4524,14 @@
|
|
|
4536
4524
|
break;
|
|
4537
4525
|
|
|
4538
4526
|
case InputBlur:
|
|
4539
|
-
changes =
|
|
4527
|
+
changes = {
|
|
4540
4528
|
isOpen: false,
|
|
4541
|
-
highlightedIndex: -1
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4529
|
+
highlightedIndex: -1,
|
|
4530
|
+
...(state.highlightedIndex >= 0 && action.selectItem && {
|
|
4531
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
4532
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4533
|
+
})
|
|
4534
|
+
};
|
|
4546
4535
|
break;
|
|
4547
4536
|
|
|
4548
4537
|
case InputChange:
|
|
@@ -4570,15 +4559,13 @@
|
|
|
4570
4559
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
4571
4560
|
}
|
|
4572
4561
|
|
|
4573
|
-
return
|
|
4562
|
+
return { ...state,
|
|
4563
|
+
...changes
|
|
4564
|
+
};
|
|
4574
4565
|
}
|
|
4575
4566
|
/* eslint-enable complexity */
|
|
4576
4567
|
|
|
4577
|
-
|
|
4578
|
-
_excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onClick", "onPress"],
|
|
4579
|
-
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
4580
|
-
_excluded4 = ["onKeyDown", "onChange", "onInput", "onBlur", "onChangeText", "refKey", "ref"],
|
|
4581
|
-
_excluded5 = ["refKey", "ref"];
|
|
4568
|
+
/* eslint-disable max-statements */
|
|
4582
4569
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
4583
4570
|
|
|
4584
4571
|
function useCombobox(userProps) {
|
|
@@ -4588,87 +4575,88 @@
|
|
|
4588
4575
|
|
|
4589
4576
|
validatePropTypes$1(userProps, useCombobox); // Props defaults and destructuring.
|
|
4590
4577
|
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4578
|
+
const props = { ...defaultProps$1,
|
|
4579
|
+
...userProps
|
|
4580
|
+
};
|
|
4581
|
+
const {
|
|
4582
|
+
initialIsOpen,
|
|
4583
|
+
defaultIsOpen,
|
|
4584
|
+
items,
|
|
4585
|
+
scrollIntoView,
|
|
4586
|
+
environment,
|
|
4587
|
+
getA11yStatusMessage,
|
|
4588
|
+
getA11ySelectionMessage,
|
|
4589
|
+
itemToString
|
|
4590
|
+
} = props; // Initial state depending on controlled props.
|
|
4591
|
+
|
|
4592
|
+
const initialState = getInitialState$1(props);
|
|
4593
|
+
const [state, dispatch] = useControlledReducer(downshiftUseComboboxReducer, initialState, props);
|
|
4594
|
+
const {
|
|
4595
|
+
isOpen,
|
|
4596
|
+
highlightedIndex,
|
|
4597
|
+
selectedItem,
|
|
4598
|
+
inputValue
|
|
4599
|
+
} = state; // Element refs.
|
|
4600
|
+
|
|
4601
|
+
const menuRef = react.useRef(null);
|
|
4602
|
+
const itemRefs = react.useRef({});
|
|
4603
|
+
const inputRef = react.useRef(null);
|
|
4604
|
+
const toggleButtonRef = react.useRef(null);
|
|
4605
|
+
const comboboxRef = react.useRef(null);
|
|
4606
|
+
const isInitialMountRef = react.useRef(true); // prevent id re-generation between renders.
|
|
4607
|
+
|
|
4608
|
+
const elementIds = useElementIds(props); // used to keep track of how many items we had on previous cycle.
|
|
4609
|
+
|
|
4610
|
+
const previousResultCountRef = react.useRef(); // utility callback to get item element.
|
|
4611
|
+
|
|
4612
|
+
const latest = useLatestRef({
|
|
4613
|
+
state,
|
|
4614
|
+
props
|
|
4627
4615
|
});
|
|
4628
|
-
|
|
4629
|
-
return itemRefs.current[elementIds.getItemId(index)];
|
|
4630
|
-
}, [elementIds]); // Effects.
|
|
4616
|
+
const getItemNodeFromIndex = react.useCallback(index => itemRefs.current[elementIds.getItemId(index)], [elementIds]); // Effects.
|
|
4631
4617
|
// Sets a11y status message on changes in state.
|
|
4632
4618
|
|
|
4633
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items],
|
|
4619
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
4634
4620
|
isInitialMount: isInitialMountRef.current,
|
|
4635
4621
|
previousResultCount: previousResultCountRef.current,
|
|
4636
|
-
items
|
|
4637
|
-
environment
|
|
4638
|
-
itemToString
|
|
4639
|
-
|
|
4622
|
+
items,
|
|
4623
|
+
environment,
|
|
4624
|
+
itemToString,
|
|
4625
|
+
...state
|
|
4626
|
+
}); // Sets a11y status message on changes in selectedItem.
|
|
4640
4627
|
|
|
4641
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem],
|
|
4628
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
4642
4629
|
isInitialMount: isInitialMountRef.current,
|
|
4643
4630
|
previousResultCount: previousResultCountRef.current,
|
|
4644
|
-
items
|
|
4645
|
-
environment
|
|
4646
|
-
itemToString
|
|
4647
|
-
|
|
4631
|
+
items,
|
|
4632
|
+
environment,
|
|
4633
|
+
itemToString,
|
|
4634
|
+
...state
|
|
4635
|
+
}); // Scroll on highlighted item if change comes from keyboard.
|
|
4648
4636
|
|
|
4649
|
-
|
|
4637
|
+
const shouldScrollRef = useScrollIntoView({
|
|
4650
4638
|
menuElement: menuRef.current,
|
|
4651
|
-
highlightedIndex
|
|
4652
|
-
isOpen
|
|
4653
|
-
itemRefs
|
|
4654
|
-
scrollIntoView
|
|
4655
|
-
getItemNodeFromIndex
|
|
4639
|
+
highlightedIndex,
|
|
4640
|
+
isOpen,
|
|
4641
|
+
itemRefs,
|
|
4642
|
+
scrollIntoView,
|
|
4643
|
+
getItemNodeFromIndex
|
|
4656
4644
|
});
|
|
4657
4645
|
useControlPropsValidator({
|
|
4658
4646
|
isInitialMount: isInitialMountRef.current,
|
|
4659
|
-
props
|
|
4660
|
-
state
|
|
4647
|
+
props,
|
|
4648
|
+
state
|
|
4661
4649
|
}); // Focus the input on first render if required.
|
|
4662
4650
|
|
|
4663
|
-
react.useEffect(
|
|
4664
|
-
|
|
4651
|
+
react.useEffect(() => {
|
|
4652
|
+
const focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
4665
4653
|
|
|
4666
4654
|
if (focusOnOpen && inputRef.current) {
|
|
4667
4655
|
inputRef.current.focus();
|
|
4668
4656
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4669
4657
|
|
|
4670
4658
|
}, []);
|
|
4671
|
-
react.useEffect(
|
|
4659
|
+
react.useEffect(() => {
|
|
4672
4660
|
if (isInitialMountRef.current) {
|
|
4673
4661
|
return;
|
|
4674
4662
|
}
|
|
@@ -4676,147 +4664,151 @@
|
|
|
4676
4664
|
previousResultCountRef.current = items.length;
|
|
4677
4665
|
}); // Add mouse/touch events to document.
|
|
4678
4666
|
|
|
4679
|
-
|
|
4667
|
+
const mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [comboboxRef, menuRef, toggleButtonRef], environment, () => {
|
|
4680
4668
|
dispatch({
|
|
4681
4669
|
type: InputBlur,
|
|
4682
4670
|
selectItem: false
|
|
4683
4671
|
});
|
|
4684
4672
|
});
|
|
4685
|
-
|
|
4673
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getComboboxProps', 'getMenuProps'); // Make initial ref false.
|
|
4686
4674
|
|
|
4687
|
-
react.useEffect(
|
|
4675
|
+
react.useEffect(() => {
|
|
4688
4676
|
isInitialMountRef.current = false;
|
|
4689
4677
|
}, []); // Reset itemRefs on close.
|
|
4690
4678
|
|
|
4691
|
-
react.useEffect(
|
|
4679
|
+
react.useEffect(() => {
|
|
4692
4680
|
if (!isOpen) {
|
|
4693
4681
|
itemRefs.current = {};
|
|
4694
4682
|
}
|
|
4695
4683
|
}, [isOpen]);
|
|
4696
4684
|
/* Event handler functions */
|
|
4697
4685
|
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
},
|
|
4708
|
-
ArrowUp: function ArrowUp(event) {
|
|
4709
|
-
event.preventDefault();
|
|
4710
|
-
dispatch({
|
|
4711
|
-
type: InputKeyDownArrowUp,
|
|
4712
|
-
shiftKey: event.shiftKey,
|
|
4713
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4714
|
-
});
|
|
4715
|
-
},
|
|
4716
|
-
Home: function Home(event) {
|
|
4717
|
-
if (!latest.current.state.isOpen) {
|
|
4718
|
-
return;
|
|
4719
|
-
}
|
|
4686
|
+
const inputKeyDownHandlers = react.useMemo(() => ({
|
|
4687
|
+
ArrowDown(event) {
|
|
4688
|
+
event.preventDefault();
|
|
4689
|
+
dispatch({
|
|
4690
|
+
type: InputKeyDownArrowDown,
|
|
4691
|
+
shiftKey: event.shiftKey,
|
|
4692
|
+
getItemNodeFromIndex
|
|
4693
|
+
});
|
|
4694
|
+
},
|
|
4720
4695
|
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
return;
|
|
4730
|
-
}
|
|
4696
|
+
ArrowUp(event) {
|
|
4697
|
+
event.preventDefault();
|
|
4698
|
+
dispatch({
|
|
4699
|
+
type: InputKeyDownArrowUp,
|
|
4700
|
+
shiftKey: event.shiftKey,
|
|
4701
|
+
getItemNodeFromIndex
|
|
4702
|
+
});
|
|
4703
|
+
},
|
|
4731
4704
|
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
});
|
|
4737
|
-
},
|
|
4738
|
-
Escape: function Escape() {
|
|
4739
|
-
var latestState = latest.current.state;
|
|
4705
|
+
Home(event) {
|
|
4706
|
+
if (!latest.current.state.isOpen) {
|
|
4707
|
+
return;
|
|
4708
|
+
}
|
|
4740
4709
|
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
Enter: function Enter(event) {
|
|
4748
|
-
var latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
4710
|
+
event.preventDefault();
|
|
4711
|
+
dispatch({
|
|
4712
|
+
type: InputKeyDownHome,
|
|
4713
|
+
getItemNodeFromIndex
|
|
4714
|
+
});
|
|
4715
|
+
},
|
|
4749
4716
|
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4717
|
+
End(event) {
|
|
4718
|
+
if (!latest.current.state.isOpen) {
|
|
4719
|
+
return;
|
|
4720
|
+
}
|
|
4754
4721
|
|
|
4755
|
-
|
|
4722
|
+
event.preventDefault();
|
|
4723
|
+
dispatch({
|
|
4724
|
+
type: InputKeyDownEnd,
|
|
4725
|
+
getItemNodeFromIndex
|
|
4726
|
+
});
|
|
4727
|
+
},
|
|
4728
|
+
|
|
4729
|
+
Escape() {
|
|
4730
|
+
const latestState = latest.current.state;
|
|
4731
|
+
|
|
4732
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
4756
4733
|
dispatch({
|
|
4757
|
-
type:
|
|
4758
|
-
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4734
|
+
type: InputKeyDownEscape
|
|
4759
4735
|
});
|
|
4760
4736
|
}
|
|
4761
|
-
}
|
|
4762
|
-
}, [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
4763
|
-
|
|
4764
|
-
var getLabelProps = react.useCallback(function (labelProps) {
|
|
4765
|
-
return _extends({
|
|
4766
|
-
id: elementIds.labelId,
|
|
4767
|
-
htmlFor: elementIds.inputId
|
|
4768
|
-
}, labelProps);
|
|
4769
|
-
}, [elementIds]);
|
|
4770
|
-
var getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
4771
|
-
var _extends2;
|
|
4772
|
-
|
|
4773
|
-
var _ref = _temp === void 0 ? {} : _temp,
|
|
4774
|
-
onMouseLeave = _ref.onMouseLeave,
|
|
4775
|
-
_ref$refKey = _ref.refKey,
|
|
4776
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
4777
|
-
ref = _ref.ref,
|
|
4778
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
4779
|
-
|
|
4780
|
-
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
4781
|
-
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
4782
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
4737
|
+
},
|
|
4783
4738
|
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4739
|
+
Enter(event) {
|
|
4740
|
+
const latestState = latest.current.state; // if closed or no highlighted index, do nothing.
|
|
4741
|
+
|
|
4742
|
+
if (!latestState.isOpen || latestState.highlightedIndex < 0 || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
4743
|
+
) {
|
|
4744
|
+
return;
|
|
4745
|
+
}
|
|
4746
|
+
|
|
4747
|
+
event.preventDefault();
|
|
4788
4748
|
dispatch({
|
|
4789
|
-
type:
|
|
4749
|
+
type: InputKeyDownEnter,
|
|
4750
|
+
getItemNodeFromIndex
|
|
4790
4751
|
});
|
|
4791
|
-
}
|
|
4752
|
+
}
|
|
4753
|
+
|
|
4754
|
+
}), [dispatch, latest, getItemNodeFromIndex]); // Getter props.
|
|
4755
|
+
|
|
4756
|
+
const getLabelProps = react.useCallback(labelProps => ({
|
|
4757
|
+
id: elementIds.labelId,
|
|
4758
|
+
htmlFor: elementIds.inputId,
|
|
4759
|
+
...labelProps
|
|
4760
|
+
}), [elementIds]);
|
|
4761
|
+
const getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
4762
|
+
let {
|
|
4763
|
+
onMouseLeave,
|
|
4764
|
+
refKey = 'ref',
|
|
4765
|
+
ref,
|
|
4766
|
+
...rest
|
|
4767
|
+
} = _temp === void 0 ? {} : _temp;
|
|
4768
|
+
let {
|
|
4769
|
+
suppressRefError = false
|
|
4770
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
4771
|
+
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
4772
|
+
return {
|
|
4773
|
+
[refKey]: handleRefs(ref, menuNode => {
|
|
4774
|
+
menuRef.current = menuNode;
|
|
4775
|
+
}),
|
|
4776
|
+
id: elementIds.menuId,
|
|
4777
|
+
role: 'listbox',
|
|
4778
|
+
'aria-labelledby': elementIds.labelId,
|
|
4779
|
+
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
4780
|
+
dispatch({
|
|
4781
|
+
type: MenuMouseLeave
|
|
4782
|
+
});
|
|
4783
|
+
}),
|
|
4784
|
+
...rest
|
|
4785
|
+
};
|
|
4792
4786
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
latestState = _latest$current.state;
|
|
4810
|
-
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4787
|
+
const getItemProps = react.useCallback(function (_temp3) {
|
|
4788
|
+
let {
|
|
4789
|
+
item,
|
|
4790
|
+
index,
|
|
4791
|
+
refKey = 'ref',
|
|
4792
|
+
ref,
|
|
4793
|
+
onMouseMove,
|
|
4794
|
+
onClick,
|
|
4795
|
+
onPress,
|
|
4796
|
+
...rest
|
|
4797
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
4798
|
+
const {
|
|
4799
|
+
props: latestProps,
|
|
4800
|
+
state: latestState
|
|
4801
|
+
} = latest.current;
|
|
4802
|
+
const itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4811
4803
|
|
|
4812
4804
|
if (itemIndex < 0) {
|
|
4813
4805
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
4814
4806
|
}
|
|
4815
4807
|
|
|
4816
|
-
|
|
4817
|
-
|
|
4808
|
+
const onSelectKey = 'onClick';
|
|
4809
|
+
const customClickHandler = onClick;
|
|
4818
4810
|
|
|
4819
|
-
|
|
4811
|
+
const itemHandleMouseMove = () => {
|
|
4820
4812
|
if (index === latestState.highlightedIndex) {
|
|
4821
4813
|
return;
|
|
4822
4814
|
}
|
|
@@ -4824,14 +4816,14 @@
|
|
|
4824
4816
|
shouldScrollRef.current = false;
|
|
4825
4817
|
dispatch({
|
|
4826
4818
|
type: ItemMouseMove,
|
|
4827
|
-
index
|
|
4819
|
+
index
|
|
4828
4820
|
});
|
|
4829
4821
|
};
|
|
4830
4822
|
|
|
4831
|
-
|
|
4823
|
+
const itemHandleClick = () => {
|
|
4832
4824
|
dispatch({
|
|
4833
4825
|
type: ItemClick,
|
|
4834
|
-
index
|
|
4826
|
+
index
|
|
4835
4827
|
});
|
|
4836
4828
|
|
|
4837
4829
|
if (inputRef.current) {
|
|
@@ -4839,26 +4831,32 @@
|
|
|
4839
4831
|
}
|
|
4840
4832
|
};
|
|
4841
4833
|
|
|
4842
|
-
return
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4834
|
+
return {
|
|
4835
|
+
[refKey]: handleRefs(ref, itemNode => {
|
|
4836
|
+
if (itemNode) {
|
|
4837
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
4838
|
+
}
|
|
4839
|
+
}),
|
|
4840
|
+
role: 'option',
|
|
4841
|
+
'aria-selected': "" + (itemIndex === latestState.highlightedIndex),
|
|
4842
|
+
id: elementIds.getItemId(itemIndex),
|
|
4843
|
+
...(!rest.disabled && {
|
|
4844
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
4845
|
+
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
4846
|
+
}),
|
|
4847
|
+
...rest
|
|
4848
|
+
};
|
|
4849
4849
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
4850
|
+
const getToggleButtonProps = react.useCallback(function (_temp4) {
|
|
4851
|
+
let {
|
|
4852
|
+
onClick,
|
|
4853
|
+
onPress,
|
|
4854
|
+
refKey = 'ref',
|
|
4855
|
+
ref,
|
|
4856
|
+
...rest
|
|
4857
|
+
} = _temp4 === void 0 ? {} : _temp4;
|
|
4858
|
+
|
|
4859
|
+
const toggleButtonHandleClick = () => {
|
|
4862
4860
|
dispatch({
|
|
4863
4861
|
type: ToggleButtonClick
|
|
4864
4862
|
});
|
|
@@ -4868,49 +4866,52 @@
|
|
|
4868
4866
|
}
|
|
4869
4867
|
};
|
|
4870
4868
|
|
|
4871
|
-
return
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4869
|
+
return {
|
|
4870
|
+
[refKey]: handleRefs(ref, toggleButtonNode => {
|
|
4871
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
4872
|
+
}),
|
|
4873
|
+
id: elementIds.toggleButtonId,
|
|
4874
|
+
tabIndex: -1,
|
|
4875
|
+
...(!rest.disabled && { ...({
|
|
4876
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
4877
|
+
})
|
|
4878
|
+
}),
|
|
4879
|
+
...rest
|
|
4880
|
+
};
|
|
4876
4881
|
}, [dispatch, latest, elementIds]);
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
var _ref7 = _temp6 === void 0 ? {} : _temp6,
|
|
4892
|
-
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
4893
|
-
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
4894
|
-
|
|
4882
|
+
const getInputProps = react.useCallback(function (_temp5, _temp6) {
|
|
4883
|
+
let {
|
|
4884
|
+
onKeyDown,
|
|
4885
|
+
onChange,
|
|
4886
|
+
onInput,
|
|
4887
|
+
onBlur,
|
|
4888
|
+
onChangeText,
|
|
4889
|
+
refKey = 'ref',
|
|
4890
|
+
ref,
|
|
4891
|
+
...rest
|
|
4892
|
+
} = _temp5 === void 0 ? {} : _temp5;
|
|
4893
|
+
let {
|
|
4894
|
+
suppressRefError = false
|
|
4895
|
+
} = _temp6 === void 0 ? {} : _temp6;
|
|
4895
4896
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
4896
|
-
|
|
4897
|
+
const latestState = latest.current.state;
|
|
4897
4898
|
|
|
4898
|
-
|
|
4899
|
-
|
|
4899
|
+
const inputHandleKeyDown = event => {
|
|
4900
|
+
const key = normalizeArrowKey(event);
|
|
4900
4901
|
|
|
4901
4902
|
if (key && inputKeyDownHandlers[key]) {
|
|
4902
4903
|
inputKeyDownHandlers[key](event);
|
|
4903
4904
|
}
|
|
4904
4905
|
};
|
|
4905
4906
|
|
|
4906
|
-
|
|
4907
|
+
const inputHandleChange = event => {
|
|
4907
4908
|
dispatch({
|
|
4908
4909
|
type: InputChange,
|
|
4909
4910
|
inputValue: event.target.value
|
|
4910
4911
|
});
|
|
4911
4912
|
};
|
|
4912
4913
|
|
|
4913
|
-
|
|
4914
|
+
const inputHandleBlur = () => {
|
|
4914
4915
|
/* istanbul ignore else */
|
|
4915
4916
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
4916
4917
|
dispatch({
|
|
@@ -4922,109 +4923,121 @@
|
|
|
4922
4923
|
/* istanbul ignore next (preact) */
|
|
4923
4924
|
|
|
4924
4925
|
|
|
4925
|
-
|
|
4926
|
-
|
|
4926
|
+
const onChangeKey = 'onChange';
|
|
4927
|
+
let eventHandlers = {};
|
|
4927
4928
|
|
|
4928
4929
|
if (!rest.disabled) {
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4930
|
+
eventHandlers = {
|
|
4931
|
+
[onChangeKey]: callAllEventHandlers(onChange, onInput, inputHandleChange),
|
|
4932
|
+
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
4933
|
+
onBlur: callAllEventHandlers(onBlur, inputHandleBlur)
|
|
4934
|
+
};
|
|
4932
4935
|
}
|
|
4933
4936
|
|
|
4934
|
-
return
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4937
|
+
return {
|
|
4938
|
+
[refKey]: handleRefs(ref, inputNode => {
|
|
4939
|
+
inputRef.current = inputNode;
|
|
4940
|
+
}),
|
|
4941
|
+
id: elementIds.inputId,
|
|
4942
|
+
'aria-autocomplete': 'list',
|
|
4943
|
+
'aria-controls': elementIds.menuId,
|
|
4944
|
+
...(latestState.isOpen && latestState.highlightedIndex > -1 && {
|
|
4945
|
+
'aria-activedescendant': elementIds.getItemId(latestState.highlightedIndex)
|
|
4946
|
+
}),
|
|
4939
4947
|
'aria-labelledby': elementIds.labelId,
|
|
4940
4948
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
4941
4949
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
4942
4950
|
autoComplete: 'off',
|
|
4943
|
-
value: latestState.inputValue
|
|
4944
|
-
|
|
4951
|
+
value: latestState.inputValue,
|
|
4952
|
+
...eventHandlers,
|
|
4953
|
+
...rest
|
|
4954
|
+
};
|
|
4945
4955
|
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
var _ref9 = _temp8 === void 0 ? {} : _temp8,
|
|
4956
|
-
_ref9$suppressRefErro = _ref9.suppressRefError,
|
|
4957
|
-
suppressRefError = _ref9$suppressRefErro === void 0 ? false : _ref9$suppressRefErro;
|
|
4958
|
-
|
|
4956
|
+
const getComboboxProps = react.useCallback(function (_temp7, _temp8) {
|
|
4957
|
+
let {
|
|
4958
|
+
refKey = 'ref',
|
|
4959
|
+
ref,
|
|
4960
|
+
...rest
|
|
4961
|
+
} = _temp7 === void 0 ? {} : _temp7;
|
|
4962
|
+
let {
|
|
4963
|
+
suppressRefError = false
|
|
4964
|
+
} = _temp8 === void 0 ? {} : _temp8;
|
|
4959
4965
|
setGetterPropCallInfo('getComboboxProps', suppressRefError, refKey, comboboxRef);
|
|
4960
|
-
return
|
|
4961
|
-
|
|
4962
|
-
|
|
4966
|
+
return {
|
|
4967
|
+
[refKey]: handleRefs(ref, comboboxNode => {
|
|
4968
|
+
comboboxRef.current = comboboxNode;
|
|
4969
|
+
}),
|
|
4970
|
+
role: 'combobox',
|
|
4971
|
+
'aria-haspopup': 'listbox',
|
|
4972
|
+
'aria-owns': elementIds.menuId,
|
|
4973
|
+
'aria-expanded': latest.current.state.isOpen,
|
|
4974
|
+
...rest
|
|
4975
|
+
};
|
|
4963
4976
|
}, [latest, setGetterPropCallInfo, elementIds]); // returns
|
|
4964
4977
|
|
|
4965
|
-
|
|
4978
|
+
const toggleMenu = react.useCallback(() => {
|
|
4966
4979
|
dispatch({
|
|
4967
4980
|
type: FunctionToggleMenu
|
|
4968
4981
|
});
|
|
4969
4982
|
}, [dispatch]);
|
|
4970
|
-
|
|
4983
|
+
const closeMenu = react.useCallback(() => {
|
|
4971
4984
|
dispatch({
|
|
4972
4985
|
type: FunctionCloseMenu
|
|
4973
4986
|
});
|
|
4974
4987
|
}, [dispatch]);
|
|
4975
|
-
|
|
4988
|
+
const openMenu = react.useCallback(() => {
|
|
4976
4989
|
dispatch({
|
|
4977
4990
|
type: FunctionOpenMenu
|
|
4978
4991
|
});
|
|
4979
4992
|
}, [dispatch]);
|
|
4980
|
-
|
|
4993
|
+
const setHighlightedIndex = react.useCallback(newHighlightedIndex => {
|
|
4981
4994
|
dispatch({
|
|
4982
4995
|
type: FunctionSetHighlightedIndex,
|
|
4983
4996
|
highlightedIndex: newHighlightedIndex
|
|
4984
4997
|
});
|
|
4985
4998
|
}, [dispatch]);
|
|
4986
|
-
|
|
4999
|
+
const selectItem = react.useCallback(newSelectedItem => {
|
|
4987
5000
|
dispatch({
|
|
4988
5001
|
type: FunctionSelectItem,
|
|
4989
5002
|
selectedItem: newSelectedItem
|
|
4990
5003
|
});
|
|
4991
5004
|
}, [dispatch]);
|
|
4992
|
-
|
|
5005
|
+
const setInputValue = react.useCallback(newInputValue => {
|
|
4993
5006
|
dispatch({
|
|
4994
5007
|
type: FunctionSetInputValue,
|
|
4995
5008
|
inputValue: newInputValue
|
|
4996
5009
|
});
|
|
4997
5010
|
}, [dispatch]);
|
|
4998
|
-
|
|
5011
|
+
const reset = react.useCallback(() => {
|
|
4999
5012
|
dispatch({
|
|
5000
5013
|
type: FunctionReset$1
|
|
5001
5014
|
});
|
|
5002
5015
|
}, [dispatch]);
|
|
5003
5016
|
return {
|
|
5004
5017
|
// prop getters.
|
|
5005
|
-
getItemProps
|
|
5006
|
-
getLabelProps
|
|
5007
|
-
getMenuProps
|
|
5008
|
-
getInputProps
|
|
5009
|
-
getComboboxProps
|
|
5010
|
-
getToggleButtonProps
|
|
5018
|
+
getItemProps,
|
|
5019
|
+
getLabelProps,
|
|
5020
|
+
getMenuProps,
|
|
5021
|
+
getInputProps,
|
|
5022
|
+
getComboboxProps,
|
|
5023
|
+
getToggleButtonProps,
|
|
5011
5024
|
// actions.
|
|
5012
|
-
toggleMenu
|
|
5013
|
-
openMenu
|
|
5014
|
-
closeMenu
|
|
5015
|
-
setHighlightedIndex
|
|
5016
|
-
setInputValue
|
|
5017
|
-
selectItem
|
|
5018
|
-
reset
|
|
5025
|
+
toggleMenu,
|
|
5026
|
+
openMenu,
|
|
5027
|
+
closeMenu,
|
|
5028
|
+
setHighlightedIndex,
|
|
5029
|
+
setInputValue,
|
|
5030
|
+
selectItem,
|
|
5031
|
+
reset,
|
|
5019
5032
|
// state.
|
|
5020
|
-
highlightedIndex
|
|
5021
|
-
isOpen
|
|
5022
|
-
selectedItem
|
|
5023
|
-
inputValue
|
|
5033
|
+
highlightedIndex,
|
|
5034
|
+
isOpen,
|
|
5035
|
+
selectedItem,
|
|
5036
|
+
inputValue
|
|
5024
5037
|
};
|
|
5025
5038
|
}
|
|
5026
5039
|
|
|
5027
|
-
|
|
5040
|
+
const defaultStateValues = {
|
|
5028
5041
|
activeIndex: -1,
|
|
5029
5042
|
selectedItems: []
|
|
5030
5043
|
};
|
|
@@ -5064,11 +5077,11 @@
|
|
|
5064
5077
|
|
|
5065
5078
|
|
|
5066
5079
|
function getInitialState(props) {
|
|
5067
|
-
|
|
5068
|
-
|
|
5080
|
+
const activeIndex = getInitialValue(props, 'activeIndex');
|
|
5081
|
+
const selectedItems = getInitialValue(props, 'selectedItems');
|
|
5069
5082
|
return {
|
|
5070
|
-
activeIndex
|
|
5071
|
-
selectedItems
|
|
5083
|
+
activeIndex,
|
|
5084
|
+
selectedItems
|
|
5072
5085
|
};
|
|
5073
5086
|
}
|
|
5074
5087
|
/**
|
|
@@ -5087,10 +5100,12 @@
|
|
|
5087
5100
|
return false;
|
|
5088
5101
|
}
|
|
5089
5102
|
|
|
5090
|
-
|
|
5103
|
+
const element = event.target;
|
|
5091
5104
|
|
|
5092
5105
|
if (element instanceof HTMLInputElement && // if element is a text input
|
|
5093
|
-
element.value !== '' && (
|
|
5106
|
+
element.value !== '' && ( // and we have text in it
|
|
5107
|
+
// and cursor is either not at the start or is currently highlighting text.
|
|
5108
|
+
element.selectionStart !== 0 || element.selectionEnd !== 0)) {
|
|
5094
5109
|
return false;
|
|
5095
5110
|
}
|
|
5096
5111
|
|
|
@@ -5105,12 +5120,14 @@
|
|
|
5105
5120
|
|
|
5106
5121
|
|
|
5107
5122
|
function getA11yRemovalMessage(selectionParameters) {
|
|
5108
|
-
|
|
5109
|
-
|
|
5123
|
+
const {
|
|
5124
|
+
removedSelectedItem,
|
|
5125
|
+
itemToString: itemToStringLocal
|
|
5126
|
+
} = selectionParameters;
|
|
5110
5127
|
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
5111
5128
|
}
|
|
5112
5129
|
|
|
5113
|
-
|
|
5130
|
+
const propTypes = {
|
|
5114
5131
|
selectedItems: PropTypes.array,
|
|
5115
5132
|
initialSelectedItems: PropTypes.array,
|
|
5116
5133
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -5134,37 +5151,37 @@
|
|
|
5134
5151
|
})
|
|
5135
5152
|
})
|
|
5136
5153
|
};
|
|
5137
|
-
|
|
5154
|
+
const defaultProps = {
|
|
5138
5155
|
itemToString: defaultProps$3.itemToString,
|
|
5139
5156
|
stateReducer: defaultProps$3.stateReducer,
|
|
5140
5157
|
environment: defaultProps$3.environment,
|
|
5141
|
-
getA11yRemovalMessage
|
|
5158
|
+
getA11yRemovalMessage,
|
|
5142
5159
|
keyNavigationNext: 'ArrowRight',
|
|
5143
5160
|
keyNavigationPrevious: 'ArrowLeft'
|
|
5144
5161
|
}; // eslint-disable-next-line import/no-mutable-exports
|
|
5145
5162
|
|
|
5146
|
-
|
|
5163
|
+
let validatePropTypes = noop;
|
|
5147
5164
|
/* istanbul ignore next */
|
|
5148
5165
|
|
|
5149
5166
|
{
|
|
5150
|
-
validatePropTypes =
|
|
5167
|
+
validatePropTypes = (options, caller) => {
|
|
5151
5168
|
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
5152
5169
|
};
|
|
5153
5170
|
}
|
|
5154
5171
|
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5172
|
+
const SelectedItemClick = '__selected_item_click__' ;
|
|
5173
|
+
const SelectedItemKeyDownDelete = '__selected_item_keydown_delete__' ;
|
|
5174
|
+
const SelectedItemKeyDownBackspace = '__selected_item_keydown_backspace__' ;
|
|
5175
|
+
const SelectedItemKeyDownNavigationNext = '__selected_item_keydown_navigation_next__' ;
|
|
5176
|
+
const SelectedItemKeyDownNavigationPrevious = '__selected_item_keydown_navigation_previous__' ;
|
|
5177
|
+
const DropdownKeyDownNavigationPrevious = '__dropdown_keydown_navigation_previous__' ;
|
|
5178
|
+
const DropdownKeyDownBackspace = '__dropdown_keydown_backspace__' ;
|
|
5179
|
+
const DropdownClick = '__dropdown_click__' ;
|
|
5180
|
+
const FunctionAddSelectedItem = '__function_add_selected_item__' ;
|
|
5181
|
+
const FunctionRemoveSelectedItem = '__function_remove_selected_item__' ;
|
|
5182
|
+
const FunctionSetSelectedItems = '__function_set_selected_items__' ;
|
|
5183
|
+
const FunctionSetActiveIndex = '__function_set_active_index__' ;
|
|
5184
|
+
const FunctionReset = '__function_reset__' ;
|
|
5168
5185
|
|
|
5169
5186
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
5170
5187
|
__proto__: null,
|
|
@@ -5186,13 +5203,17 @@
|
|
|
5186
5203
|
/* eslint-disable complexity */
|
|
5187
5204
|
|
|
5188
5205
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5206
|
+
const {
|
|
5207
|
+
type,
|
|
5208
|
+
index,
|
|
5209
|
+
props,
|
|
5210
|
+
selectedItem
|
|
5211
|
+
} = action;
|
|
5212
|
+
const {
|
|
5213
|
+
activeIndex,
|
|
5214
|
+
selectedItems
|
|
5215
|
+
} = state;
|
|
5216
|
+
let changes;
|
|
5196
5217
|
|
|
5197
5218
|
switch (type) {
|
|
5198
5219
|
case SelectedItemClick:
|
|
@@ -5216,7 +5237,7 @@
|
|
|
5216
5237
|
case SelectedItemKeyDownBackspace:
|
|
5217
5238
|
case SelectedItemKeyDownDelete:
|
|
5218
5239
|
{
|
|
5219
|
-
|
|
5240
|
+
let newActiveIndex = activeIndex;
|
|
5220
5241
|
|
|
5221
5242
|
if (selectedItems.length === 1) {
|
|
5222
5243
|
newActiveIndex = -1;
|
|
@@ -5224,11 +5245,12 @@
|
|
|
5224
5245
|
newActiveIndex = selectedItems.length - 2;
|
|
5225
5246
|
}
|
|
5226
5247
|
|
|
5227
|
-
changes =
|
|
5228
|
-
selectedItems: [
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5248
|
+
changes = {
|
|
5249
|
+
selectedItems: [...selectedItems.slice(0, activeIndex), ...selectedItems.slice(activeIndex + 1)],
|
|
5250
|
+
...{
|
|
5251
|
+
activeIndex: newActiveIndex
|
|
5252
|
+
}
|
|
5253
|
+
};
|
|
5232
5254
|
break;
|
|
5233
5255
|
}
|
|
5234
5256
|
|
|
@@ -5246,7 +5268,7 @@
|
|
|
5246
5268
|
|
|
5247
5269
|
case FunctionAddSelectedItem:
|
|
5248
5270
|
changes = {
|
|
5249
|
-
selectedItems: [
|
|
5271
|
+
selectedItems: [...selectedItems, selectedItem]
|
|
5250
5272
|
};
|
|
5251
5273
|
break;
|
|
5252
5274
|
|
|
@@ -5258,26 +5280,30 @@
|
|
|
5258
5280
|
|
|
5259
5281
|
case FunctionRemoveSelectedItem:
|
|
5260
5282
|
{
|
|
5261
|
-
|
|
5262
|
-
|
|
5283
|
+
let newActiveIndex = activeIndex;
|
|
5284
|
+
const selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
5285
|
+
|
|
5286
|
+
if (selectedItemIndex >= 0) {
|
|
5287
|
+
if (selectedItems.length === 1) {
|
|
5288
|
+
newActiveIndex = -1;
|
|
5289
|
+
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
5290
|
+
newActiveIndex = selectedItems.length - 2;
|
|
5291
|
+
}
|
|
5263
5292
|
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5293
|
+
changes = {
|
|
5294
|
+
selectedItems: [...selectedItems.slice(0, selectedItemIndex), ...selectedItems.slice(selectedItemIndex + 1)],
|
|
5295
|
+
activeIndex: newActiveIndex
|
|
5296
|
+
};
|
|
5268
5297
|
}
|
|
5269
5298
|
|
|
5270
|
-
changes = _extends({
|
|
5271
|
-
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1))
|
|
5272
|
-
}, {
|
|
5273
|
-
activeIndex: _newActiveIndex
|
|
5274
|
-
});
|
|
5275
5299
|
break;
|
|
5276
5300
|
}
|
|
5277
5301
|
|
|
5278
5302
|
case FunctionSetSelectedItems:
|
|
5279
5303
|
{
|
|
5280
|
-
|
|
5304
|
+
const {
|
|
5305
|
+
selectedItems: newSelectedItems
|
|
5306
|
+
} = action;
|
|
5281
5307
|
changes = {
|
|
5282
5308
|
selectedItems: newSelectedItems
|
|
5283
5309
|
};
|
|
@@ -5286,9 +5312,11 @@
|
|
|
5286
5312
|
|
|
5287
5313
|
case FunctionSetActiveIndex:
|
|
5288
5314
|
{
|
|
5289
|
-
|
|
5315
|
+
const {
|
|
5316
|
+
activeIndex: newActiveIndex
|
|
5317
|
+
} = action;
|
|
5290
5318
|
changes = {
|
|
5291
|
-
activeIndex:
|
|
5319
|
+
activeIndex: newActiveIndex
|
|
5292
5320
|
};
|
|
5293
5321
|
break;
|
|
5294
5322
|
}
|
|
@@ -5304,11 +5332,11 @@
|
|
|
5304
5332
|
throw new Error('Reducer called without proper action type.');
|
|
5305
5333
|
}
|
|
5306
5334
|
|
|
5307
|
-
return
|
|
5335
|
+
return { ...state,
|
|
5336
|
+
...changes
|
|
5337
|
+
};
|
|
5308
5338
|
}
|
|
5309
5339
|
|
|
5310
|
-
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
5311
|
-
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
5312
5340
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
5313
5341
|
|
|
5314
5342
|
function useMultipleSelection(userProps) {
|
|
@@ -5318,47 +5346,47 @@
|
|
|
5318
5346
|
|
|
5319
5347
|
validatePropTypes(userProps, useMultipleSelection); // Props defaults and destructuring.
|
|
5320
5348
|
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5349
|
+
const props = { ...defaultProps,
|
|
5350
|
+
...userProps
|
|
5351
|
+
};
|
|
5352
|
+
const {
|
|
5353
|
+
getA11yRemovalMessage,
|
|
5354
|
+
itemToString,
|
|
5355
|
+
environment,
|
|
5356
|
+
keyNavigationNext,
|
|
5357
|
+
keyNavigationPrevious
|
|
5358
|
+
} = props; // Reducer init.
|
|
5359
|
+
|
|
5360
|
+
const [state, dispatch] = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props);
|
|
5361
|
+
const {
|
|
5362
|
+
activeIndex,
|
|
5363
|
+
selectedItems
|
|
5364
|
+
} = state; // Refs.
|
|
5365
|
+
|
|
5366
|
+
const isInitialMountRef = react.useRef(true);
|
|
5367
|
+
const dropdownRef = react.useRef(null);
|
|
5368
|
+
const previousSelectedItemsRef = react.useRef(selectedItems);
|
|
5369
|
+
const selectedItemRefs = react.useRef();
|
|
5340
5370
|
selectedItemRefs.current = [];
|
|
5341
|
-
|
|
5342
|
-
state
|
|
5343
|
-
props
|
|
5371
|
+
const latest = useLatestRef({
|
|
5372
|
+
state,
|
|
5373
|
+
props
|
|
5344
5374
|
}); // Effects.
|
|
5345
5375
|
|
|
5346
5376
|
/* Sets a11y status message on changes in selectedItem. */
|
|
5347
5377
|
|
|
5348
|
-
react.useEffect(
|
|
5378
|
+
react.useEffect(() => {
|
|
5349
5379
|
if (isInitialMountRef.current) {
|
|
5350
5380
|
return;
|
|
5351
5381
|
}
|
|
5352
5382
|
|
|
5353
5383
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
5354
|
-
|
|
5355
|
-
return selectedItems.indexOf(item) < 0;
|
|
5356
|
-
});
|
|
5384
|
+
const removedSelectedItem = previousSelectedItemsRef.current.find(item => selectedItems.indexOf(item) < 0);
|
|
5357
5385
|
setStatus(getA11yRemovalMessage({
|
|
5358
|
-
itemToString
|
|
5386
|
+
itemToString,
|
|
5359
5387
|
resultCount: selectedItems.length,
|
|
5360
|
-
removedSelectedItem
|
|
5361
|
-
activeIndex
|
|
5388
|
+
removedSelectedItem,
|
|
5389
|
+
activeIndex,
|
|
5362
5390
|
activeSelectedItem: selectedItems[activeIndex]
|
|
5363
5391
|
}), environment.document);
|
|
5364
5392
|
}
|
|
@@ -5366,7 +5394,7 @@
|
|
|
5366
5394
|
previousSelectedItemsRef.current = selectedItems; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5367
5395
|
}, [selectedItems.length]); // Sets focus on active item.
|
|
5368
5396
|
|
|
5369
|
-
react.useEffect(
|
|
5397
|
+
react.useEffect(() => {
|
|
5370
5398
|
if (isInitialMountRef.current) {
|
|
5371
5399
|
return;
|
|
5372
5400
|
}
|
|
@@ -5379,181 +5407,191 @@
|
|
|
5379
5407
|
}, [activeIndex]);
|
|
5380
5408
|
useControlPropsValidator({
|
|
5381
5409
|
isInitialMount: isInitialMountRef.current,
|
|
5382
|
-
props
|
|
5383
|
-
state
|
|
5410
|
+
props,
|
|
5411
|
+
state
|
|
5384
5412
|
});
|
|
5385
|
-
|
|
5413
|
+
const setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps'); // Make initial ref false.
|
|
5386
5414
|
|
|
5387
|
-
react.useEffect(
|
|
5415
|
+
react.useEffect(() => {
|
|
5388
5416
|
isInitialMountRef.current = false;
|
|
5389
5417
|
}, []); // Event handler functions.
|
|
5390
5418
|
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
5419
|
+
const selectedItemKeyDownHandlers = react.useMemo(() => ({
|
|
5420
|
+
[keyNavigationPrevious]() {
|
|
5395
5421
|
dispatch({
|
|
5396
5422
|
type: SelectedItemKeyDownNavigationPrevious
|
|
5397
5423
|
});
|
|
5398
|
-
},
|
|
5424
|
+
},
|
|
5425
|
+
|
|
5426
|
+
[keyNavigationNext]() {
|
|
5399
5427
|
dispatch({
|
|
5400
5428
|
type: SelectedItemKeyDownNavigationNext
|
|
5401
5429
|
});
|
|
5402
|
-
},
|
|
5430
|
+
},
|
|
5431
|
+
|
|
5432
|
+
Delete() {
|
|
5403
5433
|
dispatch({
|
|
5404
5434
|
type: SelectedItemKeyDownDelete
|
|
5405
5435
|
});
|
|
5406
|
-
},
|
|
5436
|
+
},
|
|
5437
|
+
|
|
5438
|
+
Backspace() {
|
|
5407
5439
|
dispatch({
|
|
5408
5440
|
type: SelectedItemKeyDownBackspace
|
|
5409
5441
|
});
|
|
5410
|
-
}
|
|
5411
|
-
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
5412
|
-
var dropdownKeyDownHandlers = react.useMemo(function () {
|
|
5413
|
-
var _ref2;
|
|
5442
|
+
}
|
|
5414
5443
|
|
|
5415
|
-
|
|
5444
|
+
}), [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
5445
|
+
const dropdownKeyDownHandlers = react.useMemo(() => ({
|
|
5446
|
+
[keyNavigationPrevious](event) {
|
|
5416
5447
|
if (isKeyDownOperationPermitted(event)) {
|
|
5417
5448
|
dispatch({
|
|
5418
5449
|
type: DropdownKeyDownNavigationPrevious
|
|
5419
5450
|
});
|
|
5420
5451
|
}
|
|
5421
|
-
},
|
|
5452
|
+
},
|
|
5453
|
+
|
|
5454
|
+
Backspace(event) {
|
|
5422
5455
|
if (isKeyDownOperationPermitted(event)) {
|
|
5423
5456
|
dispatch({
|
|
5424
5457
|
type: DropdownKeyDownBackspace
|
|
5425
5458
|
});
|
|
5426
5459
|
}
|
|
5427
|
-
}
|
|
5428
|
-
}, [dispatch, keyNavigationPrevious]); // Getter props.
|
|
5429
|
-
|
|
5430
|
-
var getSelectedItemProps = react.useCallback(function (_temp) {
|
|
5431
|
-
var _extends2;
|
|
5432
|
-
|
|
5433
|
-
var _ref3 = _temp === void 0 ? {} : _temp,
|
|
5434
|
-
_ref3$refKey = _ref3.refKey,
|
|
5435
|
-
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
5436
|
-
ref = _ref3.ref,
|
|
5437
|
-
onClick = _ref3.onClick,
|
|
5438
|
-
onKeyDown = _ref3.onKeyDown,
|
|
5439
|
-
selectedItem = _ref3.selectedItem,
|
|
5440
|
-
index = _ref3.index,
|
|
5441
|
-
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
5460
|
+
}
|
|
5442
5461
|
|
|
5443
|
-
|
|
5444
|
-
|
|
5462
|
+
}), [dispatch, keyNavigationPrevious]); // Getter props.
|
|
5463
|
+
|
|
5464
|
+
const getSelectedItemProps = react.useCallback(function (_temp) {
|
|
5465
|
+
let {
|
|
5466
|
+
refKey = 'ref',
|
|
5467
|
+
ref,
|
|
5468
|
+
onClick,
|
|
5469
|
+
onKeyDown,
|
|
5470
|
+
selectedItem,
|
|
5471
|
+
index,
|
|
5472
|
+
...rest
|
|
5473
|
+
} = _temp === void 0 ? {} : _temp;
|
|
5474
|
+
const {
|
|
5475
|
+
state: latestState
|
|
5476
|
+
} = latest.current;
|
|
5477
|
+
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
5445
5478
|
|
|
5446
5479
|
if (itemIndex < 0) {
|
|
5447
5480
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
5448
5481
|
}
|
|
5449
5482
|
|
|
5450
|
-
|
|
5483
|
+
const selectedItemHandleClick = () => {
|
|
5451
5484
|
dispatch({
|
|
5452
5485
|
type: SelectedItemClick,
|
|
5453
|
-
index
|
|
5486
|
+
index
|
|
5454
5487
|
});
|
|
5455
5488
|
};
|
|
5456
5489
|
|
|
5457
|
-
|
|
5458
|
-
|
|
5490
|
+
const selectedItemHandleKeyDown = event => {
|
|
5491
|
+
const key = normalizeArrowKey(event);
|
|
5459
5492
|
|
|
5460
5493
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
5461
5494
|
selectedItemKeyDownHandlers[key](event);
|
|
5462
5495
|
}
|
|
5463
5496
|
};
|
|
5464
5497
|
|
|
5465
|
-
return
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5498
|
+
return {
|
|
5499
|
+
[refKey]: handleRefs(ref, selectedItemNode => {
|
|
5500
|
+
if (selectedItemNode) {
|
|
5501
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
5502
|
+
}
|
|
5503
|
+
}),
|
|
5504
|
+
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
5505
|
+
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
5506
|
+
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
5507
|
+
...rest
|
|
5508
|
+
};
|
|
5470
5509
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
5485
|
-
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
5486
|
-
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
5487
|
-
|
|
5510
|
+
const getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
5511
|
+
let {
|
|
5512
|
+
refKey = 'ref',
|
|
5513
|
+
ref,
|
|
5514
|
+
onKeyDown,
|
|
5515
|
+
onClick,
|
|
5516
|
+
preventKeyAction = false,
|
|
5517
|
+
...rest
|
|
5518
|
+
} = _temp2 === void 0 ? {} : _temp2;
|
|
5519
|
+
let {
|
|
5520
|
+
suppressRefError = false
|
|
5521
|
+
} = _temp3 === void 0 ? {} : _temp3;
|
|
5488
5522
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
5489
5523
|
|
|
5490
|
-
|
|
5491
|
-
|
|
5524
|
+
const dropdownHandleKeyDown = event => {
|
|
5525
|
+
const key = normalizeArrowKey(event);
|
|
5492
5526
|
|
|
5493
5527
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
5494
5528
|
dropdownKeyDownHandlers[key](event);
|
|
5495
5529
|
}
|
|
5496
5530
|
};
|
|
5497
5531
|
|
|
5498
|
-
|
|
5532
|
+
const dropdownHandleClick = () => {
|
|
5499
5533
|
dispatch({
|
|
5500
5534
|
type: DropdownClick
|
|
5501
5535
|
});
|
|
5502
5536
|
};
|
|
5503
5537
|
|
|
5504
|
-
return
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
|
|
5511
|
-
|
|
5538
|
+
return {
|
|
5539
|
+
[refKey]: handleRefs(ref, dropdownNode => {
|
|
5540
|
+
if (dropdownNode) {
|
|
5541
|
+
dropdownRef.current = dropdownNode;
|
|
5542
|
+
}
|
|
5543
|
+
}),
|
|
5544
|
+
...(!preventKeyAction && {
|
|
5545
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
5546
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
5547
|
+
}),
|
|
5548
|
+
...rest
|
|
5549
|
+
};
|
|
5512
5550
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]); // returns
|
|
5513
5551
|
|
|
5514
|
-
|
|
5552
|
+
const addSelectedItem = react.useCallback(selectedItem => {
|
|
5515
5553
|
dispatch({
|
|
5516
5554
|
type: FunctionAddSelectedItem,
|
|
5517
|
-
selectedItem
|
|
5555
|
+
selectedItem
|
|
5518
5556
|
});
|
|
5519
5557
|
}, [dispatch]);
|
|
5520
|
-
|
|
5558
|
+
const removeSelectedItem = react.useCallback(selectedItem => {
|
|
5521
5559
|
dispatch({
|
|
5522
5560
|
type: FunctionRemoveSelectedItem,
|
|
5523
|
-
selectedItem
|
|
5561
|
+
selectedItem
|
|
5524
5562
|
});
|
|
5525
5563
|
}, [dispatch]);
|
|
5526
|
-
|
|
5564
|
+
const setSelectedItems = react.useCallback(newSelectedItems => {
|
|
5527
5565
|
dispatch({
|
|
5528
5566
|
type: FunctionSetSelectedItems,
|
|
5529
5567
|
selectedItems: newSelectedItems
|
|
5530
5568
|
});
|
|
5531
5569
|
}, [dispatch]);
|
|
5532
|
-
|
|
5570
|
+
const setActiveIndex = react.useCallback(newActiveIndex => {
|
|
5533
5571
|
dispatch({
|
|
5534
5572
|
type: FunctionSetActiveIndex,
|
|
5535
5573
|
activeIndex: newActiveIndex
|
|
5536
5574
|
});
|
|
5537
5575
|
}, [dispatch]);
|
|
5538
|
-
|
|
5576
|
+
const reset = react.useCallback(() => {
|
|
5539
5577
|
dispatch({
|
|
5540
5578
|
type: FunctionReset
|
|
5541
5579
|
});
|
|
5542
5580
|
}, [dispatch]);
|
|
5543
5581
|
return {
|
|
5544
|
-
getSelectedItemProps
|
|
5545
|
-
getDropdownProps
|
|
5546
|
-
addSelectedItem
|
|
5547
|
-
removeSelectedItem
|
|
5548
|
-
setSelectedItems
|
|
5549
|
-
setActiveIndex
|
|
5550
|
-
reset
|
|
5551
|
-
selectedItems
|
|
5552
|
-
activeIndex
|
|
5582
|
+
getSelectedItemProps,
|
|
5583
|
+
getDropdownProps,
|
|
5584
|
+
addSelectedItem,
|
|
5585
|
+
removeSelectedItem,
|
|
5586
|
+
setSelectedItems,
|
|
5587
|
+
setActiveIndex,
|
|
5588
|
+
reset,
|
|
5589
|
+
selectedItems,
|
|
5590
|
+
activeIndex
|
|
5553
5591
|
};
|
|
5554
5592
|
}
|
|
5555
5593
|
|
|
5556
|
-
exports[
|
|
5594
|
+
exports["default"] = Downshift$1;
|
|
5557
5595
|
exports.resetIdCounter = resetIdCounter;
|
|
5558
5596
|
exports.useCombobox = useCombobox;
|
|
5559
5597
|
exports.useMultipleSelection = useMultipleSelection;
|
|
@@ -5561,5 +5599,5 @@
|
|
|
5561
5599
|
|
|
5562
5600
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5563
5601
|
|
|
5564
|
-
}))
|
|
5602
|
+
}));
|
|
5565
5603
|
//# sourceMappingURL=downshift.umd.js.map
|