@entur/dropdown 5.0.0-beta.0 → 5.0.0-beta.2
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/beta/MultiSelect.d.ts +11 -1
- package/dist/beta/components/FieldComponents.d.ts +3 -3
- package/dist/dropdown.cjs.development.js +87 -59
- package/dist/dropdown.cjs.development.js.map +1 -1
- package/dist/dropdown.cjs.production.min.js +1 -1
- package/dist/dropdown.cjs.production.min.js.map +1 -1
- package/dist/dropdown.esm.js +87 -59
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +46 -7
- package/package.json +2 -2
package/dist/dropdown.esm.js
CHANGED
|
@@ -1294,13 +1294,14 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1294
1294
|
};
|
|
1295
1295
|
var selectAllListItemContent = function selectAllListItemContent() {
|
|
1296
1296
|
return React.createElement(React.Fragment, null, React.createElement(Checkbox, {
|
|
1297
|
+
className: "eds-dropdown__list__item__checkbox",
|
|
1297
1298
|
checked: selectAllCheckboxState == null ? void 0 : selectAllCheckboxState(),
|
|
1298
1299
|
"aria-hidden": "true",
|
|
1299
1300
|
onChange: function onChange() {
|
|
1300
1301
|
return;
|
|
1301
1302
|
}
|
|
1302
1303
|
}), React.createElement("span", {
|
|
1303
|
-
className: "eds-
|
|
1304
|
+
className: "eds-dropdown__list__item__text"
|
|
1304
1305
|
}, selectAllItem == null ? void 0 : selectAllItem.label));
|
|
1305
1306
|
};
|
|
1306
1307
|
var listItemContent = function listItemContent(item) {
|
|
@@ -1308,18 +1309,19 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1308
1309
|
style: !isMultiselect ? {
|
|
1309
1310
|
display: 'none'
|
|
1310
1311
|
} : {},
|
|
1312
|
+
className: "eds-dropdown__list__item__checkbox",
|
|
1311
1313
|
checked: itemIsSelected(item),
|
|
1312
1314
|
"aria-hidden": "true",
|
|
1313
1315
|
onChange: function onChange() {
|
|
1314
1316
|
return;
|
|
1315
1317
|
}
|
|
1316
1318
|
}), React.createElement("span", {
|
|
1317
|
-
className: "eds-
|
|
1319
|
+
className: "eds-dropdown__list__item__text"
|
|
1318
1320
|
}, item.label, React.createElement(VisuallyHidden, null, selectedItemAriaLabel)), item.icons && React.createElement("span", null, item.icons.map(function (Icon, index) {
|
|
1319
1321
|
return React.createElement(Icon, {
|
|
1320
1322
|
key: index,
|
|
1321
1323
|
inline: true,
|
|
1322
|
-
className: "eds-
|
|
1324
|
+
className: "eds-dropdown__list__item__icon"
|
|
1323
1325
|
});
|
|
1324
1326
|
})));
|
|
1325
1327
|
};
|
|
@@ -1422,17 +1424,18 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
1422
1424
|
};
|
|
1423
1425
|
|
|
1424
1426
|
var _excluded$3 = ["tabIndex"];
|
|
1425
|
-
var
|
|
1427
|
+
var SelectedItemTag = function SelectedItemTag(_ref) {
|
|
1428
|
+
var _getSelectedItemProps;
|
|
1426
1429
|
var getSelectedItemProps = _ref.getSelectedItemProps,
|
|
1427
1430
|
removeSelectedItem = _ref.removeSelectedItem,
|
|
1428
1431
|
selectedItem = _ref.selectedItem,
|
|
1429
1432
|
index = _ref.index,
|
|
1430
1433
|
ariaLabelRemoveSelected = _ref.ariaLabelRemoveSelected;
|
|
1431
|
-
var _getSelectedItemProps = getSelectedItemProps({
|
|
1434
|
+
var _ref2 = (_getSelectedItemProps = getSelectedItemProps == null ? void 0 : getSelectedItemProps({
|
|
1432
1435
|
selectedItem: selectedItem,
|
|
1433
1436
|
index: index
|
|
1434
|
-
}),
|
|
1435
|
-
selectedItemProps = _objectWithoutPropertiesLoose(
|
|
1437
|
+
})) != null ? _getSelectedItemProps : {},
|
|
1438
|
+
selectedItemProps = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
1436
1439
|
return React.createElement(TagChip, _extends({
|
|
1437
1440
|
className: classNames('eds-dropdown__selected-element-tag')
|
|
1438
1441
|
}, selectedItemProps, {
|
|
@@ -1446,21 +1449,21 @@ var SelectedElementsTag = function SelectedElementsTag(_ref) {
|
|
|
1446
1449
|
"aria-hidden": "true"
|
|
1447
1450
|
}, selectedItem.label));
|
|
1448
1451
|
};
|
|
1449
|
-
var FieldAppend = function FieldAppend(
|
|
1450
|
-
var clearable =
|
|
1451
|
-
readOnly =
|
|
1452
|
-
getToggleButtonProps =
|
|
1453
|
-
selectedItems =
|
|
1454
|
-
|
|
1455
|
-
loading =
|
|
1456
|
-
|
|
1457
|
-
loadingText =
|
|
1458
|
-
ariaLabelClearItems =
|
|
1459
|
-
clearSelectedItemsLabel =
|
|
1460
|
-
isOpen =
|
|
1461
|
-
onClear =
|
|
1462
|
-
|
|
1463
|
-
focusable =
|
|
1452
|
+
var FieldAppend = function FieldAppend(_ref3) {
|
|
1453
|
+
var clearable = _ref3.clearable,
|
|
1454
|
+
readOnly = _ref3.readOnly,
|
|
1455
|
+
getToggleButtonProps = _ref3.getToggleButtonProps,
|
|
1456
|
+
selectedItems = _ref3.selectedItems,
|
|
1457
|
+
_ref3$loading = _ref3.loading,
|
|
1458
|
+
loading = _ref3$loading === void 0 ? false : _ref3$loading,
|
|
1459
|
+
_ref3$loadingText = _ref3.loadingText,
|
|
1460
|
+
loadingText = _ref3$loadingText === void 0 ? 'Laster resultater …' : _ref3$loadingText,
|
|
1461
|
+
ariaLabelClearItems = _ref3.ariaLabelClearItems,
|
|
1462
|
+
clearSelectedItemsLabel = _ref3.clearSelectedItemsLabel,
|
|
1463
|
+
isOpen = _ref3.isOpen,
|
|
1464
|
+
onClear = _ref3.onClear,
|
|
1465
|
+
_ref3$focusable = _ref3.focusable,
|
|
1466
|
+
focusable = _ref3$focusable === void 0 ? false : _ref3$focusable;
|
|
1464
1467
|
if (loading) {
|
|
1465
1468
|
return React.createElement(DropdownLoadingDots, null, loadingText);
|
|
1466
1469
|
}
|
|
@@ -1482,14 +1485,14 @@ var FieldAppend = function FieldAppend(_ref2) {
|
|
|
1482
1485
|
focusable: focusable
|
|
1483
1486
|
}));
|
|
1484
1487
|
};
|
|
1485
|
-
var ClearableButton = function ClearableButton(
|
|
1486
|
-
var onClear =
|
|
1487
|
-
|
|
1488
|
-
clearSelectedItemsLabel =
|
|
1489
|
-
|
|
1490
|
-
ariaLabelClearItems =
|
|
1491
|
-
|
|
1492
|
-
focusable =
|
|
1488
|
+
var ClearableButton = function ClearableButton(_ref4) {
|
|
1489
|
+
var onClear = _ref4.onClear,
|
|
1490
|
+
_ref4$clearSelectedIt = _ref4.clearSelectedItemsLabel,
|
|
1491
|
+
clearSelectedItemsLabel = _ref4$clearSelectedIt === void 0 ? 'Fjern valgte' : _ref4$clearSelectedIt,
|
|
1492
|
+
_ref4$ariaLabelClearI = _ref4.ariaLabelClearItems,
|
|
1493
|
+
ariaLabelClearItems = _ref4$ariaLabelClearI === void 0 ? 'Fjern valgte' : _ref4$ariaLabelClearI,
|
|
1494
|
+
_ref4$focusable = _ref4.focusable,
|
|
1495
|
+
focusable = _ref4$focusable === void 0 ? false : _ref4$focusable;
|
|
1493
1496
|
return React.createElement(Tooltip, {
|
|
1494
1497
|
"aria-hidden": "true",
|
|
1495
1498
|
placement: "right",
|
|
@@ -1504,15 +1507,15 @@ var ClearableButton = function ClearableButton(_ref3) {
|
|
|
1504
1507
|
"aria-hidden": "true"
|
|
1505
1508
|
})));
|
|
1506
1509
|
};
|
|
1507
|
-
var ToggleButton = function ToggleButton(
|
|
1508
|
-
var getToggleButtonProps =
|
|
1509
|
-
isOpen =
|
|
1510
|
-
|
|
1511
|
-
closeAriaLabel =
|
|
1512
|
-
|
|
1513
|
-
openAriaLabel =
|
|
1514
|
-
|
|
1515
|
-
focusable =
|
|
1510
|
+
var ToggleButton = function ToggleButton(_ref5) {
|
|
1511
|
+
var getToggleButtonProps = _ref5.getToggleButtonProps,
|
|
1512
|
+
isOpen = _ref5.isOpen,
|
|
1513
|
+
_ref5$closeAriaLabel = _ref5.closeAriaLabel,
|
|
1514
|
+
closeAriaLabel = _ref5$closeAriaLabel === void 0 ? 'Lukk liste med valg' : _ref5$closeAriaLabel,
|
|
1515
|
+
_ref5$openAriaLabel = _ref5.openAriaLabel,
|
|
1516
|
+
openAriaLabel = _ref5$openAriaLabel === void 0 ? 'Åpne liste med valg' : _ref5$openAriaLabel,
|
|
1517
|
+
_ref5$focusable = _ref5.focusable,
|
|
1518
|
+
focusable = _ref5$focusable === void 0 ? false : _ref5$focusable;
|
|
1516
1519
|
return React.createElement(IconButton, _extends({}, getToggleButtonProps({
|
|
1517
1520
|
className: classNames('eds-dropdown-appendix__toggle-button', {
|
|
1518
1521
|
'eds-dropdown-appendix__toggle-button--open': isOpen
|
|
@@ -1700,25 +1703,33 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1700
1703
|
}));
|
|
1701
1704
|
};
|
|
1702
1705
|
|
|
1703
|
-
var _excluded$1 = ["ariaLabelRemoveSelected", "className", "clearable", "debounceTimeout", "feedback", "hideSelectAll", "items", "label", "listStyle", "onChange", "openOnFocus", "placeholder", "readonly", "selectAllLabel", "selectedItems", "selectOnBlur", "style", "variant"];
|
|
1706
|
+
var _excluded$1 = ["allItemsSelectedLabel", "ariaLabelRemoveSelected", "className", "clearable", "clearInputOnSelect", "debounceTimeout", "feedback", "hideSelectAll", "items", "label", "listStyle", "maxTags", "onChange", "openOnFocus", "placeholder", "readonly", "removeAllItemsAriaLabel", "selectAllLabel", "selectedItems", "selectOnBlur", "style", "variant"];
|
|
1704
1707
|
var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
1705
|
-
var _ref$
|
|
1708
|
+
var _ref$allItemsSelected = _ref.allItemsSelectedLabel,
|
|
1709
|
+
allItemsSelectedLabel = _ref$allItemsSelected === void 0 ? 'Alle valgt' : _ref$allItemsSelected,
|
|
1710
|
+
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1706
1711
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1707
1712
|
className = _ref.className,
|
|
1708
1713
|
_ref$clearable = _ref.clearable,
|
|
1709
1714
|
clearable = _ref$clearable === void 0 ? false : _ref$clearable,
|
|
1715
|
+
_ref$clearInputOnSele = _ref.clearInputOnSelect,
|
|
1716
|
+
clearInputOnSelect = _ref$clearInputOnSele === void 0 ? false : _ref$clearInputOnSele,
|
|
1710
1717
|
feedback = _ref.feedback,
|
|
1711
1718
|
_ref$hideSelectAll = _ref.hideSelectAll,
|
|
1712
1719
|
hideSelectAll = _ref$hideSelectAll === void 0 ? false : _ref$hideSelectAll,
|
|
1713
1720
|
initialItems = _ref.items,
|
|
1714
1721
|
label = _ref.label,
|
|
1715
1722
|
listStyle = _ref.listStyle,
|
|
1723
|
+
_ref$maxTags = _ref.maxTags,
|
|
1724
|
+
maxTags = _ref$maxTags === void 0 ? 10 : _ref$maxTags,
|
|
1716
1725
|
onChange = _ref.onChange,
|
|
1717
1726
|
_ref$openOnFocus = _ref.openOnFocus,
|
|
1718
1727
|
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
1719
1728
|
placeholder = _ref.placeholder,
|
|
1720
1729
|
_ref$readonly = _ref.readonly,
|
|
1721
1730
|
readonly = _ref$readonly === void 0 ? false : _ref$readonly,
|
|
1731
|
+
_ref$removeAllItemsAr = _ref.removeAllItemsAriaLabel,
|
|
1732
|
+
removeAllItemsAriaLabel = _ref$removeAllItemsAr === void 0 ? 'Fjern valgte' : _ref$removeAllItemsAr,
|
|
1722
1733
|
_ref$selectAllLabel = _ref.selectAllLabel,
|
|
1723
1734
|
selectAllLabel = _ref$selectAllLabel === void 0 ? 'Velg alle' : _ref$selectAllLabel,
|
|
1724
1735
|
selectedItems = _ref.selectedItems,
|
|
@@ -1736,10 +1747,17 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1736
1747
|
normalizedItems = _useResolvedItems.items,
|
|
1737
1748
|
loading = _useResolvedItems.loading,
|
|
1738
1749
|
fetchItems = _useResolvedItems.fetchItems;
|
|
1750
|
+
var isAllNonAsyncItemsSelected = typeof initialItems !== 'function' && selectedItems.length === normalizedItems.length;
|
|
1739
1751
|
var selectAll = {
|
|
1740
1752
|
value: useRandomId('select-all'),
|
|
1741
1753
|
label: selectAllLabel
|
|
1742
1754
|
};
|
|
1755
|
+
var summarySelectedItems = React.useMemo(function () {
|
|
1756
|
+
return {
|
|
1757
|
+
value: '',
|
|
1758
|
+
label: isAllNonAsyncItemsSelected ? allItemsSelectedLabel : selectedItems.length + ' valgte'
|
|
1759
|
+
};
|
|
1760
|
+
}, [isAllNonAsyncItemsSelected, selectedItems, normalizedItems, allItemsSelectedLabel]);
|
|
1743
1761
|
var _useState = useState([].concat(!hideSelectAll ? [selectAll] : [], normalizedItems)),
|
|
1744
1762
|
listItems = _useState[0],
|
|
1745
1763
|
setListItems = _useState[1];
|
|
@@ -1749,6 +1767,12 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1749
1767
|
return lowerCaseFilterTest(item, inputValue);
|
|
1750
1768
|
})));
|
|
1751
1769
|
};
|
|
1770
|
+
var updateListItems = function updateListItems(inputValue) {
|
|
1771
|
+
if (typeof initialItems === 'function') fetchItems(inputValue != null ? inputValue : ''); // fetch items only if user provides a function as items
|
|
1772
|
+
filterListItems({
|
|
1773
|
+
inputValue: inputValue != null ? inputValue : ''
|
|
1774
|
+
});
|
|
1775
|
+
};
|
|
1752
1776
|
React.useEffect(function () {
|
|
1753
1777
|
filterListItems({
|
|
1754
1778
|
inputValue: inputValue
|
|
@@ -1780,23 +1804,24 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1780
1804
|
getDropdownProps = _useMultipleSelection.getDropdownProps,
|
|
1781
1805
|
removeSelectedItem = _useMultipleSelection.removeSelectedItem;
|
|
1782
1806
|
var stateReducer = React.useCallback(function (_, _ref3) {
|
|
1783
|
-
var _inputRef$current$val, _inputRef$current, _inputRef$current$val2, _inputRef$current2, _changes$inputValue
|
|
1807
|
+
var _inputRef$current$val, _inputRef$current, _inputRef$current$val2, _inputRef$current2, _changes$inputValue;
|
|
1784
1808
|
var changes = _ref3.changes,
|
|
1785
1809
|
type = _ref3.type;
|
|
1786
1810
|
if (changes != null && changes.highlightedIndex && (changes == null ? void 0 : changes.highlightedIndex) >= 0) setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1787
1811
|
switch (type) {
|
|
1788
1812
|
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1789
1813
|
case useCombobox.stateChangeTypes.ItemClick:
|
|
1814
|
+
if (clearInputOnSelect) {
|
|
1815
|
+
updateListItems('');
|
|
1816
|
+
}
|
|
1790
1817
|
return _extends({}, changes, {
|
|
1791
1818
|
isOpen: true,
|
|
1792
|
-
inputValue: (_inputRef$current$val = inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : ''
|
|
1819
|
+
inputValue: clearInputOnSelect ? '' : (_inputRef$current$val = inputRef == null ? void 0 : (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : ''
|
|
1793
1820
|
});
|
|
1794
|
-
|
|
1795
1821
|
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1796
1822
|
return _extends({}, changes, {
|
|
1797
|
-
inputValue: (_inputRef$current$val2 = inputRef == null ? void 0 : (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val2 : ''
|
|
1823
|
+
inputValue: clearInputOnSelect ? '' : (_inputRef$current$val2 = inputRef == null ? void 0 : (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val2 : ''
|
|
1798
1824
|
});
|
|
1799
|
-
|
|
1800
1825
|
case useCombobox.stateChangeTypes.InputChange:
|
|
1801
1826
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(/^\s+/g)) {
|
|
1802
1827
|
var _changes$inputValue$r;
|
|
@@ -1805,10 +1830,7 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1805
1830
|
inputValue: (_changes$inputValue$r = changes.inputValue.replace(/^\s+/g, '')) != null ? _changes$inputValue$r : ''
|
|
1806
1831
|
});
|
|
1807
1832
|
}
|
|
1808
|
-
|
|
1809
|
-
filterListItems({
|
|
1810
|
-
inputValue: (_changes$inputValue3 = changes.inputValue) != null ? _changes$inputValue3 : ''
|
|
1811
|
-
});
|
|
1833
|
+
updateListItems(changes.inputValue);
|
|
1812
1834
|
return changes;
|
|
1813
1835
|
case useCombobox.stateChangeTypes.InputBlur:
|
|
1814
1836
|
return _extends({}, changes, {
|
|
@@ -1859,6 +1881,13 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1859
1881
|
isOpen = _useCombobox.isOpen,
|
|
1860
1882
|
openMenu = _useCombobox.openMenu,
|
|
1861
1883
|
setInputValue = _useCombobox.setInputValue;
|
|
1884
|
+
var handleOnClear = function handleOnClear() {
|
|
1885
|
+
var _inputRef$current3;
|
|
1886
|
+
onChange([]);
|
|
1887
|
+
setInputValue('');
|
|
1888
|
+
(_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.focus();
|
|
1889
|
+
updateListItems(inputValue);
|
|
1890
|
+
};
|
|
1862
1891
|
// role=combobox leads to strange VoiceOver behavior and is therefor omitted
|
|
1863
1892
|
// const { role: _, ...comboboxProps } = getComboboxProps();
|
|
1864
1893
|
var _getComboboxProps = getComboboxProps(),
|
|
@@ -1870,16 +1899,11 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1870
1899
|
selectedItems: selectedItems,
|
|
1871
1900
|
isOpen: isOpen,
|
|
1872
1901
|
clearable: clearable,
|
|
1902
|
+
clearSelectedItemsLabel: removeAllItemsAriaLabel,
|
|
1873
1903
|
loading: loading,
|
|
1874
1904
|
loadingText: '',
|
|
1875
1905
|
readOnly: readonly,
|
|
1876
|
-
onClear:
|
|
1877
|
-
var _inputRef$current3;
|
|
1878
|
-
onChange([]);
|
|
1879
|
-
setInputValue('');
|
|
1880
|
-
(_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.focus();
|
|
1881
|
-
if (typeof initialItems === 'function') fetchItems(inputValue != null ? inputValue : '');
|
|
1882
|
-
},
|
|
1906
|
+
onClear: handleOnClear,
|
|
1883
1907
|
getToggleButtonProps: getToggleButtonProps
|
|
1884
1908
|
}),
|
|
1885
1909
|
className: classNames('eds-dropdown', className),
|
|
@@ -1900,8 +1924,8 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1900
1924
|
var _inputRef$current4;
|
|
1901
1925
|
if (e.target === e.currentTarget) (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
1902
1926
|
}
|
|
1903
|
-
}, selectedItems.map(function (selectedItem, index) {
|
|
1904
|
-
return React.createElement(
|
|
1927
|
+
}, selectedItems.length < maxTags ? selectedItems.map(function (selectedItem, index) {
|
|
1928
|
+
return React.createElement(SelectedItemTag, {
|
|
1905
1929
|
index: index,
|
|
1906
1930
|
key: selectedItem.value,
|
|
1907
1931
|
getSelectedItemProps: getSelectedItemProps,
|
|
@@ -1909,6 +1933,10 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1909
1933
|
removeSelectedItem: removeSelectedItem,
|
|
1910
1934
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected
|
|
1911
1935
|
});
|
|
1936
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1937
|
+
selectedItem: summarySelectedItems,
|
|
1938
|
+
removeSelectedItem: handleOnClear,
|
|
1939
|
+
ariaLabelRemoveSelected: removeAllItemsAriaLabel
|
|
1912
1940
|
}), React.createElement("input", _extends({
|
|
1913
1941
|
placeholder: placeholder,
|
|
1914
1942
|
className: "eds-dropdown__input eds-form-control",
|