downshift 7.1.3-alpha.1 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +142 -141
- package/dist/downshift.cjs.js +1470 -1578
- package/dist/downshift.esm.js +1467 -1579
- package/dist/downshift.native.cjs.js +1440 -1624
- package/dist/downshift.umd.js +1504 -1571
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +2 -1
- package/preact/dist/downshift.cjs.js +1470 -1578
- package/preact/dist/downshift.esm.js +1467 -1579
- package/preact/dist/downshift.umd.js +1504 -1571
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +9 -1
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.umd.js
CHANGED
|
@@ -4,6 +4,55 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Downshift = {}, global.React));
|
|
5
5
|
})(this, (function (exports, react) { 'use strict';
|
|
6
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
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
13
|
+
key = sourceKeys[i];
|
|
14
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
15
|
+
target[key] = source[key];
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _extends() {
|
|
21
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
22
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
23
|
+
var source = arguments[i];
|
|
24
|
+
for (var key in source) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
26
|
+
target[key] = source[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
return _extends.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function _assertThisInitialized(self) {
|
|
36
|
+
if (self === void 0) {
|
|
37
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
38
|
+
}
|
|
39
|
+
return self;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _setPrototypeOf(o, p) {
|
|
43
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
44
|
+
o.__proto__ = p;
|
|
45
|
+
return o;
|
|
46
|
+
};
|
|
47
|
+
return _setPrototypeOf(o, p);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _inheritsLoose(subClass, superClass) {
|
|
51
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
52
|
+
subClass.prototype.constructor = subClass;
|
|
53
|
+
_setPrototypeOf(subClass, superClass);
|
|
54
|
+
}
|
|
55
|
+
|
|
7
56
|
var propTypes$3 = {exports: {}};
|
|
8
57
|
|
|
9
58
|
var reactIs$1 = {exports: {}};
|
|
@@ -1265,7 +1314,7 @@
|
|
|
1265
1314
|
|
|
1266
1315
|
let e=e=>"object"==typeof e&&null!=e&&1===e.nodeType,t=(e,t)=>(!t||"hidden"!==e)&&("visible"!==e&&"clip"!==e),n=(e,n)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){let l=getComputedStyle(e,null);return t(l.overflowY,n)||t(l.overflowX,n)||(e=>{let t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}})(e);return !!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return !1},l=(e,t,n,l,i,o,r,d)=>o<e&&r>t||o>e&&r<t?0:o<=e&&d<=n||r>=t&&d>=n?o-e-l:r>t&&d<n||o<e&&d>n?r-t+i:0,i=e=>{let t=e.parentElement;return null==t?e.getRootNode().host||null:t};var o=(t,o)=>{var r,d,h,f,u,s;if("undefined"==typeof document)return [];let{scrollMode:a,block:c,inline:g,boundary:m,skipOverflowHiddenElements:p}=o,w="function"==typeof m?m:e=>e!==m;if(!e(t))throw new TypeError("Invalid target");let W=document.scrollingElement||document.documentElement,H=[],b=t;for(;e(b)&&w(b);){if(b=i(b),b===W){H.push(b);break}null!=b&&b===document.body&&n(b)&&!n(document.documentElement)||null!=b&&n(b,p)&&H.push(b);}let v=null!=(d=null==(r=window.visualViewport)?void 0:r.width)?d:innerWidth,y=null!=(f=null==(h=window.visualViewport)?void 0:h.height)?f:innerHeight,E=null!=(u=window.scrollX)?u:pageXOffset,M=null!=(s=window.scrollY)?s:pageYOffset,{height:x,width:I,top:C,right:R,bottom:T,left:V}=t.getBoundingClientRect(),k="start"===c||"nearest"===c?C:"end"===c?T:C+x/2,B="center"===g?V+I/2:"end"===g?R:V,D=[];for(let e=0;e<H.length;e++){let t=H[e],{height:n,width:i,top:o,right:r,bottom:d,left:h}=t.getBoundingClientRect();if("if-needed"===a&&C>=0&&V>=0&&T<=y&&R<=v&&C>=o&&T<=d&&V>=h&&R<=r)return D;let f=getComputedStyle(t),u=parseInt(f.borderLeftWidth,10),s=parseInt(f.borderTopWidth,10),m=parseInt(f.borderRightWidth,10),p=parseInt(f.borderBottomWidth,10),w=0,b=0,O="offsetWidth"in t?t.offsetWidth-t.clientWidth-u-m:0,X="offsetHeight"in t?t.offsetHeight-t.clientHeight-s-p:0,Y="offsetWidth"in t?0===t.offsetWidth?0:i/t.offsetWidth:0,L="offsetHeight"in t?0===t.offsetHeight?0:n/t.offsetHeight:0;if(W===t)w="start"===c?k:"end"===c?k-y:"nearest"===c?l(M,M+y,y,s,p,M+k,M+k+x,x):k-y/2,b="start"===g?B:"center"===g?B-v/2:"end"===g?B-v:l(E,E+v,v,u,m,E+B,E+B+I,I),w=Math.max(0,w+M),b=Math.max(0,b+E);else {w="start"===c?k-o-s:"end"===c?k-d+p+X:"nearest"===c?l(o,d,n,s,p+X,k,k+x,x):k-(o+n/2)+X/2,b="start"===g?B-h-u:"center"===g?B-(h+i/2)+O/2:"end"===g?B-r+m+O:l(h,r,i,u,m+O,B,B+I,I);let{scrollLeft:e,scrollTop:f}=t;w=Math.max(0,Math.min(f+w/L,t.scrollHeight-n/L+X)),b=Math.max(0,Math.min(e+b/Y,t.scrollWidth-i/Y+O)),k+=f-w,B+=e-b;}D.push({el:t,top:w,left:b});}return D};
|
|
1267
1316
|
|
|
1268
|
-
|
|
1317
|
+
var idCounter = 0;
|
|
1269
1318
|
|
|
1270
1319
|
/**
|
|
1271
1320
|
* Accepts a parameter and returns it if it's a function
|
|
@@ -1289,17 +1338,15 @@
|
|
|
1289
1338
|
if (!node) {
|
|
1290
1339
|
return;
|
|
1291
1340
|
}
|
|
1292
|
-
|
|
1341
|
+
var actions = o(node, {
|
|
1293
1342
|
boundary: menuNode,
|
|
1294
1343
|
block: 'nearest',
|
|
1295
1344
|
scrollMode: 'if-needed'
|
|
1296
1345
|
});
|
|
1297
|
-
actions.forEach(_ref
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
left
|
|
1302
|
-
} = _ref;
|
|
1346
|
+
actions.forEach(function (_ref) {
|
|
1347
|
+
var el = _ref.el,
|
|
1348
|
+
top = _ref.top,
|
|
1349
|
+
left = _ref.left;
|
|
1303
1350
|
el.scrollTop = top;
|
|
1304
1351
|
el.scrollLeft = left;
|
|
1305
1352
|
});
|
|
@@ -1312,7 +1359,7 @@
|
|
|
1312
1359
|
* @return {Boolean} whether the parent is the child or the child is in the parent
|
|
1313
1360
|
*/
|
|
1314
1361
|
function isOrContainsNode(parent, child, environment) {
|
|
1315
|
-
|
|
1362
|
+
var result = parent === child || child instanceof environment.Node && parent.contains && parent.contains(child);
|
|
1316
1363
|
return result;
|
|
1317
1364
|
}
|
|
1318
1365
|
|
|
@@ -1325,7 +1372,7 @@
|
|
|
1325
1372
|
* @return {Function} the debounced function
|
|
1326
1373
|
*/
|
|
1327
1374
|
function debounce(fn, time) {
|
|
1328
|
-
|
|
1375
|
+
var timeoutId;
|
|
1329
1376
|
function cancel() {
|
|
1330
1377
|
if (timeoutId) {
|
|
1331
1378
|
clearTimeout(timeoutId);
|
|
@@ -1336,9 +1383,9 @@
|
|
|
1336
1383
|
args[_key] = arguments[_key];
|
|
1337
1384
|
}
|
|
1338
1385
|
cancel();
|
|
1339
|
-
timeoutId = setTimeout(()
|
|
1386
|
+
timeoutId = setTimeout(function () {
|
|
1340
1387
|
timeoutId = null;
|
|
1341
|
-
fn(
|
|
1388
|
+
fn.apply(void 0, args);
|
|
1342
1389
|
}, time);
|
|
1343
1390
|
}
|
|
1344
1391
|
wrapper.cancel = cancel;
|
|
@@ -1360,9 +1407,9 @@
|
|
|
1360
1407
|
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
1361
1408
|
args[_key3 - 1] = arguments[_key3];
|
|
1362
1409
|
}
|
|
1363
|
-
return fns.some(fn
|
|
1410
|
+
return fns.some(function (fn) {
|
|
1364
1411
|
if (fn) {
|
|
1365
|
-
fn(
|
|
1412
|
+
fn.apply(void 0, [event].concat(args));
|
|
1366
1413
|
}
|
|
1367
1414
|
return event.preventDownshiftDefault || event.hasOwnProperty('nativeEvent') && event.nativeEvent.preventDownshiftDefault;
|
|
1368
1415
|
});
|
|
@@ -1372,8 +1419,8 @@
|
|
|
1372
1419
|
for (var _len4 = arguments.length, refs = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1373
1420
|
refs[_key4] = arguments[_key4];
|
|
1374
1421
|
}
|
|
1375
|
-
return node
|
|
1376
|
-
refs.forEach(ref
|
|
1422
|
+
return function (node) {
|
|
1423
|
+
refs.forEach(function (ref) {
|
|
1377
1424
|
if (typeof ref === 'function') {
|
|
1378
1425
|
ref(node);
|
|
1379
1426
|
} else if (ref) {
|
|
@@ -1407,11 +1454,9 @@
|
|
|
1407
1454
|
* @return {String} the a11y status message
|
|
1408
1455
|
*/
|
|
1409
1456
|
function getA11yStatusMessage$1(_ref2) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
previousResultCount
|
|
1414
|
-
} = _ref2;
|
|
1457
|
+
var isOpen = _ref2.isOpen,
|
|
1458
|
+
resultCount = _ref2.resultCount,
|
|
1459
|
+
previousResultCount = _ref2.previousResultCount;
|
|
1415
1460
|
if (!isOpen) {
|
|
1416
1461
|
return '';
|
|
1417
1462
|
}
|
|
@@ -1419,7 +1464,7 @@
|
|
|
1419
1464
|
return 'No results are available.';
|
|
1420
1465
|
}
|
|
1421
1466
|
if (resultCount !== previousResultCount) {
|
|
1422
|
-
return
|
|
1467
|
+
return resultCount + " result" + (resultCount === 1 ? ' is' : 's are') + " available, use up and down arrow keys to navigate. Press Enter key to select.";
|
|
1423
1468
|
}
|
|
1424
1469
|
return '';
|
|
1425
1470
|
}
|
|
@@ -1466,9 +1511,9 @@
|
|
|
1466
1511
|
*/
|
|
1467
1512
|
function requiredProp(fnName, propName) {
|
|
1468
1513
|
// eslint-disable-next-line no-console
|
|
1469
|
-
console.error(
|
|
1514
|
+
console.error("The property \"" + propName + "\" is required in \"" + fnName + "\"");
|
|
1470
1515
|
}
|
|
1471
|
-
|
|
1516
|
+
var stateKeys = ['highlightedIndex', 'inputValue', 'isOpen', 'selectedItem', 'type'];
|
|
1472
1517
|
/**
|
|
1473
1518
|
* @param {Object} state the state object
|
|
1474
1519
|
* @return {Object} state that is relevant to downshift
|
|
@@ -1477,8 +1522,8 @@
|
|
|
1477
1522
|
if (state === void 0) {
|
|
1478
1523
|
state = {};
|
|
1479
1524
|
}
|
|
1480
|
-
|
|
1481
|
-
stateKeys.forEach(k
|
|
1525
|
+
var result = {};
|
|
1526
|
+
stateKeys.forEach(function (k) {
|
|
1482
1527
|
if (state.hasOwnProperty(k)) {
|
|
1483
1528
|
result[k] = state[k];
|
|
1484
1529
|
}
|
|
@@ -1498,7 +1543,7 @@
|
|
|
1498
1543
|
* @returns {Object} The merged controlled state.
|
|
1499
1544
|
*/
|
|
1500
1545
|
function getState(state, props) {
|
|
1501
|
-
return Object.keys(state).reduce((prevState, key)
|
|
1546
|
+
return Object.keys(state).reduce(function (prevState, key) {
|
|
1502
1547
|
prevState[key] = isControlledProp(props, key) ? props[key] : state[key];
|
|
1503
1548
|
return prevState;
|
|
1504
1549
|
}, {});
|
|
@@ -1523,13 +1568,11 @@
|
|
|
1523
1568
|
* @return {String} keyboard key
|
|
1524
1569
|
*/
|
|
1525
1570
|
function normalizeArrowKey(event) {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
keyCode
|
|
1529
|
-
} = event;
|
|
1571
|
+
var key = event.key,
|
|
1572
|
+
keyCode = event.keyCode;
|
|
1530
1573
|
/* istanbul ignore next (ie) */
|
|
1531
1574
|
if (keyCode >= 37 && keyCode <= 40 && key.indexOf('Arrow') !== 0) {
|
|
1532
|
-
return
|
|
1575
|
+
return "Arrow" + key;
|
|
1533
1576
|
}
|
|
1534
1577
|
return key;
|
|
1535
1578
|
}
|
|
@@ -1561,17 +1604,17 @@
|
|
|
1561
1604
|
if (itemCount === 0) {
|
|
1562
1605
|
return -1;
|
|
1563
1606
|
}
|
|
1564
|
-
|
|
1607
|
+
var itemsLastIndex = itemCount - 1;
|
|
1565
1608
|
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
|
|
1566
1609
|
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
|
|
1567
1610
|
}
|
|
1568
|
-
|
|
1611
|
+
var newIndex = baseIndex + moveAmount;
|
|
1569
1612
|
if (newIndex < 0) {
|
|
1570
1613
|
newIndex = circular ? itemsLastIndex : 0;
|
|
1571
1614
|
} else if (newIndex > itemsLastIndex) {
|
|
1572
1615
|
newIndex = circular ? 0 : itemsLastIndex;
|
|
1573
1616
|
}
|
|
1574
|
-
|
|
1617
|
+
var nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
|
|
1575
1618
|
if (nonDisabledNewIndex === -1) {
|
|
1576
1619
|
return baseIndex >= itemCount ? -1 : baseIndex;
|
|
1577
1620
|
}
|
|
@@ -1589,20 +1632,20 @@
|
|
|
1589
1632
|
* @returns {number} The new index. Returns baseIndex if item is not disabled. Returns next non-disabled item otherwise. If no non-disabled found it will return -1.
|
|
1590
1633
|
*/
|
|
1591
1634
|
function getNextNonDisabledIndex(moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular) {
|
|
1592
|
-
|
|
1635
|
+
var currentElementNode = getItemNodeFromIndex(baseIndex);
|
|
1593
1636
|
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
|
|
1594
1637
|
return baseIndex;
|
|
1595
1638
|
}
|
|
1596
1639
|
if (moveAmount > 0) {
|
|
1597
|
-
for (
|
|
1640
|
+
for (var index = baseIndex + 1; index < itemCount; index++) {
|
|
1598
1641
|
if (!getItemNodeFromIndex(index).hasAttribute('disabled')) {
|
|
1599
1642
|
return index;
|
|
1600
1643
|
}
|
|
1601
1644
|
}
|
|
1602
1645
|
} else {
|
|
1603
|
-
for (
|
|
1604
|
-
if (!getItemNodeFromIndex(
|
|
1605
|
-
return
|
|
1646
|
+
for (var _index = baseIndex - 1; _index >= 0; _index--) {
|
|
1647
|
+
if (!getItemNodeFromIndex(_index).hasAttribute('disabled')) {
|
|
1648
|
+
return _index;
|
|
1606
1649
|
}
|
|
1607
1650
|
}
|
|
1608
1651
|
}
|
|
@@ -1626,28 +1669,30 @@
|
|
|
1626
1669
|
if (checkActiveElement === void 0) {
|
|
1627
1670
|
checkActiveElement = true;
|
|
1628
1671
|
}
|
|
1629
|
-
return downshiftElements.some(
|
|
1672
|
+
return downshiftElements.some(function (contextNode) {
|
|
1673
|
+
return contextNode && (isOrContainsNode(contextNode, target, environment) || checkActiveElement && isOrContainsNode(contextNode, environment.document.activeElement, environment));
|
|
1674
|
+
});
|
|
1630
1675
|
}
|
|
1631
1676
|
|
|
1632
1677
|
// eslint-disable-next-line import/no-mutable-exports
|
|
1633
|
-
|
|
1678
|
+
var validateControlledUnchanged = noop;
|
|
1634
1679
|
/* istanbul ignore next */
|
|
1635
1680
|
{
|
|
1636
|
-
validateControlledUnchanged = (state, prevProps, nextProps)
|
|
1637
|
-
|
|
1638
|
-
Object.keys(state).forEach(propKey
|
|
1681
|
+
validateControlledUnchanged = function validateControlledUnchanged(state, prevProps, nextProps) {
|
|
1682
|
+
var warningDescription = "This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props";
|
|
1683
|
+
Object.keys(state).forEach(function (propKey) {
|
|
1639
1684
|
if (prevProps[propKey] !== undefined && nextProps[propKey] === undefined) {
|
|
1640
1685
|
// eslint-disable-next-line no-console
|
|
1641
|
-
console.error(
|
|
1686
|
+
console.error("downshift: A component has changed the controlled prop \"" + propKey + "\" to be uncontrolled. " + warningDescription);
|
|
1642
1687
|
} else if (prevProps[propKey] === undefined && nextProps[propKey] !== undefined) {
|
|
1643
1688
|
// eslint-disable-next-line no-console
|
|
1644
|
-
console.error(
|
|
1689
|
+
console.error("downshift: A component has changed the uncontrolled prop \"" + propKey + "\" to be controlled. " + warningDescription);
|
|
1645
1690
|
}
|
|
1646
1691
|
});
|
|
1647
1692
|
};
|
|
1648
1693
|
}
|
|
1649
1694
|
|
|
1650
|
-
|
|
1695
|
+
var cleanupStatus = debounce(function (documentProp) {
|
|
1651
1696
|
getStatusDiv(documentProp).textContent = '';
|
|
1652
1697
|
}, 500);
|
|
1653
1698
|
|
|
@@ -1656,7 +1701,7 @@
|
|
|
1656
1701
|
* @param {Object} documentProp document passed by the user.
|
|
1657
1702
|
*/
|
|
1658
1703
|
function setStatus(status, documentProp) {
|
|
1659
|
-
|
|
1704
|
+
var div = getStatusDiv(documentProp);
|
|
1660
1705
|
if (!status) {
|
|
1661
1706
|
return;
|
|
1662
1707
|
}
|
|
@@ -1673,7 +1718,7 @@
|
|
|
1673
1718
|
if (documentProp === void 0) {
|
|
1674
1719
|
documentProp = document;
|
|
1675
1720
|
}
|
|
1676
|
-
|
|
1721
|
+
var statusDiv = documentProp.getElementById('a11y-status-message');
|
|
1677
1722
|
if (statusDiv) {
|
|
1678
1723
|
return statusDiv;
|
|
1679
1724
|
}
|
|
@@ -1696,23 +1741,23 @@
|
|
|
1696
1741
|
return statusDiv;
|
|
1697
1742
|
}
|
|
1698
1743
|
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1744
|
+
var unknown = '__autocomplete_unknown__' ;
|
|
1745
|
+
var mouseUp = '__autocomplete_mouseup__' ;
|
|
1746
|
+
var itemMouseEnter = '__autocomplete_item_mouseenter__' ;
|
|
1747
|
+
var keyDownArrowUp = '__autocomplete_keydown_arrow_up__' ;
|
|
1748
|
+
var keyDownArrowDown = '__autocomplete_keydown_arrow_down__' ;
|
|
1749
|
+
var keyDownEscape = '__autocomplete_keydown_escape__' ;
|
|
1750
|
+
var keyDownEnter = '__autocomplete_keydown_enter__' ;
|
|
1751
|
+
var keyDownHome = '__autocomplete_keydown_home__' ;
|
|
1752
|
+
var keyDownEnd = '__autocomplete_keydown_end__' ;
|
|
1753
|
+
var clickItem = '__autocomplete_click_item__' ;
|
|
1754
|
+
var blurInput = '__autocomplete_blur_input__' ;
|
|
1755
|
+
var changeInput = '__autocomplete_change_input__' ;
|
|
1756
|
+
var keyDownSpaceButton = '__autocomplete_keydown_space_button__' ;
|
|
1757
|
+
var clickButton = '__autocomplete_click_button__' ;
|
|
1758
|
+
var blurButton = '__autocomplete_blur_button__' ;
|
|
1759
|
+
var controlledPropUpdatedSelectedItem = '__autocomplete_controlled_prop_updated_selected_item__' ;
|
|
1760
|
+
var touchEnd = '__autocomplete_touchend__' ;
|
|
1716
1761
|
|
|
1717
1762
|
var stateChangeTypes$3 = /*#__PURE__*/Object.freeze({
|
|
1718
1763
|
__proto__: null,
|
|
@@ -1735,37 +1780,57 @@
|
|
|
1735
1780
|
touchEnd: touchEnd
|
|
1736
1781
|
});
|
|
1737
1782
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1783
|
+
var _excluded$4 = ["refKey", "ref"],
|
|
1784
|
+
_excluded2$3 = ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"],
|
|
1785
|
+
_excluded3$2 = ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"],
|
|
1786
|
+
_excluded4$1 = ["refKey", "ref"],
|
|
1787
|
+
_excluded5 = ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"];
|
|
1788
|
+
var Downshift = /*#__PURE__*/function () {
|
|
1789
|
+
var Downshift = /*#__PURE__*/function (_Component) {
|
|
1790
|
+
_inheritsLoose(Downshift, _Component);
|
|
1791
|
+
function Downshift(_props) {
|
|
1742
1792
|
var _this;
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
this
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1793
|
+
_this = _Component.call(this, _props) || this;
|
|
1794
|
+
// fancy destructuring + defaults + aliases
|
|
1795
|
+
// this basically says each value of state should either be set to
|
|
1796
|
+
// the initial value or the default value if the initial value is not provided
|
|
1797
|
+
_this.id = _this.props.id || "downshift-" + generateId();
|
|
1798
|
+
_this.menuId = _this.props.menuId || _this.id + "-menu";
|
|
1799
|
+
_this.labelId = _this.props.labelId || _this.id + "-label";
|
|
1800
|
+
_this.inputId = _this.props.inputId || _this.id + "-input";
|
|
1801
|
+
_this.getItemId = _this.props.getItemId || function (index) {
|
|
1802
|
+
return _this.id + "-item-" + index;
|
|
1803
|
+
};
|
|
1804
|
+
_this.input = null;
|
|
1805
|
+
_this.items = [];
|
|
1806
|
+
// itemCount can be changed asynchronously
|
|
1807
|
+
// from within downshift (so it can't come from a prop)
|
|
1808
|
+
// this is why we store it as an instance and use
|
|
1809
|
+
// getItemCount rather than just use items.length
|
|
1810
|
+
// (to support windowing + async)
|
|
1811
|
+
_this.itemCount = null;
|
|
1812
|
+
_this.previousResultCount = 0;
|
|
1813
|
+
_this.timeoutIds = [];
|
|
1814
|
+
/**
|
|
1815
|
+
* @param {Function} fn the function to call after the time
|
|
1816
|
+
* @param {Number} time the time to wait
|
|
1817
|
+
*/
|
|
1818
|
+
_this.internalSetTimeout = function (fn, time) {
|
|
1819
|
+
var id = setTimeout(function () {
|
|
1820
|
+
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
1821
|
+
return i !== id;
|
|
1822
|
+
});
|
|
1758
1823
|
fn();
|
|
1759
1824
|
}, time);
|
|
1760
|
-
|
|
1825
|
+
_this.timeoutIds.push(id);
|
|
1761
1826
|
};
|
|
1762
|
-
|
|
1763
|
-
|
|
1827
|
+
_this.setItemCount = function (count) {
|
|
1828
|
+
_this.itemCount = count;
|
|
1764
1829
|
};
|
|
1765
|
-
|
|
1766
|
-
|
|
1830
|
+
_this.unsetItemCount = function () {
|
|
1831
|
+
_this.itemCount = null;
|
|
1767
1832
|
};
|
|
1768
|
-
|
|
1833
|
+
_this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
1769
1834
|
if (highlightedIndex === void 0) {
|
|
1770
1835
|
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
1771
1836
|
}
|
|
@@ -1773,43 +1838,49 @@
|
|
|
1773
1838
|
otherStateToSet = {};
|
|
1774
1839
|
}
|
|
1775
1840
|
otherStateToSet = pickState(otherStateToSet);
|
|
1776
|
-
_this.internalSetState({
|
|
1777
|
-
highlightedIndex
|
|
1778
|
-
|
|
1779
|
-
});
|
|
1841
|
+
_this.internalSetState(_extends({
|
|
1842
|
+
highlightedIndex: highlightedIndex
|
|
1843
|
+
}, otherStateToSet));
|
|
1780
1844
|
};
|
|
1781
|
-
|
|
1782
|
-
|
|
1845
|
+
_this.clearSelection = function (cb) {
|
|
1846
|
+
_this.internalSetState({
|
|
1783
1847
|
selectedItem: null,
|
|
1784
1848
|
inputValue: '',
|
|
1785
|
-
highlightedIndex:
|
|
1786
|
-
isOpen:
|
|
1849
|
+
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1850
|
+
isOpen: _this.props.defaultIsOpen
|
|
1787
1851
|
}, cb);
|
|
1788
1852
|
};
|
|
1789
|
-
|
|
1853
|
+
_this.selectItem = function (item, otherStateToSet, cb) {
|
|
1790
1854
|
otherStateToSet = pickState(otherStateToSet);
|
|
1791
|
-
|
|
1792
|
-
isOpen:
|
|
1793
|
-
highlightedIndex:
|
|
1855
|
+
_this.internalSetState(_extends({
|
|
1856
|
+
isOpen: _this.props.defaultIsOpen,
|
|
1857
|
+
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1794
1858
|
selectedItem: item,
|
|
1795
|
-
inputValue:
|
|
1796
|
-
|
|
1797
|
-
}, cb);
|
|
1859
|
+
inputValue: _this.props.itemToString(item)
|
|
1860
|
+
}, otherStateToSet), cb);
|
|
1798
1861
|
};
|
|
1799
|
-
|
|
1800
|
-
|
|
1862
|
+
_this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
|
|
1863
|
+
var item = _this.items[itemIndex];
|
|
1801
1864
|
if (item == null) {
|
|
1802
1865
|
return;
|
|
1803
1866
|
}
|
|
1804
|
-
|
|
1867
|
+
_this.selectItem(item, otherStateToSet, cb);
|
|
1805
1868
|
};
|
|
1806
|
-
|
|
1807
|
-
return
|
|
1869
|
+
_this.selectHighlightedItem = function (otherStateToSet, cb) {
|
|
1870
|
+
return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
|
1808
1871
|
};
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1872
|
+
// any piece of our state can live in two places:
|
|
1873
|
+
// 1. Uncontrolled: it's internal (this.state)
|
|
1874
|
+
// We will call this.setState to update that state
|
|
1875
|
+
// 2. Controlled: it's external (this.props)
|
|
1876
|
+
// We will call this.props.onStateChange to update that state
|
|
1877
|
+
//
|
|
1878
|
+
// In addition, we'll call this.props.onChange if the
|
|
1879
|
+
// selectedItem is changed.
|
|
1880
|
+
_this.internalSetState = function (stateToSet, cb) {
|
|
1881
|
+
var isItemSelected, onChangeArg;
|
|
1882
|
+
var onStateChangeArg = {};
|
|
1883
|
+
var isStateToSetFunction = typeof stateToSet === 'function';
|
|
1813
1884
|
|
|
1814
1885
|
// we want to call `onInputValueChange` before the `setState` call
|
|
1815
1886
|
// so someone controlling the `inputValue` state gets notified of
|
|
@@ -1817,24 +1888,21 @@
|
|
|
1817
1888
|
// preserving the cursor position.
|
|
1818
1889
|
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
1819
1890
|
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
1820
|
-
|
|
1821
|
-
...this.getStateAndHelpers(),
|
|
1822
|
-
...stateToSet
|
|
1823
|
-
});
|
|
1891
|
+
_this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), stateToSet));
|
|
1824
1892
|
}
|
|
1825
|
-
return
|
|
1826
|
-
state =
|
|
1827
|
-
|
|
1893
|
+
return _this.setState(function (state) {
|
|
1894
|
+
state = _this.getState(state);
|
|
1895
|
+
var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet;
|
|
1828
1896
|
|
|
1829
1897
|
// Your own function that could modify the state that will be set.
|
|
1830
|
-
newStateToSet =
|
|
1898
|
+
newStateToSet = _this.props.stateReducer(state, newStateToSet);
|
|
1831
1899
|
|
|
1832
1900
|
// checks if an item is selected, regardless of if it's different from
|
|
1833
1901
|
// what was selected before
|
|
1834
1902
|
// used to determine if onSelect and onChange callbacks should be called
|
|
1835
1903
|
isItemSelected = newStateToSet.hasOwnProperty('selectedItem');
|
|
1836
1904
|
// this keeps track of the object we want to call with setState
|
|
1837
|
-
|
|
1905
|
+
var nextState = {};
|
|
1838
1906
|
// we need to call on change if the outside world is controlling any of our state
|
|
1839
1907
|
// and we're trying to update that state. OR if the selection has changed and we're
|
|
1840
1908
|
// trying to update the selection
|
|
@@ -1842,7 +1910,7 @@
|
|
|
1842
1910
|
onChangeArg = newStateToSet.selectedItem;
|
|
1843
1911
|
}
|
|
1844
1912
|
newStateToSet.type = newStateToSet.type || unknown;
|
|
1845
|
-
Object.keys(newStateToSet).forEach(key
|
|
1913
|
+
Object.keys(newStateToSet).forEach(function (key) {
|
|
1846
1914
|
// onStateChangeArg should only have the state that is
|
|
1847
1915
|
// actually changing
|
|
1848
1916
|
if (state[key] !== newStateToSet[key]) {
|
|
@@ -1859,7 +1927,7 @@
|
|
|
1859
1927
|
}
|
|
1860
1928
|
newStateToSet[key];
|
|
1861
1929
|
// if it's coming from props, then we don't care to set it internally
|
|
1862
|
-
if (!isControlledProp(
|
|
1930
|
+
if (!isControlledProp(_this.props, key)) {
|
|
1863
1931
|
nextState[key] = newStateToSet[key];
|
|
1864
1932
|
}
|
|
1865
1933
|
});
|
|
@@ -1867,66 +1935,60 @@
|
|
|
1867
1935
|
// if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
1868
1936
|
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
1869
1937
|
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
1870
|
-
|
|
1871
|
-
...this.getStateAndHelpers(),
|
|
1872
|
-
...newStateToSet
|
|
1873
|
-
});
|
|
1938
|
+
_this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), newStateToSet));
|
|
1874
1939
|
}
|
|
1875
1940
|
return nextState;
|
|
1876
|
-
}, ()
|
|
1941
|
+
}, function () {
|
|
1877
1942
|
// call the provided callback if it's a function
|
|
1878
1943
|
cbToCb(cb)();
|
|
1879
1944
|
|
|
1880
1945
|
// only call the onStateChange and onChange callbacks if
|
|
1881
1946
|
// we have relevant information to pass them.
|
|
1882
|
-
|
|
1947
|
+
var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
1883
1948
|
if (hasMoreStateThanType) {
|
|
1884
|
-
|
|
1949
|
+
_this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
|
|
1885
1950
|
}
|
|
1886
1951
|
if (isItemSelected) {
|
|
1887
|
-
|
|
1952
|
+
_this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
|
|
1888
1953
|
}
|
|
1889
1954
|
if (onChangeArg !== undefined) {
|
|
1890
|
-
|
|
1955
|
+
_this.props.onChange(onChangeArg, _this.getStateAndHelpers());
|
|
1891
1956
|
}
|
|
1892
1957
|
// this is currently undocumented and therefore subject to change
|
|
1893
1958
|
// We'll try to not break it, but just be warned.
|
|
1894
|
-
|
|
1959
|
+
_this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
|
1895
1960
|
});
|
|
1896
1961
|
};
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1962
|
+
//////////////////////////// ROOT
|
|
1963
|
+
_this.rootRef = function (node) {
|
|
1964
|
+
return _this._rootNode = node;
|
|
1965
|
+
};
|
|
1966
|
+
_this.getRootProps = function (_temp, _temp2) {
|
|
1967
|
+
var _extends2;
|
|
1968
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
1969
|
+
_ref$refKey = _ref.refKey,
|
|
1970
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
1971
|
+
ref = _ref.ref,
|
|
1972
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
1973
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
1974
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
1975
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
1907
1976
|
// this is used in the render to know whether the user has called getRootProps.
|
|
1908
1977
|
// It uses that to know whether to apply the props automatically
|
|
1909
1978
|
_this.getRootProps.called = true;
|
|
1910
1979
|
_this.getRootProps.refKey = refKey;
|
|
1911
1980
|
_this.getRootProps.suppressRefError = suppressRefError;
|
|
1912
|
-
|
|
1913
|
-
isOpen
|
|
1914
|
-
} = _this.
|
|
1915
|
-
return {
|
|
1916
|
-
[refKey]: handleRefs(ref, _this.rootRef),
|
|
1917
|
-
role: 'combobox',
|
|
1918
|
-
'aria-expanded': isOpen,
|
|
1919
|
-
'aria-haspopup': 'listbox',
|
|
1920
|
-
'aria-owns': isOpen ? _this.menuId : null,
|
|
1921
|
-
'aria-labelledby': _this.labelId,
|
|
1922
|
-
...rest
|
|
1923
|
-
};
|
|
1981
|
+
var _this$getState = _this.getState(),
|
|
1982
|
+
isOpen = _this$getState.isOpen;
|
|
1983
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
|
|
1924
1984
|
};
|
|
1925
|
-
|
|
1926
|
-
|
|
1985
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\ ROOT
|
|
1986
|
+
_this.keyDownHandlers = {
|
|
1987
|
+
ArrowDown: function ArrowDown(event) {
|
|
1988
|
+
var _this2 = this;
|
|
1927
1989
|
event.preventDefault();
|
|
1928
1990
|
if (this.getState().isOpen) {
|
|
1929
|
-
|
|
1991
|
+
var amount = event.shiftKey ? 5 : 1;
|
|
1930
1992
|
this.moveHighlightedIndex(amount, {
|
|
1931
1993
|
type: keyDownArrowDown
|
|
1932
1994
|
});
|
|
@@ -1934,24 +1996,26 @@
|
|
|
1934
1996
|
this.internalSetState({
|
|
1935
1997
|
isOpen: true,
|
|
1936
1998
|
type: keyDownArrowDown
|
|
1937
|
-
}, ()
|
|
1938
|
-
|
|
1999
|
+
}, function () {
|
|
2000
|
+
var itemCount = _this2.getItemCount();
|
|
1939
2001
|
if (itemCount > 0) {
|
|
1940
|
-
|
|
1941
|
-
highlightedIndex
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2002
|
+
var _this2$getState = _this2.getState(),
|
|
2003
|
+
highlightedIndex = _this2$getState.highlightedIndex;
|
|
2004
|
+
var nextHighlightedIndex = getNextWrappingIndex(1, highlightedIndex, itemCount, function (index) {
|
|
2005
|
+
return _this2.getItemNodeFromIndex(index);
|
|
2006
|
+
});
|
|
2007
|
+
_this2.setHighlightedIndex(nextHighlightedIndex, {
|
|
1945
2008
|
type: keyDownArrowDown
|
|
1946
2009
|
});
|
|
1947
2010
|
}
|
|
1948
2011
|
});
|
|
1949
2012
|
}
|
|
1950
2013
|
},
|
|
1951
|
-
ArrowUp(event) {
|
|
2014
|
+
ArrowUp: function ArrowUp(event) {
|
|
2015
|
+
var _this3 = this;
|
|
1952
2016
|
event.preventDefault();
|
|
1953
2017
|
if (this.getState().isOpen) {
|
|
1954
|
-
|
|
2018
|
+
var amount = event.shiftKey ? -5 : -1;
|
|
1955
2019
|
this.moveHighlightedIndex(amount, {
|
|
1956
2020
|
type: keyDownArrowUp
|
|
1957
2021
|
});
|
|
@@ -1959,32 +2023,32 @@
|
|
|
1959
2023
|
this.internalSetState({
|
|
1960
2024
|
isOpen: true,
|
|
1961
2025
|
type: keyDownArrowUp
|
|
1962
|
-
}, ()
|
|
1963
|
-
|
|
2026
|
+
}, function () {
|
|
2027
|
+
var itemCount = _this3.getItemCount();
|
|
1964
2028
|
if (itemCount > 0) {
|
|
1965
|
-
|
|
1966
|
-
highlightedIndex
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
2029
|
+
var _this3$getState = _this3.getState(),
|
|
2030
|
+
highlightedIndex = _this3$getState.highlightedIndex;
|
|
2031
|
+
var nextHighlightedIndex = getNextWrappingIndex(-1, highlightedIndex, itemCount, function (index) {
|
|
2032
|
+
return _this3.getItemNodeFromIndex(index);
|
|
2033
|
+
});
|
|
2034
|
+
_this3.setHighlightedIndex(nextHighlightedIndex, {
|
|
1970
2035
|
type: keyDownArrowUp
|
|
1971
2036
|
});
|
|
1972
2037
|
}
|
|
1973
2038
|
});
|
|
1974
2039
|
}
|
|
1975
2040
|
},
|
|
1976
|
-
Enter(event) {
|
|
2041
|
+
Enter: function Enter(event) {
|
|
1977
2042
|
if (event.which === 229) {
|
|
1978
2043
|
return;
|
|
1979
2044
|
}
|
|
1980
|
-
|
|
1981
|
-
isOpen,
|
|
1982
|
-
highlightedIndex
|
|
1983
|
-
} = this.getState();
|
|
2045
|
+
var _this$getState2 = this.getState(),
|
|
2046
|
+
isOpen = _this$getState2.isOpen,
|
|
2047
|
+
highlightedIndex = _this$getState2.highlightedIndex;
|
|
1984
2048
|
if (isOpen && highlightedIndex != null) {
|
|
1985
2049
|
event.preventDefault();
|
|
1986
|
-
|
|
1987
|
-
|
|
2050
|
+
var item = this.items[highlightedIndex];
|
|
2051
|
+
var itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
1988
2052
|
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
1989
2053
|
return;
|
|
1990
2054
|
}
|
|
@@ -1993,112 +2057,110 @@
|
|
|
1993
2057
|
});
|
|
1994
2058
|
}
|
|
1995
2059
|
},
|
|
1996
|
-
Escape(event) {
|
|
2060
|
+
Escape: function Escape(event) {
|
|
1997
2061
|
event.preventDefault();
|
|
1998
|
-
this.reset({
|
|
1999
|
-
type: keyDownEscape
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
});
|
|
2062
|
+
this.reset(_extends({
|
|
2063
|
+
type: keyDownEscape
|
|
2064
|
+
}, !this.state.isOpen && {
|
|
2065
|
+
selectedItem: null,
|
|
2066
|
+
inputValue: ''
|
|
2067
|
+
}));
|
|
2005
2068
|
}
|
|
2006
2069
|
};
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
' '(event) {
|
|
2070
|
+
//////////////////////////// BUTTON
|
|
2071
|
+
_this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2072
|
+
' ': function _(event) {
|
|
2010
2073
|
event.preventDefault();
|
|
2011
2074
|
this.toggleMenu({
|
|
2012
2075
|
type: keyDownSpaceButton
|
|
2013
2076
|
});
|
|
2014
2077
|
}
|
|
2015
|
-
};
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
isOpen
|
|
2021
|
-
} = this.getState();
|
|
2078
|
+
});
|
|
2079
|
+
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2080
|
+
Home: function Home(event) {
|
|
2081
|
+
var _this4 = this;
|
|
2082
|
+
var _this$getState3 = this.getState(),
|
|
2083
|
+
isOpen = _this$getState3.isOpen;
|
|
2022
2084
|
if (!isOpen) {
|
|
2023
2085
|
return;
|
|
2024
2086
|
}
|
|
2025
2087
|
event.preventDefault();
|
|
2026
|
-
|
|
2088
|
+
var itemCount = this.getItemCount();
|
|
2027
2089
|
if (itemCount <= 0 || !isOpen) {
|
|
2028
2090
|
return;
|
|
2029
2091
|
}
|
|
2030
2092
|
|
|
2031
2093
|
// get next non-disabled starting downwards from 0 if that's disabled.
|
|
2032
|
-
|
|
2094
|
+
var newHighlightedIndex = getNextNonDisabledIndex(1, 0, itemCount, function (index) {
|
|
2095
|
+
return _this4.getItemNodeFromIndex(index);
|
|
2096
|
+
}, false);
|
|
2033
2097
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
2034
2098
|
type: keyDownHome
|
|
2035
2099
|
});
|
|
2036
2100
|
},
|
|
2037
|
-
End(event) {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2101
|
+
End: function End(event) {
|
|
2102
|
+
var _this5 = this;
|
|
2103
|
+
var _this$getState4 = this.getState(),
|
|
2104
|
+
isOpen = _this$getState4.isOpen;
|
|
2041
2105
|
if (!isOpen) {
|
|
2042
2106
|
return;
|
|
2043
2107
|
}
|
|
2044
2108
|
event.preventDefault();
|
|
2045
|
-
|
|
2109
|
+
var itemCount = this.getItemCount();
|
|
2046
2110
|
if (itemCount <= 0 || !isOpen) {
|
|
2047
2111
|
return;
|
|
2048
2112
|
}
|
|
2049
2113
|
|
|
2050
2114
|
// get next non-disabled starting upwards from last index if that's disabled.
|
|
2051
|
-
|
|
2115
|
+
var newHighlightedIndex = getNextNonDisabledIndex(-1, itemCount - 1, itemCount, function (index) {
|
|
2116
|
+
return _this5.getItemNodeFromIndex(index);
|
|
2117
|
+
}, false);
|
|
2052
2118
|
this.setHighlightedIndex(newHighlightedIndex, {
|
|
2053
2119
|
type: keyDownEnd
|
|
2054
2120
|
});
|
|
2055
2121
|
}
|
|
2056
|
-
};
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
onClick
|
|
2060
|
-
onPress
|
|
2061
|
-
onKeyDown,
|
|
2062
|
-
onKeyUp,
|
|
2063
|
-
onBlur,
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
} = _this.getState();
|
|
2069
|
-
const enabledEventHandlers = {
|
|
2122
|
+
});
|
|
2123
|
+
_this.getToggleButtonProps = function (_temp3) {
|
|
2124
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
2125
|
+
onClick = _ref3.onClick;
|
|
2126
|
+
_ref3.onPress;
|
|
2127
|
+
var onKeyDown = _ref3.onKeyDown,
|
|
2128
|
+
onKeyUp = _ref3.onKeyUp,
|
|
2129
|
+
onBlur = _ref3.onBlur,
|
|
2130
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$3);
|
|
2131
|
+
var _this$getState5 = _this.getState(),
|
|
2132
|
+
isOpen = _this$getState5.isOpen;
|
|
2133
|
+
var enabledEventHandlers = {
|
|
2070
2134
|
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
2071
2135
|
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
2072
2136
|
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
2073
2137
|
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
2074
2138
|
};
|
|
2075
|
-
|
|
2076
|
-
return {
|
|
2139
|
+
var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
2140
|
+
return _extends({
|
|
2077
2141
|
type: 'button',
|
|
2078
2142
|
role: 'button',
|
|
2079
2143
|
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
2080
2144
|
'aria-haspopup': true,
|
|
2081
|
-
'data-toggle': true
|
|
2082
|
-
|
|
2083
|
-
...rest
|
|
2084
|
-
};
|
|
2145
|
+
'data-toggle': true
|
|
2146
|
+
}, eventHandlers, rest);
|
|
2085
2147
|
};
|
|
2086
|
-
|
|
2148
|
+
_this.buttonHandleKeyUp = function (event) {
|
|
2087
2149
|
// Prevent click event from emitting in Firefox
|
|
2088
2150
|
event.preventDefault();
|
|
2089
2151
|
};
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
if (
|
|
2093
|
-
|
|
2152
|
+
_this.buttonHandleKeyDown = function (event) {
|
|
2153
|
+
var key = normalizeArrowKey(event);
|
|
2154
|
+
if (_this.buttonKeyDownHandlers[key]) {
|
|
2155
|
+
_this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
|
2094
2156
|
}
|
|
2095
2157
|
};
|
|
2096
|
-
|
|
2158
|
+
_this.buttonHandleClick = function (event) {
|
|
2097
2159
|
event.preventDefault();
|
|
2098
2160
|
// handle odd case for Safari and Firefox which
|
|
2099
2161
|
// don't give the button the focus properly.
|
|
2100
2162
|
/* istanbul ignore if (can't reasonably test this) */
|
|
2101
|
-
if (
|
|
2163
|
+
if (_this.props.environment.document.activeElement === _this.props.environment.document.body) {
|
|
2102
2164
|
event.target.focus();
|
|
2103
2165
|
}
|
|
2104
2166
|
// to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
@@ -2106,59 +2168,59 @@
|
|
|
2106
2168
|
// when building for production and should therefore have no impact on production code.
|
|
2107
2169
|
{
|
|
2108
2170
|
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2171
|
+
_this.internalSetTimeout(function () {
|
|
2172
|
+
return _this.toggleMenu({
|
|
2173
|
+
type: clickButton
|
|
2174
|
+
});
|
|
2175
|
+
});
|
|
2112
2176
|
}
|
|
2113
2177
|
};
|
|
2114
|
-
|
|
2115
|
-
|
|
2178
|
+
_this.buttonHandleBlur = function (event) {
|
|
2179
|
+
var blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
2116
2180
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
2117
|
-
|
|
2118
|
-
if (!
|
|
2181
|
+
_this.internalSetTimeout(function () {
|
|
2182
|
+
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)
|
|
2119
2183
|
) {
|
|
2120
|
-
|
|
2184
|
+
_this.reset({
|
|
2121
2185
|
type: blurButton
|
|
2122
2186
|
});
|
|
2123
2187
|
}
|
|
2124
2188
|
});
|
|
2125
2189
|
};
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2190
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ BUTTON
|
|
2191
|
+
/////////////////////////////// LABEL
|
|
2192
|
+
_this.getLabelProps = function (props) {
|
|
2193
|
+
return _extends({
|
|
2194
|
+
htmlFor: _this.inputId,
|
|
2195
|
+
id: _this.labelId
|
|
2196
|
+
}, props);
|
|
2132
2197
|
};
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2198
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ LABEL
|
|
2199
|
+
/////////////////////////////// INPUT
|
|
2200
|
+
_this.getInputProps = function (_temp4) {
|
|
2201
|
+
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
2202
|
+
onKeyDown = _ref4.onKeyDown,
|
|
2203
|
+
onBlur = _ref4.onBlur,
|
|
2204
|
+
onChange = _ref4.onChange,
|
|
2205
|
+
onInput = _ref4.onInput;
|
|
2206
|
+
_ref4.onChangeText;
|
|
2207
|
+
var rest = _objectWithoutPropertiesLoose(_ref4, _excluded3$2);
|
|
2208
|
+
var onChangeKey;
|
|
2209
|
+
var eventHandlers = {};
|
|
2144
2210
|
|
|
2145
2211
|
/* istanbul ignore next (preact) */
|
|
2146
2212
|
{
|
|
2147
2213
|
onChangeKey = 'onChange';
|
|
2148
2214
|
}
|
|
2149
|
-
|
|
2150
|
-
inputValue,
|
|
2151
|
-
isOpen,
|
|
2152
|
-
highlightedIndex
|
|
2153
|
-
} = _this.getState();
|
|
2215
|
+
var _this$getState6 = _this.getState(),
|
|
2216
|
+
inputValue = _this$getState6.inputValue,
|
|
2217
|
+
isOpen = _this$getState6.isOpen,
|
|
2218
|
+
highlightedIndex = _this$getState6.highlightedIndex;
|
|
2154
2219
|
if (!rest.disabled) {
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
onKeyDown: callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown),
|
|
2158
|
-
onBlur: callAllEventHandlers(onBlur, _this.inputHandleBlur)
|
|
2159
|
-
};
|
|
2220
|
+
var _eventHandlers;
|
|
2221
|
+
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
|
|
2160
2222
|
}
|
|
2161
|
-
return {
|
|
2223
|
+
return _extends({
|
|
2162
2224
|
'aria-autocomplete': 'list',
|
|
2163
2225
|
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
2164
2226
|
'aria-controls': isOpen ? _this.menuId : null,
|
|
@@ -2167,82 +2229,80 @@
|
|
|
2167
2229
|
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
2168
2230
|
autoComplete: 'off',
|
|
2169
2231
|
value: inputValue,
|
|
2170
|
-
id: _this.inputId
|
|
2171
|
-
|
|
2172
|
-
...rest
|
|
2173
|
-
};
|
|
2232
|
+
id: _this.inputId
|
|
2233
|
+
}, eventHandlers, rest);
|
|
2174
2234
|
};
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
if (key &&
|
|
2178
|
-
|
|
2235
|
+
_this.inputHandleKeyDown = function (event) {
|
|
2236
|
+
var key = normalizeArrowKey(event);
|
|
2237
|
+
if (key && _this.inputKeyDownHandlers[key]) {
|
|
2238
|
+
_this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
|
2179
2239
|
}
|
|
2180
2240
|
};
|
|
2181
|
-
|
|
2182
|
-
|
|
2241
|
+
_this.inputHandleChange = function (event) {
|
|
2242
|
+
_this.internalSetState({
|
|
2183
2243
|
type: changeInput,
|
|
2184
2244
|
isOpen: true,
|
|
2185
2245
|
inputValue: event.target.value,
|
|
2186
|
-
highlightedIndex:
|
|
2246
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2187
2247
|
});
|
|
2188
2248
|
};
|
|
2189
|
-
|
|
2249
|
+
_this.inputHandleBlur = function () {
|
|
2190
2250
|
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
if (!
|
|
2194
|
-
|
|
2251
|
+
_this.internalSetTimeout(function () {
|
|
2252
|
+
var downshiftButtonIsActive = _this.props.environment.document && !!_this.props.environment.document.activeElement && !!_this.props.environment.document.activeElement.dataset && _this.props.environment.document.activeElement.dataset.toggle && _this._rootNode && _this._rootNode.contains(_this.props.environment.document.activeElement);
|
|
2253
|
+
if (!_this.isMouseDown && !downshiftButtonIsActive) {
|
|
2254
|
+
_this.reset({
|
|
2195
2255
|
type: blurInput
|
|
2196
2256
|
});
|
|
2197
2257
|
}
|
|
2198
2258
|
});
|
|
2199
2259
|
};
|
|
2200
|
-
|
|
2201
|
-
|
|
2260
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ INPUT
|
|
2261
|
+
/////////////////////////////// MENU
|
|
2262
|
+
_this.menuRef = function (node) {
|
|
2263
|
+
_this._menuNode = node;
|
|
2202
2264
|
};
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2265
|
+
_this.getMenuProps = function (_temp5, _temp6) {
|
|
2266
|
+
var _extends3;
|
|
2267
|
+
var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
|
2268
|
+
_ref5$refKey = _ref5.refKey,
|
|
2269
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
2270
|
+
ref = _ref5.ref,
|
|
2271
|
+
props = _objectWithoutPropertiesLoose(_ref5, _excluded4$1);
|
|
2272
|
+
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
2273
|
+
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
2274
|
+
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
2212
2275
|
_this.getMenuProps.called = true;
|
|
2213
2276
|
_this.getMenuProps.refKey = refKey;
|
|
2214
2277
|
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
2215
|
-
return {
|
|
2216
|
-
[refKey]: handleRefs(ref, _this.menuRef),
|
|
2217
|
-
role: 'listbox',
|
|
2218
|
-
'aria-labelledby': props && props['aria-label'] ? null : _this.labelId,
|
|
2219
|
-
id: _this.menuId,
|
|
2220
|
-
...props
|
|
2221
|
-
};
|
|
2278
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
|
2222
2279
|
};
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2280
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ MENU
|
|
2281
|
+
/////////////////////////////// ITEM
|
|
2282
|
+
_this.getItemProps = function (_temp7) {
|
|
2283
|
+
var _enabledEventHandlers;
|
|
2284
|
+
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
2285
|
+
onMouseMove = _ref7.onMouseMove,
|
|
2286
|
+
onMouseDown = _ref7.onMouseDown,
|
|
2287
|
+
onClick = _ref7.onClick;
|
|
2288
|
+
_ref7.onPress;
|
|
2289
|
+
var index = _ref7.index,
|
|
2290
|
+
_ref7$item = _ref7.item,
|
|
2291
|
+
item = _ref7$item === void 0 ? requiredProp('getItemProps', 'item') : _ref7$item,
|
|
2292
|
+
rest = _objectWithoutPropertiesLoose(_ref7, _excluded5);
|
|
2233
2293
|
if (index === undefined) {
|
|
2234
2294
|
_this.items.push(item);
|
|
2235
2295
|
index = _this.items.indexOf(item);
|
|
2236
2296
|
} else {
|
|
2237
2297
|
_this.items[index] = item;
|
|
2238
2298
|
}
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2299
|
+
var onSelectKey = 'onClick';
|
|
2300
|
+
var customClickHandler = onClick;
|
|
2301
|
+
var enabledEventHandlers = (_enabledEventHandlers = {
|
|
2242
2302
|
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
2243
2303
|
// is only triggered on actual mouse movement while onMouseEnter
|
|
2244
2304
|
// can fire on DOM changes, interrupting keyboard navigation
|
|
2245
|
-
onMouseMove: callAllEventHandlers(onMouseMove, ()
|
|
2305
|
+
onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
|
2246
2306
|
if (index === _this.getState().highlightedIndex) {
|
|
2247
2307
|
return;
|
|
2248
2308
|
}
|
|
@@ -2255,75 +2315,67 @@
|
|
|
2255
2315
|
// from under the user which is currently scrolling/moving the
|
|
2256
2316
|
// cursor
|
|
2257
2317
|
_this.avoidScrolling = true;
|
|
2258
|
-
_this.internalSetTimeout(()
|
|
2318
|
+
_this.internalSetTimeout(function () {
|
|
2319
|
+
return _this.avoidScrolling = false;
|
|
2320
|
+
}, 250);
|
|
2259
2321
|
}),
|
|
2260
|
-
onMouseDown: callAllEventHandlers(onMouseDown, event
|
|
2322
|
+
onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
|
|
2261
2323
|
// This prevents the activeElement from being changed
|
|
2262
2324
|
// to the item so it can remain with the current activeElement
|
|
2263
2325
|
// which is a more common use case.
|
|
2264
2326
|
event.preventDefault();
|
|
2265
|
-
}),
|
|
2266
|
-
[onSelectKey]: callAllEventHandlers(customClickHandler, () => {
|
|
2267
|
-
_this.selectItemAtIndex(index, {
|
|
2268
|
-
type: clickItem
|
|
2269
|
-
});
|
|
2270
2327
|
})
|
|
2271
|
-
}
|
|
2328
|
+
}, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
|
|
2329
|
+
_this.selectItemAtIndex(index, {
|
|
2330
|
+
type: clickItem
|
|
2331
|
+
});
|
|
2332
|
+
}), _enabledEventHandlers);
|
|
2272
2333
|
|
|
2273
2334
|
// Passing down the onMouseDown handler to prevent redirect
|
|
2274
2335
|
// of the activeElement if clicking on disabled items
|
|
2275
|
-
|
|
2336
|
+
var eventHandlers = rest.disabled ? {
|
|
2276
2337
|
onMouseDown: enabledEventHandlers.onMouseDown
|
|
2277
2338
|
} : enabledEventHandlers;
|
|
2278
|
-
return {
|
|
2339
|
+
return _extends({
|
|
2279
2340
|
id: _this.getItemId(index),
|
|
2280
2341
|
role: 'option',
|
|
2281
|
-
'aria-selected': _this.getState().highlightedIndex === index
|
|
2282
|
-
|
|
2283
|
-
...rest
|
|
2284
|
-
};
|
|
2342
|
+
'aria-selected': _this.getState().highlightedIndex === index
|
|
2343
|
+
}, eventHandlers, rest);
|
|
2285
2344
|
};
|
|
2286
|
-
|
|
2287
|
-
|
|
2345
|
+
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ITEM
|
|
2346
|
+
_this.clearItems = function () {
|
|
2347
|
+
_this.items = [];
|
|
2288
2348
|
};
|
|
2289
|
-
|
|
2349
|
+
_this.reset = function (otherStateToSet, cb) {
|
|
2290
2350
|
if (otherStateToSet === void 0) {
|
|
2291
2351
|
otherStateToSet = {};
|
|
2292
2352
|
}
|
|
2293
2353
|
otherStateToSet = pickState(otherStateToSet);
|
|
2294
|
-
_this.internalSetState(
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
} = _ref;
|
|
2298
|
-
return {
|
|
2354
|
+
_this.internalSetState(function (_ref8) {
|
|
2355
|
+
var selectedItem = _ref8.selectedItem;
|
|
2356
|
+
return _extends({
|
|
2299
2357
|
isOpen: _this.props.defaultIsOpen,
|
|
2300
2358
|
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
2301
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
2302
|
-
|
|
2303
|
-
};
|
|
2359
|
+
inputValue: _this.props.itemToString(selectedItem)
|
|
2360
|
+
}, otherStateToSet);
|
|
2304
2361
|
}, cb);
|
|
2305
2362
|
};
|
|
2306
|
-
|
|
2363
|
+
_this.toggleMenu = function (otherStateToSet, cb) {
|
|
2307
2364
|
if (otherStateToSet === void 0) {
|
|
2308
2365
|
otherStateToSet = {};
|
|
2309
2366
|
}
|
|
2310
2367
|
otherStateToSet = pickState(otherStateToSet);
|
|
2311
|
-
_this.internalSetState(
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
}, () => {
|
|
2323
|
-
const {
|
|
2324
|
-
isOpen,
|
|
2325
|
-
highlightedIndex
|
|
2326
|
-
} = _this.getState();
|
|
2368
|
+
_this.internalSetState(function (_ref9) {
|
|
2369
|
+
var isOpen = _ref9.isOpen;
|
|
2370
|
+
return _extends({
|
|
2371
|
+
isOpen: !isOpen
|
|
2372
|
+
}, isOpen && {
|
|
2373
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2374
|
+
}, otherStateToSet);
|
|
2375
|
+
}, function () {
|
|
2376
|
+
var _this$getState7 = _this.getState(),
|
|
2377
|
+
isOpen = _this$getState7.isOpen,
|
|
2378
|
+
highlightedIndex = _this$getState7.highlightedIndex;
|
|
2327
2379
|
if (isOpen) {
|
|
2328
2380
|
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
2329
2381
|
_this.setHighlightedIndex(highlightedIndex, otherStateToSet);
|
|
@@ -2332,57 +2384,58 @@
|
|
|
2332
2384
|
cbToCb(cb)();
|
|
2333
2385
|
});
|
|
2334
2386
|
};
|
|
2335
|
-
|
|
2336
|
-
|
|
2387
|
+
_this.openMenu = function (cb) {
|
|
2388
|
+
_this.internalSetState({
|
|
2337
2389
|
isOpen: true
|
|
2338
2390
|
}, cb);
|
|
2339
2391
|
};
|
|
2340
|
-
|
|
2341
|
-
|
|
2392
|
+
_this.closeMenu = function (cb) {
|
|
2393
|
+
_this.internalSetState({
|
|
2342
2394
|
isOpen: false
|
|
2343
2395
|
}, cb);
|
|
2344
2396
|
};
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
itemToString:
|
|
2351
|
-
previousResultCount:
|
|
2352
|
-
resultCount,
|
|
2353
|
-
highlightedItem: item
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
setStatus(status, this.props.environment.document);
|
|
2397
|
+
_this.updateStatus = debounce(function () {
|
|
2398
|
+
var state = _this.getState();
|
|
2399
|
+
var item = _this.items[state.highlightedIndex];
|
|
2400
|
+
var resultCount = _this.getItemCount();
|
|
2401
|
+
var status = _this.props.getA11yStatusMessage(_extends({
|
|
2402
|
+
itemToString: _this.props.itemToString,
|
|
2403
|
+
previousResultCount: _this.previousResultCount,
|
|
2404
|
+
resultCount: resultCount,
|
|
2405
|
+
highlightedItem: item
|
|
2406
|
+
}, state));
|
|
2407
|
+
_this.previousResultCount = resultCount;
|
|
2408
|
+
setStatus(status, _this.props.environment.document);
|
|
2358
2409
|
}, 200);
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
defaultIsOpen,
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2410
|
+
var _this$props = _this.props,
|
|
2411
|
+
defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
|
|
2412
|
+
_this$props$initialHi = _this$props.initialHighlightedIndex,
|
|
2413
|
+
_highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
|
|
2414
|
+
defaultIsOpen = _this$props.defaultIsOpen,
|
|
2415
|
+
_this$props$initialIs = _this$props.initialIsOpen,
|
|
2416
|
+
_isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
|
|
2417
|
+
_this$props$initialIn = _this$props.initialInputValue,
|
|
2418
|
+
_inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
|
|
2419
|
+
_this$props$initialSe = _this$props.initialSelectedItem,
|
|
2420
|
+
_selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
|
|
2421
|
+
var _state = _this.getState({
|
|
2371
2422
|
highlightedIndex: _highlightedIndex,
|
|
2372
2423
|
isOpen: _isOpen,
|
|
2373
2424
|
inputValue: _inputValue,
|
|
2374
2425
|
selectedItem: _selectedItem
|
|
2375
2426
|
});
|
|
2376
|
-
if (_state.selectedItem != null &&
|
|
2377
|
-
_state.inputValue =
|
|
2427
|
+
if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
|
|
2428
|
+
_state.inputValue = _this.props.itemToString(_state.selectedItem);
|
|
2378
2429
|
}
|
|
2379
|
-
|
|
2430
|
+
_this.state = _state;
|
|
2431
|
+
return _this;
|
|
2380
2432
|
}
|
|
2433
|
+
var _proto = Downshift.prototype;
|
|
2381
2434
|
/**
|
|
2382
2435
|
* Clear all running timeouts
|
|
2383
2436
|
*/
|
|
2384
|
-
internalClearTimeouts() {
|
|
2385
|
-
this.timeoutIds.forEach(id
|
|
2437
|
+
_proto.internalClearTimeouts = function internalClearTimeouts() {
|
|
2438
|
+
this.timeoutIds.forEach(function (id) {
|
|
2386
2439
|
clearTimeout(id);
|
|
2387
2440
|
});
|
|
2388
2441
|
this.timeoutIds = [];
|
|
@@ -2396,117 +2449,110 @@
|
|
|
2396
2449
|
*
|
|
2397
2450
|
* @param {Object} stateToMerge defaults to this.state
|
|
2398
2451
|
* @return {Object} the state
|
|
2399
|
-
|
|
2400
|
-
getState(stateToMerge) {
|
|
2452
|
+
*/;
|
|
2453
|
+
_proto.getState = function getState$1(stateToMerge) {
|
|
2401
2454
|
if (stateToMerge === void 0) {
|
|
2402
2455
|
stateToMerge = this.state;
|
|
2403
2456
|
}
|
|
2404
2457
|
return getState(stateToMerge, this.props);
|
|
2405
|
-
}
|
|
2406
|
-
getItemCount() {
|
|
2458
|
+
};
|
|
2459
|
+
_proto.getItemCount = function getItemCount() {
|
|
2407
2460
|
// things read better this way. They're in priority order:
|
|
2408
2461
|
// 1. `this.itemCount`
|
|
2409
2462
|
// 2. `this.props.itemCount`
|
|
2410
2463
|
// 3. `this.items.length`
|
|
2411
|
-
|
|
2464
|
+
var itemCount = this.items.length;
|
|
2412
2465
|
if (this.itemCount != null) {
|
|
2413
2466
|
itemCount = this.itemCount;
|
|
2414
2467
|
} else if (this.props.itemCount !== undefined) {
|
|
2415
2468
|
itemCount = this.props.itemCount;
|
|
2416
2469
|
}
|
|
2417
2470
|
return itemCount;
|
|
2418
|
-
}
|
|
2419
|
-
getItemNodeFromIndex(index) {
|
|
2471
|
+
};
|
|
2472
|
+
_proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
|
|
2420
2473
|
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
2421
|
-
}
|
|
2422
|
-
scrollHighlightedItemIntoView() {
|
|
2474
|
+
};
|
|
2475
|
+
_proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
|
|
2423
2476
|
/* istanbul ignore else (react-native) */
|
|
2424
2477
|
{
|
|
2425
|
-
|
|
2478
|
+
var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
2426
2479
|
this.props.scrollIntoView(node, this._menuNode);
|
|
2427
2480
|
}
|
|
2428
|
-
}
|
|
2429
|
-
moveHighlightedIndex(amount, otherStateToSet) {
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2481
|
+
};
|
|
2482
|
+
_proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
|
2483
|
+
var _this6 = this;
|
|
2484
|
+
var itemCount = this.getItemCount();
|
|
2485
|
+
var _this$getState8 = this.getState(),
|
|
2486
|
+
highlightedIndex = _this$getState8.highlightedIndex;
|
|
2434
2487
|
if (itemCount > 0) {
|
|
2435
|
-
|
|
2488
|
+
var nextHighlightedIndex = getNextWrappingIndex(amount, highlightedIndex, itemCount, function (index) {
|
|
2489
|
+
return _this6.getItemNodeFromIndex(index);
|
|
2490
|
+
});
|
|
2436
2491
|
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
2437
2492
|
}
|
|
2438
|
-
}
|
|
2439
|
-
getStateAndHelpers() {
|
|
2440
|
-
|
|
2441
|
-
highlightedIndex,
|
|
2442
|
-
inputValue,
|
|
2443
|
-
selectedItem,
|
|
2444
|
-
isOpen
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
clearSelection,
|
|
2467
|
-
clearItems,
|
|
2468
|
-
reset,
|
|
2469
|
-
setItemCount,
|
|
2470
|
-
unsetItemCount,
|
|
2471
|
-
internalSetState: setState
|
|
2472
|
-
} = this;
|
|
2493
|
+
};
|
|
2494
|
+
_proto.getStateAndHelpers = function getStateAndHelpers() {
|
|
2495
|
+
var _this$getState9 = this.getState(),
|
|
2496
|
+
highlightedIndex = _this$getState9.highlightedIndex,
|
|
2497
|
+
inputValue = _this$getState9.inputValue,
|
|
2498
|
+
selectedItem = _this$getState9.selectedItem,
|
|
2499
|
+
isOpen = _this$getState9.isOpen;
|
|
2500
|
+
var itemToString = this.props.itemToString;
|
|
2501
|
+
var id = this.id;
|
|
2502
|
+
var getRootProps = this.getRootProps,
|
|
2503
|
+
getToggleButtonProps = this.getToggleButtonProps,
|
|
2504
|
+
getLabelProps = this.getLabelProps,
|
|
2505
|
+
getMenuProps = this.getMenuProps,
|
|
2506
|
+
getInputProps = this.getInputProps,
|
|
2507
|
+
getItemProps = this.getItemProps,
|
|
2508
|
+
openMenu = this.openMenu,
|
|
2509
|
+
closeMenu = this.closeMenu,
|
|
2510
|
+
toggleMenu = this.toggleMenu,
|
|
2511
|
+
selectItem = this.selectItem,
|
|
2512
|
+
selectItemAtIndex = this.selectItemAtIndex,
|
|
2513
|
+
selectHighlightedItem = this.selectHighlightedItem,
|
|
2514
|
+
setHighlightedIndex = this.setHighlightedIndex,
|
|
2515
|
+
clearSelection = this.clearSelection,
|
|
2516
|
+
clearItems = this.clearItems,
|
|
2517
|
+
reset = this.reset,
|
|
2518
|
+
setItemCount = this.setItemCount,
|
|
2519
|
+
unsetItemCount = this.unsetItemCount,
|
|
2520
|
+
setState = this.internalSetState;
|
|
2473
2521
|
return {
|
|
2474
2522
|
// prop getters
|
|
2475
|
-
getRootProps,
|
|
2476
|
-
getToggleButtonProps,
|
|
2477
|
-
getLabelProps,
|
|
2478
|
-
getMenuProps,
|
|
2479
|
-
getInputProps,
|
|
2480
|
-
getItemProps,
|
|
2523
|
+
getRootProps: getRootProps,
|
|
2524
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
2525
|
+
getLabelProps: getLabelProps,
|
|
2526
|
+
getMenuProps: getMenuProps,
|
|
2527
|
+
getInputProps: getInputProps,
|
|
2528
|
+
getItemProps: getItemProps,
|
|
2481
2529
|
// actions
|
|
2482
|
-
reset,
|
|
2483
|
-
openMenu,
|
|
2484
|
-
closeMenu,
|
|
2485
|
-
toggleMenu,
|
|
2486
|
-
selectItem,
|
|
2487
|
-
selectItemAtIndex,
|
|
2488
|
-
selectHighlightedItem,
|
|
2489
|
-
setHighlightedIndex,
|
|
2490
|
-
clearSelection,
|
|
2491
|
-
clearItems,
|
|
2492
|
-
setItemCount,
|
|
2493
|
-
unsetItemCount,
|
|
2494
|
-
setState,
|
|
2530
|
+
reset: reset,
|
|
2531
|
+
openMenu: openMenu,
|
|
2532
|
+
closeMenu: closeMenu,
|
|
2533
|
+
toggleMenu: toggleMenu,
|
|
2534
|
+
selectItem: selectItem,
|
|
2535
|
+
selectItemAtIndex: selectItemAtIndex,
|
|
2536
|
+
selectHighlightedItem: selectHighlightedItem,
|
|
2537
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
2538
|
+
clearSelection: clearSelection,
|
|
2539
|
+
clearItems: clearItems,
|
|
2540
|
+
setItemCount: setItemCount,
|
|
2541
|
+
unsetItemCount: unsetItemCount,
|
|
2542
|
+
setState: setState,
|
|
2495
2543
|
// props
|
|
2496
|
-
itemToString,
|
|
2544
|
+
itemToString: itemToString,
|
|
2497
2545
|
// derived
|
|
2498
|
-
id,
|
|
2546
|
+
id: id,
|
|
2499
2547
|
// state
|
|
2500
|
-
highlightedIndex,
|
|
2501
|
-
inputValue,
|
|
2502
|
-
isOpen,
|
|
2503
|
-
selectedItem
|
|
2548
|
+
highlightedIndex: highlightedIndex,
|
|
2549
|
+
inputValue: inputValue,
|
|
2550
|
+
isOpen: isOpen,
|
|
2551
|
+
selectedItem: selectedItem
|
|
2504
2552
|
};
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
componentDidMount() {
|
|
2553
|
+
};
|
|
2554
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
2555
|
+
var _this7 = this;
|
|
2510
2556
|
/* istanbul ignore if (react-native) */
|
|
2511
2557
|
if (this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
2512
2558
|
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
@@ -2519,18 +2565,20 @@
|
|
|
2519
2565
|
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
2520
2566
|
// this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
|
|
2521
2567
|
// trigger hiding the menu.
|
|
2522
|
-
|
|
2523
|
-
|
|
2568
|
+
var onMouseDown = function onMouseDown() {
|
|
2569
|
+
_this7.isMouseDown = true;
|
|
2524
2570
|
};
|
|
2525
|
-
|
|
2526
|
-
|
|
2571
|
+
var onMouseUp = function onMouseUp(event) {
|
|
2572
|
+
_this7.isMouseDown = false;
|
|
2527
2573
|
// if the target element or the activeElement is within a downshift node
|
|
2528
2574
|
// then we don't want to reset downshift
|
|
2529
|
-
|
|
2530
|
-
if (!contextWithinDownshift &&
|
|
2531
|
-
|
|
2575
|
+
var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment);
|
|
2576
|
+
if (!contextWithinDownshift && _this7.getState().isOpen) {
|
|
2577
|
+
_this7.reset({
|
|
2532
2578
|
type: mouseUp
|
|
2533
|
-
}, ()
|
|
2579
|
+
}, function () {
|
|
2580
|
+
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
2581
|
+
});
|
|
2534
2582
|
}
|
|
2535
2583
|
};
|
|
2536
2584
|
// Touching an element in iOS gives focus and hover states, but touching out of
|
|
@@ -2539,31 +2587,31 @@
|
|
|
2539
2587
|
// this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
|
|
2540
2588
|
// If the user taps outside of Downshift, the component should be reset,
|
|
2541
2589
|
// but not if the user is swiping
|
|
2542
|
-
|
|
2543
|
-
|
|
2590
|
+
var onTouchStart = function onTouchStart() {
|
|
2591
|
+
_this7.isTouchMove = false;
|
|
2544
2592
|
};
|
|
2545
|
-
|
|
2546
|
-
|
|
2593
|
+
var onTouchMove = function onTouchMove() {
|
|
2594
|
+
_this7.isTouchMove = true;
|
|
2547
2595
|
};
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
if (!
|
|
2551
|
-
|
|
2596
|
+
var onTouchEnd = function onTouchEnd(event) {
|
|
2597
|
+
var contextWithinDownshift = targetWithinDownshift(event.target, [_this7._rootNode, _this7._menuNode], _this7.props.environment, false);
|
|
2598
|
+
if (!_this7.isTouchMove && !contextWithinDownshift && _this7.getState().isOpen) {
|
|
2599
|
+
_this7.reset({
|
|
2552
2600
|
type: touchEnd
|
|
2553
|
-
}, ()
|
|
2601
|
+
}, function () {
|
|
2602
|
+
return _this7.props.onOuterClick(_this7.getStateAndHelpers());
|
|
2603
|
+
});
|
|
2554
2604
|
}
|
|
2555
2605
|
};
|
|
2556
|
-
|
|
2557
|
-
environment
|
|
2558
|
-
} = this.props;
|
|
2606
|
+
var environment = this.props.environment;
|
|
2559
2607
|
environment.addEventListener('mousedown', onMouseDown);
|
|
2560
2608
|
environment.addEventListener('mouseup', onMouseUp);
|
|
2561
2609
|
environment.addEventListener('touchstart', onTouchStart);
|
|
2562
2610
|
environment.addEventListener('touchmove', onTouchMove);
|
|
2563
2611
|
environment.addEventListener('touchend', onTouchEnd);
|
|
2564
|
-
this.cleanup = ()
|
|
2565
|
-
|
|
2566
|
-
|
|
2612
|
+
this.cleanup = function () {
|
|
2613
|
+
_this7.internalClearTimeouts();
|
|
2614
|
+
_this7.updateStatus.cancel();
|
|
2567
2615
|
environment.removeEventListener('mousedown', onMouseDown);
|
|
2568
2616
|
environment.removeEventListener('mouseup', onMouseUp);
|
|
2569
2617
|
environment.removeEventListener('touchstart', onTouchStart);
|
|
@@ -2571,19 +2619,17 @@
|
|
|
2571
2619
|
environment.removeEventListener('touchend', onTouchEnd);
|
|
2572
2620
|
};
|
|
2573
2621
|
}
|
|
2574
|
-
}
|
|
2575
|
-
shouldScroll(prevState, prevProps) {
|
|
2576
|
-
|
|
2577
|
-
highlightedIndex
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
const scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
2583
|
-
const scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
2622
|
+
};
|
|
2623
|
+
_proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
|
2624
|
+
var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
|
2625
|
+
currentHighlightedIndex = _ref10.highlightedIndex;
|
|
2626
|
+
var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
|
2627
|
+
prevHighlightedIndex = _ref11.highlightedIndex;
|
|
2628
|
+
var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
2629
|
+
var scrollWhenNavigating = currentHighlightedIndex !== prevHighlightedIndex;
|
|
2584
2630
|
return scrollWhenOpen || scrollWhenNavigating;
|
|
2585
|
-
}
|
|
2586
|
-
componentDidUpdate(prevProps, prevState) {
|
|
2631
|
+
};
|
|
2632
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
2587
2633
|
{
|
|
2588
2634
|
validateControlledUnchanged(this.state, prevProps, this.props);
|
|
2589
2635
|
/* istanbul ignore if (react-native) */
|
|
@@ -2605,13 +2651,12 @@
|
|
|
2605
2651
|
{
|
|
2606
2652
|
this.updateStatus();
|
|
2607
2653
|
}
|
|
2608
|
-
}
|
|
2609
|
-
componentWillUnmount() {
|
|
2654
|
+
};
|
|
2655
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
2610
2656
|
this.cleanup(); // avoids memory leak
|
|
2611
|
-
}
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
const children = unwrapArray(this.props.children, noop);
|
|
2657
|
+
};
|
|
2658
|
+
_proto.render = function render() {
|
|
2659
|
+
var children = unwrapArray(this.props.children, noop);
|
|
2615
2660
|
// because the items are rerendered every time we call the children
|
|
2616
2661
|
// we clear this out each render and it will be populated again as
|
|
2617
2662
|
// getItemProps is called.
|
|
@@ -2631,7 +2676,7 @@
|
|
|
2631
2676
|
this.getLabelProps.called = false;
|
|
2632
2677
|
// and something similar for getInputProps
|
|
2633
2678
|
this.getInputProps.called = false;
|
|
2634
|
-
|
|
2679
|
+
var element = unwrapArray(children(this.getStateAndHelpers()));
|
|
2635
2680
|
if (!element) {
|
|
2636
2681
|
return null;
|
|
2637
2682
|
}
|
|
@@ -2653,13 +2698,14 @@
|
|
|
2653
2698
|
|
|
2654
2699
|
throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
|
|
2655
2700
|
}
|
|
2656
|
-
}
|
|
2657
|
-
|
|
2701
|
+
};
|
|
2702
|
+
return Downshift;
|
|
2703
|
+
}(react.Component);
|
|
2658
2704
|
Downshift.defaultProps = {
|
|
2659
2705
|
defaultHighlightedIndex: null,
|
|
2660
2706
|
defaultIsOpen: false,
|
|
2661
2707
|
getA11yStatusMessage: getA11yStatusMessage$1,
|
|
2662
|
-
itemToString: i
|
|
2708
|
+
itemToString: function itemToString(i) {
|
|
2663
2709
|
if (i == null) {
|
|
2664
2710
|
return '';
|
|
2665
2711
|
}
|
|
@@ -2675,16 +2721,20 @@
|
|
|
2675
2721
|
onChange: noop,
|
|
2676
2722
|
onSelect: noop,
|
|
2677
2723
|
onOuterClick: noop,
|
|
2678
|
-
selectedItemChanged: (prevItem, item)
|
|
2724
|
+
selectedItemChanged: function selectedItemChanged(prevItem, item) {
|
|
2725
|
+
return prevItem !== item;
|
|
2726
|
+
},
|
|
2679
2727
|
environment: /* istanbul ignore next (ssr) */
|
|
2680
2728
|
typeof window === 'undefined' ? {} : window,
|
|
2681
|
-
stateReducer: (state, stateToSet)
|
|
2729
|
+
stateReducer: function stateReducer(state, stateToSet) {
|
|
2730
|
+
return stateToSet;
|
|
2731
|
+
},
|
|
2682
2732
|
suppressRefError: false,
|
|
2683
|
-
scrollIntoView
|
|
2733
|
+
scrollIntoView: scrollIntoView
|
|
2684
2734
|
};
|
|
2685
2735
|
Downshift.stateChangeTypes = stateChangeTypes$3;
|
|
2686
2736
|
return Downshift;
|
|
2687
|
-
}
|
|
2737
|
+
}();
|
|
2688
2738
|
Downshift.propTypes = {
|
|
2689
2739
|
children: PropTypes.func,
|
|
2690
2740
|
defaultHighlightedIndex: PropTypes.number,
|
|
@@ -2730,70 +2780,61 @@
|
|
|
2730
2780
|
/* eslint-enable react/no-unused-prop-types */
|
|
2731
2781
|
} ;
|
|
2732
2782
|
var Downshift$1 = Downshift;
|
|
2733
|
-
function validateGetMenuPropsCalledCorrectly(node,
|
|
2734
|
-
|
|
2735
|
-
refKey
|
|
2736
|
-
} = _ref3;
|
|
2783
|
+
function validateGetMenuPropsCalledCorrectly(node, _ref12) {
|
|
2784
|
+
var refKey = _ref12.refKey;
|
|
2737
2785
|
if (!node) {
|
|
2738
2786
|
// eslint-disable-next-line no-console
|
|
2739
|
-
console.error(
|
|
2787
|
+
console.error("downshift: The ref prop \"" + refKey + "\" from getMenuProps was not applied correctly on your menu element.");
|
|
2740
2788
|
}
|
|
2741
2789
|
}
|
|
2742
|
-
function validateGetRootPropsCalledCorrectly(element,
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
const refKeySpecified = refKey !== 'ref';
|
|
2747
|
-
const isComposite = !isDOMElement(element);
|
|
2790
|
+
function validateGetRootPropsCalledCorrectly(element, _ref13) {
|
|
2791
|
+
var refKey = _ref13.refKey;
|
|
2792
|
+
var refKeySpecified = refKey !== 'ref';
|
|
2793
|
+
var isComposite = !isDOMElement(element);
|
|
2748
2794
|
if (isComposite && !refKeySpecified && !reactIs.exports.isForwardRef(element)) {
|
|
2749
2795
|
// eslint-disable-next-line no-console
|
|
2750
2796
|
console.error('downshift: You returned a non-DOM element. You must specify a refKey in getRootProps');
|
|
2751
2797
|
} else if (!isComposite && refKeySpecified) {
|
|
2752
2798
|
// eslint-disable-next-line no-console
|
|
2753
|
-
console.error(
|
|
2799
|
+
console.error("downshift: You returned a DOM element. You should not specify a refKey in getRootProps. You specified \"" + refKey + "\"");
|
|
2754
2800
|
}
|
|
2755
2801
|
if (!reactIs.exports.isForwardRef(element) && !getElementProps(element)[refKey]) {
|
|
2756
2802
|
// eslint-disable-next-line no-console
|
|
2757
|
-
console.error(
|
|
2803
|
+
console.error("downshift: You must apply the ref prop \"" + refKey + "\" from getRootProps onto your root element.");
|
|
2758
2804
|
}
|
|
2759
2805
|
}
|
|
2760
2806
|
|
|
2761
|
-
|
|
2807
|
+
var _excluded$3 = ["isInitialMount", "highlightedIndex", "items", "environment"];
|
|
2808
|
+
var dropdownDefaultStateValues = {
|
|
2762
2809
|
highlightedIndex: -1,
|
|
2763
2810
|
isOpen: false,
|
|
2764
2811
|
selectedItem: null,
|
|
2765
2812
|
inputValue: ''
|
|
2766
2813
|
};
|
|
2767
2814
|
function callOnChangeProps(action, state, newState) {
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
const changes = {};
|
|
2773
|
-
Object.keys(state).forEach(key => {
|
|
2815
|
+
var props = action.props,
|
|
2816
|
+
type = action.type;
|
|
2817
|
+
var changes = {};
|
|
2818
|
+
Object.keys(state).forEach(function (key) {
|
|
2774
2819
|
invokeOnChangeHandler(key, action, state, newState);
|
|
2775
2820
|
if (newState[key] !== state[key]) {
|
|
2776
2821
|
changes[key] = newState[key];
|
|
2777
2822
|
}
|
|
2778
2823
|
});
|
|
2779
2824
|
if (props.onStateChange && Object.keys(changes).length) {
|
|
2780
|
-
props.onStateChange({
|
|
2781
|
-
type
|
|
2782
|
-
|
|
2783
|
-
});
|
|
2825
|
+
props.onStateChange(_extends({
|
|
2826
|
+
type: type
|
|
2827
|
+
}, changes));
|
|
2784
2828
|
}
|
|
2785
2829
|
}
|
|
2786
2830
|
function invokeOnChangeHandler(key, action, state, newState) {
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
} = action;
|
|
2791
|
-
const handler = `on${capitalizeString(key)}Change`;
|
|
2831
|
+
var props = action.props,
|
|
2832
|
+
type = action.type;
|
|
2833
|
+
var handler = "on" + capitalizeString(key) + "Change";
|
|
2792
2834
|
if (props[handler] && newState[key] !== undefined && newState[key] !== state[key]) {
|
|
2793
|
-
props[handler]({
|
|
2794
|
-
type
|
|
2795
|
-
|
|
2796
|
-
});
|
|
2835
|
+
props[handler](_extends({
|
|
2836
|
+
type: type
|
|
2837
|
+
}, newState));
|
|
2797
2838
|
}
|
|
2798
2839
|
}
|
|
2799
2840
|
|
|
@@ -2815,37 +2856,36 @@
|
|
|
2815
2856
|
* @returns {string} The a11y message.
|
|
2816
2857
|
*/
|
|
2817
2858
|
function getA11ySelectionMessage(selectionParameters) {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
} = selectionParameters;
|
|
2822
|
-
return selectedItem ? `${itemToStringLocal(selectedItem)} has been selected.` : '';
|
|
2859
|
+
var selectedItem = selectionParameters.selectedItem,
|
|
2860
|
+
itemToStringLocal = selectionParameters.itemToString;
|
|
2861
|
+
return selectedItem ? itemToStringLocal(selectedItem) + " has been selected." : '';
|
|
2823
2862
|
}
|
|
2824
2863
|
|
|
2825
2864
|
/**
|
|
2826
2865
|
* Debounced call for updating the a11y message.
|
|
2827
2866
|
*/
|
|
2828
|
-
|
|
2867
|
+
var updateA11yStatus = debounce(function (getA11yMessage, document) {
|
|
2829
2868
|
setStatus(getA11yMessage(), document);
|
|
2830
2869
|
}, 200);
|
|
2831
2870
|
|
|
2832
2871
|
// istanbul ignore next
|
|
2833
|
-
|
|
2872
|
+
var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? react.useLayoutEffect : react.useEffect;
|
|
2834
2873
|
function useElementIds(_ref) {
|
|
2835
|
-
|
|
2836
|
-
id =
|
|
2837
|
-
labelId,
|
|
2838
|
-
menuId,
|
|
2839
|
-
getItemId,
|
|
2840
|
-
toggleButtonId,
|
|
2841
|
-
inputId
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2874
|
+
var _ref$id = _ref.id,
|
|
2875
|
+
id = _ref$id === void 0 ? "downshift-" + generateId() : _ref$id,
|
|
2876
|
+
labelId = _ref.labelId,
|
|
2877
|
+
menuId = _ref.menuId,
|
|
2878
|
+
getItemId = _ref.getItemId,
|
|
2879
|
+
toggleButtonId = _ref.toggleButtonId,
|
|
2880
|
+
inputId = _ref.inputId;
|
|
2881
|
+
var elementIdsRef = react.useRef({
|
|
2882
|
+
labelId: labelId || id + "-label",
|
|
2883
|
+
menuId: menuId || id + "-menu",
|
|
2884
|
+
getItemId: getItemId || function (index) {
|
|
2885
|
+
return id + "-item-" + index;
|
|
2886
|
+
},
|
|
2887
|
+
toggleButtonId: toggleButtonId || id + "-toggle-button",
|
|
2888
|
+
inputId: inputId || id + "-input"
|
|
2849
2889
|
});
|
|
2850
2890
|
return elementIdsRef.current;
|
|
2851
2891
|
}
|
|
@@ -2865,10 +2905,10 @@
|
|
|
2865
2905
|
return /^\S{1}$/.test(key);
|
|
2866
2906
|
}
|
|
2867
2907
|
function capitalizeString(string) {
|
|
2868
|
-
return
|
|
2908
|
+
return "" + string.slice(0, 1).toUpperCase() + string.slice(1);
|
|
2869
2909
|
}
|
|
2870
2910
|
function useLatestRef(val) {
|
|
2871
|
-
|
|
2911
|
+
var ref = react.useRef(val);
|
|
2872
2912
|
// technically this is not "concurrent mode safe" because we're manipulating
|
|
2873
2913
|
// the value during render (so it's not idempotent). However, the places this
|
|
2874
2914
|
// hook is used is to support memoizing callbacks which will be called
|
|
@@ -2889,26 +2929,28 @@
|
|
|
2889
2929
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
2890
2930
|
*/
|
|
2891
2931
|
function useEnhancedReducer(reducer, initialState, props) {
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2932
|
+
var prevStateRef = react.useRef();
|
|
2933
|
+
var actionRef = react.useRef();
|
|
2934
|
+
var enhancedReducer = react.useCallback(function (state, action) {
|
|
2895
2935
|
actionRef.current = action;
|
|
2896
2936
|
state = getState(state, action.props);
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
});
|
|
2937
|
+
var changes = reducer(state, action);
|
|
2938
|
+
var newState = action.props.stateReducer(state, _extends({}, action, {
|
|
2939
|
+
changes: changes
|
|
2940
|
+
}));
|
|
2902
2941
|
return newState;
|
|
2903
2942
|
}, [reducer]);
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2943
|
+
var _useReducer = react.useReducer(enhancedReducer, initialState),
|
|
2944
|
+
state = _useReducer[0],
|
|
2945
|
+
dispatch = _useReducer[1];
|
|
2946
|
+
var propsRef = useLatestRef(props);
|
|
2947
|
+
var dispatchWithProps = react.useCallback(function (action) {
|
|
2948
|
+
return dispatch(_extends({
|
|
2949
|
+
props: propsRef.current
|
|
2950
|
+
}, action));
|
|
2951
|
+
}, [propsRef]);
|
|
2952
|
+
var action = actionRef.current;
|
|
2953
|
+
react.useEffect(function () {
|
|
2912
2954
|
if (action && prevStateRef.current && prevStateRef.current !== state) {
|
|
2913
2955
|
callOnChangeProps(action, getState(prevStateRef.current, action.props), state);
|
|
2914
2956
|
}
|
|
@@ -2927,14 +2969,16 @@
|
|
|
2927
2969
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
2928
2970
|
*/
|
|
2929
2971
|
function useControlledReducer$1(reducer, initialState, props) {
|
|
2930
|
-
|
|
2972
|
+
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
2973
|
+
state = _useEnhancedReducer[0],
|
|
2974
|
+
dispatch = _useEnhancedReducer[1];
|
|
2931
2975
|
return [getState(state, props), dispatch];
|
|
2932
2976
|
}
|
|
2933
|
-
|
|
2934
|
-
itemToString,
|
|
2935
|
-
stateReducer,
|
|
2936
|
-
getA11ySelectionMessage,
|
|
2937
|
-
scrollIntoView,
|
|
2977
|
+
var defaultProps$3 = {
|
|
2978
|
+
itemToString: itemToString,
|
|
2979
|
+
stateReducer: stateReducer,
|
|
2980
|
+
getA11ySelectionMessage: getA11ySelectionMessage,
|
|
2981
|
+
scrollIntoView: scrollIntoView,
|
|
2938
2982
|
environment: /* istanbul ignore next (ssr) */
|
|
2939
2983
|
typeof window === 'undefined' ? {} : window
|
|
2940
2984
|
};
|
|
@@ -2942,7 +2986,7 @@
|
|
|
2942
2986
|
if (defaultStateValues === void 0) {
|
|
2943
2987
|
defaultStateValues = dropdownDefaultStateValues;
|
|
2944
2988
|
}
|
|
2945
|
-
|
|
2989
|
+
var defaultValue = props["default" + capitalizeString(propKey)];
|
|
2946
2990
|
if (defaultValue !== undefined) {
|
|
2947
2991
|
return defaultValue;
|
|
2948
2992
|
}
|
|
@@ -2952,38 +2996,34 @@
|
|
|
2952
2996
|
if (defaultStateValues === void 0) {
|
|
2953
2997
|
defaultStateValues = dropdownDefaultStateValues;
|
|
2954
2998
|
}
|
|
2955
|
-
|
|
2999
|
+
var value = props[propKey];
|
|
2956
3000
|
if (value !== undefined) {
|
|
2957
3001
|
return value;
|
|
2958
3002
|
}
|
|
2959
|
-
|
|
3003
|
+
var initialValue = props["initial" + capitalizeString(propKey)];
|
|
2960
3004
|
if (initialValue !== undefined) {
|
|
2961
3005
|
return initialValue;
|
|
2962
3006
|
}
|
|
2963
3007
|
return getDefaultValue$1(props, propKey, defaultStateValues);
|
|
2964
3008
|
}
|
|
2965
3009
|
function getInitialState$2(props) {
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
3010
|
+
var selectedItem = getInitialValue$1(props, 'selectedItem');
|
|
3011
|
+
var isOpen = getInitialValue$1(props, 'isOpen');
|
|
3012
|
+
var highlightedIndex = getInitialValue$1(props, 'highlightedIndex');
|
|
3013
|
+
var inputValue = getInitialValue$1(props, 'inputValue');
|
|
2970
3014
|
return {
|
|
2971
3015
|
highlightedIndex: highlightedIndex < 0 && selectedItem && isOpen ? props.items.indexOf(selectedItem) : highlightedIndex,
|
|
2972
|
-
isOpen,
|
|
2973
|
-
selectedItem,
|
|
2974
|
-
inputValue
|
|
3016
|
+
isOpen: isOpen,
|
|
3017
|
+
selectedItem: selectedItem,
|
|
3018
|
+
inputValue: inputValue
|
|
2975
3019
|
};
|
|
2976
3020
|
}
|
|
2977
3021
|
function getHighlightedIndexOnOpen(props, state, offset) {
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
const {
|
|
2984
|
-
selectedItem,
|
|
2985
|
-
highlightedIndex
|
|
2986
|
-
} = state;
|
|
3022
|
+
var items = props.items,
|
|
3023
|
+
initialHighlightedIndex = props.initialHighlightedIndex,
|
|
3024
|
+
defaultHighlightedIndex = props.defaultHighlightedIndex;
|
|
3025
|
+
var selectedItem = state.selectedItem,
|
|
3026
|
+
highlightedIndex = state.highlightedIndex;
|
|
2987
3027
|
if (items.length === 0) {
|
|
2988
3028
|
return -1;
|
|
2989
3029
|
}
|
|
@@ -3014,30 +3054,35 @@
|
|
|
3014
3054
|
* @returns {Object} Ref containing whether mouseDown or touchMove event is happening
|
|
3015
3055
|
*/
|
|
3016
3056
|
function useMouseAndTouchTracker(isOpen, downshiftElementRefs, environment, handleBlur) {
|
|
3017
|
-
|
|
3057
|
+
var mouseAndTouchTrackersRef = react.useRef({
|
|
3018
3058
|
isMouseDown: false,
|
|
3019
3059
|
isTouchMove: false
|
|
3020
3060
|
});
|
|
3021
|
-
react.useEffect(()
|
|
3061
|
+
react.useEffect(function () {
|
|
3062
|
+
|
|
3022
3063
|
// The same strategy for checking if a click occurred inside or outside downsift
|
|
3023
3064
|
// as in downshift.js.
|
|
3024
|
-
|
|
3065
|
+
var onMouseDown = function onMouseDown() {
|
|
3025
3066
|
mouseAndTouchTrackersRef.current.isMouseDown = true;
|
|
3026
3067
|
};
|
|
3027
|
-
|
|
3068
|
+
var onMouseUp = function onMouseUp(event) {
|
|
3028
3069
|
mouseAndTouchTrackersRef.current.isMouseDown = false;
|
|
3029
|
-
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
3070
|
+
if (isOpen && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
|
|
3071
|
+
return ref.current;
|
|
3072
|
+
}), environment)) {
|
|
3030
3073
|
handleBlur();
|
|
3031
3074
|
}
|
|
3032
3075
|
};
|
|
3033
|
-
|
|
3076
|
+
var onTouchStart = function onTouchStart() {
|
|
3034
3077
|
mouseAndTouchTrackersRef.current.isTouchMove = false;
|
|
3035
3078
|
};
|
|
3036
|
-
|
|
3079
|
+
var onTouchMove = function onTouchMove() {
|
|
3037
3080
|
mouseAndTouchTrackersRef.current.isTouchMove = true;
|
|
3038
3081
|
};
|
|
3039
|
-
|
|
3040
|
-
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(
|
|
3082
|
+
var onTouchEnd = function onTouchEnd(event) {
|
|
3083
|
+
if (isOpen && !mouseAndTouchTrackersRef.current.isTouchMove && !targetWithinDownshift(event.target, downshiftElementRefs.map(function (ref) {
|
|
3084
|
+
return ref.current;
|
|
3085
|
+
}), environment, false)) {
|
|
3041
3086
|
handleBlur();
|
|
3042
3087
|
}
|
|
3043
3088
|
};
|
|
@@ -3046,6 +3091,8 @@
|
|
|
3046
3091
|
environment.addEventListener('touchstart', onTouchStart);
|
|
3047
3092
|
environment.addEventListener('touchmove', onTouchMove);
|
|
3048
3093
|
environment.addEventListener('touchend', onTouchEnd);
|
|
3094
|
+
|
|
3095
|
+
// eslint-disable-next-line consistent-return
|
|
3049
3096
|
return function cleanup() {
|
|
3050
3097
|
environment.removeEventListener('mousedown', onMouseDown);
|
|
3051
3098
|
environment.removeEventListener('mouseup', onMouseUp);
|
|
@@ -3060,7 +3107,9 @@
|
|
|
3060
3107
|
|
|
3061
3108
|
/* istanbul ignore next */
|
|
3062
3109
|
// eslint-disable-next-line import/no-mutable-exports
|
|
3063
|
-
|
|
3110
|
+
var useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
3111
|
+
return noop;
|
|
3112
|
+
};
|
|
3064
3113
|
/**
|
|
3065
3114
|
* Custom hook that checks if getter props are called correctly.
|
|
3066
3115
|
*
|
|
@@ -3069,82 +3118,77 @@
|
|
|
3069
3118
|
*/
|
|
3070
3119
|
/* istanbul ignore next */
|
|
3071
3120
|
{
|
|
3072
|
-
useGetterPropsCalledChecker = function () {
|
|
3073
|
-
|
|
3121
|
+
useGetterPropsCalledChecker = function useGetterPropsCalledChecker() {
|
|
3122
|
+
var isInitialMountRef = react.useRef(true);
|
|
3074
3123
|
for (var _len = arguments.length, propKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3075
3124
|
propKeys[_key] = arguments[_key];
|
|
3076
3125
|
}
|
|
3077
|
-
|
|
3126
|
+
var getterPropsCalledRef = react.useRef(propKeys.reduce(function (acc, propKey) {
|
|
3078
3127
|
acc[propKey] = {};
|
|
3079
3128
|
return acc;
|
|
3080
3129
|
}, {}));
|
|
3081
|
-
react.useEffect(()
|
|
3082
|
-
Object.keys(getterPropsCalledRef.current).forEach(propKey
|
|
3083
|
-
|
|
3130
|
+
react.useEffect(function () {
|
|
3131
|
+
Object.keys(getterPropsCalledRef.current).forEach(function (propKey) {
|
|
3132
|
+
var propCallInfo = getterPropsCalledRef.current[propKey];
|
|
3084
3133
|
if (isInitialMountRef.current) {
|
|
3085
3134
|
if (!Object.keys(propCallInfo).length) {
|
|
3086
3135
|
// eslint-disable-next-line no-console
|
|
3087
|
-
console.error(
|
|
3136
|
+
console.error("downshift: You forgot to call the " + propKey + " getter function on your component / element.");
|
|
3088
3137
|
return;
|
|
3089
3138
|
}
|
|
3090
3139
|
}
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
elementRef
|
|
3095
|
-
} = propCallInfo;
|
|
3140
|
+
var suppressRefError = propCallInfo.suppressRefError,
|
|
3141
|
+
refKey = propCallInfo.refKey,
|
|
3142
|
+
elementRef = propCallInfo.elementRef;
|
|
3096
3143
|
if ((!elementRef || !elementRef.current) && !suppressRefError) {
|
|
3097
3144
|
// eslint-disable-next-line no-console
|
|
3098
|
-
console.error(
|
|
3145
|
+
console.error("downshift: The ref prop \"" + refKey + "\" from " + propKey + " was not applied correctly on your element.");
|
|
3099
3146
|
}
|
|
3100
3147
|
});
|
|
3101
3148
|
isInitialMountRef.current = false;
|
|
3102
3149
|
});
|
|
3103
|
-
|
|
3150
|
+
var setGetterPropCallInfo = react.useCallback(function (propKey, suppressRefError, refKey, elementRef) {
|
|
3104
3151
|
getterPropsCalledRef.current[propKey] = {
|
|
3105
|
-
suppressRefError,
|
|
3106
|
-
refKey,
|
|
3107
|
-
elementRef
|
|
3152
|
+
suppressRefError: suppressRefError,
|
|
3153
|
+
refKey: refKey,
|
|
3154
|
+
elementRef: elementRef
|
|
3108
3155
|
};
|
|
3109
3156
|
}, []);
|
|
3110
3157
|
return setGetterPropCallInfo;
|
|
3111
3158
|
};
|
|
3112
3159
|
}
|
|
3113
3160
|
function useA11yMessageSetter(getA11yMessage, dependencyArray, _ref2) {
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
...rest
|
|
3120
|
-
} = _ref2;
|
|
3161
|
+
var isInitialMount = _ref2.isInitialMount,
|
|
3162
|
+
highlightedIndex = _ref2.highlightedIndex,
|
|
3163
|
+
items = _ref2.items,
|
|
3164
|
+
environment = _ref2.environment,
|
|
3165
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
3121
3166
|
// Sets a11y status message on changes in state.
|
|
3122
|
-
react.useEffect(()
|
|
3167
|
+
react.useEffect(function () {
|
|
3123
3168
|
if (isInitialMount || false) {
|
|
3124
3169
|
return;
|
|
3125
3170
|
}
|
|
3126
|
-
updateA11yStatus(()
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3171
|
+
updateA11yStatus(function () {
|
|
3172
|
+
return getA11yMessage(_extends({
|
|
3173
|
+
highlightedIndex: highlightedIndex,
|
|
3174
|
+
highlightedItem: items[highlightedIndex],
|
|
3175
|
+
resultCount: items.length
|
|
3176
|
+
}, rest));
|
|
3177
|
+
}, environment.document);
|
|
3132
3178
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3133
3179
|
}, dependencyArray);
|
|
3134
3180
|
}
|
|
3135
3181
|
function useScrollIntoView(_ref3) {
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
scrollIntoView: scrollIntoViewProp
|
|
3143
|
-
} = _ref3;
|
|
3182
|
+
var highlightedIndex = _ref3.highlightedIndex,
|
|
3183
|
+
isOpen = _ref3.isOpen,
|
|
3184
|
+
itemRefs = _ref3.itemRefs,
|
|
3185
|
+
getItemNodeFromIndex = _ref3.getItemNodeFromIndex,
|
|
3186
|
+
menuElement = _ref3.menuElement,
|
|
3187
|
+
scrollIntoViewProp = _ref3.scrollIntoView;
|
|
3144
3188
|
// used not to scroll on highlight by mouse.
|
|
3145
|
-
|
|
3189
|
+
var shouldScrollRef = react.useRef(true);
|
|
3146
3190
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3147
|
-
useIsomorphicLayoutEffect(()
|
|
3191
|
+
useIsomorphicLayoutEffect(function () {
|
|
3148
3192
|
if (highlightedIndex < 0 || !isOpen || !Object.keys(itemRefs.current).length) {
|
|
3149
3193
|
return;
|
|
3150
3194
|
}
|
|
@@ -3159,18 +3203,16 @@
|
|
|
3159
3203
|
}
|
|
3160
3204
|
|
|
3161
3205
|
// eslint-disable-next-line import/no-mutable-exports
|
|
3162
|
-
|
|
3206
|
+
var useControlPropsValidator = noop;
|
|
3163
3207
|
/* istanbul ignore next */
|
|
3164
3208
|
{
|
|
3165
|
-
useControlPropsValidator = _ref4
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
state
|
|
3170
|
-
} = _ref4;
|
|
3209
|
+
useControlPropsValidator = function useControlPropsValidator(_ref4) {
|
|
3210
|
+
var isInitialMount = _ref4.isInitialMount,
|
|
3211
|
+
props = _ref4.props,
|
|
3212
|
+
state = _ref4.state;
|
|
3171
3213
|
// used for checking when props are moving from controlled to uncontrolled.
|
|
3172
|
-
|
|
3173
|
-
react.useEffect(()
|
|
3214
|
+
var prevPropsRef = react.useRef(props);
|
|
3215
|
+
react.useEffect(function () {
|
|
3174
3216
|
if (isInitialMount) {
|
|
3175
3217
|
return;
|
|
3176
3218
|
}
|
|
@@ -3181,11 +3223,9 @@
|
|
|
3181
3223
|
}
|
|
3182
3224
|
|
|
3183
3225
|
function downshiftCommonReducer(state, action, stateChangeTypes) {
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
} = action;
|
|
3188
|
-
let changes;
|
|
3226
|
+
var type = action.type,
|
|
3227
|
+
props = action.props;
|
|
3228
|
+
var changes;
|
|
3189
3229
|
switch (type) {
|
|
3190
3230
|
case stateChangeTypes.ItemMouseMove:
|
|
3191
3231
|
changes = {
|
|
@@ -3236,10 +3276,7 @@
|
|
|
3236
3276
|
default:
|
|
3237
3277
|
throw new Error('Reducer called without proper action type.');
|
|
3238
3278
|
}
|
|
3239
|
-
return {
|
|
3240
|
-
...state,
|
|
3241
|
-
...changes
|
|
3242
|
-
};
|
|
3279
|
+
return _extends({}, state, changes);
|
|
3243
3280
|
}
|
|
3244
3281
|
/* eslint-enable complexity */
|
|
3245
3282
|
|
|
@@ -3351,28 +3388,28 @@
|
|
|
3351
3388
|
};
|
|
3352
3389
|
}
|
|
3353
3390
|
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3391
|
+
var ToggleButtonClick$1 = '__togglebutton_click__' ;
|
|
3392
|
+
var ToggleButtonKeyDownArrowDown = '__togglebutton_keydown_arrow_down__' ;
|
|
3393
|
+
var ToggleButtonKeyDownArrowUp = '__togglebutton_keydown_arrow_up__' ;
|
|
3394
|
+
var ToggleButtonKeyDownCharacter = '__togglebutton_keydown_character__' ;
|
|
3395
|
+
var ToggleButtonKeyDownEscape = '__togglebutton_keydown_escape__' ;
|
|
3396
|
+
var ToggleButtonKeyDownHome = '__togglebutton_keydown_home__' ;
|
|
3397
|
+
var ToggleButtonKeyDownEnd = '__togglebutton_keydown_end__' ;
|
|
3398
|
+
var ToggleButtonKeyDownEnter = '__togglebutton_keydown_enter__' ;
|
|
3399
|
+
var ToggleButtonKeyDownSpaceButton = '__togglebutton_keydown_space_button__' ;
|
|
3400
|
+
var ToggleButtonKeyDownPageUp = '__togglebutton_keydown_page_up__' ;
|
|
3401
|
+
var ToggleButtonKeyDownPageDown = '__togglebutton_keydown_page_down__' ;
|
|
3402
|
+
var ToggleButtonBlur = '__togglebutton_blur__' ;
|
|
3403
|
+
var MenuMouseLeave$1 = '__menu_mouse_leave__' ;
|
|
3404
|
+
var ItemMouseMove$1 = '__item_mouse_move__' ;
|
|
3405
|
+
var ItemClick$1 = '__item_click__' ;
|
|
3406
|
+
var FunctionToggleMenu$1 = '__function_toggle_menu__' ;
|
|
3407
|
+
var FunctionOpenMenu$1 = '__function_open_menu__' ;
|
|
3408
|
+
var FunctionCloseMenu$1 = '__function_close_menu__' ;
|
|
3409
|
+
var FunctionSetHighlightedIndex$1 = '__function_set_highlighted_index__' ;
|
|
3410
|
+
var FunctionSelectItem$1 = '__function_select_item__' ;
|
|
3411
|
+
var FunctionSetInputValue$1 = '__function_set_input_value__' ;
|
|
3412
|
+
var FunctionReset$2 = '__function_reset__' ;
|
|
3376
3413
|
|
|
3377
3414
|
var stateChangeTypes$2 = /*#__PURE__*/Object.freeze({
|
|
3378
3415
|
__proto__: null,
|
|
@@ -3402,12 +3439,10 @@
|
|
|
3402
3439
|
|
|
3403
3440
|
/* eslint-disable complexity */
|
|
3404
3441
|
function downshiftSelectReducer(state, action) {
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
} = action;
|
|
3410
|
-
let changes;
|
|
3442
|
+
var type = action.type,
|
|
3443
|
+
props = action.props,
|
|
3444
|
+
altKey = action.altKey;
|
|
3445
|
+
var changes;
|
|
3411
3446
|
switch (type) {
|
|
3412
3447
|
case ItemClick$1:
|
|
3413
3448
|
changes = {
|
|
@@ -3418,10 +3453,10 @@
|
|
|
3418
3453
|
break;
|
|
3419
3454
|
case ToggleButtonKeyDownCharacter:
|
|
3420
3455
|
{
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3456
|
+
var lowercasedKey = action.key;
|
|
3457
|
+
var inputValue = "" + state.inputValue + lowercasedKey;
|
|
3458
|
+
var prevHighlightedIndex = !state.isOpen && state.selectedItem ? props.items.indexOf(state.selectedItem) : state.highlightedIndex;
|
|
3459
|
+
var highlightedIndex = getItemIndexByCharacterKey({
|
|
3425
3460
|
keysSoFar: inputValue,
|
|
3426
3461
|
highlightedIndex: prevHighlightedIndex,
|
|
3427
3462
|
items: props.items,
|
|
@@ -3429,34 +3464,33 @@
|
|
|
3429
3464
|
getItemNodeFromIndex: action.getItemNodeFromIndex
|
|
3430
3465
|
});
|
|
3431
3466
|
changes = {
|
|
3432
|
-
inputValue,
|
|
3433
|
-
highlightedIndex,
|
|
3467
|
+
inputValue: inputValue,
|
|
3468
|
+
highlightedIndex: highlightedIndex,
|
|
3434
3469
|
isOpen: true
|
|
3435
3470
|
};
|
|
3436
3471
|
}
|
|
3437
3472
|
break;
|
|
3438
3473
|
case ToggleButtonKeyDownArrowDown:
|
|
3439
3474
|
{
|
|
3440
|
-
|
|
3475
|
+
var _highlightedIndex = state.isOpen ? getNextWrappingIndex(1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : altKey && state.selectedItem == null ? -1 : getHighlightedIndexOnOpen(props, state, 1);
|
|
3441
3476
|
changes = {
|
|
3442
|
-
highlightedIndex,
|
|
3477
|
+
highlightedIndex: _highlightedIndex,
|
|
3443
3478
|
isOpen: true
|
|
3444
3479
|
};
|
|
3445
3480
|
}
|
|
3446
3481
|
break;
|
|
3447
3482
|
case ToggleButtonKeyDownArrowUp:
|
|
3448
3483
|
if (state.isOpen && altKey) {
|
|
3449
|
-
changes = {
|
|
3484
|
+
changes = _extends({
|
|
3450
3485
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3451
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
};
|
|
3486
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3487
|
+
}, state.highlightedIndex >= 0 && {
|
|
3488
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
3489
|
+
});
|
|
3456
3490
|
} else {
|
|
3457
|
-
|
|
3491
|
+
var _highlightedIndex2 = state.isOpen ? getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, false) : getHighlightedIndexOnOpen(props, state, -1);
|
|
3458
3492
|
changes = {
|
|
3459
|
-
highlightedIndex,
|
|
3493
|
+
highlightedIndex: _highlightedIndex2,
|
|
3460
3494
|
isOpen: true
|
|
3461
3495
|
};
|
|
3462
3496
|
}
|
|
@@ -3464,13 +3498,12 @@
|
|
|
3464
3498
|
// only triggered when menu is open.
|
|
3465
3499
|
case ToggleButtonKeyDownEnter:
|
|
3466
3500
|
case ToggleButtonKeyDownSpaceButton:
|
|
3467
|
-
changes = {
|
|
3501
|
+
changes = _extends({
|
|
3468
3502
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
3469
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
};
|
|
3503
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
3504
|
+
}, state.highlightedIndex >= 0 && {
|
|
3505
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
3506
|
+
});
|
|
3474
3507
|
break;
|
|
3475
3508
|
case ToggleButtonKeyDownHome:
|
|
3476
3509
|
changes = {
|
|
@@ -3501,13 +3534,12 @@
|
|
|
3501
3534
|
};
|
|
3502
3535
|
break;
|
|
3503
3536
|
case ToggleButtonBlur:
|
|
3504
|
-
changes = {
|
|
3537
|
+
changes = _extends({
|
|
3505
3538
|
isOpen: false,
|
|
3506
|
-
highlightedIndex: -1
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
};
|
|
3539
|
+
highlightedIndex: -1
|
|
3540
|
+
}, state.highlightedIndex >= 0 && {
|
|
3541
|
+
selectedItem: props.items[state.highlightedIndex]
|
|
3542
|
+
});
|
|
3511
3543
|
break;
|
|
3512
3544
|
case FunctionSelectItem$1:
|
|
3513
3545
|
changes = {
|
|
@@ -3517,13 +3549,13 @@
|
|
|
3517
3549
|
default:
|
|
3518
3550
|
return downshiftCommonReducer(state, action, stateChangeTypes$2);
|
|
3519
3551
|
}
|
|
3520
|
-
return {
|
|
3521
|
-
...state,
|
|
3522
|
-
...changes
|
|
3523
|
-
};
|
|
3552
|
+
return _extends({}, state, changes);
|
|
3524
3553
|
}
|
|
3525
3554
|
/* eslint-enable complexity */
|
|
3526
3555
|
|
|
3556
|
+
var _excluded$2 = ["onMouseLeave", "refKey", "onKeyDown", "onBlur", "ref"],
|
|
3557
|
+
_excluded2$2 = ["onBlur", "onClick", "onKeyDown", "refKey", "ref"],
|
|
3558
|
+
_excluded3$1 = ["item", "index", "onMouseMove", "onClick", "refKey", "ref", "disabled"];
|
|
3527
3559
|
useSelect.stateChangeTypes = stateChangeTypes$2;
|
|
3528
3560
|
function useSelect(userProps) {
|
|
3529
3561
|
if (userProps === void 0) {
|
|
@@ -3531,81 +3563,76 @@
|
|
|
3531
3563
|
}
|
|
3532
3564
|
validatePropTypes$2(userProps, useSelect);
|
|
3533
3565
|
// Props defaults and destructuring.
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
environment,
|
|
3542
|
-
itemToString,
|
|
3543
|
-
getA11ySelectionMessage,
|
|
3544
|
-
getA11yStatusMessage
|
|
3545
|
-
} = props;
|
|
3566
|
+
var props = _extends({}, defaultProps$2, userProps);
|
|
3567
|
+
var items = props.items,
|
|
3568
|
+
scrollIntoView = props.scrollIntoView,
|
|
3569
|
+
environment = props.environment,
|
|
3570
|
+
itemToString = props.itemToString,
|
|
3571
|
+
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
3572
|
+
getA11yStatusMessage = props.getA11yStatusMessage;
|
|
3546
3573
|
// Initial state depending on controlled props.
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3574
|
+
var initialState = getInitialState$2(props);
|
|
3575
|
+
var _useControlledReducer = useControlledReducer$1(downshiftSelectReducer, initialState, props),
|
|
3576
|
+
state = _useControlledReducer[0],
|
|
3577
|
+
dispatch = _useControlledReducer[1];
|
|
3578
|
+
var isOpen = state.isOpen,
|
|
3579
|
+
highlightedIndex = state.highlightedIndex,
|
|
3580
|
+
selectedItem = state.selectedItem,
|
|
3581
|
+
inputValue = state.inputValue;
|
|
3555
3582
|
|
|
3556
3583
|
// Element efs.
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3584
|
+
var toggleButtonRef = react.useRef(null);
|
|
3585
|
+
var menuRef = react.useRef(null);
|
|
3586
|
+
var itemRefs = react.useRef({});
|
|
3560
3587
|
// used to keep the inputValue clearTimeout object between renders.
|
|
3561
|
-
|
|
3588
|
+
var clearTimeoutRef = react.useRef(null);
|
|
3562
3589
|
// prevent id re-generation between renders.
|
|
3563
|
-
|
|
3590
|
+
var elementIds = useElementIds(props);
|
|
3564
3591
|
// used to keep track of how many items we had on previous cycle.
|
|
3565
|
-
|
|
3566
|
-
|
|
3592
|
+
var previousResultCountRef = react.useRef();
|
|
3593
|
+
var isInitialMountRef = react.useRef(true);
|
|
3567
3594
|
// utility callback to get item element.
|
|
3568
|
-
|
|
3569
|
-
state,
|
|
3570
|
-
props
|
|
3595
|
+
var latest = useLatestRef({
|
|
3596
|
+
state: state,
|
|
3597
|
+
props: props
|
|
3571
3598
|
});
|
|
3572
3599
|
|
|
3573
3600
|
// Some utils.
|
|
3574
|
-
|
|
3601
|
+
var getItemNodeFromIndex = react.useCallback(function (index) {
|
|
3602
|
+
return itemRefs.current[elementIds.getItemId(index)];
|
|
3603
|
+
}, [elementIds]);
|
|
3575
3604
|
|
|
3576
3605
|
// Effects.
|
|
3577
3606
|
// Sets a11y status message on changes in state.
|
|
3578
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
3607
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
|
|
3579
3608
|
isInitialMount: isInitialMountRef.current,
|
|
3580
3609
|
previousResultCount: previousResultCountRef.current,
|
|
3581
|
-
items,
|
|
3582
|
-
environment,
|
|
3583
|
-
itemToString
|
|
3584
|
-
|
|
3585
|
-
});
|
|
3610
|
+
items: items,
|
|
3611
|
+
environment: environment,
|
|
3612
|
+
itemToString: itemToString
|
|
3613
|
+
}, state));
|
|
3586
3614
|
// Sets a11y status message on changes in selectedItem.
|
|
3587
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
3615
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
3588
3616
|
isInitialMount: isInitialMountRef.current,
|
|
3589
3617
|
previousResultCount: previousResultCountRef.current,
|
|
3590
|
-
items,
|
|
3591
|
-
environment,
|
|
3592
|
-
itemToString
|
|
3593
|
-
|
|
3594
|
-
});
|
|
3618
|
+
items: items,
|
|
3619
|
+
environment: environment,
|
|
3620
|
+
itemToString: itemToString
|
|
3621
|
+
}, state));
|
|
3595
3622
|
// Scroll on highlighted item if change comes from keyboard.
|
|
3596
|
-
|
|
3623
|
+
var shouldScrollRef = useScrollIntoView({
|
|
3597
3624
|
menuElement: menuRef.current,
|
|
3598
|
-
highlightedIndex,
|
|
3599
|
-
isOpen,
|
|
3600
|
-
itemRefs,
|
|
3601
|
-
scrollIntoView,
|
|
3602
|
-
getItemNodeFromIndex
|
|
3625
|
+
highlightedIndex: highlightedIndex,
|
|
3626
|
+
isOpen: isOpen,
|
|
3627
|
+
itemRefs: itemRefs,
|
|
3628
|
+
scrollIntoView: scrollIntoView,
|
|
3629
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3603
3630
|
});
|
|
3604
3631
|
|
|
3605
3632
|
// Sets cleanup for the keysSoFar callback, debounded after 500ms.
|
|
3606
|
-
react.useEffect(()
|
|
3633
|
+
react.useEffect(function () {
|
|
3607
3634
|
// init the clean function here as we need access to dispatch.
|
|
3608
|
-
clearTimeoutRef.current = debounce(outerDispatch
|
|
3635
|
+
clearTimeoutRef.current = debounce(function (outerDispatch) {
|
|
3609
3636
|
outerDispatch({
|
|
3610
3637
|
type: FunctionSetInputValue$1,
|
|
3611
3638
|
inputValue: ''
|
|
@@ -3613,13 +3640,13 @@
|
|
|
3613
3640
|
}, 500);
|
|
3614
3641
|
|
|
3615
3642
|
// Cancel any pending debounced calls on mount
|
|
3616
|
-
return ()
|
|
3643
|
+
return function () {
|
|
3617
3644
|
clearTimeoutRef.current.cancel();
|
|
3618
3645
|
};
|
|
3619
3646
|
}, []);
|
|
3620
3647
|
|
|
3621
3648
|
// Invokes the keysSoFar callback set up above.
|
|
3622
|
-
react.useEffect(()
|
|
3649
|
+
react.useEffect(function () {
|
|
3623
3650
|
if (!inputValue) {
|
|
3624
3651
|
return;
|
|
3625
3652
|
}
|
|
@@ -3627,249 +3654,234 @@
|
|
|
3627
3654
|
}, [dispatch, inputValue]);
|
|
3628
3655
|
useControlPropsValidator({
|
|
3629
3656
|
isInitialMount: isInitialMountRef.current,
|
|
3630
|
-
props,
|
|
3631
|
-
state
|
|
3657
|
+
props: props,
|
|
3658
|
+
state: state
|
|
3632
3659
|
});
|
|
3633
|
-
react.useEffect(()
|
|
3660
|
+
react.useEffect(function () {
|
|
3634
3661
|
if (isInitialMountRef.current) {
|
|
3635
3662
|
return;
|
|
3636
3663
|
}
|
|
3637
3664
|
previousResultCountRef.current = items.length;
|
|
3638
3665
|
});
|
|
3639
3666
|
// Add mouse/touch events to document.
|
|
3640
|
-
|
|
3667
|
+
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [menuRef, toggleButtonRef], environment, function () {
|
|
3641
3668
|
dispatch({
|
|
3642
3669
|
type: ToggleButtonBlur
|
|
3643
3670
|
});
|
|
3644
3671
|
});
|
|
3645
|
-
|
|
3672
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getMenuProps', 'getToggleButtonProps');
|
|
3646
3673
|
// Make initial ref false.
|
|
3647
|
-
react.useEffect(()
|
|
3674
|
+
react.useEffect(function () {
|
|
3648
3675
|
isInitialMountRef.current = false;
|
|
3649
|
-
return ()
|
|
3676
|
+
return function () {
|
|
3650
3677
|
isInitialMountRef.current = true;
|
|
3651
3678
|
};
|
|
3652
3679
|
}, []);
|
|
3653
3680
|
// Reset itemRefs on close.
|
|
3654
|
-
react.useEffect(()
|
|
3681
|
+
react.useEffect(function () {
|
|
3655
3682
|
if (!isOpen) {
|
|
3656
3683
|
itemRefs.current = {};
|
|
3657
3684
|
}
|
|
3658
3685
|
}, [isOpen]);
|
|
3659
3686
|
|
|
3660
3687
|
// Event handler functions.
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
event
|
|
3664
|
-
dispatch({
|
|
3665
|
-
type: ToggleButtonKeyDownArrowDown,
|
|
3666
|
-
getItemNodeFromIndex,
|
|
3667
|
-
altKey: event.altKey
|
|
3668
|
-
});
|
|
3669
|
-
},
|
|
3670
|
-
ArrowUp(event) {
|
|
3671
|
-
event.preventDefault();
|
|
3672
|
-
dispatch({
|
|
3673
|
-
type: ToggleButtonKeyDownArrowUp,
|
|
3674
|
-
getItemNodeFromIndex,
|
|
3675
|
-
altKey: event.altKey
|
|
3676
|
-
});
|
|
3677
|
-
},
|
|
3678
|
-
Home(event) {
|
|
3679
|
-
event.preventDefault();
|
|
3680
|
-
dispatch({
|
|
3681
|
-
type: ToggleButtonKeyDownHome,
|
|
3682
|
-
getItemNodeFromIndex
|
|
3683
|
-
});
|
|
3684
|
-
},
|
|
3685
|
-
End(event) {
|
|
3686
|
-
event.preventDefault();
|
|
3687
|
-
dispatch({
|
|
3688
|
-
type: ToggleButtonKeyDownEnd,
|
|
3689
|
-
getItemNodeFromIndex
|
|
3690
|
-
});
|
|
3691
|
-
},
|
|
3692
|
-
Escape() {
|
|
3693
|
-
if (latest.current.state.isOpen) {
|
|
3694
|
-
dispatch({
|
|
3695
|
-
type: ToggleButtonKeyDownEscape
|
|
3696
|
-
});
|
|
3697
|
-
}
|
|
3698
|
-
},
|
|
3699
|
-
Enter(event) {
|
|
3700
|
-
event.preventDefault();
|
|
3701
|
-
dispatch({
|
|
3702
|
-
type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
|
|
3703
|
-
});
|
|
3704
|
-
},
|
|
3705
|
-
PageUp(event) {
|
|
3706
|
-
if (latest.current.state.isOpen) {
|
|
3688
|
+
var toggleButtonKeyDownHandlers = react.useMemo(function () {
|
|
3689
|
+
return {
|
|
3690
|
+
ArrowDown: function ArrowDown(event) {
|
|
3707
3691
|
event.preventDefault();
|
|
3708
3692
|
dispatch({
|
|
3709
|
-
type:
|
|
3710
|
-
getItemNodeFromIndex
|
|
3693
|
+
type: ToggleButtonKeyDownArrowDown,
|
|
3694
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3695
|
+
altKey: event.altKey
|
|
3711
3696
|
});
|
|
3712
|
-
}
|
|
3713
|
-
|
|
3714
|
-
PageDown(event) {
|
|
3715
|
-
if (latest.current.state.isOpen) {
|
|
3697
|
+
},
|
|
3698
|
+
ArrowUp: function ArrowUp(event) {
|
|
3716
3699
|
event.preventDefault();
|
|
3717
3700
|
dispatch({
|
|
3718
|
-
type:
|
|
3719
|
-
getItemNodeFromIndex
|
|
3701
|
+
type: ToggleButtonKeyDownArrowUp,
|
|
3702
|
+
getItemNodeFromIndex: getItemNodeFromIndex,
|
|
3703
|
+
altKey: event.altKey
|
|
3720
3704
|
});
|
|
3721
|
-
}
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
event.preventDefault();
|
|
3725
|
-
const currentState = latest.current.state;
|
|
3726
|
-
if (!currentState.isOpen) {
|
|
3705
|
+
},
|
|
3706
|
+
Home: function Home(event) {
|
|
3707
|
+
event.preventDefault();
|
|
3727
3708
|
dispatch({
|
|
3728
|
-
type:
|
|
3709
|
+
type: ToggleButtonKeyDownHome,
|
|
3710
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3729
3711
|
});
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3712
|
+
},
|
|
3713
|
+
End: function End(event) {
|
|
3714
|
+
event.preventDefault();
|
|
3733
3715
|
dispatch({
|
|
3734
|
-
type:
|
|
3735
|
-
|
|
3736
|
-
getItemNodeFromIndex
|
|
3716
|
+
type: ToggleButtonKeyDownEnd,
|
|
3717
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3737
3718
|
});
|
|
3738
|
-
}
|
|
3719
|
+
},
|
|
3720
|
+
Escape: function Escape() {
|
|
3721
|
+
if (latest.current.state.isOpen) {
|
|
3722
|
+
dispatch({
|
|
3723
|
+
type: ToggleButtonKeyDownEscape
|
|
3724
|
+
});
|
|
3725
|
+
}
|
|
3726
|
+
},
|
|
3727
|
+
Enter: function Enter(event) {
|
|
3728
|
+
event.preventDefault();
|
|
3739
3729
|
dispatch({
|
|
3740
|
-
type:
|
|
3730
|
+
type: latest.current.state.isOpen ? ToggleButtonKeyDownEnter : ToggleButtonClick$1
|
|
3741
3731
|
});
|
|
3732
|
+
},
|
|
3733
|
+
PageUp: function PageUp(event) {
|
|
3734
|
+
if (latest.current.state.isOpen) {
|
|
3735
|
+
event.preventDefault();
|
|
3736
|
+
dispatch({
|
|
3737
|
+
type: ToggleButtonKeyDownPageUp,
|
|
3738
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3739
|
+
});
|
|
3740
|
+
}
|
|
3741
|
+
},
|
|
3742
|
+
PageDown: function PageDown(event) {
|
|
3743
|
+
if (latest.current.state.isOpen) {
|
|
3744
|
+
event.preventDefault();
|
|
3745
|
+
dispatch({
|
|
3746
|
+
type: ToggleButtonKeyDownPageDown,
|
|
3747
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3748
|
+
});
|
|
3749
|
+
}
|
|
3750
|
+
},
|
|
3751
|
+
' ': function _(event) {
|
|
3752
|
+
event.preventDefault();
|
|
3753
|
+
var currentState = latest.current.state;
|
|
3754
|
+
if (!currentState.isOpen) {
|
|
3755
|
+
dispatch({
|
|
3756
|
+
type: ToggleButtonClick$1
|
|
3757
|
+
});
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3760
|
+
if (currentState.inputValue) {
|
|
3761
|
+
dispatch({
|
|
3762
|
+
type: ToggleButtonKeyDownCharacter,
|
|
3763
|
+
key: ' ',
|
|
3764
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3765
|
+
});
|
|
3766
|
+
} else {
|
|
3767
|
+
dispatch({
|
|
3768
|
+
type: ToggleButtonKeyDownSpaceButton
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3742
3771
|
}
|
|
3743
|
-
}
|
|
3744
|
-
}
|
|
3772
|
+
};
|
|
3773
|
+
}, [dispatch, getItemNodeFromIndex, latest]);
|
|
3745
3774
|
|
|
3746
3775
|
// Action functions.
|
|
3747
|
-
|
|
3776
|
+
var toggleMenu = react.useCallback(function () {
|
|
3748
3777
|
dispatch({
|
|
3749
3778
|
type: FunctionToggleMenu$1
|
|
3750
3779
|
});
|
|
3751
3780
|
}, [dispatch]);
|
|
3752
|
-
|
|
3781
|
+
var closeMenu = react.useCallback(function () {
|
|
3753
3782
|
dispatch({
|
|
3754
3783
|
type: FunctionCloseMenu$1
|
|
3755
3784
|
});
|
|
3756
3785
|
}, [dispatch]);
|
|
3757
|
-
|
|
3786
|
+
var openMenu = react.useCallback(function () {
|
|
3758
3787
|
dispatch({
|
|
3759
3788
|
type: FunctionOpenMenu$1
|
|
3760
3789
|
});
|
|
3761
3790
|
}, [dispatch]);
|
|
3762
|
-
|
|
3791
|
+
var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
|
|
3763
3792
|
dispatch({
|
|
3764
3793
|
type: FunctionSetHighlightedIndex$1,
|
|
3765
3794
|
highlightedIndex: newHighlightedIndex
|
|
3766
3795
|
});
|
|
3767
3796
|
}, [dispatch]);
|
|
3768
|
-
|
|
3797
|
+
var selectItem = react.useCallback(function (newSelectedItem) {
|
|
3769
3798
|
dispatch({
|
|
3770
3799
|
type: FunctionSelectItem$1,
|
|
3771
3800
|
selectedItem: newSelectedItem
|
|
3772
3801
|
});
|
|
3773
3802
|
}, [dispatch]);
|
|
3774
|
-
|
|
3803
|
+
var reset = react.useCallback(function () {
|
|
3775
3804
|
dispatch({
|
|
3776
3805
|
type: FunctionReset$2
|
|
3777
3806
|
});
|
|
3778
3807
|
}, [dispatch]);
|
|
3779
|
-
|
|
3808
|
+
var setInputValue = react.useCallback(function (newInputValue) {
|
|
3780
3809
|
dispatch({
|
|
3781
3810
|
type: FunctionSetInputValue$1,
|
|
3782
3811
|
inputValue: newInputValue
|
|
3783
3812
|
});
|
|
3784
3813
|
}, [dispatch]);
|
|
3785
3814
|
// Getter functions.
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
ref
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3815
|
+
var getLabelProps = react.useCallback(function (labelProps) {
|
|
3816
|
+
return _extends({
|
|
3817
|
+
id: elementIds.labelId,
|
|
3818
|
+
htmlFor: elementIds.toggleButtonId
|
|
3819
|
+
}, labelProps);
|
|
3820
|
+
}, [elementIds]);
|
|
3821
|
+
var getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
3822
|
+
var _extends2;
|
|
3823
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
3824
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
3825
|
+
_ref$refKey = _ref.refKey,
|
|
3826
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey;
|
|
3827
|
+
_ref.onKeyDown;
|
|
3828
|
+
_ref.onBlur;
|
|
3829
|
+
var ref = _ref.ref,
|
|
3830
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
3831
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
3832
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
3833
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
3834
|
+
var menuHandleMouseLeave = function menuHandleMouseLeave() {
|
|
3804
3835
|
dispatch({
|
|
3805
3836
|
type: MenuMouseLeave$1
|
|
3806
3837
|
});
|
|
3807
3838
|
};
|
|
3808
3839
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
3809
|
-
return {
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
}),
|
|
3813
|
-
id: elementIds.menuId,
|
|
3814
|
-
role: 'listbox',
|
|
3815
|
-
'aria-labelledby': elementIds.labelId,
|
|
3816
|
-
tabIndex: -1,
|
|
3817
|
-
onMouseLeave: callAllEventHandlers(onMouseLeave, menuHandleMouseLeave),
|
|
3818
|
-
...rest
|
|
3819
|
-
};
|
|
3840
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
3841
|
+
menuRef.current = menuNode;
|
|
3842
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.tabIndex = -1, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, menuHandleMouseLeave), _extends2), rest);
|
|
3820
3843
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3844
|
+
var getToggleButtonProps = react.useCallback(function (_temp3, _temp4) {
|
|
3845
|
+
var _extends3;
|
|
3846
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
3847
|
+
onBlur = _ref3.onBlur,
|
|
3848
|
+
onClick = _ref3.onClick,
|
|
3849
|
+
onKeyDown = _ref3.onKeyDown,
|
|
3850
|
+
_ref3$refKey = _ref3.refKey,
|
|
3851
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
3852
|
+
ref = _ref3.ref,
|
|
3853
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$2);
|
|
3854
|
+
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
3855
|
+
_ref4$suppressRefErro = _ref4.suppressRefError,
|
|
3856
|
+
suppressRefError = _ref4$suppressRefErro === void 0 ? false : _ref4$suppressRefErro;
|
|
3857
|
+
var latestState = latest.current.state;
|
|
3858
|
+
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
3835
3859
|
dispatch({
|
|
3836
3860
|
type: ToggleButtonClick$1
|
|
3837
3861
|
});
|
|
3838
3862
|
};
|
|
3839
|
-
|
|
3863
|
+
var toggleButtonHandleBlur = function toggleButtonHandleBlur() {
|
|
3840
3864
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
3841
3865
|
dispatch({
|
|
3842
3866
|
type: ToggleButtonBlur
|
|
3843
3867
|
});
|
|
3844
3868
|
}
|
|
3845
3869
|
};
|
|
3846
|
-
|
|
3847
|
-
|
|
3870
|
+
var toggleButtonHandleKeyDown = function toggleButtonHandleKeyDown(event) {
|
|
3871
|
+
var key = normalizeArrowKey(event);
|
|
3848
3872
|
if (key && toggleButtonKeyDownHandlers[key]) {
|
|
3849
3873
|
toggleButtonKeyDownHandlers[key](event);
|
|
3850
3874
|
} else if (isAcceptedCharacterKey(key)) {
|
|
3851
3875
|
dispatch({
|
|
3852
3876
|
type: ToggleButtonKeyDownCharacter,
|
|
3853
|
-
key,
|
|
3854
|
-
getItemNodeFromIndex
|
|
3877
|
+
key: key,
|
|
3878
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
3855
3879
|
});
|
|
3856
3880
|
}
|
|
3857
3881
|
};
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
}),
|
|
3862
|
-
'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
|
|
3863
|
-
'aria-controls': elementIds.menuId,
|
|
3864
|
-
'aria-expanded': latest.current.state.isOpen,
|
|
3865
|
-
'aria-haspopup': 'listbox',
|
|
3866
|
-
'aria-labelledby': `${elementIds.labelId}`,
|
|
3867
|
-
id: elementIds.toggleButtonId,
|
|
3868
|
-
role: 'combobox',
|
|
3869
|
-
tabIndex: 0,
|
|
3870
|
-
onBlur: callAllEventHandlers(onBlur, toggleButtonHandleBlur),
|
|
3871
|
-
...rest
|
|
3872
|
-
};
|
|
3882
|
+
var toggleProps = _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
3883
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
3884
|
+
}), _extends3['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends3['aria-controls'] = elementIds.menuId, _extends3['aria-expanded'] = latest.current.state.isOpen, _extends3['aria-haspopup'] = 'listbox', _extends3['aria-labelledby'] = "" + elementIds.labelId, _extends3.id = elementIds.toggleButtonId, _extends3.role = 'combobox', _extends3.tabIndex = 0, _extends3.onBlur = callAllEventHandlers(onBlur, toggleButtonHandleBlur), _extends3), rest);
|
|
3873
3885
|
if (!rest.disabled) {
|
|
3874
3886
|
toggleProps.onClick = callAllEventHandlers(onClick, toggleButtonHandleClick);
|
|
3875
3887
|
toggleProps.onKeyDown = callAllEventHandlers(onKeyDown, toggleButtonHandleKeyDown);
|
|
@@ -3877,56 +3889,54 @@
|
|
|
3877
3889
|
setGetterPropCallInfo('getToggleButtonProps', suppressRefError, refKey, toggleButtonRef);
|
|
3878
3890
|
return toggleProps;
|
|
3879
3891
|
}, [latest, elementIds, setGetterPropCallInfo, dispatch, mouseAndTouchTrackersRef, toggleButtonKeyDownHandlers, getItemNodeFromIndex]);
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3892
|
+
var getItemProps = react.useCallback(function (_temp5) {
|
|
3893
|
+
var _extends4;
|
|
3894
|
+
var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
|
3895
|
+
itemProp = _ref5.item,
|
|
3896
|
+
indexProp = _ref5.index,
|
|
3897
|
+
onMouseMove = _ref5.onMouseMove,
|
|
3898
|
+
onClick = _ref5.onClick,
|
|
3899
|
+
_ref5$refKey = _ref5.refKey,
|
|
3900
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
3901
|
+
ref = _ref5.ref,
|
|
3902
|
+
disabled = _ref5.disabled,
|
|
3903
|
+
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3$1);
|
|
3904
|
+
var _latest$current = latest.current,
|
|
3905
|
+
latestState = _latest$current.state,
|
|
3906
|
+
latestProps = _latest$current.props;
|
|
3907
|
+
var item = itemProp != null ? itemProp : items[indexProp];
|
|
3908
|
+
var index = getItemIndex(indexProp, item, latestProps.items);
|
|
3909
|
+
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
3898
3910
|
if (index === latestState.highlightedIndex) {
|
|
3899
3911
|
return;
|
|
3900
3912
|
}
|
|
3901
3913
|
shouldScrollRef.current = false;
|
|
3902
3914
|
dispatch({
|
|
3903
3915
|
type: ItemMouseMove$1,
|
|
3904
|
-
index,
|
|
3905
|
-
disabled
|
|
3916
|
+
index: index,
|
|
3917
|
+
disabled: disabled
|
|
3906
3918
|
});
|
|
3907
3919
|
};
|
|
3908
|
-
|
|
3920
|
+
var itemHandleClick = function itemHandleClick() {
|
|
3909
3921
|
dispatch({
|
|
3910
3922
|
type: ItemClick$1,
|
|
3911
|
-
index
|
|
3923
|
+
index: index
|
|
3912
3924
|
});
|
|
3913
3925
|
};
|
|
3914
|
-
|
|
3926
|
+
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
3915
3927
|
if (itemIndex < 0) {
|
|
3916
3928
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
3917
3929
|
}
|
|
3918
|
-
|
|
3919
|
-
disabled,
|
|
3930
|
+
var itemProps = _extends((_extends4 = {
|
|
3931
|
+
disabled: disabled,
|
|
3920
3932
|
role: 'option',
|
|
3921
|
-
'aria-selected':
|
|
3922
|
-
id: elementIds.getItemId(itemIndex)
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
...rest
|
|
3929
|
-
};
|
|
3933
|
+
'aria-selected': "" + (item === selectedItem),
|
|
3934
|
+
id: elementIds.getItemId(itemIndex)
|
|
3935
|
+
}, _extends4[refKey] = handleRefs(ref, function (itemNode) {
|
|
3936
|
+
if (itemNode) {
|
|
3937
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
3938
|
+
}
|
|
3939
|
+
}), _extends4), rest);
|
|
3930
3940
|
if (!disabled) {
|
|
3931
3941
|
itemProps.onClick = callAllEventHandlers(onClick, itemHandleClick);
|
|
3932
3942
|
}
|
|
@@ -3935,49 +3945,49 @@
|
|
|
3935
3945
|
}, [latest, items, selectedItem, elementIds, shouldScrollRef, dispatch]);
|
|
3936
3946
|
return {
|
|
3937
3947
|
// prop getters.
|
|
3938
|
-
getToggleButtonProps,
|
|
3939
|
-
getLabelProps,
|
|
3940
|
-
getMenuProps,
|
|
3941
|
-
getItemProps,
|
|
3948
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
3949
|
+
getLabelProps: getLabelProps,
|
|
3950
|
+
getMenuProps: getMenuProps,
|
|
3951
|
+
getItemProps: getItemProps,
|
|
3942
3952
|
// actions.
|
|
3943
|
-
toggleMenu,
|
|
3944
|
-
openMenu,
|
|
3945
|
-
closeMenu,
|
|
3946
|
-
setHighlightedIndex,
|
|
3947
|
-
selectItem,
|
|
3948
|
-
reset,
|
|
3949
|
-
setInputValue,
|
|
3953
|
+
toggleMenu: toggleMenu,
|
|
3954
|
+
openMenu: openMenu,
|
|
3955
|
+
closeMenu: closeMenu,
|
|
3956
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
3957
|
+
selectItem: selectItem,
|
|
3958
|
+
reset: reset,
|
|
3959
|
+
setInputValue: setInputValue,
|
|
3950
3960
|
// state.
|
|
3951
|
-
highlightedIndex,
|
|
3952
|
-
isOpen,
|
|
3953
|
-
selectedItem,
|
|
3954
|
-
inputValue
|
|
3961
|
+
highlightedIndex: highlightedIndex,
|
|
3962
|
+
isOpen: isOpen,
|
|
3963
|
+
selectedItem: selectedItem,
|
|
3964
|
+
inputValue: inputValue
|
|
3955
3965
|
};
|
|
3956
3966
|
}
|
|
3957
3967
|
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3968
|
+
var InputKeyDownArrowDown = '__input_keydown_arrow_down__' ;
|
|
3969
|
+
var InputKeyDownArrowUp = '__input_keydown_arrow_up__' ;
|
|
3970
|
+
var InputKeyDownEscape = '__input_keydown_escape__' ;
|
|
3971
|
+
var InputKeyDownHome = '__input_keydown_home__' ;
|
|
3972
|
+
var InputKeyDownEnd = '__input_keydown_end__' ;
|
|
3973
|
+
var InputKeyDownPageUp = '__input_keydown_page_up__' ;
|
|
3974
|
+
var InputKeyDownPageDown = '__input_keydown_page_down__' ;
|
|
3975
|
+
var InputKeyDownEnter = '__input_keydown_enter__' ;
|
|
3976
|
+
var InputChange = '__input_change__' ;
|
|
3977
|
+
var InputBlur = '__input_blur__' ;
|
|
3978
|
+
var InputFocus = '__input_focus__' ;
|
|
3979
|
+
var MenuMouseLeave = '__menu_mouse_leave__' ;
|
|
3980
|
+
var ItemMouseMove = '__item_mouse_move__' ;
|
|
3981
|
+
var ItemClick = '__item_click__' ;
|
|
3982
|
+
var ToggleButtonClick = '__togglebutton_click__' ;
|
|
3983
|
+
var FunctionToggleMenu = '__function_toggle_menu__' ;
|
|
3984
|
+
var FunctionOpenMenu = '__function_open_menu__' ;
|
|
3985
|
+
var FunctionCloseMenu = '__function_close_menu__' ;
|
|
3986
|
+
var FunctionSetHighlightedIndex = '__function_set_highlighted_index__' ;
|
|
3987
|
+
var FunctionSelectItem = '__function_select_item__' ;
|
|
3988
|
+
var FunctionSetInputValue = '__function_set_input_value__' ;
|
|
3989
|
+
var FunctionReset$1 = '__function_reset__' ;
|
|
3990
|
+
var ControlledPropUpdatedSelectedItem = '__controlled_prop_updated_selected_item__' ;
|
|
3981
3991
|
|
|
3982
3992
|
var stateChangeTypes$1 = /*#__PURE__*/Object.freeze({
|
|
3983
3993
|
__proto__: null,
|
|
@@ -4007,22 +4017,17 @@
|
|
|
4007
4017
|
});
|
|
4008
4018
|
|
|
4009
4019
|
function getInitialState$1(props) {
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
} = initialState;
|
|
4014
|
-
let {
|
|
4015
|
-
inputValue
|
|
4016
|
-
} = initialState;
|
|
4020
|
+
var initialState = getInitialState$2(props);
|
|
4021
|
+
var selectedItem = initialState.selectedItem;
|
|
4022
|
+
var inputValue = initialState.inputValue;
|
|
4017
4023
|
if (inputValue === '' && selectedItem && props.defaultInputValue === undefined && props.initialInputValue === undefined && props.inputValue === undefined) {
|
|
4018
4024
|
inputValue = props.itemToString(selectedItem);
|
|
4019
4025
|
}
|
|
4020
|
-
return {
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
};
|
|
4026
|
+
return _extends({}, initialState, {
|
|
4027
|
+
inputValue: inputValue
|
|
4028
|
+
});
|
|
4024
4029
|
}
|
|
4025
|
-
|
|
4030
|
+
var propTypes$1 = {
|
|
4026
4031
|
items: PropTypes.array.isRequired,
|
|
4027
4032
|
itemToString: PropTypes.func,
|
|
4028
4033
|
getA11yStatusMessage: PropTypes.func,
|
|
@@ -4075,11 +4080,13 @@
|
|
|
4075
4080
|
* @returns {Array} An array with the state and an action dispatcher.
|
|
4076
4081
|
*/
|
|
4077
4082
|
function useControlledReducer(reducer, initialState, props) {
|
|
4078
|
-
|
|
4079
|
-
|
|
4083
|
+
var previousSelectedItemRef = react.useRef();
|
|
4084
|
+
var _useEnhancedReducer = useEnhancedReducer(reducer, initialState, props),
|
|
4085
|
+
state = _useEnhancedReducer[0],
|
|
4086
|
+
dispatch = _useEnhancedReducer[1];
|
|
4080
4087
|
|
|
4081
4088
|
// ToDo: if needed, make same approach as selectedItemChanged from Downshift.
|
|
4082
|
-
react.useEffect(()
|
|
4089
|
+
react.useEffect(function () {
|
|
4083
4090
|
if (isControlledProp(props, 'selectedItem')) {
|
|
4084
4091
|
if (previousSelectedItemRef.current !== props.selectedItem) {
|
|
4085
4092
|
dispatch({
|
|
@@ -4094,26 +4101,23 @@
|
|
|
4094
4101
|
}
|
|
4095
4102
|
|
|
4096
4103
|
// eslint-disable-next-line import/no-mutable-exports
|
|
4097
|
-
|
|
4104
|
+
var validatePropTypes$1 = noop;
|
|
4098
4105
|
/* istanbul ignore next */
|
|
4099
4106
|
{
|
|
4100
|
-
validatePropTypes$1 = (options, caller)
|
|
4107
|
+
validatePropTypes$1 = function validatePropTypes(options, caller) {
|
|
4101
4108
|
PropTypes.checkPropTypes(propTypes$1, options, 'prop', caller.name);
|
|
4102
4109
|
};
|
|
4103
4110
|
}
|
|
4104
|
-
|
|
4105
|
-
...defaultProps$3,
|
|
4111
|
+
var defaultProps$1 = _extends({}, defaultProps$3, {
|
|
4106
4112
|
getA11yStatusMessage: getA11yStatusMessage$1
|
|
4107
|
-
};
|
|
4113
|
+
});
|
|
4108
4114
|
|
|
4109
4115
|
/* eslint-disable complexity */
|
|
4110
4116
|
function downshiftUseComboboxReducer(state, action) {
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
} = action;
|
|
4116
|
-
let changes;
|
|
4117
|
+
var type = action.type,
|
|
4118
|
+
props = action.props,
|
|
4119
|
+
altKey = action.altKey;
|
|
4120
|
+
var changes;
|
|
4117
4121
|
switch (type) {
|
|
4118
4122
|
case ItemClick:
|
|
4119
4123
|
changes = {
|
|
@@ -4138,14 +4142,13 @@
|
|
|
4138
4142
|
case InputKeyDownArrowUp:
|
|
4139
4143
|
if (state.isOpen) {
|
|
4140
4144
|
if (altKey) {
|
|
4141
|
-
changes = {
|
|
4145
|
+
changes = _extends({
|
|
4142
4146
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4143
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
};
|
|
4147
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4148
|
+
}, state.highlightedIndex >= 0 && {
|
|
4149
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
4150
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4151
|
+
});
|
|
4149
4152
|
} else {
|
|
4150
4153
|
changes = {
|
|
4151
4154
|
highlightedIndex: getNextWrappingIndex(-1, state.highlightedIndex, props.items.length, action.getItemNodeFromIndex, true)
|
|
@@ -4159,24 +4162,22 @@
|
|
|
4159
4162
|
}
|
|
4160
4163
|
break;
|
|
4161
4164
|
case InputKeyDownEnter:
|
|
4162
|
-
changes = {
|
|
4165
|
+
changes = _extends({
|
|
4163
4166
|
isOpen: getDefaultValue$1(props, 'isOpen'),
|
|
4164
|
-
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
};
|
|
4167
|
+
highlightedIndex: getDefaultValue$1(props, 'highlightedIndex')
|
|
4168
|
+
}, state.highlightedIndex >= 0 && {
|
|
4169
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
4170
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4171
|
+
});
|
|
4170
4172
|
break;
|
|
4171
4173
|
case InputKeyDownEscape:
|
|
4172
|
-
changes = {
|
|
4174
|
+
changes = _extends({
|
|
4173
4175
|
isOpen: false,
|
|
4174
|
-
highlightedIndex: -1
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
};
|
|
4176
|
+
highlightedIndex: -1
|
|
4177
|
+
}, !state.isOpen && {
|
|
4178
|
+
selectedItem: null,
|
|
4179
|
+
inputValue: ''
|
|
4180
|
+
});
|
|
4180
4181
|
break;
|
|
4181
4182
|
case InputKeyDownPageUp:
|
|
4182
4183
|
changes = {
|
|
@@ -4199,14 +4200,13 @@
|
|
|
4199
4200
|
};
|
|
4200
4201
|
break;
|
|
4201
4202
|
case InputBlur:
|
|
4202
|
-
changes = {
|
|
4203
|
+
changes = _extends({
|
|
4203
4204
|
isOpen: false,
|
|
4204
|
-
highlightedIndex: -1
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
};
|
|
4205
|
+
highlightedIndex: -1
|
|
4206
|
+
}, state.highlightedIndex >= 0 && action.selectItem && {
|
|
4207
|
+
selectedItem: props.items[state.highlightedIndex],
|
|
4208
|
+
inputValue: props.itemToString(props.items[state.highlightedIndex])
|
|
4209
|
+
});
|
|
4210
4210
|
break;
|
|
4211
4211
|
case InputChange:
|
|
4212
4212
|
changes = {
|
|
@@ -4235,14 +4235,14 @@
|
|
|
4235
4235
|
default:
|
|
4236
4236
|
return downshiftCommonReducer(state, action, stateChangeTypes$1);
|
|
4237
4237
|
}
|
|
4238
|
-
return {
|
|
4239
|
-
...state,
|
|
4240
|
-
...changes
|
|
4241
|
-
};
|
|
4238
|
+
return _extends({}, state, changes);
|
|
4242
4239
|
}
|
|
4243
4240
|
/* eslint-enable complexity */
|
|
4244
4241
|
|
|
4245
|
-
|
|
4242
|
+
var _excluded$1 = ["onMouseLeave", "refKey", "ref"],
|
|
4243
|
+
_excluded2$1 = ["item", "index", "refKey", "ref", "onMouseMove", "onMouseDown", "onClick", "onPress", "disabled"],
|
|
4244
|
+
_excluded3 = ["onClick", "onPress", "refKey", "ref"],
|
|
4245
|
+
_excluded4 = ["onKeyDown", "onChange", "onInput", "onFocus", "onBlur", "onChangeText", "refKey", "ref"];
|
|
4246
4246
|
useCombobox.stateChangeTypes = stateChangeTypes$1;
|
|
4247
4247
|
function useCombobox(userProps) {
|
|
4248
4248
|
if (userProps === void 0) {
|
|
@@ -4250,349 +4250,327 @@
|
|
|
4250
4250
|
}
|
|
4251
4251
|
validatePropTypes$1(userProps, useCombobox);
|
|
4252
4252
|
// Props defaults and destructuring.
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
environment,
|
|
4263
|
-
getA11yStatusMessage,
|
|
4264
|
-
getA11ySelectionMessage,
|
|
4265
|
-
itemToString
|
|
4266
|
-
} = props;
|
|
4253
|
+
var props = _extends({}, defaultProps$1, userProps);
|
|
4254
|
+
var initialIsOpen = props.initialIsOpen,
|
|
4255
|
+
defaultIsOpen = props.defaultIsOpen,
|
|
4256
|
+
items = props.items,
|
|
4257
|
+
scrollIntoView = props.scrollIntoView,
|
|
4258
|
+
environment = props.environment,
|
|
4259
|
+
getA11yStatusMessage = props.getA11yStatusMessage,
|
|
4260
|
+
getA11ySelectionMessage = props.getA11ySelectionMessage,
|
|
4261
|
+
itemToString = props.itemToString;
|
|
4267
4262
|
// Initial state depending on controlled props.
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4263
|
+
var initialState = getInitialState$1(props);
|
|
4264
|
+
var _useControlledReducer = useControlledReducer(downshiftUseComboboxReducer, initialState, props),
|
|
4265
|
+
state = _useControlledReducer[0],
|
|
4266
|
+
dispatch = _useControlledReducer[1];
|
|
4267
|
+
var isOpen = state.isOpen,
|
|
4268
|
+
highlightedIndex = state.highlightedIndex,
|
|
4269
|
+
selectedItem = state.selectedItem,
|
|
4270
|
+
inputValue = state.inputValue;
|
|
4276
4271
|
|
|
4277
4272
|
// Element refs.
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4273
|
+
var menuRef = react.useRef(null);
|
|
4274
|
+
var itemRefs = react.useRef({});
|
|
4275
|
+
var inputRef = react.useRef(null);
|
|
4276
|
+
var toggleButtonRef = react.useRef(null);
|
|
4277
|
+
var isInitialMountRef = react.useRef(true);
|
|
4283
4278
|
// prevent id re-generation between renders.
|
|
4284
|
-
|
|
4279
|
+
var elementIds = useElementIds(props);
|
|
4285
4280
|
// used to keep track of how many items we had on previous cycle.
|
|
4286
|
-
|
|
4281
|
+
var previousResultCountRef = react.useRef();
|
|
4287
4282
|
// utility callback to get item element.
|
|
4288
|
-
|
|
4289
|
-
state,
|
|
4290
|
-
props
|
|
4283
|
+
var latest = useLatestRef({
|
|
4284
|
+
state: state,
|
|
4285
|
+
props: props
|
|
4291
4286
|
});
|
|
4292
|
-
|
|
4287
|
+
var getItemNodeFromIndex = react.useCallback(function (index) {
|
|
4288
|
+
return itemRefs.current[elementIds.getItemId(index)];
|
|
4289
|
+
}, [elementIds]);
|
|
4293
4290
|
|
|
4294
4291
|
// Effects.
|
|
4295
4292
|
// Sets a11y status message on changes in state.
|
|
4296
|
-
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], {
|
|
4293
|
+
useA11yMessageSetter(getA11yStatusMessage, [isOpen, highlightedIndex, inputValue, items], _extends({
|
|
4297
4294
|
isInitialMount: isInitialMountRef.current,
|
|
4298
4295
|
previousResultCount: previousResultCountRef.current,
|
|
4299
|
-
items,
|
|
4300
|
-
environment,
|
|
4301
|
-
itemToString
|
|
4302
|
-
|
|
4303
|
-
});
|
|
4296
|
+
items: items,
|
|
4297
|
+
environment: environment,
|
|
4298
|
+
itemToString: itemToString
|
|
4299
|
+
}, state));
|
|
4304
4300
|
// Sets a11y status message on changes in selectedItem.
|
|
4305
|
-
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], {
|
|
4301
|
+
useA11yMessageSetter(getA11ySelectionMessage, [selectedItem], _extends({
|
|
4306
4302
|
isInitialMount: isInitialMountRef.current,
|
|
4307
4303
|
previousResultCount: previousResultCountRef.current,
|
|
4308
|
-
items,
|
|
4309
|
-
environment,
|
|
4310
|
-
itemToString
|
|
4311
|
-
|
|
4312
|
-
});
|
|
4304
|
+
items: items,
|
|
4305
|
+
environment: environment,
|
|
4306
|
+
itemToString: itemToString
|
|
4307
|
+
}, state));
|
|
4313
4308
|
// Scroll on highlighted item if change comes from keyboard.
|
|
4314
|
-
|
|
4309
|
+
var shouldScrollRef = useScrollIntoView({
|
|
4315
4310
|
menuElement: menuRef.current,
|
|
4316
|
-
highlightedIndex,
|
|
4317
|
-
isOpen,
|
|
4318
|
-
itemRefs,
|
|
4319
|
-
scrollIntoView,
|
|
4320
|
-
getItemNodeFromIndex
|
|
4311
|
+
highlightedIndex: highlightedIndex,
|
|
4312
|
+
isOpen: isOpen,
|
|
4313
|
+
itemRefs: itemRefs,
|
|
4314
|
+
scrollIntoView: scrollIntoView,
|
|
4315
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4321
4316
|
});
|
|
4322
4317
|
useControlPropsValidator({
|
|
4323
4318
|
isInitialMount: isInitialMountRef.current,
|
|
4324
|
-
props,
|
|
4325
|
-
state
|
|
4319
|
+
props: props,
|
|
4320
|
+
state: state
|
|
4326
4321
|
});
|
|
4327
4322
|
// Focus the input on first render if required.
|
|
4328
|
-
react.useEffect(()
|
|
4329
|
-
|
|
4323
|
+
react.useEffect(function () {
|
|
4324
|
+
var focusOnOpen = initialIsOpen || defaultIsOpen || isOpen;
|
|
4330
4325
|
if (focusOnOpen && inputRef.current) {
|
|
4331
4326
|
inputRef.current.focus();
|
|
4332
4327
|
}
|
|
4333
4328
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
4334
4329
|
}, []);
|
|
4335
|
-
react.useEffect(()
|
|
4330
|
+
react.useEffect(function () {
|
|
4336
4331
|
if (isInitialMountRef.current) {
|
|
4337
4332
|
return;
|
|
4338
4333
|
}
|
|
4339
4334
|
previousResultCountRef.current = items.length;
|
|
4340
4335
|
});
|
|
4341
4336
|
// Add mouse/touch events to document.
|
|
4342
|
-
|
|
4337
|
+
var mouseAndTouchTrackersRef = useMouseAndTouchTracker(isOpen, [inputRef, menuRef, toggleButtonRef], environment, function () {
|
|
4343
4338
|
dispatch({
|
|
4344
4339
|
type: InputBlur,
|
|
4345
4340
|
selectItem: false
|
|
4346
4341
|
});
|
|
4347
4342
|
});
|
|
4348
|
-
|
|
4343
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getInputProps', 'getMenuProps');
|
|
4349
4344
|
// Make initial ref false.
|
|
4350
|
-
react.useEffect(()
|
|
4345
|
+
react.useEffect(function () {
|
|
4351
4346
|
isInitialMountRef.current = false;
|
|
4352
|
-
return ()
|
|
4347
|
+
return function () {
|
|
4353
4348
|
isInitialMountRef.current = true;
|
|
4354
4349
|
};
|
|
4355
4350
|
}, []);
|
|
4356
4351
|
// Reset itemRefs on close.
|
|
4357
|
-
react.useEffect(()
|
|
4352
|
+
react.useEffect(function () {
|
|
4358
4353
|
if (!isOpen) {
|
|
4359
4354
|
itemRefs.current = {};
|
|
4360
4355
|
} else if (document.activeElement !== inputRef.current) {
|
|
4361
|
-
|
|
4356
|
+
var _inputRef$current;
|
|
4357
|
+
inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
4362
4358
|
}
|
|
4363
4359
|
}, [isOpen]);
|
|
4364
4360
|
|
|
4365
4361
|
/* Event handler functions */
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
event
|
|
4369
|
-
dispatch({
|
|
4370
|
-
type: InputKeyDownArrowDown,
|
|
4371
|
-
altKey: event.altKey,
|
|
4372
|
-
getItemNodeFromIndex
|
|
4373
|
-
});
|
|
4374
|
-
},
|
|
4375
|
-
ArrowUp(event) {
|
|
4376
|
-
event.preventDefault();
|
|
4377
|
-
dispatch({
|
|
4378
|
-
type: InputKeyDownArrowUp,
|
|
4379
|
-
altKey: event.altKey,
|
|
4380
|
-
getItemNodeFromIndex
|
|
4381
|
-
});
|
|
4382
|
-
},
|
|
4383
|
-
Home(event) {
|
|
4384
|
-
if (!latest.current.state.isOpen) {
|
|
4385
|
-
return;
|
|
4386
|
-
}
|
|
4387
|
-
event.preventDefault();
|
|
4388
|
-
dispatch({
|
|
4389
|
-
type: InputKeyDownHome,
|
|
4390
|
-
getItemNodeFromIndex
|
|
4391
|
-
});
|
|
4392
|
-
},
|
|
4393
|
-
End(event) {
|
|
4394
|
-
if (!latest.current.state.isOpen) {
|
|
4395
|
-
return;
|
|
4396
|
-
}
|
|
4397
|
-
event.preventDefault();
|
|
4398
|
-
dispatch({
|
|
4399
|
-
type: InputKeyDownEnd,
|
|
4400
|
-
getItemNodeFromIndex
|
|
4401
|
-
});
|
|
4402
|
-
},
|
|
4403
|
-
Escape(event) {
|
|
4404
|
-
const latestState = latest.current.state;
|
|
4405
|
-
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
4362
|
+
var inputKeyDownHandlers = react.useMemo(function () {
|
|
4363
|
+
return {
|
|
4364
|
+
ArrowDown: function ArrowDown(event) {
|
|
4406
4365
|
event.preventDefault();
|
|
4407
4366
|
dispatch({
|
|
4408
|
-
type:
|
|
4367
|
+
type: InputKeyDownArrowDown,
|
|
4368
|
+
altKey: event.altKey,
|
|
4369
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4409
4370
|
});
|
|
4410
|
-
}
|
|
4411
|
-
|
|
4412
|
-
Enter(event) {
|
|
4413
|
-
const latestState = latest.current.state;
|
|
4414
|
-
// if closed or no highlighted index, do nothing.
|
|
4415
|
-
if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
4416
|
-
) {
|
|
4417
|
-
return;
|
|
4418
|
-
}
|
|
4419
|
-
event.preventDefault();
|
|
4420
|
-
dispatch({
|
|
4421
|
-
type: InputKeyDownEnter,
|
|
4422
|
-
getItemNodeFromIndex
|
|
4423
|
-
});
|
|
4424
|
-
},
|
|
4425
|
-
PageUp(event) {
|
|
4426
|
-
if (latest.current.state.isOpen) {
|
|
4371
|
+
},
|
|
4372
|
+
ArrowUp: function ArrowUp(event) {
|
|
4427
4373
|
event.preventDefault();
|
|
4428
4374
|
dispatch({
|
|
4429
|
-
type:
|
|
4430
|
-
|
|
4375
|
+
type: InputKeyDownArrowUp,
|
|
4376
|
+
altKey: event.altKey,
|
|
4377
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4431
4378
|
});
|
|
4432
|
-
}
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4379
|
+
},
|
|
4380
|
+
Home: function Home(event) {
|
|
4381
|
+
if (!latest.current.state.isOpen) {
|
|
4382
|
+
return;
|
|
4383
|
+
}
|
|
4436
4384
|
event.preventDefault();
|
|
4437
4385
|
dispatch({
|
|
4438
|
-
type:
|
|
4439
|
-
getItemNodeFromIndex
|
|
4386
|
+
type: InputKeyDownHome,
|
|
4387
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4440
4388
|
});
|
|
4389
|
+
},
|
|
4390
|
+
End: function End(event) {
|
|
4391
|
+
if (!latest.current.state.isOpen) {
|
|
4392
|
+
return;
|
|
4393
|
+
}
|
|
4394
|
+
event.preventDefault();
|
|
4395
|
+
dispatch({
|
|
4396
|
+
type: InputKeyDownEnd,
|
|
4397
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4398
|
+
});
|
|
4399
|
+
},
|
|
4400
|
+
Escape: function Escape(event) {
|
|
4401
|
+
var latestState = latest.current.state;
|
|
4402
|
+
if (latestState.isOpen || latestState.inputValue || latestState.selectedItem || latestState.highlightedIndex > -1) {
|
|
4403
|
+
event.preventDefault();
|
|
4404
|
+
dispatch({
|
|
4405
|
+
type: InputKeyDownEscape
|
|
4406
|
+
});
|
|
4407
|
+
}
|
|
4408
|
+
},
|
|
4409
|
+
Enter: function Enter(event) {
|
|
4410
|
+
var latestState = latest.current.state;
|
|
4411
|
+
// if closed or no highlighted index, do nothing.
|
|
4412
|
+
if (!latestState.isOpen || event.which === 229 // if IME composing, wait for next Enter keydown event.
|
|
4413
|
+
) {
|
|
4414
|
+
return;
|
|
4415
|
+
}
|
|
4416
|
+
event.preventDefault();
|
|
4417
|
+
dispatch({
|
|
4418
|
+
type: InputKeyDownEnter,
|
|
4419
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4420
|
+
});
|
|
4421
|
+
},
|
|
4422
|
+
PageUp: function PageUp(event) {
|
|
4423
|
+
if (latest.current.state.isOpen) {
|
|
4424
|
+
event.preventDefault();
|
|
4425
|
+
dispatch({
|
|
4426
|
+
type: InputKeyDownPageUp,
|
|
4427
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4428
|
+
});
|
|
4429
|
+
}
|
|
4430
|
+
},
|
|
4431
|
+
PageDown: function PageDown(event) {
|
|
4432
|
+
if (latest.current.state.isOpen) {
|
|
4433
|
+
event.preventDefault();
|
|
4434
|
+
dispatch({
|
|
4435
|
+
type: InputKeyDownPageDown,
|
|
4436
|
+
getItemNodeFromIndex: getItemNodeFromIndex
|
|
4437
|
+
});
|
|
4438
|
+
}
|
|
4441
4439
|
}
|
|
4442
|
-
}
|
|
4443
|
-
}
|
|
4440
|
+
};
|
|
4441
|
+
}, [dispatch, latest, getItemNodeFromIndex]);
|
|
4444
4442
|
|
|
4445
4443
|
// Getter props.
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4444
|
+
var getLabelProps = react.useCallback(function (labelProps) {
|
|
4445
|
+
return _extends({
|
|
4446
|
+
id: elementIds.labelId,
|
|
4447
|
+
htmlFor: elementIds.inputId
|
|
4448
|
+
}, labelProps);
|
|
4449
|
+
}, [elementIds]);
|
|
4450
|
+
var getMenuProps = react.useCallback(function (_temp, _temp2) {
|
|
4451
|
+
var _extends2;
|
|
4452
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
4453
|
+
onMouseLeave = _ref.onMouseLeave,
|
|
4454
|
+
_ref$refKey = _ref.refKey,
|
|
4455
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
4456
|
+
ref = _ref.ref,
|
|
4457
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
4458
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
4459
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
4460
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
4461
4461
|
setGetterPropCallInfo('getMenuProps', suppressRefError, refKey, menuRef);
|
|
4462
|
-
return {
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
onMouseLeave: callAllEventHandlers(onMouseLeave, () => {
|
|
4470
|
-
dispatch({
|
|
4471
|
-
type: MenuMouseLeave
|
|
4472
|
-
});
|
|
4473
|
-
}),
|
|
4474
|
-
...rest
|
|
4475
|
-
};
|
|
4462
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (menuNode) {
|
|
4463
|
+
menuRef.current = menuNode;
|
|
4464
|
+
}), _extends2.id = elementIds.menuId, _extends2.role = 'listbox', _extends2['aria-labelledby'] = elementIds.labelId, _extends2.onMouseLeave = callAllEventHandlers(onMouseLeave, function () {
|
|
4465
|
+
dispatch({
|
|
4466
|
+
type: MenuMouseLeave
|
|
4467
|
+
});
|
|
4468
|
+
}), _extends2), rest);
|
|
4476
4469
|
}, [dispatch, setGetterPropCallInfo, elementIds]);
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4470
|
+
var getItemProps = react.useCallback(function (_temp3) {
|
|
4471
|
+
var _extends3, _ref4;
|
|
4472
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
4473
|
+
item = _ref3.item,
|
|
4474
|
+
index = _ref3.index,
|
|
4475
|
+
_ref3$refKey = _ref3.refKey,
|
|
4476
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
4477
|
+
ref = _ref3.ref,
|
|
4478
|
+
onMouseMove = _ref3.onMouseMove,
|
|
4479
|
+
onMouseDown = _ref3.onMouseDown,
|
|
4480
|
+
onClick = _ref3.onClick;
|
|
4481
|
+
_ref3.onPress;
|
|
4482
|
+
var disabled = _ref3.disabled,
|
|
4483
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded2$1);
|
|
4484
|
+
var _latest$current = latest.current,
|
|
4485
|
+
latestProps = _latest$current.props,
|
|
4486
|
+
latestState = _latest$current.state;
|
|
4487
|
+
var itemIndex = getItemIndex(index, item, latestProps.items);
|
|
4495
4488
|
if (itemIndex < 0) {
|
|
4496
4489
|
throw new Error('Pass either item or item index in getItemProps!');
|
|
4497
4490
|
}
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4491
|
+
var onSelectKey = 'onClick';
|
|
4492
|
+
var customClickHandler = onClick;
|
|
4493
|
+
var itemHandleMouseMove = function itemHandleMouseMove() {
|
|
4501
4494
|
if (index === latestState.highlightedIndex) {
|
|
4502
4495
|
return;
|
|
4503
4496
|
}
|
|
4504
4497
|
shouldScrollRef.current = false;
|
|
4505
4498
|
dispatch({
|
|
4506
4499
|
type: ItemMouseMove,
|
|
4507
|
-
index,
|
|
4508
|
-
disabled
|
|
4500
|
+
index: index,
|
|
4501
|
+
disabled: disabled
|
|
4509
4502
|
});
|
|
4510
4503
|
};
|
|
4511
|
-
|
|
4504
|
+
var itemHandleClick = function itemHandleClick() {
|
|
4512
4505
|
dispatch({
|
|
4513
4506
|
type: ItemClick,
|
|
4514
|
-
index
|
|
4507
|
+
index: index
|
|
4515
4508
|
});
|
|
4516
4509
|
};
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
[refKey]: handleRefs(ref, itemNode => {
|
|
4520
|
-
if (itemNode) {
|
|
4521
|
-
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
4522
|
-
}
|
|
4523
|
-
}),
|
|
4524
|
-
disabled,
|
|
4525
|
-
role: 'option',
|
|
4526
|
-
'aria-selected': `${itemIndex === latestState.highlightedIndex}`,
|
|
4527
|
-
id: elementIds.getItemId(itemIndex),
|
|
4528
|
-
...(!disabled && {
|
|
4529
|
-
[onSelectKey]: callAllEventHandlers(customClickHandler, itemHandleClick)
|
|
4530
|
-
}),
|
|
4531
|
-
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
4532
|
-
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown),
|
|
4533
|
-
...rest
|
|
4510
|
+
var itemHandleMouseDown = function itemHandleMouseDown(e) {
|
|
4511
|
+
return e.preventDefault();
|
|
4534
4512
|
};
|
|
4513
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (itemNode) {
|
|
4514
|
+
if (itemNode) {
|
|
4515
|
+
itemRefs.current[elementIds.getItemId(itemIndex)] = itemNode;
|
|
4516
|
+
}
|
|
4517
|
+
}), _extends3.disabled = disabled, _extends3.role = 'option', _extends3['aria-selected'] = "" + (itemIndex === latestState.highlightedIndex), _extends3.id = elementIds.getItemId(itemIndex), _extends3), !disabled && (_ref4 = {}, _ref4[onSelectKey] = callAllEventHandlers(customClickHandler, itemHandleClick), _ref4), {
|
|
4518
|
+
onMouseMove: callAllEventHandlers(onMouseMove, itemHandleMouseMove),
|
|
4519
|
+
onMouseDown: callAllEventHandlers(onMouseDown, itemHandleMouseDown)
|
|
4520
|
+
}, rest);
|
|
4535
4521
|
}, [dispatch, latest, shouldScrollRef, elementIds]);
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4522
|
+
var getToggleButtonProps = react.useCallback(function (_temp4) {
|
|
4523
|
+
var _extends4;
|
|
4524
|
+
var _ref5 = _temp4 === void 0 ? {} : _temp4,
|
|
4525
|
+
onClick = _ref5.onClick;
|
|
4526
|
+
_ref5.onPress;
|
|
4527
|
+
var _ref5$refKey = _ref5.refKey,
|
|
4528
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
4529
|
+
ref = _ref5.ref,
|
|
4530
|
+
rest = _objectWithoutPropertiesLoose(_ref5, _excluded3);
|
|
4531
|
+
var latestState = latest.current.state;
|
|
4532
|
+
var toggleButtonHandleClick = function toggleButtonHandleClick() {
|
|
4546
4533
|
dispatch({
|
|
4547
4534
|
type: ToggleButtonClick
|
|
4548
4535
|
});
|
|
4549
4536
|
};
|
|
4550
|
-
return {
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
'aria-expanded': latestState.isOpen,
|
|
4556
|
-
id: elementIds.toggleButtonId,
|
|
4557
|
-
tabIndex: -1,
|
|
4558
|
-
...(!rest.disabled && {
|
|
4559
|
-
...({
|
|
4560
|
-
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
4561
|
-
})
|
|
4562
|
-
}),
|
|
4563
|
-
...rest
|
|
4564
|
-
};
|
|
4537
|
+
return _extends((_extends4 = {}, _extends4[refKey] = handleRefs(ref, function (toggleButtonNode) {
|
|
4538
|
+
toggleButtonRef.current = toggleButtonNode;
|
|
4539
|
+
}), _extends4['aria-controls'] = elementIds.menuId, _extends4['aria-expanded'] = latestState.isOpen, _extends4.id = elementIds.toggleButtonId, _extends4.tabIndex = -1, _extends4), !rest.disabled && _extends({}, {
|
|
4540
|
+
onClick: callAllEventHandlers(onClick, toggleButtonHandleClick)
|
|
4541
|
+
}), rest);
|
|
4565
4542
|
}, [dispatch, latest, elementIds]);
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4543
|
+
var getInputProps = react.useCallback(function (_temp5, _temp6) {
|
|
4544
|
+
var _extends5;
|
|
4545
|
+
var _ref6 = _temp5 === void 0 ? {} : _temp5,
|
|
4546
|
+
onKeyDown = _ref6.onKeyDown,
|
|
4547
|
+
onChange = _ref6.onChange,
|
|
4548
|
+
onInput = _ref6.onInput,
|
|
4549
|
+
onFocus = _ref6.onFocus,
|
|
4550
|
+
onBlur = _ref6.onBlur;
|
|
4551
|
+
_ref6.onChangeText;
|
|
4552
|
+
var _ref6$refKey = _ref6.refKey,
|
|
4553
|
+
refKey = _ref6$refKey === void 0 ? 'ref' : _ref6$refKey,
|
|
4554
|
+
ref = _ref6.ref,
|
|
4555
|
+
rest = _objectWithoutPropertiesLoose(_ref6, _excluded4);
|
|
4556
|
+
var _ref7 = _temp6 === void 0 ? {} : _temp6,
|
|
4557
|
+
_ref7$suppressRefErro = _ref7.suppressRefError,
|
|
4558
|
+
suppressRefError = _ref7$suppressRefErro === void 0 ? false : _ref7$suppressRefErro;
|
|
4581
4559
|
setGetterPropCallInfo('getInputProps', suppressRefError, refKey, inputRef);
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4560
|
+
var latestState = latest.current.state;
|
|
4561
|
+
var inputHandleKeyDown = function inputHandleKeyDown(event) {
|
|
4562
|
+
var key = normalizeArrowKey(event);
|
|
4585
4563
|
if (key && inputKeyDownHandlers[key]) {
|
|
4586
4564
|
inputKeyDownHandlers[key](event);
|
|
4587
4565
|
}
|
|
4588
4566
|
};
|
|
4589
|
-
|
|
4567
|
+
var inputHandleChange = function inputHandleChange(event) {
|
|
4590
4568
|
dispatch({
|
|
4591
4569
|
type: InputChange,
|
|
4592
4570
|
inputValue: event.target.value
|
|
4593
4571
|
});
|
|
4594
4572
|
};
|
|
4595
|
-
|
|
4573
|
+
var inputHandleBlur = function inputHandleBlur() {
|
|
4596
4574
|
/* istanbul ignore else */
|
|
4597
4575
|
if (latestState.isOpen && !mouseAndTouchTrackersRef.current.isMouseDown) {
|
|
4598
4576
|
dispatch({
|
|
@@ -4601,7 +4579,7 @@
|
|
|
4601
4579
|
});
|
|
4602
4580
|
}
|
|
4603
4581
|
};
|
|
4604
|
-
|
|
4582
|
+
var inputHandleFocus = function inputHandleFocus() {
|
|
4605
4583
|
if (!latestState.isOpen) {
|
|
4606
4584
|
dispatch({
|
|
4607
4585
|
type: InputFocus
|
|
@@ -4610,99 +4588,80 @@
|
|
|
4610
4588
|
};
|
|
4611
4589
|
|
|
4612
4590
|
/* istanbul ignore next (preact) */
|
|
4613
|
-
|
|
4614
|
-
|
|
4591
|
+
var onChangeKey = 'onChange';
|
|
4592
|
+
var eventHandlers = {};
|
|
4615
4593
|
if (!rest.disabled) {
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
onKeyDown: callAllEventHandlers(onKeyDown, inputHandleKeyDown),
|
|
4619
|
-
onBlur: callAllEventHandlers(onBlur, inputHandleBlur),
|
|
4620
|
-
onFocus: callAllEventHandlers(onFocus, inputHandleFocus)
|
|
4621
|
-
};
|
|
4594
|
+
var _eventHandlers;
|
|
4595
|
+
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, inputHandleBlur), _eventHandlers.onFocus = callAllEventHandlers(onFocus, inputHandleFocus), _eventHandlers);
|
|
4622
4596
|
}
|
|
4623
|
-
return {
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
}),
|
|
4627
|
-
'aria-activedescendant': latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '',
|
|
4628
|
-
'aria-autocomplete': 'list',
|
|
4629
|
-
'aria-controls': elementIds.menuId,
|
|
4630
|
-
'aria-expanded': latestState.isOpen,
|
|
4631
|
-
'aria-labelledby': elementIds.labelId,
|
|
4632
|
-
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
4633
|
-
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
4634
|
-
autoComplete: 'off',
|
|
4635
|
-
id: elementIds.inputId,
|
|
4636
|
-
role: 'combobox',
|
|
4637
|
-
value: latestState.inputValue,
|
|
4638
|
-
...eventHandlers,
|
|
4639
|
-
...rest
|
|
4640
|
-
};
|
|
4597
|
+
return _extends((_extends5 = {}, _extends5[refKey] = handleRefs(ref, function (inputNode) {
|
|
4598
|
+
inputRef.current = inputNode;
|
|
4599
|
+
}), _extends5['aria-activedescendant'] = latestState.isOpen && latestState.highlightedIndex > -1 ? elementIds.getItemId(latestState.highlightedIndex) : '', _extends5['aria-autocomplete'] = 'list', _extends5['aria-controls'] = elementIds.menuId, _extends5['aria-expanded'] = latestState.isOpen, _extends5['aria-labelledby'] = elementIds.labelId, _extends5.autoComplete = 'off', _extends5.id = elementIds.inputId, _extends5.role = 'combobox', _extends5.value = latestState.inputValue, _extends5), eventHandlers, rest);
|
|
4641
4600
|
}, [dispatch, inputKeyDownHandlers, latest, mouseAndTouchTrackersRef, setGetterPropCallInfo, elementIds]);
|
|
4642
4601
|
|
|
4643
4602
|
// returns
|
|
4644
|
-
|
|
4603
|
+
var toggleMenu = react.useCallback(function () {
|
|
4645
4604
|
dispatch({
|
|
4646
4605
|
type: FunctionToggleMenu
|
|
4647
4606
|
});
|
|
4648
4607
|
}, [dispatch]);
|
|
4649
|
-
|
|
4608
|
+
var closeMenu = react.useCallback(function () {
|
|
4650
4609
|
dispatch({
|
|
4651
4610
|
type: FunctionCloseMenu
|
|
4652
4611
|
});
|
|
4653
4612
|
}, [dispatch]);
|
|
4654
|
-
|
|
4613
|
+
var openMenu = react.useCallback(function () {
|
|
4655
4614
|
dispatch({
|
|
4656
4615
|
type: FunctionOpenMenu
|
|
4657
4616
|
});
|
|
4658
4617
|
}, [dispatch]);
|
|
4659
|
-
|
|
4618
|
+
var setHighlightedIndex = react.useCallback(function (newHighlightedIndex) {
|
|
4660
4619
|
dispatch({
|
|
4661
4620
|
type: FunctionSetHighlightedIndex,
|
|
4662
4621
|
highlightedIndex: newHighlightedIndex
|
|
4663
4622
|
});
|
|
4664
4623
|
}, [dispatch]);
|
|
4665
|
-
|
|
4624
|
+
var selectItem = react.useCallback(function (newSelectedItem) {
|
|
4666
4625
|
dispatch({
|
|
4667
4626
|
type: FunctionSelectItem,
|
|
4668
4627
|
selectedItem: newSelectedItem
|
|
4669
4628
|
});
|
|
4670
4629
|
}, [dispatch]);
|
|
4671
|
-
|
|
4630
|
+
var setInputValue = react.useCallback(function (newInputValue) {
|
|
4672
4631
|
dispatch({
|
|
4673
4632
|
type: FunctionSetInputValue,
|
|
4674
4633
|
inputValue: newInputValue
|
|
4675
4634
|
});
|
|
4676
4635
|
}, [dispatch]);
|
|
4677
|
-
|
|
4636
|
+
var reset = react.useCallback(function () {
|
|
4678
4637
|
dispatch({
|
|
4679
4638
|
type: FunctionReset$1
|
|
4680
4639
|
});
|
|
4681
4640
|
}, [dispatch]);
|
|
4682
4641
|
return {
|
|
4683
4642
|
// prop getters.
|
|
4684
|
-
getItemProps,
|
|
4685
|
-
getLabelProps,
|
|
4686
|
-
getMenuProps,
|
|
4687
|
-
getInputProps,
|
|
4688
|
-
getToggleButtonProps,
|
|
4643
|
+
getItemProps: getItemProps,
|
|
4644
|
+
getLabelProps: getLabelProps,
|
|
4645
|
+
getMenuProps: getMenuProps,
|
|
4646
|
+
getInputProps: getInputProps,
|
|
4647
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
4689
4648
|
// actions.
|
|
4690
|
-
toggleMenu,
|
|
4691
|
-
openMenu,
|
|
4692
|
-
closeMenu,
|
|
4693
|
-
setHighlightedIndex,
|
|
4694
|
-
setInputValue,
|
|
4695
|
-
selectItem,
|
|
4696
|
-
reset,
|
|
4649
|
+
toggleMenu: toggleMenu,
|
|
4650
|
+
openMenu: openMenu,
|
|
4651
|
+
closeMenu: closeMenu,
|
|
4652
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
4653
|
+
setInputValue: setInputValue,
|
|
4654
|
+
selectItem: selectItem,
|
|
4655
|
+
reset: reset,
|
|
4697
4656
|
// state.
|
|
4698
|
-
highlightedIndex,
|
|
4699
|
-
isOpen,
|
|
4700
|
-
selectedItem,
|
|
4701
|
-
inputValue
|
|
4657
|
+
highlightedIndex: highlightedIndex,
|
|
4658
|
+
isOpen: isOpen,
|
|
4659
|
+
selectedItem: selectedItem,
|
|
4660
|
+
inputValue: inputValue
|
|
4702
4661
|
};
|
|
4703
4662
|
}
|
|
4704
4663
|
|
|
4705
|
-
|
|
4664
|
+
var defaultStateValues = {
|
|
4706
4665
|
activeIndex: -1,
|
|
4707
4666
|
selectedItems: []
|
|
4708
4667
|
};
|
|
@@ -4740,11 +4699,11 @@
|
|
|
4740
4699
|
* @returns {Object} The initial state.
|
|
4741
4700
|
*/
|
|
4742
4701
|
function getInitialState(props) {
|
|
4743
|
-
|
|
4744
|
-
|
|
4702
|
+
var activeIndex = getInitialValue(props, 'activeIndex');
|
|
4703
|
+
var selectedItems = getInitialValue(props, 'selectedItems');
|
|
4745
4704
|
return {
|
|
4746
|
-
activeIndex,
|
|
4747
|
-
selectedItems
|
|
4705
|
+
activeIndex: activeIndex,
|
|
4706
|
+
selectedItems: selectedItems
|
|
4748
4707
|
};
|
|
4749
4708
|
}
|
|
4750
4709
|
|
|
@@ -4761,7 +4720,7 @@
|
|
|
4761
4720
|
if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey) {
|
|
4762
4721
|
return false;
|
|
4763
4722
|
}
|
|
4764
|
-
|
|
4723
|
+
var element = event.target;
|
|
4765
4724
|
if (element instanceof HTMLInputElement &&
|
|
4766
4725
|
// if element is a text input
|
|
4767
4726
|
element.value !== '' && (
|
|
@@ -4780,13 +4739,11 @@
|
|
|
4780
4739
|
* @returns {string} The a11y message.
|
|
4781
4740
|
*/
|
|
4782
4741
|
function getA11yRemovalMessage(selectionParameters) {
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
} = selectionParameters;
|
|
4787
|
-
return `${itemToStringLocal(removedSelectedItem)} has been removed.`;
|
|
4742
|
+
var removedSelectedItem = selectionParameters.removedSelectedItem,
|
|
4743
|
+
itemToStringLocal = selectionParameters.itemToString;
|
|
4744
|
+
return itemToStringLocal(removedSelectedItem) + " has been removed.";
|
|
4788
4745
|
}
|
|
4789
|
-
|
|
4746
|
+
var propTypes = {
|
|
4790
4747
|
selectedItems: PropTypes.array,
|
|
4791
4748
|
initialSelectedItems: PropTypes.array,
|
|
4792
4749
|
defaultSelectedItems: PropTypes.array,
|
|
@@ -4810,37 +4767,37 @@
|
|
|
4810
4767
|
})
|
|
4811
4768
|
})
|
|
4812
4769
|
};
|
|
4813
|
-
|
|
4770
|
+
var defaultProps = {
|
|
4814
4771
|
itemToString: defaultProps$3.itemToString,
|
|
4815
4772
|
stateReducer: defaultProps$3.stateReducer,
|
|
4816
4773
|
environment: defaultProps$3.environment,
|
|
4817
|
-
getA11yRemovalMessage,
|
|
4774
|
+
getA11yRemovalMessage: getA11yRemovalMessage,
|
|
4818
4775
|
keyNavigationNext: 'ArrowRight',
|
|
4819
4776
|
keyNavigationPrevious: 'ArrowLeft'
|
|
4820
4777
|
};
|
|
4821
4778
|
|
|
4822
4779
|
// eslint-disable-next-line import/no-mutable-exports
|
|
4823
|
-
|
|
4780
|
+
var validatePropTypes = noop;
|
|
4824
4781
|
/* istanbul ignore next */
|
|
4825
4782
|
{
|
|
4826
|
-
validatePropTypes = (options, caller)
|
|
4783
|
+
validatePropTypes = function validatePropTypes(options, caller) {
|
|
4827
4784
|
PropTypes.checkPropTypes(propTypes, options, 'prop', caller.name);
|
|
4828
4785
|
};
|
|
4829
4786
|
}
|
|
4830
4787
|
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4788
|
+
var SelectedItemClick = '__selected_item_click__' ;
|
|
4789
|
+
var SelectedItemKeyDownDelete = '__selected_item_keydown_delete__' ;
|
|
4790
|
+
var SelectedItemKeyDownBackspace = '__selected_item_keydown_backspace__' ;
|
|
4791
|
+
var SelectedItemKeyDownNavigationNext = '__selected_item_keydown_navigation_next__' ;
|
|
4792
|
+
var SelectedItemKeyDownNavigationPrevious = '__selected_item_keydown_navigation_previous__' ;
|
|
4793
|
+
var DropdownKeyDownNavigationPrevious = '__dropdown_keydown_navigation_previous__' ;
|
|
4794
|
+
var DropdownKeyDownBackspace = '__dropdown_keydown_backspace__' ;
|
|
4795
|
+
var DropdownClick = '__dropdown_click__' ;
|
|
4796
|
+
var FunctionAddSelectedItem = '__function_add_selected_item__' ;
|
|
4797
|
+
var FunctionRemoveSelectedItem = '__function_remove_selected_item__' ;
|
|
4798
|
+
var FunctionSetSelectedItems = '__function_set_selected_items__' ;
|
|
4799
|
+
var FunctionSetActiveIndex = '__function_set_active_index__' ;
|
|
4800
|
+
var FunctionReset = '__function_reset__' ;
|
|
4844
4801
|
|
|
4845
4802
|
var stateChangeTypes = /*#__PURE__*/Object.freeze({
|
|
4846
4803
|
__proto__: null,
|
|
@@ -4861,17 +4818,13 @@
|
|
|
4861
4818
|
|
|
4862
4819
|
/* eslint-disable complexity */
|
|
4863
4820
|
function downshiftMultipleSelectionReducer(state, action) {
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
activeIndex,
|
|
4872
|
-
selectedItems
|
|
4873
|
-
} = state;
|
|
4874
|
-
let changes;
|
|
4821
|
+
var type = action.type,
|
|
4822
|
+
index = action.index,
|
|
4823
|
+
props = action.props,
|
|
4824
|
+
selectedItem = action.selectedItem;
|
|
4825
|
+
var activeIndex = state.activeIndex,
|
|
4826
|
+
selectedItems = state.selectedItems;
|
|
4827
|
+
var changes;
|
|
4875
4828
|
switch (type) {
|
|
4876
4829
|
case SelectedItemClick:
|
|
4877
4830
|
changes = {
|
|
@@ -4894,18 +4847,17 @@
|
|
|
4894
4847
|
if (activeIndex < 0) {
|
|
4895
4848
|
break;
|
|
4896
4849
|
}
|
|
4897
|
-
|
|
4850
|
+
var newActiveIndex = activeIndex;
|
|
4898
4851
|
if (selectedItems.length === 1) {
|
|
4899
4852
|
newActiveIndex = -1;
|
|
4900
4853
|
} else if (activeIndex === selectedItems.length - 1) {
|
|
4901
4854
|
newActiveIndex = selectedItems.length - 2;
|
|
4902
4855
|
}
|
|
4903
|
-
changes = {
|
|
4904
|
-
selectedItems: [
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
};
|
|
4856
|
+
changes = _extends({
|
|
4857
|
+
selectedItems: [].concat(selectedItems.slice(0, activeIndex), selectedItems.slice(activeIndex + 1))
|
|
4858
|
+
}, {
|
|
4859
|
+
activeIndex: newActiveIndex
|
|
4860
|
+
});
|
|
4909
4861
|
break;
|
|
4910
4862
|
}
|
|
4911
4863
|
case DropdownKeyDownNavigationPrevious:
|
|
@@ -4920,7 +4872,7 @@
|
|
|
4920
4872
|
break;
|
|
4921
4873
|
case FunctionAddSelectedItem:
|
|
4922
4874
|
changes = {
|
|
4923
|
-
selectedItems: [
|
|
4875
|
+
selectedItems: [].concat(selectedItems, [selectedItem])
|
|
4924
4876
|
};
|
|
4925
4877
|
break;
|
|
4926
4878
|
case DropdownClick:
|
|
@@ -4930,27 +4882,25 @@
|
|
|
4930
4882
|
break;
|
|
4931
4883
|
case FunctionRemoveSelectedItem:
|
|
4932
4884
|
{
|
|
4933
|
-
|
|
4934
|
-
|
|
4885
|
+
var _newActiveIndex = activeIndex;
|
|
4886
|
+
var selectedItemIndex = selectedItems.indexOf(selectedItem);
|
|
4935
4887
|
if (selectedItemIndex < 0) {
|
|
4936
4888
|
break;
|
|
4937
4889
|
}
|
|
4938
4890
|
if (selectedItems.length === 1) {
|
|
4939
|
-
|
|
4891
|
+
_newActiveIndex = -1;
|
|
4940
4892
|
} else if (selectedItemIndex === selectedItems.length - 1) {
|
|
4941
|
-
|
|
4893
|
+
_newActiveIndex = selectedItems.length - 2;
|
|
4942
4894
|
}
|
|
4943
4895
|
changes = {
|
|
4944
|
-
selectedItems: [
|
|
4945
|
-
activeIndex:
|
|
4896
|
+
selectedItems: [].concat(selectedItems.slice(0, selectedItemIndex), selectedItems.slice(selectedItemIndex + 1)),
|
|
4897
|
+
activeIndex: _newActiveIndex
|
|
4946
4898
|
};
|
|
4947
4899
|
break;
|
|
4948
4900
|
}
|
|
4949
4901
|
case FunctionSetSelectedItems:
|
|
4950
4902
|
{
|
|
4951
|
-
|
|
4952
|
-
selectedItems: newSelectedItems
|
|
4953
|
-
} = action;
|
|
4903
|
+
var newSelectedItems = action.selectedItems;
|
|
4954
4904
|
changes = {
|
|
4955
4905
|
selectedItems: newSelectedItems
|
|
4956
4906
|
};
|
|
@@ -4958,11 +4908,9 @@
|
|
|
4958
4908
|
}
|
|
4959
4909
|
case FunctionSetActiveIndex:
|
|
4960
4910
|
{
|
|
4961
|
-
|
|
4962
|
-
activeIndex: newActiveIndex
|
|
4963
|
-
} = action;
|
|
4911
|
+
var _newActiveIndex2 = action.activeIndex;
|
|
4964
4912
|
changes = {
|
|
4965
|
-
activeIndex:
|
|
4913
|
+
activeIndex: _newActiveIndex2
|
|
4966
4914
|
};
|
|
4967
4915
|
break;
|
|
4968
4916
|
}
|
|
@@ -4975,12 +4923,11 @@
|
|
|
4975
4923
|
default:
|
|
4976
4924
|
throw new Error('Reducer called without proper action type.');
|
|
4977
4925
|
}
|
|
4978
|
-
return {
|
|
4979
|
-
...state,
|
|
4980
|
-
...changes
|
|
4981
|
-
};
|
|
4926
|
+
return _extends({}, state, changes);
|
|
4982
4927
|
}
|
|
4983
4928
|
|
|
4929
|
+
var _excluded = ["refKey", "ref", "onClick", "onKeyDown", "selectedItem", "index"],
|
|
4930
|
+
_excluded2 = ["refKey", "ref", "onKeyDown", "onClick", "preventKeyAction"];
|
|
4984
4931
|
useMultipleSelection.stateChangeTypes = stateChangeTypes;
|
|
4985
4932
|
function useMultipleSelection(userProps) {
|
|
4986
4933
|
if (userProps === void 0) {
|
|
@@ -4988,49 +4935,46 @@
|
|
|
4988
4935
|
}
|
|
4989
4936
|
validatePropTypes(userProps, useMultipleSelection);
|
|
4990
4937
|
// Props defaults and destructuring.
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
itemToString,
|
|
4998
|
-
environment,
|
|
4999
|
-
keyNavigationNext,
|
|
5000
|
-
keyNavigationPrevious
|
|
5001
|
-
} = props;
|
|
4938
|
+
var props = _extends({}, defaultProps, userProps);
|
|
4939
|
+
var getA11yRemovalMessage = props.getA11yRemovalMessage,
|
|
4940
|
+
itemToString = props.itemToString,
|
|
4941
|
+
environment = props.environment,
|
|
4942
|
+
keyNavigationNext = props.keyNavigationNext,
|
|
4943
|
+
keyNavigationPrevious = props.keyNavigationPrevious;
|
|
5002
4944
|
|
|
5003
4945
|
// Reducer init.
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
4946
|
+
var _useControlledReducer = useControlledReducer$1(downshiftMultipleSelectionReducer, getInitialState(props), props),
|
|
4947
|
+
state = _useControlledReducer[0],
|
|
4948
|
+
dispatch = _useControlledReducer[1];
|
|
4949
|
+
var activeIndex = state.activeIndex,
|
|
4950
|
+
selectedItems = state.selectedItems;
|
|
5009
4951
|
|
|
5010
4952
|
// Refs.
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
4953
|
+
var isInitialMountRef = react.useRef(true);
|
|
4954
|
+
var dropdownRef = react.useRef(null);
|
|
4955
|
+
var previousSelectedItemsRef = react.useRef(selectedItems);
|
|
4956
|
+
var selectedItemRefs = react.useRef();
|
|
5015
4957
|
selectedItemRefs.current = [];
|
|
5016
|
-
|
|
5017
|
-
state,
|
|
5018
|
-
props
|
|
4958
|
+
var latest = useLatestRef({
|
|
4959
|
+
state: state,
|
|
4960
|
+
props: props
|
|
5019
4961
|
});
|
|
5020
4962
|
|
|
5021
4963
|
// Effects.
|
|
5022
4964
|
/* Sets a11y status message on changes in selectedItem. */
|
|
5023
|
-
react.useEffect(()
|
|
4965
|
+
react.useEffect(function () {
|
|
5024
4966
|
if (isInitialMountRef.current) {
|
|
5025
4967
|
return;
|
|
5026
4968
|
}
|
|
5027
4969
|
if (selectedItems.length < previousSelectedItemsRef.current.length) {
|
|
5028
|
-
|
|
4970
|
+
var removedSelectedItem = previousSelectedItemsRef.current.find(function (item) {
|
|
4971
|
+
return selectedItems.indexOf(item) < 0;
|
|
4972
|
+
});
|
|
5029
4973
|
setStatus(getA11yRemovalMessage({
|
|
5030
|
-
itemToString,
|
|
4974
|
+
itemToString: itemToString,
|
|
5031
4975
|
resultCount: selectedItems.length,
|
|
5032
|
-
removedSelectedItem,
|
|
5033
|
-
activeIndex,
|
|
4976
|
+
removedSelectedItem: removedSelectedItem,
|
|
4977
|
+
activeIndex: activeIndex,
|
|
5034
4978
|
activeSelectedItem: selectedItems[activeIndex]
|
|
5035
4979
|
}), environment.document);
|
|
5036
4980
|
}
|
|
@@ -5039,7 +4983,7 @@
|
|
|
5039
4983
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
5040
4984
|
}, [selectedItems.length]);
|
|
5041
4985
|
// Sets focus on active item.
|
|
5042
|
-
react.useEffect(()
|
|
4986
|
+
react.useEffect(function () {
|
|
5043
4987
|
if (isInitialMountRef.current) {
|
|
5044
4988
|
return;
|
|
5045
4989
|
}
|
|
@@ -5051,178 +4995,167 @@
|
|
|
5051
4995
|
}, [activeIndex]);
|
|
5052
4996
|
useControlPropsValidator({
|
|
5053
4997
|
isInitialMount: isInitialMountRef.current,
|
|
5054
|
-
props,
|
|
5055
|
-
state
|
|
4998
|
+
props: props,
|
|
4999
|
+
state: state
|
|
5056
5000
|
});
|
|
5057
|
-
|
|
5001
|
+
var setGetterPropCallInfo = useGetterPropsCalledChecker('getDropdownProps');
|
|
5058
5002
|
// Make initial ref false.
|
|
5059
|
-
react.useEffect(()
|
|
5003
|
+
react.useEffect(function () {
|
|
5060
5004
|
isInitialMountRef.current = false;
|
|
5061
|
-
return ()
|
|
5005
|
+
return function () {
|
|
5062
5006
|
isInitialMountRef.current = true;
|
|
5063
5007
|
};
|
|
5064
5008
|
}, []);
|
|
5065
5009
|
|
|
5066
5010
|
// Event handler functions.
|
|
5067
|
-
|
|
5068
|
-
|
|
5011
|
+
var selectedItemKeyDownHandlers = react.useMemo(function () {
|
|
5012
|
+
var _ref;
|
|
5013
|
+
return _ref = {}, _ref[keyNavigationPrevious] = function () {
|
|
5069
5014
|
dispatch({
|
|
5070
5015
|
type: SelectedItemKeyDownNavigationPrevious
|
|
5071
5016
|
});
|
|
5072
|
-
},
|
|
5073
|
-
[keyNavigationNext]() {
|
|
5017
|
+
}, _ref[keyNavigationNext] = function () {
|
|
5074
5018
|
dispatch({
|
|
5075
5019
|
type: SelectedItemKeyDownNavigationNext
|
|
5076
5020
|
});
|
|
5077
|
-
},
|
|
5078
|
-
Delete() {
|
|
5021
|
+
}, _ref.Delete = function Delete() {
|
|
5079
5022
|
dispatch({
|
|
5080
5023
|
type: SelectedItemKeyDownDelete
|
|
5081
5024
|
});
|
|
5082
|
-
},
|
|
5083
|
-
Backspace() {
|
|
5025
|
+
}, _ref.Backspace = function Backspace() {
|
|
5084
5026
|
dispatch({
|
|
5085
5027
|
type: SelectedItemKeyDownBackspace
|
|
5086
5028
|
});
|
|
5087
|
-
}
|
|
5088
|
-
}
|
|
5089
|
-
|
|
5090
|
-
|
|
5029
|
+
}, _ref;
|
|
5030
|
+
}, [dispatch, keyNavigationNext, keyNavigationPrevious]);
|
|
5031
|
+
var dropdownKeyDownHandlers = react.useMemo(function () {
|
|
5032
|
+
var _ref2;
|
|
5033
|
+
return _ref2 = {}, _ref2[keyNavigationPrevious] = function (event) {
|
|
5091
5034
|
if (isKeyDownOperationPermitted(event)) {
|
|
5092
5035
|
dispatch({
|
|
5093
5036
|
type: DropdownKeyDownNavigationPrevious
|
|
5094
5037
|
});
|
|
5095
5038
|
}
|
|
5096
|
-
},
|
|
5097
|
-
Backspace(event) {
|
|
5039
|
+
}, _ref2.Backspace = function Backspace(event) {
|
|
5098
5040
|
if (isKeyDownOperationPermitted(event)) {
|
|
5099
5041
|
dispatch({
|
|
5100
5042
|
type: DropdownKeyDownBackspace
|
|
5101
5043
|
});
|
|
5102
5044
|
}
|
|
5103
|
-
}
|
|
5104
|
-
}
|
|
5045
|
+
}, _ref2;
|
|
5046
|
+
}, [dispatch, keyNavigationPrevious]);
|
|
5105
5047
|
|
|
5106
5048
|
// Getter props.
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
const itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
5049
|
+
var getSelectedItemProps = react.useCallback(function (_temp) {
|
|
5050
|
+
var _extends2;
|
|
5051
|
+
var _ref3 = _temp === void 0 ? {} : _temp,
|
|
5052
|
+
_ref3$refKey = _ref3.refKey,
|
|
5053
|
+
refKey = _ref3$refKey === void 0 ? 'ref' : _ref3$refKey,
|
|
5054
|
+
ref = _ref3.ref,
|
|
5055
|
+
onClick = _ref3.onClick,
|
|
5056
|
+
onKeyDown = _ref3.onKeyDown,
|
|
5057
|
+
selectedItem = _ref3.selectedItem,
|
|
5058
|
+
index = _ref3.index,
|
|
5059
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
5060
|
+
var latestState = latest.current.state;
|
|
5061
|
+
var itemIndex = getItemIndex(index, selectedItem, latestState.selectedItems);
|
|
5121
5062
|
if (itemIndex < 0) {
|
|
5122
5063
|
throw new Error('Pass either selectedItem or index in getSelectedItemProps!');
|
|
5123
5064
|
}
|
|
5124
|
-
|
|
5065
|
+
var selectedItemHandleClick = function selectedItemHandleClick() {
|
|
5125
5066
|
dispatch({
|
|
5126
5067
|
type: SelectedItemClick,
|
|
5127
|
-
index
|
|
5068
|
+
index: index
|
|
5128
5069
|
});
|
|
5129
5070
|
};
|
|
5130
|
-
|
|
5131
|
-
|
|
5071
|
+
var selectedItemHandleKeyDown = function selectedItemHandleKeyDown(event) {
|
|
5072
|
+
var key = normalizeArrowKey(event);
|
|
5132
5073
|
if (key && selectedItemKeyDownHandlers[key]) {
|
|
5133
5074
|
selectedItemKeyDownHandlers[key](event);
|
|
5134
5075
|
}
|
|
5135
5076
|
};
|
|
5136
|
-
return {
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
}),
|
|
5142
|
-
tabIndex: index === latestState.activeIndex ? 0 : -1,
|
|
5143
|
-
onClick: callAllEventHandlers(onClick, selectedItemHandleClick),
|
|
5144
|
-
onKeyDown: callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown),
|
|
5145
|
-
...rest
|
|
5146
|
-
};
|
|
5077
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, function (selectedItemNode) {
|
|
5078
|
+
if (selectedItemNode) {
|
|
5079
|
+
selectedItemRefs.current.push(selectedItemNode);
|
|
5080
|
+
}
|
|
5081
|
+
}), _extends2.tabIndex = index === latestState.activeIndex ? 0 : -1, _extends2.onClick = callAllEventHandlers(onClick, selectedItemHandleClick), _extends2.onKeyDown = callAllEventHandlers(onKeyDown, selectedItemHandleKeyDown), _extends2), rest);
|
|
5147
5082
|
}, [dispatch, latest, selectedItemKeyDownHandlers]);
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5083
|
+
var getDropdownProps = react.useCallback(function (_temp2, _temp3) {
|
|
5084
|
+
var _extends3;
|
|
5085
|
+
var _ref4 = _temp2 === void 0 ? {} : _temp2,
|
|
5086
|
+
_ref4$refKey = _ref4.refKey,
|
|
5087
|
+
refKey = _ref4$refKey === void 0 ? 'ref' : _ref4$refKey,
|
|
5088
|
+
ref = _ref4.ref,
|
|
5089
|
+
onKeyDown = _ref4.onKeyDown,
|
|
5090
|
+
onClick = _ref4.onClick,
|
|
5091
|
+
_ref4$preventKeyActio = _ref4.preventKeyAction,
|
|
5092
|
+
preventKeyAction = _ref4$preventKeyActio === void 0 ? false : _ref4$preventKeyActio,
|
|
5093
|
+
rest = _objectWithoutPropertiesLoose(_ref4, _excluded2);
|
|
5094
|
+
var _ref5 = _temp3 === void 0 ? {} : _temp3,
|
|
5095
|
+
_ref5$suppressRefErro = _ref5.suppressRefError,
|
|
5096
|
+
suppressRefError = _ref5$suppressRefErro === void 0 ? false : _ref5$suppressRefErro;
|
|
5160
5097
|
setGetterPropCallInfo('getDropdownProps', suppressRefError, refKey, dropdownRef);
|
|
5161
|
-
|
|
5162
|
-
|
|
5098
|
+
var dropdownHandleKeyDown = function dropdownHandleKeyDown(event) {
|
|
5099
|
+
var key = normalizeArrowKey(event);
|
|
5163
5100
|
if (key && dropdownKeyDownHandlers[key]) {
|
|
5164
5101
|
dropdownKeyDownHandlers[key](event);
|
|
5165
5102
|
}
|
|
5166
5103
|
};
|
|
5167
|
-
|
|
5104
|
+
var dropdownHandleClick = function dropdownHandleClick() {
|
|
5168
5105
|
dispatch({
|
|
5169
5106
|
type: DropdownClick
|
|
5170
5107
|
});
|
|
5171
5108
|
};
|
|
5172
|
-
return {
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
5181
|
-
}),
|
|
5182
|
-
...rest
|
|
5183
|
-
};
|
|
5109
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, function (dropdownNode) {
|
|
5110
|
+
if (dropdownNode) {
|
|
5111
|
+
dropdownRef.current = dropdownNode;
|
|
5112
|
+
}
|
|
5113
|
+
}), _extends3), !preventKeyAction && {
|
|
5114
|
+
onKeyDown: callAllEventHandlers(onKeyDown, dropdownHandleKeyDown),
|
|
5115
|
+
onClick: callAllEventHandlers(onClick, dropdownHandleClick)
|
|
5116
|
+
}, rest);
|
|
5184
5117
|
}, [dispatch, dropdownKeyDownHandlers, setGetterPropCallInfo]);
|
|
5185
5118
|
|
|
5186
5119
|
// returns
|
|
5187
|
-
|
|
5120
|
+
var addSelectedItem = react.useCallback(function (selectedItem) {
|
|
5188
5121
|
dispatch({
|
|
5189
5122
|
type: FunctionAddSelectedItem,
|
|
5190
|
-
selectedItem
|
|
5123
|
+
selectedItem: selectedItem
|
|
5191
5124
|
});
|
|
5192
5125
|
}, [dispatch]);
|
|
5193
|
-
|
|
5126
|
+
var removeSelectedItem = react.useCallback(function (selectedItem) {
|
|
5194
5127
|
dispatch({
|
|
5195
5128
|
type: FunctionRemoveSelectedItem,
|
|
5196
|
-
selectedItem
|
|
5129
|
+
selectedItem: selectedItem
|
|
5197
5130
|
});
|
|
5198
5131
|
}, [dispatch]);
|
|
5199
|
-
|
|
5132
|
+
var setSelectedItems = react.useCallback(function (newSelectedItems) {
|
|
5200
5133
|
dispatch({
|
|
5201
5134
|
type: FunctionSetSelectedItems,
|
|
5202
5135
|
selectedItems: newSelectedItems
|
|
5203
5136
|
});
|
|
5204
5137
|
}, [dispatch]);
|
|
5205
|
-
|
|
5138
|
+
var setActiveIndex = react.useCallback(function (newActiveIndex) {
|
|
5206
5139
|
dispatch({
|
|
5207
5140
|
type: FunctionSetActiveIndex,
|
|
5208
5141
|
activeIndex: newActiveIndex
|
|
5209
5142
|
});
|
|
5210
5143
|
}, [dispatch]);
|
|
5211
|
-
|
|
5144
|
+
var reset = react.useCallback(function () {
|
|
5212
5145
|
dispatch({
|
|
5213
5146
|
type: FunctionReset
|
|
5214
5147
|
});
|
|
5215
5148
|
}, [dispatch]);
|
|
5216
5149
|
return {
|
|
5217
|
-
getSelectedItemProps,
|
|
5218
|
-
getDropdownProps,
|
|
5219
|
-
addSelectedItem,
|
|
5220
|
-
removeSelectedItem,
|
|
5221
|
-
setSelectedItems,
|
|
5222
|
-
setActiveIndex,
|
|
5223
|
-
reset,
|
|
5224
|
-
selectedItems,
|
|
5225
|
-
activeIndex
|
|
5150
|
+
getSelectedItemProps: getSelectedItemProps,
|
|
5151
|
+
getDropdownProps: getDropdownProps,
|
|
5152
|
+
addSelectedItem: addSelectedItem,
|
|
5153
|
+
removeSelectedItem: removeSelectedItem,
|
|
5154
|
+
setSelectedItems: setSelectedItems,
|
|
5155
|
+
setActiveIndex: setActiveIndex,
|
|
5156
|
+
reset: reset,
|
|
5157
|
+
selectedItems: selectedItems,
|
|
5158
|
+
activeIndex: activeIndex
|
|
5226
5159
|
};
|
|
5227
5160
|
}
|
|
5228
5161
|
|