@entur/dropdown 5.0.0-beta.1 → 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 +82 -56
- 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 +82 -56
- package/dist/dropdown.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/dropdown.esm.js
CHANGED
|
@@ -1424,17 +1424,18 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
|
|
|
1424
1424
|
};
|
|
1425
1425
|
|
|
1426
1426
|
var _excluded$3 = ["tabIndex"];
|
|
1427
|
-
var
|
|
1427
|
+
var SelectedItemTag = function SelectedItemTag(_ref) {
|
|
1428
|
+
var _getSelectedItemProps;
|
|
1428
1429
|
var getSelectedItemProps = _ref.getSelectedItemProps,
|
|
1429
1430
|
removeSelectedItem = _ref.removeSelectedItem,
|
|
1430
1431
|
selectedItem = _ref.selectedItem,
|
|
1431
1432
|
index = _ref.index,
|
|
1432
1433
|
ariaLabelRemoveSelected = _ref.ariaLabelRemoveSelected;
|
|
1433
|
-
var _getSelectedItemProps = getSelectedItemProps({
|
|
1434
|
+
var _ref2 = (_getSelectedItemProps = getSelectedItemProps == null ? void 0 : getSelectedItemProps({
|
|
1434
1435
|
selectedItem: selectedItem,
|
|
1435
1436
|
index: index
|
|
1436
|
-
}),
|
|
1437
|
-
selectedItemProps = _objectWithoutPropertiesLoose(
|
|
1437
|
+
})) != null ? _getSelectedItemProps : {},
|
|
1438
|
+
selectedItemProps = _objectWithoutPropertiesLoose(_ref2, _excluded$3);
|
|
1438
1439
|
return React.createElement(TagChip, _extends({
|
|
1439
1440
|
className: classNames('eds-dropdown__selected-element-tag')
|
|
1440
1441
|
}, selectedItemProps, {
|
|
@@ -1448,21 +1449,21 @@ var SelectedElementsTag = function SelectedElementsTag(_ref) {
|
|
|
1448
1449
|
"aria-hidden": "true"
|
|
1449
1450
|
}, selectedItem.label));
|
|
1450
1451
|
};
|
|
1451
|
-
var FieldAppend = function FieldAppend(
|
|
1452
|
-
var clearable =
|
|
1453
|
-
readOnly =
|
|
1454
|
-
getToggleButtonProps =
|
|
1455
|
-
selectedItems =
|
|
1456
|
-
|
|
1457
|
-
loading =
|
|
1458
|
-
|
|
1459
|
-
loadingText =
|
|
1460
|
-
ariaLabelClearItems =
|
|
1461
|
-
clearSelectedItemsLabel =
|
|
1462
|
-
isOpen =
|
|
1463
|
-
onClear =
|
|
1464
|
-
|
|
1465
|
-
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;
|
|
1466
1467
|
if (loading) {
|
|
1467
1468
|
return React.createElement(DropdownLoadingDots, null, loadingText);
|
|
1468
1469
|
}
|
|
@@ -1484,14 +1485,14 @@ var FieldAppend = function FieldAppend(_ref2) {
|
|
|
1484
1485
|
focusable: focusable
|
|
1485
1486
|
}));
|
|
1486
1487
|
};
|
|
1487
|
-
var ClearableButton = function ClearableButton(
|
|
1488
|
-
var onClear =
|
|
1489
|
-
|
|
1490
|
-
clearSelectedItemsLabel =
|
|
1491
|
-
|
|
1492
|
-
ariaLabelClearItems =
|
|
1493
|
-
|
|
1494
|
-
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;
|
|
1495
1496
|
return React.createElement(Tooltip, {
|
|
1496
1497
|
"aria-hidden": "true",
|
|
1497
1498
|
placement: "right",
|
|
@@ -1506,15 +1507,15 @@ var ClearableButton = function ClearableButton(_ref3) {
|
|
|
1506
1507
|
"aria-hidden": "true"
|
|
1507
1508
|
})));
|
|
1508
1509
|
};
|
|
1509
|
-
var ToggleButton = function ToggleButton(
|
|
1510
|
-
var getToggleButtonProps =
|
|
1511
|
-
isOpen =
|
|
1512
|
-
|
|
1513
|
-
closeAriaLabel =
|
|
1514
|
-
|
|
1515
|
-
openAriaLabel =
|
|
1516
|
-
|
|
1517
|
-
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;
|
|
1518
1519
|
return React.createElement(IconButton, _extends({}, getToggleButtonProps({
|
|
1519
1520
|
className: classNames('eds-dropdown-appendix__toggle-button', {
|
|
1520
1521
|
'eds-dropdown-appendix__toggle-button--open': isOpen
|
|
@@ -1702,25 +1703,33 @@ var SearchableDropdownBeta = function SearchableDropdownBeta(_ref) {
|
|
|
1702
1703
|
}));
|
|
1703
1704
|
};
|
|
1704
1705
|
|
|
1705
|
-
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"];
|
|
1706
1707
|
var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
1707
|
-
var _ref$
|
|
1708
|
+
var _ref$allItemsSelected = _ref.allItemsSelectedLabel,
|
|
1709
|
+
allItemsSelectedLabel = _ref$allItemsSelected === void 0 ? 'Alle valgt' : _ref$allItemsSelected,
|
|
1710
|
+
_ref$ariaLabelRemoveS = _ref.ariaLabelRemoveSelected,
|
|
1708
1711
|
ariaLabelRemoveSelected = _ref$ariaLabelRemoveS === void 0 ? 'trykk for å fjerne valg' : _ref$ariaLabelRemoveS,
|
|
1709
1712
|
className = _ref.className,
|
|
1710
1713
|
_ref$clearable = _ref.clearable,
|
|
1711
1714
|
clearable = _ref$clearable === void 0 ? false : _ref$clearable,
|
|
1715
|
+
_ref$clearInputOnSele = _ref.clearInputOnSelect,
|
|
1716
|
+
clearInputOnSelect = _ref$clearInputOnSele === void 0 ? false : _ref$clearInputOnSele,
|
|
1712
1717
|
feedback = _ref.feedback,
|
|
1713
1718
|
_ref$hideSelectAll = _ref.hideSelectAll,
|
|
1714
1719
|
hideSelectAll = _ref$hideSelectAll === void 0 ? false : _ref$hideSelectAll,
|
|
1715
1720
|
initialItems = _ref.items,
|
|
1716
1721
|
label = _ref.label,
|
|
1717
1722
|
listStyle = _ref.listStyle,
|
|
1723
|
+
_ref$maxTags = _ref.maxTags,
|
|
1724
|
+
maxTags = _ref$maxTags === void 0 ? 10 : _ref$maxTags,
|
|
1718
1725
|
onChange = _ref.onChange,
|
|
1719
1726
|
_ref$openOnFocus = _ref.openOnFocus,
|
|
1720
1727
|
openOnFocus = _ref$openOnFocus === void 0 ? false : _ref$openOnFocus,
|
|
1721
1728
|
placeholder = _ref.placeholder,
|
|
1722
1729
|
_ref$readonly = _ref.readonly,
|
|
1723
1730
|
readonly = _ref$readonly === void 0 ? false : _ref$readonly,
|
|
1731
|
+
_ref$removeAllItemsAr = _ref.removeAllItemsAriaLabel,
|
|
1732
|
+
removeAllItemsAriaLabel = _ref$removeAllItemsAr === void 0 ? 'Fjern valgte' : _ref$removeAllItemsAr,
|
|
1724
1733
|
_ref$selectAllLabel = _ref.selectAllLabel,
|
|
1725
1734
|
selectAllLabel = _ref$selectAllLabel === void 0 ? 'Velg alle' : _ref$selectAllLabel,
|
|
1726
1735
|
selectedItems = _ref.selectedItems,
|
|
@@ -1738,10 +1747,17 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1738
1747
|
normalizedItems = _useResolvedItems.items,
|
|
1739
1748
|
loading = _useResolvedItems.loading,
|
|
1740
1749
|
fetchItems = _useResolvedItems.fetchItems;
|
|
1750
|
+
var isAllNonAsyncItemsSelected = typeof initialItems !== 'function' && selectedItems.length === normalizedItems.length;
|
|
1741
1751
|
var selectAll = {
|
|
1742
1752
|
value: useRandomId('select-all'),
|
|
1743
1753
|
label: selectAllLabel
|
|
1744
1754
|
};
|
|
1755
|
+
var summarySelectedItems = React.useMemo(function () {
|
|
1756
|
+
return {
|
|
1757
|
+
value: '',
|
|
1758
|
+
label: isAllNonAsyncItemsSelected ? allItemsSelectedLabel : selectedItems.length + ' valgte'
|
|
1759
|
+
};
|
|
1760
|
+
}, [isAllNonAsyncItemsSelected, selectedItems, normalizedItems, allItemsSelectedLabel]);
|
|
1745
1761
|
var _useState = useState([].concat(!hideSelectAll ? [selectAll] : [], normalizedItems)),
|
|
1746
1762
|
listItems = _useState[0],
|
|
1747
1763
|
setListItems = _useState[1];
|
|
@@ -1751,6 +1767,12 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1751
1767
|
return lowerCaseFilterTest(item, inputValue);
|
|
1752
1768
|
})));
|
|
1753
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
|
+
};
|
|
1754
1776
|
React.useEffect(function () {
|
|
1755
1777
|
filterListItems({
|
|
1756
1778
|
inputValue: inputValue
|
|
@@ -1782,23 +1804,24 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1782
1804
|
getDropdownProps = _useMultipleSelection.getDropdownProps,
|
|
1783
1805
|
removeSelectedItem = _useMultipleSelection.removeSelectedItem;
|
|
1784
1806
|
var stateReducer = React.useCallback(function (_, _ref3) {
|
|
1785
|
-
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;
|
|
1786
1808
|
var changes = _ref3.changes,
|
|
1787
1809
|
type = _ref3.type;
|
|
1788
1810
|
if (changes != null && changes.highlightedIndex && (changes == null ? void 0 : changes.highlightedIndex) >= 0) setLastHighlightedIndex(changes == null ? void 0 : changes.highlightedIndex);
|
|
1789
1811
|
switch (type) {
|
|
1790
1812
|
case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1791
1813
|
case useCombobox.stateChangeTypes.ItemClick:
|
|
1814
|
+
if (clearInputOnSelect) {
|
|
1815
|
+
updateListItems('');
|
|
1816
|
+
}
|
|
1792
1817
|
return _extends({}, changes, {
|
|
1793
1818
|
isOpen: true,
|
|
1794
|
-
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 : ''
|
|
1795
1820
|
});
|
|
1796
|
-
|
|
1797
1821
|
case useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1798
1822
|
return _extends({}, changes, {
|
|
1799
|
-
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 : ''
|
|
1800
1824
|
});
|
|
1801
|
-
|
|
1802
1825
|
case useCombobox.stateChangeTypes.InputChange:
|
|
1803
1826
|
if ((_changes$inputValue = changes.inputValue) != null && _changes$inputValue.match(/^\s+/g)) {
|
|
1804
1827
|
var _changes$inputValue$r;
|
|
@@ -1807,10 +1830,7 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1807
1830
|
inputValue: (_changes$inputValue$r = changes.inputValue.replace(/^\s+/g, '')) != null ? _changes$inputValue$r : ''
|
|
1808
1831
|
});
|
|
1809
1832
|
}
|
|
1810
|
-
|
|
1811
|
-
filterListItems({
|
|
1812
|
-
inputValue: (_changes$inputValue3 = changes.inputValue) != null ? _changes$inputValue3 : ''
|
|
1813
|
-
});
|
|
1833
|
+
updateListItems(changes.inputValue);
|
|
1814
1834
|
return changes;
|
|
1815
1835
|
case useCombobox.stateChangeTypes.InputBlur:
|
|
1816
1836
|
return _extends({}, changes, {
|
|
@@ -1861,6 +1881,13 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1861
1881
|
isOpen = _useCombobox.isOpen,
|
|
1862
1882
|
openMenu = _useCombobox.openMenu,
|
|
1863
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
|
+
};
|
|
1864
1891
|
// role=combobox leads to strange VoiceOver behavior and is therefor omitted
|
|
1865
1892
|
// const { role: _, ...comboboxProps } = getComboboxProps();
|
|
1866
1893
|
var _getComboboxProps = getComboboxProps(),
|
|
@@ -1872,16 +1899,11 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1872
1899
|
selectedItems: selectedItems,
|
|
1873
1900
|
isOpen: isOpen,
|
|
1874
1901
|
clearable: clearable,
|
|
1902
|
+
clearSelectedItemsLabel: removeAllItemsAriaLabel,
|
|
1875
1903
|
loading: loading,
|
|
1876
1904
|
loadingText: '',
|
|
1877
1905
|
readOnly: readonly,
|
|
1878
|
-
onClear:
|
|
1879
|
-
var _inputRef$current3;
|
|
1880
|
-
onChange([]);
|
|
1881
|
-
setInputValue('');
|
|
1882
|
-
(_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.focus();
|
|
1883
|
-
if (typeof initialItems === 'function') fetchItems(inputValue != null ? inputValue : '');
|
|
1884
|
-
},
|
|
1906
|
+
onClear: handleOnClear,
|
|
1885
1907
|
getToggleButtonProps: getToggleButtonProps
|
|
1886
1908
|
}),
|
|
1887
1909
|
className: classNames('eds-dropdown', className),
|
|
@@ -1902,8 +1924,8 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1902
1924
|
var _inputRef$current4;
|
|
1903
1925
|
if (e.target === e.currentTarget) (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
1904
1926
|
}
|
|
1905
|
-
}, selectedItems.map(function (selectedItem, index) {
|
|
1906
|
-
return React.createElement(
|
|
1927
|
+
}, selectedItems.length < maxTags ? selectedItems.map(function (selectedItem, index) {
|
|
1928
|
+
return React.createElement(SelectedItemTag, {
|
|
1907
1929
|
index: index,
|
|
1908
1930
|
key: selectedItem.value,
|
|
1909
1931
|
getSelectedItemProps: getSelectedItemProps,
|
|
@@ -1911,6 +1933,10 @@ var MultiSelectBeta = function MultiSelectBeta(_ref) {
|
|
|
1911
1933
|
removeSelectedItem: removeSelectedItem,
|
|
1912
1934
|
ariaLabelRemoveSelected: ariaLabelRemoveSelected
|
|
1913
1935
|
});
|
|
1936
|
+
}) : React.createElement(SelectedItemTag, {
|
|
1937
|
+
selectedItem: summarySelectedItems,
|
|
1938
|
+
removeSelectedItem: handleOnClear,
|
|
1939
|
+
ariaLabelRemoveSelected: removeAllItemsAriaLabel
|
|
1914
1940
|
}), React.createElement("input", _extends({
|
|
1915
1941
|
placeholder: placeholder,
|
|
1916
1942
|
className: "eds-dropdown__input eds-form-control",
|