@entur/dropdown 5.4.11 → 5.5.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/components/DropdownList.d.ts +2 -1
- package/dist/dropdown.cjs.development.js +66 -12
- 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 +69 -15
- package/dist/dropdown.esm.js.map +1 -1
- package/dist/styles.css +31 -33
- package/package.json +5 -4
|
@@ -13,6 +13,7 @@ type DropdownListProps<ValueType> = {
|
|
|
13
13
|
listStyle: {
|
|
14
14
|
[key: string]: any;
|
|
15
15
|
} | undefined;
|
|
16
|
+
listRef?: React.Ref<HTMLUListElement>;
|
|
16
17
|
loading?: boolean;
|
|
17
18
|
loadingText?: string;
|
|
18
19
|
noMatchesText?: string;
|
|
@@ -21,5 +22,5 @@ type DropdownListProps<ValueType> = {
|
|
|
21
22
|
selectedItems: NormalizedDropdownItemType<ValueType>[];
|
|
22
23
|
[key: string]: any;
|
|
23
24
|
};
|
|
24
|
-
export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, inputValue, isOpen, highlightedIndex, listItems, listStyle, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, showSelectAllInList, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
|
|
25
|
+
export declare const DropdownList: <ValueType extends unknown>({ ariaLabelChosenSingular, ariaLabelSelectedItem, getItemProps, getMenuProps, inputValue, isOpen, highlightedIndex, listItems, listStyle, listRef, loading, loadingText, noMatchesText, selectAllCheckboxState, selectAllItem, selectedItems, showSelectAllInList, ...rest }: DropdownListProps<ValueType>) => React.JSX.Element;
|
|
25
26
|
export {};
|
|
@@ -11,6 +11,7 @@ var icons = require('@entur/icons');
|
|
|
11
11
|
var a11y = require('@entur/a11y');
|
|
12
12
|
var loader = require('@entur/loader');
|
|
13
13
|
var tokens = require('@entur/tokens');
|
|
14
|
+
var reactDom = require('@floating-ui/react-dom');
|
|
14
15
|
var button = require('@entur/button');
|
|
15
16
|
var chip = require('@entur/chip');
|
|
16
17
|
var tooltip = require('@entur/tooltip');
|
|
@@ -1238,7 +1239,7 @@ function SelectedItemsLabel(items) {
|
|
|
1238
1239
|
}).toString() : items.length + " elementer valgt";
|
|
1239
1240
|
}
|
|
1240
1241
|
|
|
1241
|
-
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "inputValue", "isOpen", "highlightedIndex", "listItems", "listStyle", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "showSelectAllInList"];
|
|
1242
|
+
var _excluded$5 = ["ariaLabelChosenSingular", "ariaLabelSelectedItem", "getItemProps", "getMenuProps", "inputValue", "isOpen", "highlightedIndex", "listItems", "listStyle", "listRef", "loading", "loadingText", "noMatchesText", "selectAllCheckboxState", "selectAllItem", "selectedItems", "showSelectAllInList"];
|
|
1242
1243
|
var DropdownList = function DropdownList(_ref) {
|
|
1243
1244
|
var _listItems$;
|
|
1244
1245
|
var _ref$ariaLabelChosenS = _ref.ariaLabelChosenSingular,
|
|
@@ -1251,6 +1252,7 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1251
1252
|
highlightedIndex = _ref.highlightedIndex,
|
|
1252
1253
|
listItems = _ref.listItems,
|
|
1253
1254
|
listStyle = _ref.listStyle,
|
|
1255
|
+
listRef = _ref.listRef,
|
|
1254
1256
|
_ref$loading = _ref.loading,
|
|
1255
1257
|
loading = _ref$loading === void 0 ? false : _ref$loading,
|
|
1256
1258
|
_ref$loadingText = _ref.loadingText,
|
|
@@ -1333,7 +1335,8 @@ var DropdownList = function DropdownList(_ref) {
|
|
|
1333
1335
|
return (
|
|
1334
1336
|
// use popover from @entur/tooltip when that package upgrades to floating-ui
|
|
1335
1337
|
React.createElement("ul", _extends({}, getMenuProps({
|
|
1336
|
-
'aria-multiselectable': isMultiselect
|
|
1338
|
+
'aria-multiselectable': isMultiselect,
|
|
1339
|
+
ref: utils.mergeRefs(getMenuProps().ref, listRef)
|
|
1337
1340
|
}), {
|
|
1338
1341
|
className: "eds-dropdown__list",
|
|
1339
1342
|
style: _extends({
|
|
@@ -1687,17 +1690,17 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1687
1690
|
var _useState = React.useState(value !== null),
|
|
1688
1691
|
showSelectedItem = _useState[0],
|
|
1689
1692
|
setShowSelectedItem = _useState[1];
|
|
1690
|
-
var
|
|
1691
|
-
lastHighlightedIndex =
|
|
1692
|
-
setLastHighlightedIndex =
|
|
1693
|
+
var _useState2 = React.useState(0),
|
|
1694
|
+
lastHighlightedIndex = _useState2[0],
|
|
1695
|
+
setLastHighlightedIndex = _useState2[1];
|
|
1693
1696
|
var inputRef = React.useRef(null);
|
|
1694
1697
|
var _useResolvedItems = useResolvedItems(initialItems, debounceTimeout),
|
|
1695
1698
|
normalizedItems = _useResolvedItems.items,
|
|
1696
1699
|
loading = _useResolvedItems.loading,
|
|
1697
1700
|
fetchItems = _useResolvedItems.fetchItems;
|
|
1698
|
-
var
|
|
1699
|
-
listItems =
|
|
1700
|
-
setListItems =
|
|
1701
|
+
var _useState3 = React.useState(normalizedItems),
|
|
1702
|
+
listItems = _useState3[0],
|
|
1703
|
+
setListItems = _useState3[1];
|
|
1701
1704
|
var filterListItems = function filterListItems(_ref2) {
|
|
1702
1705
|
var inputValue = _ref2.inputValue;
|
|
1703
1706
|
return setListItems(normalizedItems.filter(function (item) {
|
|
@@ -1712,12 +1715,22 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1712
1715
|
inputValue: inputValue != null ? inputValue : EMPTY_INPUT
|
|
1713
1716
|
});
|
|
1714
1717
|
};
|
|
1718
|
+
var inputHasFocus = typeof document !== 'undefined' ? (inputRef == null ? void 0 : inputRef.current) === ((_document = document) == null ? void 0 : _document.activeElement) : false;
|
|
1715
1719
|
React.useEffect(function () {
|
|
1716
1720
|
filterListItems({
|
|
1717
1721
|
inputValue: inputValue
|
|
1718
1722
|
});
|
|
1719
1723
|
}, [normalizedItems]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
1720
|
-
|
|
1724
|
+
React.useEffect(function () {
|
|
1725
|
+
// sync internal state on initial render
|
|
1726
|
+
if (selectedItem !== null && !inputHasFocus) {
|
|
1727
|
+
setShowSelectedItem(true);
|
|
1728
|
+
updateListItems({
|
|
1729
|
+
inputValue: EMPTY_INPUT
|
|
1730
|
+
});
|
|
1731
|
+
setInputValue(EMPTY_INPUT);
|
|
1732
|
+
}
|
|
1733
|
+
}, []);
|
|
1721
1734
|
var stateReducer = React.useCallback(function (_, _ref4) {
|
|
1722
1735
|
var type = _ref4.type,
|
|
1723
1736
|
changes = _ref4.changes;
|
|
@@ -1811,6 +1824,16 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1811
1824
|
selectedItem = _useCombobox.selectedItem,
|
|
1812
1825
|
inputValue = _useCombobox.inputValue,
|
|
1813
1826
|
setInputValue = _useCombobox.setInputValue;
|
|
1827
|
+
var _useFloating = reactDom.useFloating({
|
|
1828
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
1829
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
1830
|
+
},
|
|
1831
|
+
placement: 'bottom-start',
|
|
1832
|
+
open: isOpen,
|
|
1833
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
1834
|
+
}),
|
|
1835
|
+
refs = _useFloating.refs,
|
|
1836
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
1814
1837
|
var handleOnClear = function handleOnClear() {
|
|
1815
1838
|
var _inputRef$current;
|
|
1816
1839
|
onChange(null);
|
|
@@ -1842,6 +1865,7 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1842
1865
|
},
|
|
1843
1866
|
prepend: prepend,
|
|
1844
1867
|
readOnly: readOnly,
|
|
1868
|
+
ref: refs.setReference,
|
|
1845
1869
|
variant: variant
|
|
1846
1870
|
}, rest, {
|
|
1847
1871
|
append: React.createElement(FieldAppend$1, {
|
|
@@ -1890,7 +1914,8 @@ var SearchableDropdown = function SearchableDropdown(_ref) {
|
|
|
1890
1914
|
ariaLabelSelectedItem: ariaLabelSelectedItem,
|
|
1891
1915
|
isOpen: isOpen,
|
|
1892
1916
|
listItems: listItems,
|
|
1893
|
-
listStyle: listStyle,
|
|
1917
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
1918
|
+
listRef: refs.setFloating,
|
|
1894
1919
|
loading: loading,
|
|
1895
1920
|
loadingText: loadingText,
|
|
1896
1921
|
noMatchesText: noMatchesText,
|
|
@@ -2095,6 +2120,11 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2095
2120
|
updateListItems({
|
|
2096
2121
|
inputValue: changes.inputValue
|
|
2097
2122
|
});
|
|
2123
|
+
// set highlighted item to first item after search
|
|
2124
|
+
setLastHighlightedIndex(hideSelectAll ? 0 : 1);
|
|
2125
|
+
return _extends({}, changes, {
|
|
2126
|
+
highlightedIndex: hideSelectAll ? 0 : 1
|
|
2127
|
+
});
|
|
2098
2128
|
}
|
|
2099
2129
|
return changes;
|
|
2100
2130
|
}
|
|
@@ -2162,6 +2192,16 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2162
2192
|
isOpen = _useCombobox.isOpen,
|
|
2163
2193
|
openMenu = _useCombobox.openMenu,
|
|
2164
2194
|
setInputValue = _useCombobox.setInputValue;
|
|
2195
|
+
var _useFloating = reactDom.useFloating({
|
|
2196
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
2197
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
2198
|
+
},
|
|
2199
|
+
placement: 'bottom-start',
|
|
2200
|
+
open: isOpen,
|
|
2201
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
2202
|
+
}),
|
|
2203
|
+
refs = _useFloating.refs,
|
|
2204
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
2165
2205
|
var handleOnClear = function handleOnClear() {
|
|
2166
2206
|
var _inputRef$current3;
|
|
2167
2207
|
onChange([]);
|
|
@@ -2204,6 +2244,7 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2204
2244
|
if (e.target === e.currentTarget) (_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.focus();
|
|
2205
2245
|
},
|
|
2206
2246
|
readOnly: readOnly,
|
|
2247
|
+
ref: refs.setReference,
|
|
2207
2248
|
variant: variant
|
|
2208
2249
|
}, rest), React.createElement("div", {
|
|
2209
2250
|
className: classNames('eds-dropdown--multiselect__selected-items-and-input', {
|
|
@@ -2275,7 +2316,8 @@ var MultiSelect = function MultiSelect(_ref) {
|
|
|
2275
2316
|
inputValue: inputValue,
|
|
2276
2317
|
isOpen: isOpen,
|
|
2277
2318
|
listItems: listItems,
|
|
2278
|
-
listStyle: listStyle,
|
|
2319
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
2320
|
+
listRef: refs.setFloating,
|
|
2279
2321
|
loading: loading,
|
|
2280
2322
|
loadingText: loadingText,
|
|
2281
2323
|
noMatchesText: noMatchesText,
|
|
@@ -2353,6 +2395,16 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2353
2395
|
getMenuProps = _useSelect.getMenuProps,
|
|
2354
2396
|
getToggleButtonProps = _useSelect.getToggleButtonProps,
|
|
2355
2397
|
highlightedIndex = _useSelect.highlightedIndex;
|
|
2398
|
+
var _useFloating = reactDom.useFloating({
|
|
2399
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
2400
|
+
return reactDom.autoUpdate(ref, _float, update);
|
|
2401
|
+
},
|
|
2402
|
+
placement: 'bottom-start',
|
|
2403
|
+
open: isOpen,
|
|
2404
|
+
middleware: [reactDom.offset(tokens.space.extraSmall2), reactDom.flip()]
|
|
2405
|
+
}),
|
|
2406
|
+
refs = _useFloating.refs,
|
|
2407
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
2356
2408
|
return React.createElement("div", {
|
|
2357
2409
|
className: classNames('eds-dropdown__wrapper', className, {
|
|
2358
2410
|
'eds-dropdown__wrapper--has-tooltip': labelTooltip !== undefined
|
|
@@ -2391,6 +2443,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2391
2443
|
labelTooltip: labelTooltip,
|
|
2392
2444
|
prepend: prepend,
|
|
2393
2445
|
readOnly: readOnly,
|
|
2446
|
+
ref: refs.setReference,
|
|
2394
2447
|
variant: variant
|
|
2395
2448
|
}, rest), React.createElement("div", _extends({
|
|
2396
2449
|
className: "eds-dropdown__selected-item"
|
|
@@ -2418,7 +2471,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
2418
2471
|
highlightedIndex: highlightedIndex,
|
|
2419
2472
|
isOpen: isOpen,
|
|
2420
2473
|
listItems: normalizedItems,
|
|
2421
|
-
listStyle: listStyle,
|
|
2474
|
+
listStyle: _extends({}, floatingStyles, listStyle),
|
|
2475
|
+
listRef: refs.setFloating,
|
|
2422
2476
|
loading: loading,
|
|
2423
2477
|
loadingText: loadingText,
|
|
2424
2478
|
selectedItems: selectedItem !== null ? [selectedItem] : []
|