@entur/dropdown 7.2.3-beta.0 → 7.3.0
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/dropdown.cjs.development.js +50 -61
- 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 +50 -61
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +77 -77
- package/dist/utils.d.ts +1 -1
- package/package.json +4 -4
|
@@ -425,7 +425,9 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
425
425
|
checked: selectAllCheckboxState == null ? void 0 : selectAllCheckboxState(),
|
|
426
426
|
className: "eds-dropdown__list__item__checkbox",
|
|
427
427
|
tabIndex: -1,
|
|
428
|
-
|
|
428
|
+
onChange: function onChange() {
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
429
431
|
}), React.createElement("span", {
|
|
430
432
|
className: "eds-dropdown__list__item__text",
|
|
431
433
|
"aria-label": ariaValuesSelectAll().label
|
|
@@ -440,7 +442,9 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
440
442
|
checked: isItemSelected(item),
|
|
441
443
|
className: "eds-dropdown__list__item__checkbox",
|
|
442
444
|
tabIndex: -1,
|
|
443
|
-
|
|
445
|
+
onChange: function onChange() {
|
|
446
|
+
return undefined;
|
|
447
|
+
}
|
|
444
448
|
}), React.createElement("span", {
|
|
445
449
|
className: "eds-dropdown__list__item__text"
|
|
446
450
|
}, item.label, React.createElement(a11y.VisuallyHidden, null, isItemSelected(item) ? ariaLabelSelectedItem : '')), Array.isArray(item.icons) ? item.icons.filter(isReactComponent).map(function (Icon, index) {
|
|
@@ -880,7 +884,7 @@ function getA11yStatusMessage(options) {
|
|
|
880
884
|
|
|
881
885
|
var _excluded$3 = ["ariaLabelChosenSingular", "ariaLabelCloseList", "ariaLabelOpenList", "ariaLabelSelectedItem", "className", "clearable", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "items", "itemFilter", "label", "labelClearSelectedItem", "labelTooltip", "listStyle", "loading", "loadingText", "noMatchesText", "onChange", "placeholder", "prepend", "readOnly", "selectedItem", "selectOnBlur", "selectOnTab", "style", "variant"];
|
|
882
886
|
var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
883
|
-
var _document, _selectedItem$label;
|
|
887
|
+
var _document, _getInputProps2, _selectedItem$label;
|
|
884
888
|
var ariaLabelChosenSingular = _ref.ariaLabelChosenSingular,
|
|
885
889
|
_ref$ariaLabelCloseLi = _ref.ariaLabelCloseList,
|
|
886
890
|
ariaLabelCloseList = _ref$ariaLabelCloseLi === void 0 ? 'Lukk liste med valg' : _ref$ariaLabelCloseLi,
|
|
@@ -1039,9 +1043,8 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1039
1043
|
inputValue: changes.inputValue
|
|
1040
1044
|
});
|
|
1041
1045
|
},
|
|
1042
|
-
|
|
1046
|
+
onSelectedItemChange: function onSelectedItemChange(_ref6) {
|
|
1043
1047
|
var newSelectedItem = _ref6.selectedItem;
|
|
1044
|
-
if (newSelectedItem === undefined) return;
|
|
1045
1048
|
onChange(newSelectedItem);
|
|
1046
1049
|
},
|
|
1047
1050
|
// Accessibility
|
|
@@ -1051,7 +1054,6 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1051
1054
|
}));
|
|
1052
1055
|
}
|
|
1053
1056
|
}),
|
|
1054
|
-
closeMenu = _useCombobox.closeMenu,
|
|
1055
1057
|
isOpen = _useCombobox.isOpen,
|
|
1056
1058
|
getToggleButtonProps = _useCombobox.getToggleButtonProps,
|
|
1057
1059
|
getLabelProps = _useCombobox.getLabelProps,
|
|
@@ -1061,7 +1063,9 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1061
1063
|
getItemProps = _useCombobox.getItemProps,
|
|
1062
1064
|
selectedItem = _useCombobox.selectedItem,
|
|
1063
1065
|
inputValue = _useCombobox.inputValue,
|
|
1064
|
-
setInputValue = _useCombobox.setInputValue
|
|
1066
|
+
setInputValue = _useCombobox.setInputValue,
|
|
1067
|
+
selectItem = _useCombobox.selectItem,
|
|
1068
|
+
reset = _useCombobox.reset;
|
|
1065
1069
|
// calculations for floating-UI popover position
|
|
1066
1070
|
var _useFloating = reactDom.useFloating({
|
|
1067
1071
|
open: isOpen,
|
|
@@ -1098,13 +1102,8 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1098
1102
|
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1099
1103
|
var handleOnClear = function handleOnClear() {
|
|
1100
1104
|
var _inputRef$current;
|
|
1101
|
-
onChange(null);
|
|
1102
|
-
setInputValue(EMPTY_INPUT);
|
|
1103
1105
|
(_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
|
|
1104
|
-
|
|
1105
|
-
inputValue: inputValue
|
|
1106
|
-
});
|
|
1107
|
-
setShowSelectedItem(false);
|
|
1106
|
+
reset();
|
|
1108
1107
|
};
|
|
1109
1108
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1110
1109
|
className: classNames('eds-dropdown', 'eds-dropdown--searchable', className, {
|
|
@@ -1118,6 +1117,9 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1118
1117
|
labelId: getLabelProps().id,
|
|
1119
1118
|
labelProps: getLabelProps(),
|
|
1120
1119
|
labelTooltip: labelTooltip,
|
|
1120
|
+
onBlur: function onBlur() {
|
|
1121
|
+
return setInputValue('');
|
|
1122
|
+
},
|
|
1121
1123
|
onClick: function onClick(e) {
|
|
1122
1124
|
if (e.target === e.currentTarget) {
|
|
1123
1125
|
var _getInputProps;
|
|
@@ -1154,13 +1156,7 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1154
1156
|
className: classNames('eds-dropdown--searchable__selected-item', {
|
|
1155
1157
|
'eds-dropdown--searchable__selected-item--hidden': !showSelectedItem
|
|
1156
1158
|
}),
|
|
1157
|
-
onClick:
|
|
1158
|
-
if (!disabled && !readOnly) {
|
|
1159
|
-
var _inputRef$current2, _getInputProps2;
|
|
1160
|
-
(_inputRef$current2 = inputRef.current) == null || _inputRef$current2.focus();
|
|
1161
|
-
(_getInputProps2 = getInputProps()) == null || _getInputProps2.onClick == null || _getInputProps2.onClick(event);
|
|
1162
|
-
}
|
|
1163
|
-
},
|
|
1159
|
+
onClick: readOnly ? undefined : (_getInputProps2 = getInputProps()) == null ? void 0 : _getInputProps2.onClick,
|
|
1164
1160
|
tabIndex: readOnly ? 0 : -1
|
|
1165
1161
|
}, showSelectedItem ? selectedItem == null ? void 0 : selectedItem.label : ''), React.createElement("input", _extends({
|
|
1166
1162
|
className: classNames('eds-dropdown__input eds-form-control', {
|
|
@@ -1172,10 +1168,8 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1172
1168
|
var highlitedItem = listItems[highlightedIndex];
|
|
1173
1169
|
// we don't want to clear selection with tab
|
|
1174
1170
|
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1175
|
-
|
|
1171
|
+
selectItem(highlitedItem);
|
|
1176
1172
|
}
|
|
1177
|
-
closeMenu();
|
|
1178
|
-
e.preventDefault();
|
|
1179
1173
|
}
|
|
1180
1174
|
},
|
|
1181
1175
|
onBlur: function onBlur() {
|
|
@@ -1210,7 +1204,7 @@ var SearchableDropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1210
1204
|
|
|
1211
1205
|
var _excluded$2 = ["className", "clearable", "clearInputOnSelect", "debounceTimeout", "disabled", "disableLabelAnimation", "feedback", "hideSelectAll", "items", "itemFilter", "label", "labelAllItemsSelected", "labelClearAllItems", "labelSelectAll", "labelTooltip", "listStyle", "loading", "loadingText", "maxChips", "noMatchesText", "onChange", "placeholder", "readOnly", "selectedItems", "selectOnBlur", "selectOnTab", "style", "variant", "ariaLabelChosenSingular", "ariaLabelChosenPlural", "ariaLabelCloseList", "ariaLabelJumpToInput", "ariaLabelOpenList", "ariaLabelRemoveSelected", "ariaLabelSelectedItem"];
|
|
1212
1206
|
var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
1213
|
-
var _inputRef$
|
|
1207
|
+
var _inputRef$current4;
|
|
1214
1208
|
var className = _ref.className,
|
|
1215
1209
|
_ref$clearable = _ref.clearable,
|
|
1216
1210
|
clearable = _ref$clearable === void 0 ? true : _ref$clearable,
|
|
@@ -1324,21 +1318,25 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1324
1318
|
}),
|
|
1325
1319
|
hasSelectedItems = _useMultiselectUtils.hasSelectedItems,
|
|
1326
1320
|
handleListItemClicked = _useMultiselectUtils.handleListItemClicked,
|
|
1327
|
-
selectAllCheckboxState = _useMultiselectUtils.selectAllCheckboxState
|
|
1321
|
+
selectAllCheckboxState = _useMultiselectUtils.selectAllCheckboxState,
|
|
1322
|
+
clickedItemIsInSelectedItems = _useMultiselectUtils.clickedItemIsInSelectedItems,
|
|
1323
|
+
clickedItemIsSelectAll = _useMultiselectUtils.clickedItemIsSelectAll;
|
|
1328
1324
|
var _useMultipleSelection = downshift.useMultipleSelection({
|
|
1329
1325
|
selectedItems: selectedItems,
|
|
1330
1326
|
// @ts-expect-error prop missing from library types
|
|
1331
1327
|
itemToString: itemToString,
|
|
1332
1328
|
itemToKey: itemToKey,
|
|
1333
|
-
|
|
1329
|
+
onSelectedItemsChange: function onSelectedItemsChange(_ref4) {
|
|
1334
1330
|
var newSelectedItems = _ref4.selectedItems;
|
|
1335
|
-
|
|
1331
|
+
onChange(newSelectedItems);
|
|
1336
1332
|
}
|
|
1337
1333
|
}),
|
|
1338
1334
|
getSelectedItemProps = _useMultipleSelection.getSelectedItemProps,
|
|
1339
|
-
getDropdownProps = _useMultipleSelection.getDropdownProps
|
|
1335
|
+
getDropdownProps = _useMultipleSelection.getDropdownProps,
|
|
1336
|
+
reset = _useMultipleSelection.reset,
|
|
1337
|
+
_removeSelectedItem = _useMultipleSelection.removeSelectedItem,
|
|
1338
|
+
setSelectedItems = _useMultipleSelection.setSelectedItems;
|
|
1340
1339
|
var stateReducer = React.useCallback(function (state, _ref5) {
|
|
1341
|
-
var _inputRef$current;
|
|
1342
1340
|
var changes = _ref5.changes,
|
|
1343
1341
|
type = _ref5.type;
|
|
1344
1342
|
if (changes.highlightedIndex !== undefined && (changes == null ? void 0 : changes.highlightedIndex) >= 0) {
|
|
@@ -1347,7 +1345,6 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1347
1345
|
switch (type) {
|
|
1348
1346
|
// reset input value when leaving input field
|
|
1349
1347
|
case downshift.useCombobox.stateChangeTypes.InputBlur:
|
|
1350
|
-
if (state.isOpen) (_inputRef$current = inputRef.current) == null || _inputRef$current.focus();
|
|
1351
1348
|
return _extends({}, changes, {
|
|
1352
1349
|
inputValue: EMPTY_INPUT
|
|
1353
1350
|
});
|
|
@@ -1355,18 +1352,18 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1355
1352
|
case downshift.useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
1356
1353
|
case downshift.useCombobox.stateChangeTypes.ItemClick:
|
|
1357
1354
|
{
|
|
1358
|
-
var _inputRef$current$val, _inputRef$
|
|
1355
|
+
var _inputRef$current$val, _inputRef$current;
|
|
1359
1356
|
return _extends({}, changes, {
|
|
1360
1357
|
isOpen: true,
|
|
1361
|
-
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$
|
|
1358
|
+
inputValue: clearInputOnSelect ? EMPTY_INPUT : (_inputRef$current$val = inputRef == null || (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value) != null ? _inputRef$current$val : EMPTY_INPUT
|
|
1362
1359
|
});
|
|
1363
1360
|
}
|
|
1364
1361
|
// edit input value when selected items is updated outside component
|
|
1365
1362
|
case downshift.useCombobox.stateChangeTypes.ControlledPropUpdatedSelectedItem:
|
|
1366
1363
|
{
|
|
1367
|
-
var _inputRef$current$val2, _inputRef$
|
|
1364
|
+
var _inputRef$current$val2, _inputRef$current2;
|
|
1368
1365
|
return _extends({}, changes, {
|
|
1369
|
-
inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$
|
|
1366
|
+
inputValue: (_inputRef$current$val2 = inputRef == null || (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value) != null ? _inputRef$current$val2 : EMPTY_INPUT
|
|
1370
1367
|
});
|
|
1371
1368
|
}
|
|
1372
1369
|
// remove leading whitespace, select item with spacebar if input is empty and filter list items
|
|
@@ -1411,13 +1408,13 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1411
1408
|
setHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1412
1409
|
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
1413
1410
|
},
|
|
1414
|
-
|
|
1411
|
+
onSelectedItemChange: function onSelectedItemChange(_ref6) {
|
|
1415
1412
|
var clickedItem = _ref6.selectedItem;
|
|
1416
1413
|
// clickedItem means item chosen either via mouse or keyboard
|
|
1417
1414
|
if (!clickedItem) return;
|
|
1418
1415
|
handleListItemClicked({
|
|
1419
1416
|
clickedItem: clickedItem,
|
|
1420
|
-
onChange:
|
|
1417
|
+
onChange: setSelectedItems
|
|
1421
1418
|
});
|
|
1422
1419
|
},
|
|
1423
1420
|
// Accessibility
|
|
@@ -1473,13 +1470,9 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1473
1470
|
}
|
|
1474
1471
|
}, [isOpen, refs.reference, refs.floating, update]);
|
|
1475
1472
|
var handleOnClear = function handleOnClear() {
|
|
1476
|
-
var _inputRef$
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
(_inputRef$current4 = inputRef.current) == null || _inputRef$current4.focus();
|
|
1480
|
-
updateListItems({
|
|
1481
|
-
inputValue: inputValue
|
|
1482
|
-
});
|
|
1473
|
+
var _inputRef$current3;
|
|
1474
|
+
(_inputRef$current3 = inputRef.current) == null || _inputRef$current3.focus();
|
|
1475
|
+
reset();
|
|
1483
1476
|
};
|
|
1484
1477
|
return React.createElement(form.BaseFormControl, _extends({
|
|
1485
1478
|
className: classNames('eds-dropdown', 'eds-dropdown--multiselect', className, {
|
|
@@ -1530,7 +1523,7 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1530
1523
|
'eds-dropdown--multiselect__selected-items-and-input--filled': hasSelectedItems
|
|
1531
1524
|
})
|
|
1532
1525
|
}, selectedItems.length > 1 ? React.createElement(a11y.VisuallyHidden, {
|
|
1533
|
-
onClick: (_inputRef$
|
|
1526
|
+
onClick: (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus
|
|
1534
1527
|
}, ariaLabelJumpToInput) : null, selectedItems.length <= maxChips ? selectedItems.map(function (selectedItem, index) {
|
|
1535
1528
|
return React.createElement(SelectedItemTag, {
|
|
1536
1529
|
ariaLabelChosen: ariaLabelChosenSingular,
|
|
@@ -1541,12 +1534,9 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1541
1534
|
key: (selectedItem == null ? void 0 : selectedItem.label) + (typeof (selectedItem == null ? void 0 : selectedItem.value) === 'string' ? selectedItem.value : ''),
|
|
1542
1535
|
readOnly: readOnly,
|
|
1543
1536
|
removeSelectedItem: function removeSelectedItem() {
|
|
1544
|
-
var _inputRef$
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
onChange: onChange
|
|
1548
|
-
});
|
|
1549
|
-
inputRef == null || (_inputRef$current6 = inputRef.current) == null || _inputRef$current6.focus();
|
|
1537
|
+
var _inputRef$current5;
|
|
1538
|
+
_removeSelectedItem(selectedItem);
|
|
1539
|
+
inputRef == null || (_inputRef$current5 = inputRef.current) == null || _inputRef$current5.focus();
|
|
1550
1540
|
},
|
|
1551
1541
|
selectedItem: selectedItem
|
|
1552
1542
|
});
|
|
@@ -1561,13 +1551,14 @@ var MultiSelect = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1561
1551
|
onKeyDown: function onKeyDown(e) {
|
|
1562
1552
|
if (selectOnTab && isOpen && e.key === 'Tab') {
|
|
1563
1553
|
var highlitedItem = listItems[highlightedIndex];
|
|
1564
|
-
|
|
1565
|
-
if
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1554
|
+
if (!highlitedItem) return;
|
|
1555
|
+
// Skip tab selection for select all or if item already is selected
|
|
1556
|
+
var shouldSkipTabSelection = clickedItemIsSelectAll(highlitedItem) || !clickedItemIsSelectAll(highlitedItem) && clickedItemIsInSelectedItems(highlitedItem);
|
|
1557
|
+
if (shouldSkipTabSelection) return;
|
|
1558
|
+
handleListItemClicked({
|
|
1559
|
+
clickedItem: highlitedItem,
|
|
1560
|
+
onChange: setSelectedItems
|
|
1561
|
+
});
|
|
1571
1562
|
}
|
|
1572
1563
|
}
|
|
1573
1564
|
}, getDropdownProps({
|
|
@@ -1670,13 +1661,13 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1670
1661
|
},
|
|
1671
1662
|
itemToString: itemToString
|
|
1672
1663
|
}),
|
|
1673
|
-
closeMenu = _useSelect.closeMenu,
|
|
1674
1664
|
isOpen = _useSelect.isOpen,
|
|
1675
1665
|
getItemProps = _useSelect.getItemProps,
|
|
1676
1666
|
getLabelProps = _useSelect.getLabelProps,
|
|
1677
1667
|
getMenuProps = _useSelect.getMenuProps,
|
|
1678
1668
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
1679
1669
|
highlightedIndex = _useSelect.highlightedIndex,
|
|
1670
|
+
selectItem = _useSelect.selectItem,
|
|
1680
1671
|
reset = _useSelect.reset;
|
|
1681
1672
|
// calculations for floating-UI popover position
|
|
1682
1673
|
var _useFloating = reactDom.useFloating({
|
|
@@ -1744,10 +1735,8 @@ var Dropdown = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
1744
1735
|
var highlitedItem = normalizedItems[highlightedIndex];
|
|
1745
1736
|
// we don't want to clear selection with tab
|
|
1746
1737
|
if ((selectOnTab || selectOnBlur) && highlitedItem && highlitedItem !== selectedItem) {
|
|
1747
|
-
|
|
1738
|
+
selectItem(highlitedItem);
|
|
1748
1739
|
}
|
|
1749
|
-
closeMenu();
|
|
1750
|
-
e.preventDefault();
|
|
1751
1740
|
}
|
|
1752
1741
|
}
|
|
1753
1742
|
}), {
|