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